Package com.squareup.javapoet
Class ClassName
- java.lang.Object
-
- com.squareup.javapoet.TypeName
-
- com.squareup.javapoet.ClassName
-
- All Implemented Interfaces:
Comparable<ClassName>
public final class ClassName extends TypeName implements Comparable<ClassName>
A fully-qualified class name for top-level and member classes.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ClassNameannotated(List<AnnotationSpec> annotations)static ClassNamebestGuess(String classNameString)Returns a newClassNameinstance for the given fully-qualified class name string.intcompareTo(ClassName o)ClassNameenclosingClassName()Returns the enclosing class, likeMapforMap.Entry.static ClassNameget(Class<?> clazz)static ClassNameget(String packageName, String simpleName, String... simpleNames)Returns a class name created from the given parts.static ClassNameget(TypeElement element)Returns the class name forelement.ClassNamenestedClass(String name)Returns a newClassNameinstance for the specifiednameas nested inside this class.StringpackageName()Returns the package name, like"java.util"forMap.Entry.ClassNamepeerClass(String name)Returns a class that shares the same enclosing package or class.StringsimpleName()Returns the simple name of this class, like"Entry"forMap.Entry.List<String>simpleNames()ClassNametopLevelClassName()Returns the top class in this nesting group.TypeNamewithoutAnnotations()-
Methods inherited from class com.squareup.javapoet.TypeName
annotated, box, concatAnnotations, equals, get, get, hashCode, isAnnotated, isBoxedPrimitive, isPrimitive, toString, unbox
-
-
-
-
Field Detail
-
OBJECT
public static final ClassName OBJECT
-
-
Method Detail
-
annotated
public ClassName annotated(List<AnnotationSpec> annotations)
-
withoutAnnotations
public TypeName withoutAnnotations()
- Overrides:
withoutAnnotationsin classTypeName
-
packageName
public 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(String name)
Returns a newClassNameinstance for the specifiednameas nested inside this class.
-
peerClass
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 toenclosingClassName().nestedClass(name). Otherwise it is equivalent toget(packageName(), name).
-
simpleName
public String simpleName()
Returns the simple name of this class, like"Entry"forMap.Entry.
-
bestGuess
public static ClassName bestGuess(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(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"yieldsMap.Entry.
-
get
public static ClassName get(TypeElement element)
Returns the class name forelement.
-
compareTo
public int compareTo(ClassName o)
- Specified by:
compareToin interfaceComparable<ClassName>
-
-