Package com.squareup.javapoet
Class ClassName
- java.lang.Object
-
- com.squareup.javapoet.TypeName
-
- com.squareup.javapoet.ClassName
-
-
Field Summary
Fields Modifier and Type Field Description (package private) java.lang.String
canonicalName
The full class name like "java.util.Map.Entry".(package private) ClassName
enclosingClassName
The enclosing class, or null if this is not enclosed in another class.private static java.lang.String
NO_PACKAGE
The name representing the default Java package.static ClassName
OBJECT
(package private) java.lang.String
packageName
The package name of this class, or "" if this is in the default package.(package private) java.lang.String
simpleName
This class name, like "Entry" for java.util.Map.Entry.private java.util.List<java.lang.String>
simpleNames
-
Constructor Summary
Constructors Modifier Constructor Description private
ClassName(java.lang.String packageName, ClassName enclosingClassName, java.lang.String simpleName)
private
ClassName(java.lang.String packageName, ClassName enclosingClassName, java.lang.String simpleName, java.util.List<AnnotationSpec> annotations)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ClassName
annotated(java.util.List<AnnotationSpec> annotations)
static ClassName
bestGuess(java.lang.String classNameString)
Returns a newClassName
instance for the given fully-qualified class name string.java.lang.String
canonicalName()
Returns the full class name of this class.int
compareTo(ClassName o)
(package private) CodeWriter
emit(CodeWriter out)
private java.util.List<ClassName>
enclosingClasses()
Returns all enclosing classes in this, outermost first.ClassName
enclosingClassName()
Returns the enclosing class, likeMap
forMap.Entry
.static ClassName
get(java.lang.Class<?> clazz)
static ClassName
get(java.lang.String packageName, java.lang.String simpleName, java.lang.String... simpleNames)
Returns a class name created from the given parts.static ClassName
get(javax.lang.model.element.TypeElement element)
Returns the class name forelement
.boolean
isAnnotated()
ClassName
nestedClass(java.lang.String name)
Returns a newClassName
instance for the specifiedname
as nested inside this class.java.lang.String
packageName()
Returns the package name, like"java.util"
forMap.Entry
.ClassName
peerClass(java.lang.String name)
Returns a class that shares the same enclosing package or class.java.lang.String
reflectionName()
Return the binary name of a class.java.lang.String
simpleName()
Returns the simple name of this class, like"Entry"
forMap.Entry
.java.util.List<java.lang.String>
simpleNames()
ClassName
topLevelClassName()
Returns the top class in this nesting group.ClassName
withoutAnnotations()
-
Methods inherited from class com.squareup.javapoet.TypeName
annotated, arrayComponent, asArray, box, concatAnnotations, emitAnnotations, equals, get, get, get, get, hashCode, isBoxedPrimitive, isPrimitive, list, list, toString, unbox
-
-
-
-
Field Detail
-
OBJECT
public static final ClassName OBJECT
-
NO_PACKAGE
private static final java.lang.String NO_PACKAGE
The name representing the default Java package.- See Also:
- Constant Field Values
-
packageName
final java.lang.String packageName
The package name of this class, or "" if this is in the default package.
-
enclosingClassName
final ClassName enclosingClassName
The enclosing class, or null if this is not enclosed in another class.
-
simpleName
final java.lang.String simpleName
This class name, like "Entry" for java.util.Map.Entry.
-
simpleNames
private java.util.List<java.lang.String> simpleNames
-
canonicalName
final java.lang.String canonicalName
The full class name like "java.util.Map.Entry".
-
-
Constructor Detail
-
ClassName
private ClassName(java.lang.String packageName, ClassName enclosingClassName, java.lang.String simpleName)
-
ClassName
private ClassName(java.lang.String packageName, ClassName enclosingClassName, java.lang.String simpleName, java.util.List<AnnotationSpec> annotations)
-
-
Method Detail
-
annotated
public ClassName annotated(java.util.List<AnnotationSpec> annotations)
-
withoutAnnotations
public ClassName withoutAnnotations()
- Overrides:
withoutAnnotations
in classTypeName
-
isAnnotated
public boolean isAnnotated()
- Overrides:
isAnnotated
in classTypeName
-
packageName
public java.lang.String packageName()
Returns the package name, like"java.util"
forMap.Entry
. Returns the empty string for the default package.
-
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.
-
reflectionName
public java.lang.String reflectionName()
Return the binary name of a class.
-
simpleNames
public java.util.List<java.lang.String> simpleNames()
-
peerClass
public ClassName peerClass(java.lang.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)
.
-
nestedClass
public ClassName nestedClass(java.lang.String name)
Returns a newClassName
instance for the specifiedname
as nested inside this class.
-
simpleName
public java.lang.String simpleName()
Returns the simple name of this class, like"Entry"
forMap.Entry
.
-
canonicalName
public java.lang.String canonicalName()
Returns the full class name of this class. Like"java.util.Map.Entry"
forMap.Entry
.
-
get
public static ClassName get(java.lang.Class<?> clazz)
-
bestGuess
public static ClassName bestGuess(java.lang.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(java.lang.String packageName, java.lang.String simpleName, java.lang.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(javax.lang.model.element.TypeElement element)
Returns the class name forelement
.
-
compareTo
public int compareTo(ClassName o)
- Specified by:
compareTo
in interfacejava.lang.Comparable<ClassName>
-
emit
CodeWriter emit(CodeWriter out) throws java.io.IOException
-
enclosingClasses
private java.util.List<ClassName> enclosingClasses()
Returns all enclosing classes in this, outermost first.
-
-