Class TypeClass

  • All Implemented Interfaces:
    Excerpt

    public class TypeClass
    extends Type
    Representation of a class or interface element.

    When used as an excerpt or Type, it acts as a prototypical type of the class. This is the element's invocation on the type variables corresponding to its own formal type parameters. For example, the TypeClass of EnumSet would appear in code as EnumSet<E>. This is probably the most common use of a type class in code generation.

    The declaration() and declarationParameters() methods, on the other hand, return excerpts reflecting the type element. For example, the declaration of EnumSet would be EnumSet<E extends Enum<E>>.

    A hybrid of a TypeElement and its prototypical DeclaredType.

    See Also:
    Element.asType()
    • Field Detail

      • typeParameters

        private final java.util.List<javax.lang.model.element.TypeParameterElement> typeParameters
    • Constructor Detail

      • TypeClass

        TypeClass​(QualifiedName qualifiedName,
                  java.util.Collection<? extends javax.lang.model.element.TypeParameterElement> typeParameters)
    • Method Detail

      • from

        public static TypeClass from​(javax.lang.model.element.TypeElement typeElement)
      • fromNonGeneric

        public static TypeClass fromNonGeneric​(java.lang.Class<?> cls)
      • getQualifiedName

        public QualifiedName getQualifiedName()
        Description copied from class: Type
        Returns the qualified name of the type class.
        Specified by:
        getQualifiedName in class Type
      • declaration

        public Excerpt declaration()
        Returns a source excerpt suitable for declaring this type element.

        e.g. MyType<N extends Number, C extends Consumer<N>>

      • declarationParameters

        public Excerpt declarationParameters()
        Returns a source excerpt of the type parameters of this type element, including bounds and angle brackets.

        e.g. <N extends Number, C extends Consumer<N>>

      • getTypeParameters

        protected java.util.List<javax.lang.model.element.TypeParameterElement> getTypeParameters()
        Specified by:
        getTypeParameters in class Type
      • toString

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

        private static void addDeclarationParameters​(SourceBuilder source,
                                                     java.util.List<javax.lang.model.element.TypeParameterElement> typeParameters)
      • extendsObject

        private static boolean extendsObject​(javax.lang.model.element.TypeParameterElement element)