Interface TypeName
- All Superinterfaces:
Annotated, Comparable<TypeName>, Prototype.Api
- All Known Implementing Classes:
TypeArgument, TypeName.BuilderBase.TypeNameImpl
TypeName is similar to
Type in its most basic use case. The name() returns the package +
class name tuple for the given type (i.e., the canonical type name).
This class also provides a number of methods that are typically found in Class that can be used to avoid
classloading resolution:
packageName()andclassName()- access to the package and simple class names.primitive()andarray()- access to flags that is typically found inClass.
generic()- true when this type is declared to include generics (i.e., has type arguments).wildcard()- true if using wildcard generics usage.typeArguments()- access to generics / parametrized type information.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic classFluent API builder forTypeName.static classTypeName.BuilderBase<BUILDER extends TypeName.BuilderBase<BUILDER, PROTOTYPE>, PROTOTYPE extends TypeName>Fluent API builder base forTypeName. -
Method Summary
Modifier and TypeMethodDescriptionbooleanarray()Functions similar toClass.isArray().default TypeNameboxed()Return the boxed equivalent of this type.static TypeName.Builderbuilder()Create a new fluent API builder to customize configuration.static TypeName.BuilderCreate a new fluent API builder from an existing instance.Functions similar toClass.getSimpleName().default StringClass name with enclosing types, separated by..default StringSimple class name with generic declaration (if part of this name).default intCompare with another type name.Component type of array.static TypeNameCreate a type name from a type (such as class).static TypeNameCreates a type name from a fully qualified class name.static TypeNamecreateFromGenericDeclaration(String genericAliasTypeName) Creates a type name from a generic alias type name.default StringTypically used as part of code-gen, when ".class" is tacked onto the suffix of what this returns.Simple names of enclosing classes (if any exist).default StringfqName()The fully qualified type name.booleangeneric()Indicates whether this type is using generics.default TypeNameThe base generic type name, stripped of anytypeArguments().default booleanisList()Indicates whether this type is ajava.util.List.default booleanisMap()Indicates whether this type is ajava.util.Map.default booleanIndicates whether this type is ajava.util.Optional.default booleanisSet()Indicates whether this type is ajava.util.Set.default booleanIndicates whether this type is aSupplier.Generic types that provide keywordextendswill have a lower bound defined.default Stringname()The base name that includes the package name concatenated with the class name.Functions similar toClass.getPackageName().booleanFunctions similar toClass.isPrimitive().default StringThe fully resolved type.Returns the list of generic type arguments, or an empty list if no generics are in use.Type parameters associated with the type arguments.default TypeNameunboxed()Return the unboxed equivalent of this type.Generic types that provide keywordsuperwill have an upper bound defined.booleanvararg()If this is a representation ofarray(), this method can identify that it was declared as a vararg.booleanwildcard()Indicates whether this type is using wildcard generics.Methods inherited from interface Annotated
allAnnotations, annotation, annotations, findAnnotation, hasAnnotation, inheritedAnnotationsModifier and TypeMethodDescriptiondefault List<Annotation> List of all annotations - bothAnnotated.annotations()andAnnotated.inheritedAnnotations().default Annotationannotation(TypeName annotationType) Get an annotation on this annotated type.List of declared and known annotations for this element.default Optional<Annotation> findAnnotation(TypeName annotationType) Find an annotation on this annotated type.default booleanhasAnnotation(TypeName annotationType) Check if the annotation exists on this annotated.List of all inherited annotations for this element.
-
Method Details
-
builder
Create a new fluent API builder to customize configuration.- Returns:
- a new builder
-
builder
Create a new fluent API builder from an existing instance.- Parameters:
instance- an existing instance used as a base for the builder- Returns:
- a builder based on an instance
-
create
-
create
-
createFromGenericDeclaration
-
compareTo
Compare with another type name. First compares byname(), than byprimitive(), and finally byarray().- Specified by:
compareToin interfaceComparable<TypeName>- Parameters:
o- type name to compare to- Returns:
- comparison result
- See Also:
-
boxed
Return the boxed equivalent of this type. If this is not a primitive type, returns this instance.- Returns:
- boxed type for this type, or this type if not primitive
-
unboxed
Return the unboxed equivalent of this type. If this is a boxed primitive, the primitive type is returned.- Returns:
- primitive type for this type, or this type if not boxed primitive type
-
name
The base name that includes the package name concatenated with the class name. Similar toType.getTypeName(). Name contains possible enclosing types, separated by$.- Returns:
- the base type name given the set package and class name, but not including the generics/parameterized types
-
genericTypeName
The base generic type name, stripped of anytypeArguments(). This is equivalent to the type name represented byname().- Returns:
- based generic type name
-
fqName
-
declaredName
Typically used as part of code-gen, when ".class" is tacked onto the suffix of what this returns.- Returns:
- same as getName() unless the type is an array, and then will add "[]" to the return
-
resolvedName
The fully resolved type. This will include the generic portion of the declaration, as well as any array declaration, etc.- Returns:
- the fully qualified name which includes the use of generics/parameterized types, arrays, etc.
-
classNameWithEnclosingNames
Class name with enclosing types, separated by.. If we have an inner classBuilderof classType, this method would returnType.Builder.- Returns:
- class name with enclosing types
-
isList
default boolean isList()Indicates whether this type is ajava.util.List.- Returns:
- if this is a list
-
isSet
default boolean isSet()Indicates whether this type is ajava.util.Set.- Returns:
- if this is a set
-
isMap
default boolean isMap()Indicates whether this type is ajava.util.Map.- Returns:
- if this is a map
-
isOptional
default boolean isOptional()Indicates whether this type is ajava.util.Optional.- Returns:
- if this is an optional
-
isSupplier
default boolean isSupplier()Indicates whether this type is aSupplier.- Returns:
- if this is a supplier
-
classNameWithTypes
Simple class name with generic declaration (if part of this name).- Returns:
- class name with generics, such as
Consumer<java.lang.String>, orConsumer<T>
-
packageName
String packageName()Functions similar toClass.getPackageName().- Returns:
- the package name, never null
-
className
-
enclosingNames
-
primitive
boolean primitive()Functions similar toClass.isPrimitive().- Returns:
- true if this type represents a primitive type
-
array
boolean array()Functions similar toClass.isArray().- Returns:
- true if this type represents a primitive array []
-
vararg
boolean vararg()If this is a representation ofarray(), this method can identify that it was declared as a vararg. This may be used for method/constructor parameters (which is the only place this is supported in Java).- Returns:
- whether an array is declared as a vararg
-
generic
boolean generic()Indicates whether this type is using generics.- Returns:
- used to represent a generic (e.g., "Optional<CB>")
-
wildcard
boolean wildcard()Indicates whether this type is using wildcard generics.- Returns:
- used to represent a wildcard (e.g., "? extends SomeType")
-
typeArguments
-
typeParameters
Type parameters associated with the type arguments. The type argument list may be empty, even if this list is not, for example in declaration of the top level type (as arguments are a function of usage of the type). iftypeArguments()exist, this list MUST exist and have the same size and order (it maps the name to the type).- Returns:
- type parameter names as declared on this type, or names that represent the
typeArguments()
-
lowerBounds
-
upperBounds
-
componentType
-