Package-level declarations

Types

Link copied to clipboard
class AnnotationTagsBuilder(pluginContext: IrPluginContext, finder: DeclarationFinder, messageCollector: MessageCollector)

Materializes annotation tags as IR expressions. Resolves the required stdlib symbols (kotlin.Pair, kotlin.collections.mapOf/emptyMap) once and offers the two shapes the transformers need: a Map<String, Any> argument (buildMap, used by @Logged for Logger.logged) and a vararg tags: Pair<String, Any> argument (buildVararg, used by @Timed for Meter.timed).

Link copied to clipboard

The log4k Level enum, resolved once per module: its class symbol plus the entries by name. Shared by the transformers that materialize Level arguments (io.github.smyrgeorge.log4k.compiler.logged.LoggedIrTransformer and io.github.smyrgeorge.log4k.compiler.callsite.CallSiteIrTransformer).

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

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

Link copied to clipboard

The log4k tracing symbols the transformers correlate logs and spans with, resolved once per module: TracingContext (plus its currentOrNull()) and TracingEvent.Span. Each is null when the runtime on the classpath predates it — callers degrade gracefully.

Properties

Link copied to clipboard
val LOG4K_PACKAGE: FqName

The root package of the log4k runtime API.

Functions

Link copied to clipboard
fun IrPluginContext.buildInlineLambda(enclosing: IrFunction, returnType: IrType, extensionReceiverType: IrType? = null, extensionReceiverName: Name = Name.identifier($$"$this$lambda")): IrSimpleFunction

Builds the inline lambda that wraps enclosing's original body (moved in via moveBody) so it can be passed to an inline helper such as span { … }, logged { … } or measure { … }.

Link copied to clipboard
fun IrPluginContext.buildInlineLambdaExpression(enclosing: IrFunction, returnType: IrType, extensionReceiverType: IrType? = null, extensionReceiverName: Name = Name.identifier($$"$this$lambda")): Log4kIrFunctionExpression

buildInlineLambda wrapped in the Log4kIrFunctionExpression the transformers pass as the f argument of the inline runtime helpers (logged/measure/traced): a () -> T — or, with extensionReceiverType, an R.() -> T — carrying enclosing's original body. The moved body is reachable through Log4kIrFunctionExpression.function (e.g., to prepend statements to it).

Link copied to clipboard
fun IrFunction.dispatchReceiverParam(): IrValueParameter?

The single dispatch-receiver parameter of this, or null (new-API parameters accessor).

Link copied to clipboard
fun DeclarationFinder.findLog4kFunction(className: String, name: String, regularParams: Int): IrSimpleFunctionSymbol?

The log4k member function name declared on className (dot-separated for nested classes, e.g. "Meter.Timed") with exactly regularParams regular parameters, or null when the runtime on the classpath does not provide that overload. The parameter count pins the exact overload the plugin was built against, so an unexpected runtime degrades to "not found" instead of a mis-shaped call.

Link copied to clipboard
fun DeclarationFinder.findSourceLocationConstructor(): IrConstructorSymbol?

The SourceLocation(file, line, function) constructor, or null on an older log4k runtime.

Link copied to clipboard
fun IrFunction.instrumentationName(annotation: FqName): String

The instrumentation name configured on this function's annotation: its first argument (@Timed(name = …) / @Traced(name = …)) when it is a non-blank string constant, else the default qualifiedName.

Link copied to clipboard
fun DeclarationIrBuilder.irOfThisClass(pluginContext: IrPluginContext, ofFn: IrSimpleFunctionSymbol, thisReceiver: IrValueParameter): IrExpression

Builds <Companion>.of(this::class) for a companion of(KClass<*>) factory such as Logger.of or Meter.of, using thisReceiver (a class or function dispatch receiver) as this.

Link copied to clipboard
fun IrBuilderWithScope.irSourceLocation(constructor: IrConstructorSymbol, file: IrFile, offset: Int, function: String): IrExpression?

Builds SourceLocation(file, line, function) for the source offset inside file — the value the instrumentation passes attach to emitted events (a call site in io.github.smyrgeorge.log4k.compiler.callsite.CallSiteIrTransformer, a function declaration in io.github.smyrgeorge.log4k.compiler.logged.LoggedIrTransformer). Returns null for synthetic offsets — there is no source position to record.

Link copied to clipboard
fun IrFunction.isClassLevelEligible(): Boolean

Whether this function is an eligible target for class-level instrumentation: a public, concrete member function that is not a constructor, property accessor, or inherited (fake-override) member.

Link copied to clipboard
fun IrFunction.isInstrumentationTarget(annotation: FqName, killSwitch: FqName): Boolean

Whether this function is a target of the instrumentation driven by annotation: it must have a body, not be disabled by killSwitch (on the function or its class — the per-class opt-out wins over any annotation), and either carry annotation itself or be an eligible member (see isClassLevelEligible) of a class annotated with it.

Link copied to clipboard
fun IrPluginContext.moveBody(function: IrFunction, lambda: IrFunction): IrBlockBody

Detaches the original body from function and re-homes it inside lambda, so it can be used as the body of an inline lambda that wraps the original code (e.g. span { … } or logged { … }).

Link copied to clipboard
fun IrFunction.qualifiedName(): String

The instrumentation name of this function: "ClassName.functionName", or just the function name for a top-level function. Used as the default span name (@Traced) and the log name (@Logged).

Link copied to clipboard
fun IrFunction.receiverOrContextOf(type: IrClassSymbol): IrValueParameter?

The first context parameter or extension receiver of this function whose type is a subtype of type — i.e., a value of type "in scope" for the function. Used to pick up a TracingContext or TracingEvent.Span provided via context(_: …) or an extension receiver.

Link copied to clipboard
fun IrFunction.regularParams(): List<IrValueParameter>

The regular (value) parameters of this — excluding receivers and context parameters.

Link copied to clipboard
fun MessageCollector.reportError(function: IrFunction, message: String): Nothing?

Reports a compilation error anchored at function, failing the build. Returns null so it can be used as ?: return messageCollector.reportError(...) from functions with a nullable return type.

Link copied to clipboard
fun IrFunction.resolveTags(annotation: FqName): List<Pair<String, String>>

Reads the tags = [Tag(key, value), …] array of annotation — parameter index 1 on @Logged, @Timed and @Traced alike — into (key, value) pairs.