SemanticsPropertyKey


SemanticsPropertyKey is the infrastructure for setting key/value pairs inside semantics blocks in a type-safe way. Each key has one particular statically defined value type T.

Summary

Public constructors

<T : Any?> SemanticsPropertyKey(name: String, mergePolicy: (T, T?) -> T?)
Cmn

Public functions

operator T
getValue(thisRef: SemanticsPropertyReceiver, property: KProperty<*>)

Throws UnsupportedOperationException.

Cmn
T?
merge(parentValue: T?, childValue: T)

Method implementing the semantics merge policy of a particular key.

Cmn
operator Unit
setValue(
    thisRef: SemanticsPropertyReceiver,
    property: KProperty<*>,
    value: T
)
Cmn
open String
Cmn

Public properties

String

The name of the property.

Cmn

Public constructors

SemanticsPropertyKey

<T : Any?> SemanticsPropertyKey(
    name: String,
    mergePolicy: (T, T?) -> T? = { parentValue, childValue -> parentValue ?: childValue }
)

Public functions

getValue

operator fun getValue(thisRef: SemanticsPropertyReceiver, property: KProperty<*>): T

Throws UnsupportedOperationException. Should not be called.

merge

fun merge(parentValue: T?, childValue: T): T?

Method implementing the semantics merge policy of a particular key.

When mergeDescendants is set on a semantics node, then this function will called for each descendant node of a given key in depth-first-search order. The parent value accumulates the result of merging the values seen so far, similar to reduce().

The default implementation returns the parent value if one exists, otherwise uses the child element. This means by default, a SemanticsNode with mergeDescendants = true winds up with the first value found for each key in its subtree in depth-first-search order.

setValue

operator fun setValue(
    thisRef: SemanticsPropertyReceiver,
    property: KProperty<*>,
    value: T
): Unit

toString

open fun toString(): String

Public properties

name

val nameString

The name of the property. Should be the same as the constant from which it is accessed.