Package com.squareup.javapoet
Class ClassName
- java.lang.Object
-
- com.squareup.javapoet.TypeName
-
- com.squareup.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.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ClassName
annotated(List<AnnotationSpec> annotations)
static ClassName
bestGuess(String classNameString)
Returns a newClassName
instance for the given fully-qualified class name string.int
compareTo(ClassName o)
ClassName
enclosingClassName()
Returns the enclosing class, likeMap
forMap.Entry
.static ClassName
get(Class<?> clazz)
static ClassName
get(String packageName, String simpleName, String... simpleNames)
Returns a class name created from the given parts.static ClassName
get(TypeElement element)
Returns the class name forelement
.ClassName
nestedClass(String name)
Returns a newClassName
instance for the specifiedname
as nested inside this class.String
packageName()
Returns the package name, like"java.util"
forMap.Entry
.ClassName
peerClass(String name)
Returns a class that shares the same enclosing package or class.String
simpleName()
Returns the simple name of this class, like"Entry"
forMap.Entry
.List<String>
simpleNames()
ClassName
topLevelClassName()
Returns the top class in this nesting group.TypeName
withoutAnnotations()
-
Methods inherited from class com.squareup.javapoet.TypeName
annotated, box, concatAnnotations, equals, get, get, hashCode, isAnnotated, isBoxedPrimitive, isPrimitive, toString, unbox
-
-
-
-
Field Detail
-
OBJECT
public static final ClassName OBJECT
-
-
Method Detail
-
annotated
public ClassName annotated(List<AnnotationSpec> annotations)
-
withoutAnnotations
public TypeName withoutAnnotations()
- Overrides:
withoutAnnotations
in classTypeName
-
packageName
public String packageName()
Returns the package name, like"java.util"
forMap.Entry
.
-
enclosingClassName
public ClassName enclosingClassName()
Returns the enclosing class, likeMap
forMap.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 toenclosingClassName()
until the result's enclosing class is null.
-
nestedClass
public ClassName nestedClass(String name)
Returns a newClassName
instance for the specifiedname
as nested inside this class.
-
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 toenclosingClassName().nestedClass(name)
. Otherwise it is equivalent toget(packageName(), name)
.
-
simpleName
public String simpleName()
Returns the simple name of this class, like"Entry"
forMap.Entry
.
-
bestGuess
public static ClassName bestGuess(String classNameString)
Returns a newClassName
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 throwIllegalArgumentException
otherwise. For that reason,get(Class)
andget(Class)
should be preferred as they can correctly createClassName
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"
yieldsMap.Entry
.
-
get
public static ClassName get(TypeElement element)
Returns the class name forelement
.
-
compareTo
public int compareTo(ClassName o)
- Specified by:
compareTo
in interfaceComparable<ClassName>
-
-