Class TypeFactory


  • public class TypeFactory
    extends java.lang.Object
    Factory creating Type instances.
    • Field Detail

      • BUILDER_INFO_CREATION_METHOD_EXTRACTOR

        private static final Extractor<BuilderInfo,​java.lang.String> BUILDER_INFO_CREATION_METHOD_EXTRACTOR
      • typeUtils

        private final TypeUtils typeUtils
      • iterableType

        private final javax.lang.model.type.TypeMirror iterableType
      • collectionType

        private final javax.lang.model.type.TypeMirror collectionType
      • mapType

        private final javax.lang.model.type.TypeMirror mapType
      • streamType

        private final javax.lang.model.type.TypeMirror streamType
      • implementationTypes

        private final java.util.Map<java.lang.String,​ImplementationType> implementationTypes
      • toBeImportedTypes

        private final java.util.Map<java.lang.String,​java.lang.String> toBeImportedTypes
      • notToBeImportedTypes

        private final java.util.Map<java.lang.String,​java.lang.String> notToBeImportedTypes
      • loggingVerbose

        private final boolean loggingVerbose
    • Method Detail

      • getTypeForLiteral

        public Type getTypeForLiteral​(java.lang.Class<?> type)
      • getType

        public Type getType​(java.lang.Class<?> type)
      • getType

        public Type getType​(java.lang.String canonicalName)
      • getType

        private Type getType​(java.lang.String canonicalName,
                             boolean isLiteral)
      • isTypeAvailable

        public boolean isTypeAvailable​(java.lang.String canonicalName)
        Determines if the type with the given full qualified name is part of the classpath
        Parameters:
        canonicalName - Name of the type to be checked for availability
        Returns:
        true if the type with the given full qualified name is part of the classpath.
      • getWrappedType

        public Type getWrappedType​(Type type)
      • getType

        public Type getType​(javax.lang.model.element.TypeElement typeElement)
      • getType

        private Type getType​(javax.lang.model.element.TypeElement typeElement,
                             boolean isLiteral)
      • getType

        public Type getType​(javax.lang.model.type.TypeMirror mirror)
      • getAlwaysImportedType

        public Type getAlwaysImportedType​(javax.lang.model.type.TypeMirror mirror)
        Return a type that is always going to be imported. This is useful when using it in Mapper#imports for types that should be used in expressions.
        Parameters:
        mirror - the type mirror for which we need a type
        Returns:
        the type
      • getType

        private Type getType​(javax.lang.model.type.TypeMirror mirror,
                             boolean isLiteral)
      • getType

        private Type getType​(javax.lang.model.type.TypeMirror mirror,
                             boolean isLiteral,
                             java.lang.Boolean alwaysImport)
      • classTypeOf

        public Type classTypeOf​(Type type)
        Returns the Type that represents the declared Class type of the given type. For primitive types, the boxed class will be used. Examples:
        • If type represents java.lang.Integer, it will return the type that represents Class<Integer>.
        • If type represents int, it will return the type that represents Class<Integer>.
        Parameters:
        type - the type to return the declared class type for
        Returns:
        the type representing Class<type>.
      • getMethodType

        public javax.lang.model.type.ExecutableType getMethodType​(javax.lang.model.type.DeclaredType includingType,
                                                                  javax.lang.model.element.ExecutableElement method)
        Get the ExecutableType for given method as part of usedMapper. Possibly parameterized types in method declaration will be evaluated to concrete types then. IMPORTANT: This should only be used from the Processors, as they are operating over executable elements. The internals should not be using this function and should not be using the ExecutableElement directly.
        Parameters:
        includingType - the type on which's scope the method type shall be evaluated
        method - the method
        Returns:
        the ExecutableType representing the method as part of usedMapper
      • getMethodType

        public javax.lang.model.type.TypeMirror getMethodType​(javax.lang.model.type.DeclaredType includingType,
                                                              javax.lang.model.element.Element method)
        Get the Type for given method as part of usedMapper. Possibly parameterized types in method declaration will be evaluated to concrete types then.
        Parameters:
        includingType - the type on which's scope the method type shall be evaluated
        method - the method
        Returns:
        the ExecutableType representing the method as part of usedMapper
      • getSingleParameter

        public Parameter getSingleParameter​(javax.lang.model.type.DeclaredType includingType,
                                            Accessor method)
      • getParameters

        public java.util.List<Parameter> getParameters​(javax.lang.model.type.DeclaredType includingType,
                                                       Accessor accessor)
      • getParameters

        public java.util.List<Parameter> getParameters​(javax.lang.model.type.DeclaredType includingType,
                                                       javax.lang.model.element.ExecutableElement method)
      • getParameters

        public java.util.List<Parameter> getParameters​(javax.lang.model.type.ExecutableType methodType,
                                                       javax.lang.model.element.ExecutableElement method)
      • getReturnType

        public Type getReturnType​(javax.lang.model.type.DeclaredType includingType,
                                  Accessor accessor)
      • isExecutableType

        private boolean isExecutableType​(javax.lang.model.type.TypeMirror accessorType)
      • getReturnType

        public Type getReturnType​(javax.lang.model.type.ExecutableType method)
      • getThrownTypes

        public java.util.List<Type> getThrownTypes​(javax.lang.model.type.ExecutableType method)
      • getThrownTypes

        public java.util.List<Type> getThrownTypes​(Accessor accessor)
      • extractTypes

        private java.util.List<Type> extractTypes​(java.util.List<? extends javax.lang.model.type.TypeMirror> typeMirrors)
      • getTypeParameters

        private java.util.List<Type> getTypeParameters​(javax.lang.model.type.TypeMirror mirror,
                                                       boolean isImplementationType)
      • getPrimitiveType

        private javax.lang.model.type.TypeMirror getPrimitiveType​(java.lang.Class<?> primitiveType)
      • getImplementationType

        private ImplementationType getImplementationType​(javax.lang.model.type.TypeMirror mirror)
      • findBuilder

        private BuilderInfo findBuilder​(javax.lang.model.type.TypeMirror type,
                                        BuilderGem builderGem,
                                        boolean report)
      • getComponentType

        private javax.lang.model.type.TypeMirror getComponentType​(javax.lang.model.type.TypeMirror mirror)
      • createVoidType

        public Type createVoidType()
        creates a void return type
        Returns:
        void type
      • getTypeBound

        public javax.lang.model.type.TypeMirror getTypeBound​(javax.lang.model.type.TypeMirror typeMirror)
        Establishes the type bound:
        1. <? extends Number>, returns Number
        2. <? super Number>, returns Number
        3. <?>, returns Object
        4. <T extends Number>, returns Number
        Parameters:
        typeMirror - the type to return the bound for
        Returns:
        the bound for this parameter
      • canBeProcessed

        private boolean canBeProcessed​(javax.lang.model.type.TypeMirror type)
        Whether the given type is ready to be processed or not. It can be processed if it is not of kind TypeKind.ERROR and all AstModifyingAnnotationProcessors (if any) indicated that they've fully processed the type.
      • effectiveResultTypeFor

        public Type effectiveResultTypeFor​(Type type,
                                           BuilderGem builder)