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.StringcanonicalName(package private) java.util.List<java.lang.String>namesFrom top to bottom.static ClassNameOBJECT
-
Constructor Summary
Constructors Modifier Constructor Description privateClassName(java.util.List<java.lang.String> names)privateClassName(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 ClassNameannotated(java.util.List<AnnotationSpec> annotations)static ClassNamebestGuess(java.lang.String classNameString)Returns a newClassNameinstance for the given fully-qualified class name string.intcompareTo(ClassName o)(package private) CodeWriteremit(CodeWriter out)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.private static javax.lang.model.element.PackageElementgetPackage(javax.lang.model.element.Element type)private static booleanisClassOrInterface(javax.lang.model.element.Element e)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.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.TypeNamewithoutAnnotations()-
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:
withoutAnnotationsin classTypeName
-
packageName
public java.lang.String packageName()
Returns the package name, like"java.util"forMap.Entry.
-
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.
-
nestedClass
public ClassName nestedClass(java.lang.String name)
Returns a newClassNameinstance for the specifiednameas 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 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.
-
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:
compareToin interfacejava.lang.Comparable<ClassName>
-
emit
CodeWriter emit(CodeWriter out) throws java.io.IOException
-
-