Class MoreTypes
java.lang.Object
tech.picnic.errorprone.bugpatterns.util.MoreTypes
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 TypeMethodDescriptionstatic 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 Twildcard type, withTbound 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 Twildcard type, withTbound to the given type.static com.google.errorprone.suppliers.Supplier<com.sun.tools.javac.code.Type>Creates a supplier of the type with the given fully qualified name.static com.google.errorprone.suppliers.Supplier<com.sun.tools.javac.code.Type>unbound()Creates an unbound wildcard type (?).
-
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
MoreTypesmethods. In other cases prefer directly callingSuppliers.typeFromString(String).- Parameters:
typeName- The type of interest.- Returns:
- A supplier which returns the described type if available in the given state, and
nullotherwise.
-
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
nullotherwise.
-
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
nullotherwise.
-
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 Twildcard type, withTbound 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
nullotherwise.
-
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 Twildcard type, withTbound 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
nullotherwise.
-
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.
-