Class MoreTypes

java.lang.Object
tech.picnic.errorprone.bugpatterns.util.MoreTypes

public final class MoreTypes extends Object
A set of helper methods which together define a DSL for defining types.

These methods are meant to be statically imported. Example usage:


 Supplier<Type> type =
     VisitorState.memoize(
         generic(
             type("reactor.core.publisher.Flux"),
             subOf(generic(type("org.reactivestreams.Publisher"), unbound()))));
 
This statement produces a memoized supplier of the type Flux<? extends Publisher<?>>.
  • Method Summary

    Modifier and Type
    Method
    Description
    static com.google.errorprone.suppliers.Supplier<com.sun.tools.javac.code.Type>
    generic(com.google.errorprone.suppliers.Supplier<com.sun.tools.javac.code.Type> type, com.google.errorprone.suppliers.Supplier<com.sun.tools.javac.code.Type>... typeArgs)
    Creates a supplier of the described generic type.
    static com.google.errorprone.suppliers.Supplier<com.sun.tools.javac.code.Type>
    raw(com.google.errorprone.suppliers.Supplier<com.sun.tools.javac.code.Type> type)
    Creates a raw (erased, non-generic) variant of the given type.
    static com.google.errorprone.suppliers.Supplier<com.sun.tools.javac.code.Type>
    subOf(com.google.errorprone.suppliers.Supplier<com.sun.tools.javac.code.Type> type)
    Creates a ? extends T wildcard type, with T bound to the given type.
    static com.google.errorprone.suppliers.Supplier<com.sun.tools.javac.code.Type>
    superOf(com.google.errorprone.suppliers.Supplier<com.sun.tools.javac.code.Type> type)
    Creates a ? super T wildcard type, with T bound to the given type.
    static com.google.errorprone.suppliers.Supplier<com.sun.tools.javac.code.Type>
    type(String typeName)
    Creates a supplier of the type with the given fully qualified name.
    static com.google.errorprone.suppliers.Supplier<com.sun.tools.javac.code.Type>
    Creates an unbound wildcard type (?).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • type

      public static com.google.errorprone.suppliers.Supplier<com.sun.tools.javac.code.Type> type(String typeName)
      Creates a supplier of the type with the given fully qualified name.

      This method should only be used when building more complex types in combination with other MoreTypes methods. In other cases prefer directly calling Suppliers.typeFromString(String).

      Parameters:
      typeName - The type of interest.
      Returns:
      A supplier which returns the described type if available in the given state, and null otherwise.
    • generic

      @SafeVarargs public static com.google.errorprone.suppliers.Supplier<com.sun.tools.javac.code.Type> generic(com.google.errorprone.suppliers.Supplier<com.sun.tools.javac.code.Type> type, com.google.errorprone.suppliers.Supplier<com.sun.tools.javac.code.Type>... typeArgs)
      Creates a supplier of the described generic type.
      Parameters:
      type - The base type of interest.
      typeArgs - The desired type arguments.
      Returns:
      A supplier which returns the described type if available in the given state, and null otherwise.
    • raw

      public static com.google.errorprone.suppliers.Supplier<com.sun.tools.javac.code.Type> raw(com.google.errorprone.suppliers.Supplier<com.sun.tools.javac.code.Type> type)
      Creates a raw (erased, non-generic) variant of the given type.
      Parameters:
      type - The base type of interest.
      Returns:
      A supplier which returns the described type if available in the given state, and null otherwise.
    • superOf

      public static com.google.errorprone.suppliers.Supplier<com.sun.tools.javac.code.Type> superOf(com.google.errorprone.suppliers.Supplier<com.sun.tools.javac.code.Type> type)
      Creates a ? super T wildcard type, with T bound to the given type.
      Parameters:
      type - The base type of interest.
      Returns:
      A supplier which returns the described type if available in the given state, and null otherwise.
    • subOf

      public static com.google.errorprone.suppliers.Supplier<com.sun.tools.javac.code.Type> subOf(com.google.errorprone.suppliers.Supplier<com.sun.tools.javac.code.Type> type)
      Creates a ? extends T wildcard type, with T bound to the given type.
      Parameters:
      type - The base type of interest.
      Returns:
      A supplier which returns the described type if available in the given state, and null otherwise.
    • unbound

      public static com.google.errorprone.suppliers.Supplier<com.sun.tools.javac.code.Type> unbound()
      Creates an unbound wildcard type (?).
      Returns:
      A supplier which returns the described type.