kotlinpoet / com.squareup.kotlinpoet / ClassName

ClassName

class ClassName : TypeName, Comparable<ClassName>

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

Properties

canonicalName val canonicalName: String

Inherited Properties

annotations val annotations: List<AnnotationSpec>
isAnnotated val isAnnotated: Boolean

Functions

annotated fun annotated(annotations: List<AnnotationSpec>): ClassName
compareTo fun compareTo(other: ClassName): Int
enclosingClassName fun enclosingClassName(): ClassName?

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

nestedClass fun nestedClass(name: String): ClassName

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

packageName fun packageName(): String

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

peerClass fun peerClass(name: String): ClassName

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).

reflectionName fun reflectionName(): String
simpleName fun simpleName(): String

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

simpleNames fun simpleNames(): MutableList<String>
topLevelClassName fun topLevelClassName(): ClassName

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

withoutAnnotations fun withoutAnnotations(): ClassName

Inherited Functions

annotated fun annotated(vararg annotations: AnnotationSpec): TypeName
equals open fun equals(other: Any?): Boolean
hashCode open fun hashCode(): Int
toString open fun toString(): String

Companion Object Functions

bestGuess fun bestGuess(classNameString: String): ClassName

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 and .get should be preferred as they can correctly create ClassName instances without such restrictions.

get fun get(clazz: Class<*>): ClassName
fun get(clazz: KClass<*>): ClassNamefun get(packageName: String, simpleName: String, vararg simpleNames: String): ClassName

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.

fun get(element: TypeElement): ClassName

Returns the class name for element.