Skip to content

CallableBuilder

A fluent builder for a function, constructor, or read-only property declaration string. The available steps and their order depend on the Target; call asString to obtain the resulting text, then pass it to the matching create* method.

Calls are expected in state order. Order and target violations are checked only when JVM assertions are enabled.

Constructors

CallableBuilder

Types

Companion

object Companion

State

The stages in the expected order for building a callable.

Target

The kind of callable being built.

Functions

asString

fun asString(): String

Returns the assembled callable declaration text.

blockBody

Appends a block body containing the given body text (a getter block for a property).

getterExpression

fun getterExpression(@NonNls expression: String, breakLine: Boolean = true): KtPsiFactory.CallableBuilder

Appends an expression-body getter (get() = expression). Read-only properties only.

initializer

Appends an initializer (= body). Read-only properties only.

lazyBody

Appends a lazy delegate (by kotlin.lazy { body }). Read-only properties only.

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

name

fun name(@NonNls name: String = CONSTRUCTOR_NAME): KtPsiFactory.CallableBuilder

Appends the callable name (defaulting to the constructor pseudo-name), opening the parameter list for functions and constructors.

noReturnType

Closes the parameter list (if any) without appending a return type.

param

fun param(
    @NonNls name: String, 
    @NonNls type: String, 
    @NonNls defaultValue: String? = null
): KtPsiFactory.CallableBuilder

Appends a value parameter with the given name, type, and optional defaultValue. Functions and constructors only.

receiver

fun receiver(@NonNls receiverType: String): KtPsiFactory.CallableBuilder

Appends the extension receiver type.

returnType

Closes the parameter list (if any) and appends the return type.

superDelegation

fun superDelegation(@NonNls argumentList: String): KtPsiFactory.CallableBuilder

Appends a : super(...) delegation call with the given argumentList. Constructors only.

transform

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

Applies an arbitrary transformation to the underlying text buffer.

typeConstraints

Appends the where clause type constraints, if any. Not allowed for constructors.

typeParams

Appends the declaration keyword (fun/val) and the type parameters, if any.