Skip to content

KaResolveExtensionFile

abstract class KaResolveExtensionFile

Represents a Kotlin file that contains generated declarations. It is provided by its resolve extension.

The file content is built lazily with buildFileText, which ensures that resolve extension files are only initialized when needed. The additional information provided by functions like getFilePackageName and getTopLevelClassifierNames is used to avoid building the resolve extension file's text unless absolutely necessary.

All member implementations should:

  • Consider caching the results for subsequent invocations.

  • Be lightweight and avoid building the whole file structure eagerly.

  • Avoid using Kotlin resolution, as these functions are called during session initialization, so Analysis API access is forbidden.

See also

Constructors

KaResolveExtensionFile

constructor()

Functions

buildFileText

abstract fun buildFileText(): String

Builds the text of the generated Kotlin source file. It should be valid Kotlin code.

The content must be consistent with other information provided by KaResolveExtensionFile:

In addition, the file text has the following restrictions:

  • The file should not contain the JvmMultifileClass and JvmName annotations on the file level.

  • All declaration types should be specified explicitly.

createNavigationTargetsProvider

getFileName

abstract fun getFileName(): String

The name of the Kotlin file which will be generated. It should have the .kt extension.

If the file contains top-level properties or functions, the name will be used as a Java facade name. For example, given the file name myFile.kt, a MyFileKt facade would be generated.

getFilePackageName

abstract fun getFilePackageName(): FqName

The FqName of the package that the resolve extension file belongs to.

The function might be called regularly, so it should be fast and avoid building the whole file text.

getTopLevelCallableNames

abstract fun getTopLevelCallableNames(): Set<Name>

Returns the set of top-level callable names (functions and properties) in the file. It must contain all such names in the package, but may contain additional false positives.

The function might be called regularly, so it should be fast and avoid building the whole file text.

getTopLevelClassifierNames

abstract fun getTopLevelClassifierNames(): Set<Name>

Returns the set of top-level classifier names (classes, interfaces, objects, and type-aliases) in the file. It must contain all such names in the package, but may contain additional false positives.

The function might be called regularly, so it should be fast and avoid building the whole file text.