ClassName

class ClassName : TypeName, Comparable<ClassName>

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

Constructors

Link copied to clipboard
fun ClassName(packageName: 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.

Link copied to clipboard
fun ClassName(packageName: String, simpleNames: List<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.

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
open operator override 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:

Link copied to clipboard
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.

Link copied to clipboard
fun copy(nullable: Boolean = this.isNullable, annotations: List<AnnotationSpec> = this.annotations.toList()): TypeName
open override fun copy(    nullable: Boolean,     annotations: List<AnnotationSpec>,     tags: Map<KClass<*>, Any>): ClassName
Link copied to clipboard
fun enclosingClassName(): ClassName?

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

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
fun nestedClass(name: String): ClassName

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

Link copied to clipboard
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).

Link copied to clipboard
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.

Link copied to clipboard
open override fun <T : Any> tag(type: Class<T>): T?

Returns the tag attached with type as a key, or null if no tag is attached with that key.

open override fun <T : Any> tag(type: KClass<T>): T?

Returns the tag attached with type as a key, or null if no tag is attached with that key.

Link copied to clipboard
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.

Link copied to clipboard
open override fun toString(): String

Properties

Link copied to clipboard
val annotations: List<AnnotationSpec>
Link copied to clipboard
val canonicalName: String

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

Link copied to clipboard
val isAnnotated: Boolean
Link copied to clipboard
val isNullable: Boolean
Link copied to clipboard
val packageName: String

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

Link copied to clipboard
val simpleName: String

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

Link copied to clipboard
val simpleNames: List<String>

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

Link copied to clipboard
open override val tags: Map<KClass<*>, Any>

Returns all tags.

Extensions

Link copied to clipboard
inline fun ClassName.member(simpleName: String): MemberName
Link copied to clipboard
@JvmName(name = "get")
fun ClassName.parameterizedBy(vararg typeArguments: TypeName): ParameterizedTypeName
@JvmName(name = "get")
fun ClassName.parameterizedBy(typeArguments: List<TypeName>): ParameterizedTypeName

Returns a parameterized type, applying typeArguments to this.

Link copied to clipboard
@JvmName(name = "get")
fun ClassName.plusParameter(typeArgument: TypeName): ParameterizedTypeName

Returns a parameterized type, applying typeArgument to this.