kotlinpoet / com.squareup.kotlinpoet / ClassName

ClassName

class ClassName : TypeName, Comparable<ClassName>

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

Constructors

<init>

ClassName(packageName: String, simpleName: String, vararg simpleNames: String)

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.

Properties

canonicalName

val canonicalName: String

Fully qualified name using . as a separator, like kotlin.collections.Map.Entry.

packageName

val packageName: String

Package name, like "kotlin.collections" for Map.Entry.

simpleName

val simpleName: String

Simple name of this class, like "Entry" for Map.Entry.

simpleNames

val simpleNames: List<String>

The enclosing classes, outermost first, followed by the simple name. This is ["Map", "Entry"] for Map.Entry.

Inherited Properties

annotations

val annotations: List<AnnotationSpec>

isAnnotated

val isAnnotated: Boolean

isNullable

val isNullable: Boolean

Functions

compareTo

fun compareTo(other: ClassName): Int

Orders by the fully-qualified name. Nested types are ordered immediately after their enclosing type. For example, the following types are ordered by this method:

constructorReference

fun constructorReference(): CodeBlock

Callable reference to the constructor of this class. Emits the enclosing class if one exists, followed by the reference operator ::, followed by either simpleName or the fully-qualified name if this is a top-level class.

copy

fun copy(nullable: Boolean, annotations: List<AnnotationSpec>): ClassName

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.

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

Fully qualified name using . to separate package from the top level class name, and $ to separate nested classes, like kotlin.collections.Map$Entry.

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.

Inherited Functions

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, the constructor should be preferred as it can create ClassName instances without such restrictions.

Extension Functions

jvmSuppressWildcards

fun TypeName.jvmSuppressWildcards(suppress: Boolean = true): TypeName

jvmWildcard

fun TypeName.jvmWildcard(): TypeName