Class ClassName

java.lang.Object
io.micronaut.sourcegen.javapoet.TypeName
io.micronaut.sourcegen.javapoet.ClassName
All Implemented Interfaces:
Comparable<ClassName>

public final class ClassName extends TypeName implements Comparable<ClassName>
A fully-qualified class name for top-level and member classes.
  • Field Details

    • OBJECT

      public static final ClassName OBJECT
  • Method Details

    • annotated

      public ClassName annotated(List<AnnotationSpec> annotations)
      Overrides:
      annotated in class TypeName
    • withoutAnnotations

      public ClassName withoutAnnotations()
      Overrides:
      withoutAnnotations in class TypeName
    • isAnnotated

      public boolean isAnnotated()
      Overrides:
      isAnnotated in class TypeName
    • packageName

      public String packageName()
      Returns the package name, like "java.util" for Map.Entry. Returns the empty string for the default package.
    • enclosingClassName

      public ClassName enclosingClassName()
      Returns the enclosing class, like Map for Map.Entry. Returns null if this class is not nested in another class.
    • topLevelClassName

      public ClassName topLevelClassName()
      Returns the top class in this nesting group. Equivalent to chained calls to enclosingClassName() until the result's enclosing class is null.
    • reflectionName

      public String reflectionName()
      Return the binary name of a class.
    • simpleNames

      public List<String> simpleNames()
    • peerClass

      public ClassName peerClass(String name)
      Returns a class that shares the same enclosing package or class. If this class is enclosed by another class, this is equivalent to enclosingClassName().nestedClass(name). Otherwise it is equivalent to get(packageName(), name).
    • nestedClass

      public ClassName nestedClass(String name)
      Returns a new ClassName instance for the specified name as nested inside this class.
    • simpleName

      public String simpleName()
      Returns the simple name of this class, like "Entry" for Map.Entry.
    • canonicalName

      public String canonicalName()
      Returns the full class name of this class. Like "java.util.Map.Entry" for Map.Entry.
    • get

      public static ClassName get(Class<?> clazz)
    • bestGuess

      public static ClassName bestGuess(String classNameString)
      Returns a new ClassName instance for the given fully-qualified class name string. This method assumes that the input is ASCII and follows typical Java style (lowercase package names, UpperCamelCase class names) and may produce incorrect results or throw IllegalArgumentException otherwise. For that reason, get(Class) and get(Class) should be preferred as they can correctly create ClassName instances without such restrictions.
    • get

      public static ClassName get(String packageName, String simpleName, String... simpleNames)
      Returns a class name created from the given parts. For example, calling this with package name "java.util" and simple names "Map", "Entry" yields Map.Entry.
    • get

      public static ClassName get(TypeElement element)
      Returns the class name for element.
    • compareTo

      public int compareTo(ClassName o)
      Specified by:
      compareTo in interface Comparable<ClassName>