Class FunctionalType


  • public class FunctionalType
    extends ValueType
    Metadata about a functional interface.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      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 Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void addFields​(ValueType.FieldReceiver fields)
      Implement this method to report the name and value of each field.
      boolean canReturnNull()  
      static FunctionalType consumer​(javax.lang.model.type.TypeMirror type)
      Returns Consumer<type>.
      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 by methodName on type, assignable to prototype, or prototype itself 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 by methodName on type.
      Type getFunctionalInterface()  
      java.lang.String getMethodName()  
      java.util.List<javax.lang.model.type.TypeMirror> getParameters()  
      javax.lang.model.type.TypeMirror getReturnType()  
      private static boolean isAssignable​(javax.lang.model.type.TypeMirror fromParam, javax.lang.model.type.TypeMirror toParam, javax.lang.model.util.Types types)  
      static boolean isAssignable​(FunctionalType fromType, FunctionalType toType, javax.lang.model.util.Types types)  
      private static boolean isVoid​(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 FunctionalType primitiveUnaryOperator​(javax.lang.model.type.PrimitiveType type)
      Returns one of IntUnaryOperator, LongUnaryOperator or DoubleUnaryOperator, depending on type.
      java.lang.String toString()  
      static FunctionalType unaryOperator​(javax.lang.model.type.TypeMirror type)
      Returns UnaryOperator<type>.
      static FunctionalType unboxedUnaryOperator​(javax.lang.model.type.TypeMirror type, javax.lang.model.util.Types types)
      Returns a unary operator that will accept type, without autoboxing if possible.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • 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)
        Returns Consumer<type>.
        Throws:
        java.lang.IllegalArgumentException - if type is primitive
      • unaryOperator

        public static FunctionalType unaryOperator​(javax.lang.model.type.TypeMirror type)
        Returns UnaryOperator<type>.
        Throws:
        java.lang.IllegalArgumentException - if type is primitive
      • primitiveUnaryOperator

        public static FunctionalType primitiveUnaryOperator​(javax.lang.model.type.PrimitiveType type)
        Returns one of IntUnaryOperator, LongUnaryOperator or DoubleUnaryOperator, depending on type.
        Throws:
        java.lang.IllegalArgumentException - if type is 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 accept type, 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 by methodName on type, assignable to prototype, or prototype itself 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 by methodName on type.
      • 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()
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class ValueType