Package com.squareup.javapoet
Class ClassName
java.lang.Object
com.squareup.javapoet.TypeName
com.squareup.javapoet.ClassName
- All Implemented Interfaces:
Comparable<ClassName>
A fully-qualified class name for top-level and member classes.
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) final String
The full class name like "java.util.Map.Entry".(package private) final ClassName
The enclosing class, or null if this is not enclosed in another class.private static final String
The name representing the default Java package.static final ClassName
(package private) final String
The package name of this class, or "" if this is in the default package.(package private) final String
This class name, like "Entry" for java.util.Map.Entry. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionannotated
(List<AnnotationSpec> annotations) static ClassName
Returns a newClassName
instance for the given fully-qualified class name string.Returns the full class name of this class.int
(package private) CodeWriter
emit
(CodeWriter out) Returns all enclosing classes in this, outermost first.Returns the enclosing class, likeMap
forMap.Entry
.static ClassName
static ClassName
Returns a class name created from the given parts.static ClassName
get
(TypeElement element) Returns the class name forelement
.boolean
nestedClass
(String name) Returns a newClassName
instance for the specifiedname
as nested inside this class.Returns the package name, like"java.util"
forMap.Entry
.Returns a class that shares the same enclosing package or class.Return the binary name of a class.Returns the simple name of this class, like"Entry"
forMap.Entry
.Returns the top class in this nesting group.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 Details
-
OBJECT
-
NO_PACKAGE
The name representing the default Java package.- See Also:
-
packageName
The package name of this class, or "" if this is in the default package. -
enclosingClassName
The enclosing class, or null if this is not enclosed in another class. -
simpleName
This class name, like "Entry" for java.util.Map.Entry. -
simpleNames
-
canonicalName
The full class name like "java.util.Map.Entry".
-
-
Constructor Details
-
ClassName
-
ClassName
private ClassName(String packageName, ClassName enclosingClassName, String simpleName, List<AnnotationSpec> annotations)
-
-
Method Details
-
annotated
-
withoutAnnotations
- Overrides:
withoutAnnotations
in classTypeName
-
isAnnotated
public boolean isAnnotated()- Overrides:
isAnnotated
in classTypeName
-
packageName
Returns the package name, like"java.util"
forMap.Entry
. Returns the empty string for the default package. -
enclosingClassName
Returns the enclosing class, likeMap
forMap.Entry
. Returns null if this class is not nested in another class. -
topLevelClassName
Returns the top class in this nesting group. Equivalent to chained calls toenclosingClassName()
until the result's enclosing class is null. -
reflectionName
Return the binary name of a class. -
simpleNames
-
peerClass
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
Returns a newClassName
instance for the specifiedname
as nested inside this class. -
simpleName
Returns the simple name of this class, like"Entry"
forMap.Entry
. -
canonicalName
Returns the full class name of this class. Like"java.util.Map.Entry"
forMap.Entry
. -
get
-
bestGuess
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
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
Returns the class name forelement
. -
compareTo
- Specified by:
compareTo
in interfaceComparable<ClassName>
-
emit
- Overrides:
emit
in classTypeName
- Throws:
IOException
-
enclosingClasses
Returns all enclosing classes in this, outermost first.
-