Skip to content

ClassHeaderBuilder

A fluent builder for a class header string, assembled in a fixed order: modifiers, name, type parameters, base class, and type constraints. Call asString to obtain the resulting header text, then pass it to createClass to build the PSI.

Calls are expected in that order. Order violations are checked only when JVM assertions are enabled.

Constructors

ClassHeaderBuilder

constructor()

Types

State

The stages in the expected order for building a class header.

Functions

asString

fun asString(): String

Returns the assembled class header text.

baseClass

fun baseClass(
    @NonNls name: String, 
    typeArguments: Collection<String>, 
    isInterface: Boolean
): KtPsiFactory.ClassHeaderBuilder

Appends the base class or interface: its name and typeArguments. When isInterface is false, an empty constructor call () is appended.

modifier

Appends modifier verbatim. No separator is added between repeated calls, so callers must include any required whitespace. This is expected to be called before name.

name

Appends the class keyword and the class name. Ends the modifiers stage.

transform

fun transform(f: StringBuilder.() -> Unit)

Applies an arbitrary transformation to the underlying text buffer.

typeConstraints

Appends the where clause type constraints, if any.

typeParameters

Appends the type parameters, if any.