Top Description Fields Constructors Methods
com.squareup.javapoet

public final Class ClassName

extends TypeName
implements Comparable<ClassName>
Class Inheritance
All Implemented Interfaces
java.lang.Comparable
Imports
java.io.IOException, java.util.ArrayList, .Collections, .List, .Map, .Objects, javax.lang.model.element.Element, .PackageElement, .TypeElement, javax.lang.model.util.SimpleElementVisitor8

A fully-qualified class name for top-level and member classes.

Field Summary

Modifier and TypeField and Description
pack-priv final String
canonicalName

The full class name like "java.util.Map.Entry".

pack-priv final ClassName
enclosingClassName

The enclosing class, or null if this is not enclosed in another class.

private static final String
NO_PACKAGE

The name representing the default Java package.

public static final ClassName
pack-priv final String
packageName

The package name of this class, or "" if this is in the default package.

pack-priv final String
simpleName

This class name, like "Entry" for java.util.Map.Entry.

private List<String>
Inherited from com.squareup.javapoet.TypeName:
annotationsBOOLEANBYTECHARDOUBLEFLOATINTLONGSHORTVOID

Constructor Summary

AccessConstructor and Description
private
ClassName(String packageName, ClassName enclosingClassName, String simpleName)

private
ClassName(String packageName, ClassName enclosingClassName, String simpleName, List<AnnotationSpec> annotations)

Method Summary

Modifier and TypeMethod and Description
public ClassName
public static ClassName
bestGuess(String classNameString)

Returns a new ClassName instance for the given fully-qualified class name string.

public String
canonicalName()

Returns the full class name of this class.

public int
compareTo(ClassName
the object to be compared.
o
)

Implements java.lang.Comparable.compareTo.

Compares this object with the specified object for order.
pack-priv CodeWriter
private List<ClassName>
enclosingClasses()

Returns all enclosing classes in this, outermost first.

public ClassName
enclosingClassName()

Returns the enclosing class, like Map for Map.Entry.

public static ClassName
get(Class<?> clazz)

public static ClassName
get(String packageName, String simpleName, String... simpleNames)

Returns a class name created from the given parts.

public static ClassName
get(TypeElement element)

Returns the class name for element.

public boolean
public ClassName
nestedClass(String name)

Returns a new ClassName instance for the specified name as nested inside this class.

public String
packageName()

Returns the package name, like "java.util" for Map.Entry.

public ClassName
peerClass(String name)

Returns a class that shares the same enclosing package or class.

public String
reflectionName()

Return the binary name of a class.

public String
simpleName()

Returns the simple name of this class, like "Entry" for Map.Entry.

public List<String>
public ClassName
topLevelClassName()

Returns the top class in this nesting group.

public ClassName
Inherited from com.squareup.javapoet.TypeName:
annotatedarrayComponentasArrayboxconcatAnnotationsemitAnnotationsequalsgetgetgetgethashCodeisBoxedPrimitiveisPrimitivelistlisttoStringunbox

Field Detail

canonicalNameback to summary
pack-priv final String canonicalName

The full class name like "java.util.Map.Entry".

enclosingClassNameback to summary
pack-priv final ClassName enclosingClassName

The enclosing class, or null if this is not enclosed in another class.

NO_PACKAGEback to summary
private static final String NO_PACKAGE

The name representing the default Java package.

OBJECTback to summary
public static final ClassName OBJECT

Hides com.squareup.javapoet.TypeName.OBJECT.

packageNameback to summary
pack-priv final String packageName

The package name of this class, or "" if this is in the default package.

simpleNameback to summary
pack-priv final String simpleName

This class name, like "Entry" for java.util.Map.Entry.

simpleNamesback to summary
private List<String> simpleNames

Constructor Detail

ClassNameback to summary
private ClassName(String packageName, ClassName enclosingClassName, String simpleName)
ClassNameback to summary
private ClassName(String packageName, ClassName enclosingClassName, String simpleName, List<AnnotationSpec> annotations)

Method Detail

annotatedback to summary
public ClassName annotated(List<AnnotationSpec> annotations)

Overrides com.squareup.javapoet.TypeName.annotated.

Annotations
@Override
bestGuessback to summary
public static ClassName bestGuess(String classNameString)

Returns a new ClassName 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 throw IllegalArgumentException otherwise. For that reason, get(Class) and get(Class) should be preferred as they can correctly create ClassName instances without such restrictions.

canonicalNameback to summary
public String canonicalName()

Returns the full class name of this class. Like "java.util.Map.Entry" for Map.Entry.

compareToback to summary
public int compareTo(ClassName o)

Implements java.lang.Comparable.compareTo.

Doc from java.lang.Comparable.compareTo.

Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

The implementor must ensure signum(x.compareTo(y)) == -signum(y.compareTo(x)) for all x and y. (This implies that x.compareTo(y) must throw an exception if and only if y.compareTo(x) throws an exception.)

The implementor must also ensure that the relation is transitive: (x.compareTo(y) > 0 && y.compareTo(z) > 0) implies x.compareTo(z) > 0.

Finally, the implementor must ensure that x.compareTo(y)==0 implies that signum(x.compareTo(z)) == signum(y.compareTo(z)), for all z.

Parameters
o:ClassName

the object to be compared.

Returns:int

a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

Annotations
@Override
emitback to summary
pack-priv CodeWriter emit(CodeWriter out) throws IOException

Overrides com.squareup.javapoet.TypeName.emit.

Annotations
@Override
enclosingClassesback to summary
private List<ClassName> enclosingClasses()

Returns all enclosing classes in this, outermost first.

enclosingClassNameback to summary
public ClassName enclosingClassName()

Returns the enclosing class, like Map for Map.Entry. Returns null if this class is not nested in another class.

getback to summary
public static ClassName get(Class<?> clazz)
getback to summary
public static ClassName get(String packageName, String simpleName, 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" yields Map.Entry.

getback to summary
public static ClassName get(TypeElement element)

Returns the class name for element.

isAnnotatedback to summary
public boolean isAnnotated()

Overrides com.squareup.javapoet.TypeName.isAnnotated.

Annotations
@Override
nestedClassback to summary
public ClassName nestedClass(String name)

Returns a new ClassName instance for the specified name as nested inside this class.

packageNameback to summary
public String packageName()

Returns the package name, like "java.util" for Map.Entry. Returns the empty string for the default package.

peerClassback to summary
public ClassName peerClass(String name)

Returns a class that shares the same enclosing package or class. If this class is enclosed by another class, this is equivalent to enclosingClassName().nestedClass(name). Otherwise it is equivalent to get(packageName(), name).

reflectionNameback to summary
public String reflectionName()

Return the binary name of a class.

simpleNameback to summary
public String simpleName()

Returns the simple name of this class, like "Entry" for Map.Entry.

simpleNamesback to summary
public List<String> simpleNames()
topLevelClassNameback to summary
public ClassName topLevelClassName()

Returns the top class in this nesting group. Equivalent to chained calls to enclosingClassName() until the result's enclosing class is null.

withoutAnnotationsback to summary
public ClassName withoutAnnotations()

Overrides com.squareup.javapoet.TypeName.withoutAnnotations.

Annotations
@Override