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.StringcanonicalNameThe full class name like "java.util.Map.Entry".(package private) ClassNameenclosingClassNameThe enclosing class, or null if this is not enclosed in another class.private static java.lang.StringNO_PACKAGEThe name representing the default Java package.static ClassNameOBJECT(package private) java.lang.StringpackageNameThe package name of this class, or "" if this is in the default package.(package private) java.lang.StringsimpleNameThis class name, like "Entry" for java.util.Map.Entry.private java.util.List<java.lang.String>simpleNames
-
Constructor Summary
Constructors Modifier Constructor Description privateClassName(java.lang.String packageName, ClassName enclosingClassName, java.lang.String simpleName)privateClassName(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 ClassNameannotated(java.util.List<AnnotationSpec> annotations)static ClassNamebestGuess(java.lang.String classNameString)Returns a newClassNameinstance for the given fully-qualified class name string.java.lang.StringcanonicalName()Returns the full class name of this class.intcompareTo(ClassName o)(package private) CodeWriteremit(CodeWriter out)private java.util.List<ClassName>enclosingClasses()Returns all enclosing classes in this, outermost first.ClassNameenclosingClassName()Returns the enclosing class, likeMapforMap.Entry.static ClassNameget(java.lang.Class<?> clazz)static ClassNameget(java.lang.String packageName, java.lang.String simpleName, java.lang.String... simpleNames)Returns a class name created from the given parts.static ClassNameget(javax.lang.model.element.TypeElement element)Returns the class name forelement.booleanisAnnotated()ClassNamenestedClass(java.lang.String name)Returns a newClassNameinstance for the specifiednameas nested inside this class.java.lang.StringpackageName()Returns the package name, like"java.util"forMap.Entry.ClassNamepeerClass(java.lang.String name)Returns a class that shares the same enclosing package or class.java.lang.StringreflectionName()Return the binary name of a class.java.lang.StringsimpleName()Returns the simple name of this class, like"Entry"forMap.Entry.java.util.List<java.lang.String>simpleNames()ClassNametopLevelClassName()Returns the top class in this nesting group.ClassNamewithoutAnnotations()-
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:
withoutAnnotationsin classTypeName
-
isAnnotated
public boolean isAnnotated()
- Overrides:
isAnnotatedin 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, likeMapforMap.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 newClassNameinstance for the specifiednameas 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 newClassNameinstance 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 throwIllegalArgumentExceptionotherwise. For that reason,get(Class)andget(Class)should be preferred as they can correctly createClassNameinstances 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:
compareToin 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.
-
-