- 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
Modifier and TypeInterfaceDescriptionstatic class
Fluent API builder forTypeName
.static class
TypeName.BuilderBase<BUILDER extends TypeName.BuilderBase<BUILDER,
PROTOTYPE>, PROTOTYPE extends TypeName> Fluent API builder base forTypeName
. -
Method Summary
Modifier and TypeMethodDescriptionboolean
array()
Functions the same asClass.isArray()
.boxed()
Return the boxed equivalent of this type.static TypeName.Builder
builder()
Create a new fluent API builder to customize configuration.static TypeName.Builder
Create a new fluent API builder from an existing instance.Functions the same asClass.getSimpleName()
.default String
Class name with enclosing types, separated by.
.default String
Simple class name with generic declaration (if part of this name).static TypeName
Create a type name from a type (such as class).static TypeName
Creates a type name from a fully qualified class name.static TypeName
createFromGenericDeclaration
(String genericAliasTypeName) Creates a type name from a generic alias type name.default String
Typically 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 String
fqName()
The fully qualified type name.boolean
generic()
Indicates whether this type is using generics.The base generic type name, stripped of anyTypeNameBlueprint.typeArguments()
.default boolean
isList()
Indicates whether this type is ajava.util.List
.default boolean
isMap()
Indicates whether this type is ajava.util.Map
.default boolean
Indicates whether this type is ajava.util.Optional
.default boolean
isSet()
Indicates whether this type is ajava.util.Set
.default boolean
Indicates whether this type is aSupplier
.default String
name()
The base name that includes the package name concatenated with the class name.Functions the same asClass.getPackageName()
.boolean
Functions the same asClass.isPrimitive()
.default String
The 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.boolean
wildcard()
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 the same asClass.getPackageName()
.- Returns:
- the package name, never null
-
className
String className()Functions the same asClass.getSimpleName()
.- Returns:
- the simple class name
-
classNameWithEnclosingNames
Class name with enclosing types, separated by.
. If we have an inner classBuilder
of 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 the same asClass.isPrimitive()
.- Returns:
- true if this type represents a primitive type
-
array
boolean array()Functions the same asClass.isArray()
.- Returns:
- true if this type represents a primitive array []
-
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
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()
-
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.
-