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.
      Returns:
      a new builder
    • builder

      static TypeName.Builder builder(TypeName instance)
      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

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

      static TypeName create(String typeName)
      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

      static TypeName createFromGenericDeclaration(String genericAliasTypeName)
      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 any TypeNameBlueprint.typeArguments(). This is equivalent to the type name represented by TypeNameBlueprint.name().
      Returns:
      based generic type name
    • packageName

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

      String className()
      Functions the same as Class.getSimpleName().
      Returns:
      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.
      Returns:
      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.
      Returns:
      enclosing classes simple names
    • primitive

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

      boolean array()
      Functions the same as Class.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

      List<TypeName> 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

      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).
      Returns:
      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.
      Returns:
      if this is a list
    • isSet

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

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

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

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

      default String classNameWithTypes()
      Simple class name with generic declaration (if part of this name).
      Returns:
      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 $.
      Returns:
      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.
      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.
      Returns:
      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.
      Returns:
      the fully qualified name which includes the use of generics/parameterized types, arrays, etc.