Skip to content

KaRenderingOutput

interface KaRenderingOutput

A destination for rendered output. A KaRenderer writes text fragments, each tagged with KaTextAttributes that describe its semantic role, so an output may add syntax highlighting, produce plain text, or ignore the attributes entirely.

All methods return this to allow chaining.

Types

Companion

object Companion

Functions

append

abstract fun append(text: String, attributes: Set<KaTextAttribute>): KaRenderingOutput

Appends text tagged with the given attributes.

append

Appends text tagged with the given attributes.

enter

open fun enter(piece: KaPiece<*>)

Called when rendering of piece begins. Everything appended until the balancing leave call is the output of that piece; the calls nest when a piece renders other pieces.

group

open fun group(children: KaPiece<*>, block: () -> Unit)

Renders a region which groups a sequence of child pieces of the children kind, such as a value parameter list grouping its KaPiece.ValueParameters.

block renders the entire content of the group, including the enclosing brackets and the separators between the children. The hook lets an output lay the group out as a whole, e.g. to fold it.

An output which needs no special treatment of groups invokes block as it is.

identifier

context(session: KaSession, context: KaRenderingContext)
fun KaRenderingOutput.identifier(name: String, symbol: KaSymbol): KaRenderingOutput

context(session: KaSession, context: KaRenderingContext)
fun KaRenderingOutput.identifier(name: Name, symbol: KaSymbol): KaRenderingOutput

Renders name as an identifier, linked to symbol when KaRenderingOption.LinkSymbols is enabled.

keyword

context(session: KaSession, context: KaRenderingContext)
fun KaRenderingOutput.keyword(token: KtKeywordToken, trailingSpace: Boolean = true): KaRenderingOutput

Renders token unless it is filtered out by KaRenderingOption.AllowedKeywords.

Parameters

  • trailingSpace: whether a space is appended after the keyword. Pass false when the keyword is directly followed by punctuation, as in constructor(.

leave

open fun leave(piece: KaPiece<*>)

Called when rendering of piece ends. Balances the corresponding enter call, also when rendering fails with an exception.

newLine

abstract fun newLine(): KaRenderingOutput

Starts a new line at the current indentation level.

popIndent

abstract fun popIndent(): KaRenderingOutput

Decreases the indentation level. Must be balanced with a preceding pushIndent.

punctuation

Appends text as a KaTextAttribute.Punctuation fragment, such as ( or ..

pushIndent

abstract fun pushIndent(): KaRenderingOutput

Increases the indentation level applied at the start of subsequent lines.

space

abstract fun space(): KaRenderingOutput

Append a single space unless the last rendered character was a whitespace.

withIndent

inline fun KaRenderingOutput.withIndent(block: () -> Unit)

Runs block with the indentation level increased, balancing pushIndent with popIndent.