- All Superinterfaces:
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().boxed()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).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.The base generic type name, stripped of anyTypeNameBlueprint.typeArguments().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.Deprecated, for removal: This API element is subject to removal in a future version.Generic types that provide keywordsuperwill have an upper bound defined.booleanvararg()If this is a representation ofTypeNameBlueprint.array(), this method can identify that it was declared as a vararg.booleanwildcard()Indicates whether this type is using wildcard generics.Methods inherited from interface java.lang.Comparable
compareTo
-
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 a type name from a type (such as class).- Parameters:
type- the type- Returns:
- type name for the provided type
-
create
Creates a type name from a fully qualified class name.- Parameters:
typeName- the FQN of the class type- Returns:
- the TypeName for the provided type name
-
createFromGenericDeclaration
Creates a type name from a generic alias type name.- Parameters:
genericAliasTypeName- the generic alias type name- Returns:
- the TypeName for the provided type name
-
boxed
TypeName 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
-
genericTypeName
TypeName genericTypeName()The base generic type name, stripped of anyTypeNameBlueprint.typeArguments(). This is equivalent to the type name represented byTypeNameBlueprint.name().- Returns:
- based generic type name
-
packageName
String packageName()Functions similar toClass.getPackageName().- Returns:
- the package name, never null
-
className
String className()Functions similar toClass.getSimpleName().- Returns:
- the simple class name
-
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
-
enclosingNames
Simple names of enclosing classes (if any exist). For example for typeio.helidon.example.Type$NestOne$NestTwo, this would return a list ofType, NestOne.- Returns:
- enclosing classes simple names
-
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 ofTypeNameBlueprint.array(), 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
Returns the list of generic type arguments, or an empty list if no generics are in use.- Returns:
- the type arguments of this type, if this type supports generics/parameterized type
- See Also:
-
typeParameters
Deprecated, for removal: This API element is subject to removal in a future version.theTypeNameBlueprint.typeArguments()will contain all required informationType 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
Generic types that provide keywordextendswill have a lower bound defined. Each lower bound may be a real type, or another generic type.This list may only have value if this is a generic type.
- Returns:
- list of lower bounds of this type
- See Also:
-
upperBounds
Generic types that provide keywordsuperwill have an upper bound defined. Upper bound may be a real type, or another generic type.This list may only have value if this is a generic type.
- Returns:
- list of upper bounds of this type
- See Also:
-
componentType
Component type of array.- Returns:
- component type of array
-
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>
-
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
-
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
-
fqName
The fully qualified type name.- Returns:
- the fully qualified name
-
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.
-
TypeNameBlueprint.typeArguments()will contain all required information