Skip to content

KaCompilerFacility

@SubclassOptInRequired(markerClass = [KaSessionComponentImplementationDetail::class])
interface KaCompilerFacility : KaSessionComponent

Inheritors

Properties

token

abstract val token: KaLifetimeToken

The KaLifetimeToken which determines the lifetime of the lifetime owner.

Functions

assertIsValidAndAccessible

compile

abstract fun compile(file: KtFile, options: KaCompilationOptions): KaCompilationResult

Compiles the given file in-memory using the specified options.

The function rethrows exceptions from the compiler, wrapped in KaCodeCompilationException. The implementation should wrap the compile() call into a try/catch block when necessary.

Parameters

  • file: A file to compile. The file must be either a source module file, or a KtCodeFragment. For a KtCodeFragment, a source module context, a compiled library source context, or an empty context (null) are supported.

  • options: The compilation options created via createCompilationOptions.

See also

createCompilationOptions

Creates a new KaCompilationOptions instance using the given DSL init block.

Example usage:

val options = createCompilationOptions {
    target(KaCompilationTarget.JVM)
    moduleName("myModule")
    languageVersionSettings(languageSettings)
    allowedErrorFilter { diagnostic -> diagnostic.factoryName in allowedErrors }
}

Parameters

isValid

Whether the lifetime owner is still valid, i.e. we are still in the scope of the lifetime owner's regular lifetime.

modify

Creates a copy of these KaCompilationOptions, applying the given init modifications.

Options not explicitly overridden in init retain their original values.

Parameters

withValidityAssertion

inline fun <R> KaLifetimeOwner.withValidityAssertion(action: () -> R): R

Executes action only if the KaLifetimeOwner is still valid and accessible. Otherwise, throws a validity exception based on the concrete violation.