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
(package private) java.util.List<java.lang.String>
names
From top to bottom.static ClassName
OBJECT
-
Constructor Summary
Constructors Modifier Constructor Description private
ClassName(java.util.List<java.lang.String> names)
private
ClassName(java.util.List<java.lang.String> names, 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.int
compareTo(ClassName o)
(package private) CodeWriter
emit(CodeWriter out)
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
.private static javax.lang.model.element.PackageElement
getPackage(javax.lang.model.element.Element type)
private static boolean
isClassOrInterface(javax.lang.model.element.Element e)
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
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.TypeName
withoutAnnotations()
-
Methods inherited from class com.squareup.javapoet.TypeName
annotated, arrayComponent, box, concatAnnotations, emitAnnotations, equals, get, get, get, get, hashCode, isAnnotated, isBoxedPrimitive, isPrimitive, list, list, toString, unbox
-
-
-
-
Field Detail
-
OBJECT
public static final ClassName OBJECT
-
names
final java.util.List<java.lang.String> names
From top to bottom. This will be ["java.util", "Map", "Entry"] forMap.Entry
.
-
canonicalName
final java.lang.String canonicalName
-
-
Constructor Detail
-
ClassName
private ClassName(java.util.List<java.lang.String> names)
-
ClassName
private ClassName(java.util.List<java.lang.String> names, java.util.List<AnnotationSpec> annotations)
-
-
Method Detail
-
annotated
public ClassName annotated(java.util.List<AnnotationSpec> annotations)
-
withoutAnnotations
public TypeName withoutAnnotations()
- Overrides:
withoutAnnotations
in classTypeName
-
packageName
public java.lang.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(java.lang.String name)
Returns a newClassName
instance for the specifiedname
as nested inside this 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)
.
-
simpleName
public java.lang.String simpleName()
Returns the simple name of this class, like"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
.
-
isClassOrInterface
private static boolean isClassOrInterface(javax.lang.model.element.Element e)
-
getPackage
private static javax.lang.model.element.PackageElement getPackage(javax.lang.model.element.Element type)
-
compareTo
public int compareTo(ClassName o)
- Specified by:
compareTo
in interfacejava.lang.Comparable<ClassName>
-
emit
CodeWriter emit(CodeWriter out) throws java.io.IOException
-
-