Class FunctionalType
- java.lang.Object
-
- org.inferred.freebuilder.processor.source.ValueType
-
- org.inferred.freebuilder.processor.source.FunctionalType
-
public class FunctionalType extends ValueType
Metadata about a functional interface.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.inferred.freebuilder.processor.source.ValueType
ValueType.FieldReceiver
-
-
Field Summary
Fields Modifier and Type Field Description private TypefunctionalInterfaceprivate java.lang.StringmethodNameprivate java.util.List<javax.lang.model.type.TypeMirror>parametersprivate javax.lang.model.type.TypeMirrorreturnType
-
Constructor Summary
Constructors Modifier Constructor Description privateFunctionalType(Type functionalInterface, java.lang.String methodName, java.util.Collection<? extends javax.lang.model.type.TypeMirror> parameters, javax.lang.model.type.TypeMirror returnType)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddFields(ValueType.FieldReceiver fields)Implement this method to report the name and value of each field.booleancanReturnNull()static FunctionalTypeconsumer(javax.lang.model.type.TypeMirror type)ReturnsConsumer<type>.static FunctionalTypefunctionalTypeAcceptedByMethod(javax.lang.model.type.DeclaredType type, java.lang.String methodName, FunctionalType prototype, javax.lang.model.util.Elements elements, javax.lang.model.util.Types types)Returns the functional type accepted bymethodNameontype, assignable toprototype, orprototypeitself if no such method has been declared.static java.util.List<FunctionalType>functionalTypesAcceptedByMethod(javax.lang.model.type.DeclaredType type, java.lang.String methodName, javax.lang.model.util.Elements elements, javax.lang.model.util.Types types)Returns the functional types accepted bymethodNameontype.TypegetFunctionalInterface()java.lang.StringgetMethodName()java.util.List<javax.lang.model.type.TypeMirror>getParameters()javax.lang.model.type.TypeMirrorgetReturnType()private static booleanisAssignable(javax.lang.model.type.TypeMirror fromParam, javax.lang.model.type.TypeMirror toParam, javax.lang.model.util.Types types)static booleanisAssignable(FunctionalType fromType, FunctionalType toType, javax.lang.model.util.Types types)private static booleanisVoid(javax.lang.model.type.TypeMirror type)static java.util.Optional<FunctionalType>maybeFunctionalType(javax.lang.model.type.DeclaredType type, javax.lang.model.util.Elements elements, javax.lang.model.util.Types types)static java.util.Optional<FunctionalType>maybeFunctionalType(javax.lang.model.type.TypeMirror type, javax.lang.model.util.Elements elements, javax.lang.model.util.Types types)static FunctionalTypeprimitiveUnaryOperator(javax.lang.model.type.PrimitiveType type)Returns one ofIntUnaryOperator,LongUnaryOperatororDoubleUnaryOperator, depending ontype.java.lang.StringtoString()static FunctionalTypeunaryOperator(javax.lang.model.type.TypeMirror type)ReturnsUnaryOperator<type>.static FunctionalTypeunboxedUnaryOperator(javax.lang.model.type.TypeMirror type, javax.lang.model.util.Types types)Returns a unary operator that will accepttype, without autoboxing if possible.
-
-
-
Field Detail
-
functionalInterface
private final Type functionalInterface
-
methodName
private final java.lang.String methodName
-
parameters
private final java.util.List<javax.lang.model.type.TypeMirror> parameters
-
returnType
private final javax.lang.model.type.TypeMirror returnType
-
-
Constructor Detail
-
FunctionalType
private FunctionalType(Type functionalInterface, java.lang.String methodName, java.util.Collection<? extends javax.lang.model.type.TypeMirror> parameters, javax.lang.model.type.TypeMirror returnType)
-
-
Method Detail
-
consumer
public static FunctionalType consumer(javax.lang.model.type.TypeMirror type)
ReturnsConsumer<type>.- Throws:
java.lang.IllegalArgumentException- iftypeis primitive
-
unaryOperator
public static FunctionalType unaryOperator(javax.lang.model.type.TypeMirror type)
ReturnsUnaryOperator<type>.- Throws:
java.lang.IllegalArgumentException- iftypeis primitive
-
primitiveUnaryOperator
public static FunctionalType primitiveUnaryOperator(javax.lang.model.type.PrimitiveType type)
Returns one ofIntUnaryOperator,LongUnaryOperatororDoubleUnaryOperator, depending ontype.- Throws:
java.lang.IllegalArgumentException- iftypeis not one of int, long or double
-
unboxedUnaryOperator
public static FunctionalType unboxedUnaryOperator(javax.lang.model.type.TypeMirror type, javax.lang.model.util.Types types)
Returns a unary operator that will accepttype, without autoboxing if possible.
-
functionalTypeAcceptedByMethod
public static FunctionalType functionalTypeAcceptedByMethod(javax.lang.model.type.DeclaredType type, java.lang.String methodName, FunctionalType prototype, javax.lang.model.util.Elements elements, javax.lang.model.util.Types types)
Returns the functional type accepted bymethodNameontype, assignable toprototype, orprototypeitself if no such method has been declared.Used to allow the user to override the functional interface used on builder methods, e.g. to force boxing, or to use Guava types.
-
functionalTypesAcceptedByMethod
public static java.util.List<FunctionalType> functionalTypesAcceptedByMethod(javax.lang.model.type.DeclaredType type, java.lang.String methodName, javax.lang.model.util.Elements elements, javax.lang.model.util.Types types)
Returns the functional types accepted bymethodNameontype.
-
maybeFunctionalType
public static java.util.Optional<FunctionalType> maybeFunctionalType(javax.lang.model.type.TypeMirror type, javax.lang.model.util.Elements elements, javax.lang.model.util.Types types)
-
maybeFunctionalType
public static java.util.Optional<FunctionalType> maybeFunctionalType(javax.lang.model.type.DeclaredType type, javax.lang.model.util.Elements elements, javax.lang.model.util.Types types)
-
isAssignable
public static boolean isAssignable(FunctionalType fromType, FunctionalType toType, javax.lang.model.util.Types types)
-
isAssignable
private static boolean isAssignable(javax.lang.model.type.TypeMirror fromParam, javax.lang.model.type.TypeMirror toParam, javax.lang.model.util.Types types)
-
isVoid
private static boolean isVoid(javax.lang.model.type.TypeMirror type)
-
getFunctionalInterface
public Type getFunctionalInterface()
-
getMethodName
public java.lang.String getMethodName()
-
getParameters
public java.util.List<javax.lang.model.type.TypeMirror> getParameters()
-
getReturnType
public javax.lang.model.type.TypeMirror getReturnType()
-
canReturnNull
public boolean canReturnNull()
-
addFields
protected void addFields(ValueType.FieldReceiver fields)
Description copied from class:ValueTypeImplement this method to report the name and value of each field.
-
-