Interface TypeName

All Superinterfaces:
Comparable<TypeName>
All Known Implementing Classes:
DefaultTypeName

public interface TypeName extends 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:
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Functions the same as Class.isArray().
    Functions the same as Class.getSimpleName().
    Typically used as part of code-gen, when ".class" is tacked onto the suffix of what this returns.
    The fully qualified type name.
    boolean
    Indicates whether this type is using generics.
    default boolean
    Indicates whether this type is a java.util.List.
    default boolean
    Indicates whether this type is a java.util.Map.
    default boolean
    Indicates whether this type is a java.util.Optional.
    default boolean
    Indicates whether this type is a java.util.Set.
    The base name that includes the package name concatenated with the class name.
    Functions the same as Class.getPackageName().
    boolean
    Functions the same as Class.isPrimitive().
    Returns the list of generic type parameters, or an empty list if no generics are in use.
    boolean
    Indicates whether this type is using wildcard generics.

    Methods inherited from interface java.lang.Comparable

    compareTo
  • Method Details

    • 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
    • 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").
    • 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
    • typeArguments

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

      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

      String fqName()
      The fully qualified type name. 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.
    • name

      String name()
      The base name that includes the package name concatenated with the class name. Similar to Type.getTypeName().
      Returns:
      the base type name given the set package and class name, but not including the generics/parameterized types.