OfThisClassField

class OfThisClassField(pluginContext: IrPluginContext, messageCollector: MessageCollector, typeSymbol: IrClassSymbol, ofFunction: IrSimpleFunctionSymbol, annotation: String, memberName: String, syntheticName: String)(source)

Resolves — or synthesizes — a per-class member holding an instance of typeSymbol obtained via a companion of(KClass<*>) factory (e.g. Logger.of(this::class) / Meter.of(this::class)).

access resolves the member in three steps:

  1. a member named memberName (e.g. log) is reused when its type is the target type;

  2. otherwise the class's single property of the target type — whatever its name (e.g. private val logger = Logger.of(this::class)) — is reused; two or more such properties are ambiguous, so none is picked;

  3. otherwise private val [syntheticName] = <Type>.of(this::class) is synthesized (created once per class). A memberName member of a foreign type (e.g. org.slf4j.Logger when we want a log4k Logger) is never reused — the synthetic name is distinct, so it never clashes.

Synthesized fields are collected during the module traversal and only attached to their classes by commit afterwards, so a class's declaration list is never mutated while it is being iterated.

Constructors

Link copied to clipboard
constructor(pluginContext: IrPluginContext, messageCollector: MessageCollector, typeSymbol: IrClassSymbol, ofFunction: IrSimpleFunctionSymbol, annotation: String, memberName: String, syntheticName: String)

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
fun access(function: IrFunction): IrExpression?

Returns an expression that yields the typeSymbol instance for function (reused member or synthesized field), or null (after reporting an error) when function has no enclosing class or dispatch receiver.

Link copied to clipboard
fun commit()

Attaches every synthesized field to its class. Must run after the module transform.