Interface TypeName

All Superinterfaces:
Comparable<TypeName>, Prototype.Api
All Known Implementing Classes:
TypeArgument, TypeName.BuilderBase.TypeNameImpl

public interface TypeName extends Prototype.Api, Comparable<TypeName>
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:

Additionally, this class offers a number of additional methods that are useful for handling generics:
  • 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.
Finally, this class offers a number of methods that are helpful for code generation:
See Also:
  • Method Details

    • builder

      static TypeName.Builder builder()
      Create a new fluent API builder to customize configuration.
      a new builder
    • builder

      static TypeName.Builder builder(TypeName instance)
      Create a new fluent API builder from an existing instance.
      instance - an existing instance used as a base for the builder
      a builder based on an instance
    • create

      static TypeName create(Type type)
      Create a type name from a type (such as class).
      type - the type
      type name for the provided type
    • create

      static TypeName create(String typeName)
      Creates a type name from a fully qualified class name.
      typeName - the FQN of the class type
      the TypeName for the provided type name
    • createFromGenericDeclaration

      static TypeName createFromGenericDeclaration(String genericAliasTypeName)
      Creates a type name from a generic alias type name.
      genericAliasTypeName - the generic alias type name
      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.
      boxed type for this type, or this type if not primitive
    • genericTypeName

      TypeName genericTypeName()
      The base generic type name, stripped of any TypeNameBlueprint.typeArguments(). This is equivalent to the type name represented by
      based generic type name
    • packageName

      String packageName()
      Functions the same as Class.getPackageName().
      the package name, never null
    • className

      String className()
      Functions the same as Class.getSimpleName().
      the simple class name
    • classNameWithEnclosingNames

      default String classNameWithEnclosingNames()
      Class name with enclosing types, separated by .. If we have an inner class Builder of class Type, this method would return Type.Builder.
      class name with enclosing types
    • enclosingNames

      List<String> enclosingNames()
      Simple names of enclosing classes (if any exist). For example for type io.helidon.example.Type$NestOne$NestTwo, this would return a list of Type, NestOne.
      enclosing classes simple names
    • primitive

      boolean primitive()
      Functions the same as Class.isPrimitive().
      true if this type represents a primitive type
    • array

      boolean array()
      Functions the same as Class.isArray().
      true if this type represents a primitive array []
    • generic

      boolean generic()
      Indicates whether this type is using generics.
      used to represent a generic (e.g., "Optional<CB>")
    • wildcard

      boolean wildcard()
      Indicates whether this type is using wildcard generics.
      used to represent a wildcard (e.g., "? extends SomeType")
    • typeArguments

      List<TypeName> typeArguments()
      Returns the list of generic type arguments, or an empty list if no generics are in use.
      the type arguments of this type, if this type supports generics/parameterized type
      See Also:
    • typeParameters

      List<String> 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). if typeArguments() exist, this list MUST exist and have the same size and order (it maps the name to the type).
      type parameter names as declared on this type, or names that represent the typeArguments()
    • isList

      default boolean isList()
      Indicates whether this type is a java.util.List.
      if this is a list
    • isSet

      default boolean isSet()
      Indicates whether this type is a java.util.Set.
      if this is a set
    • isMap

      default boolean isMap()
      Indicates whether this type is a java.util.Map.
      if this is a map
    • isOptional

      default boolean isOptional()
      Indicates whether this type is a java.util.Optional.
      if this is an optional
    • isSupplier

      default boolean isSupplier()
      Indicates whether this type is a Supplier.
      if this is a supplier
    • classNameWithTypes

      default String classNameWithTypes()
      Simple class name with generic declaration (if part of this name).
      class name with generics, such as Consumer<java.lang.String>, or Consumer<T>
    • name

      default String name()
      The base name that includes the package name concatenated with the class name. Similar to Type.getTypeName(). Name contains possible enclosing types, separated by $.
      the base type name given the set package and class name, but not including the generics/parameterized types
    • declaredName

      default String declaredName()
      Typically used as part of code-gen, when ".class" is tacked onto the suffix of what this returns.
      same as getName() unless the type is an array, and then will add "[]" to the return
    • fqName

      default String fqName()
      The fully qualified type name.
      the fully qualified name
    • resolvedName

      default String resolvedName()
      The fully resolved type. This will include the generic portion of the declaration, as well as any array declaration, etc.
      the fully qualified name which includes the use of generics/parameterized types, arrays, etc.