Skip to content

KaModule

KaModule is the Analysis API's view on a module inside a project. A KaModule represents a source set (with production and test sources being separate modules), script, library, and various niche concepts such as dangling files.

As an Analysis API user, you will mainly interact with KaModules indirectly when providing a use-site module to an analyze call (usually derived from the use-site KtElement instead). However, it is possible to utilize the Analysis API's module support to explore the project structure and retrieve information about individual modules when needed.

Modules are crucial to establish the use-site view of analysis sessions. An analysis session always exists in the context of a particular use-site module. The module determines the session's resolution scope, and generally the content and dependencies from which symbols are resolved.

Individual KaModules for specific PsiElements can be retrieved from KaModuleProvider. The implementation of this provider, and the project structure in general, are provided by the Analysis API platform, such as IntelliJ or Standalone. As such, KaModule implementations are not provided by the Analysis API engine (in contrast to most of the Analysis API surface), but rather by individual platforms.

Modules are also the Analysis API's unit of modification. When a code change has possible non-local consequences (i.e. it happens outside an isolated function or property body), the resulting cache invalidation occurs on the level of a module and its dependents. While modification handling overall is an Analysis API platform topic, it is important to establish this basic fact.

Inheritors

Properties

baseContentScope

abstract val baseContentScope: GlobalSearchScope

A base content scope of the module, which is not yet refined by extension and restriction scopes provided by KotlinContentScopeRefiner.

Note that baseContentScope doesn't represent the actual content scope of the current module. To get a content scope of the module, contentScope should be used instead.

baseContextModuleOrSelf

compilerPluginGeneratedDeclarations

Declarations generated by compiler plugins for this module, not including the generated declarations for dependencies of this module.

contentScope

abstract val contentScope: GlobalSearchScope

Represents the content scope of a current module, i.e., a GlobalSearchScope which determines all the files that are contained in the module.

This scope should be lazily built from baseContentScope using KotlinContentScopeRefiner extension points.

directDependsOnDependencies

The module's dependsOn dependencies.

A dependsOn dependency expresses that the current module can provide actual declarations for expect declarations from the dependency module, as well as see internal symbols of the dependency module. As such, dependsOn dependencies are a Kotlin Multiplatform concept.

dependsOn dependencies in general are transitive, but the resulting list is not a transitive closure. To get all transitive dependsOn dependencies, transitiveDependsOnDependencies should be used. The list also does not include the current module.

directFriendDependencies

The module's friend dependencies. Friend dependencies allow the current module to use internal symbols from the dependency module.

The resulting list is not transitive and does not include the current module.

directRegularDependencies

The module's regular dependencies. Regular dependencies allow the current module to use symbols from the dependency module.

The resulting list is not transitive and does not include the current module.

isResolvable

Whether the given KaModule can be the use-site module of an analyze call. A module which is not resolvable will be rejected by analyze with an exception.

All modules returned by KaModuleProvider.getModule are guaranteed to be resolvable. By extension, all possible use-site PsiElements are also part of resolvable modules. As such, module resolvability is normally not a concern of an Analysis API user.

moduleDescription

abstract val moduleDescription: String

A human-readable description of the module, such as "main sources of module 'analysis-api'".

project

abstract val project: Project

The Project to which the module belongs.

All the module's dependencies should belong to the same Project as the module itself.

stableModuleName

A stable binary name of module from the Kotlin point of view. Having a correct module name is critical for internal-visibility mangling.

NOTE: stableModuleName will be removed in the future and replaced with a platform interface service.

targetPlatform

abstract val targetPlatform: TargetPlatform

A platform which the module represents (e.g, JVM, JS, Native).

See also

  • TargetPlatform

transitiveDependsOnDependencies

A list of directDependsOnDependencies and all of their own dependsOn dependencies (directly and indirectly), sorted topologically with the nearest dependencies first in the list. The list does not include the current module.

Functions

allDirectDependencies

allDirectDependenciesOfType

A list of all modules of type M that the given module directly depends on.

See also

directDependsOnDependenciesOfType

A list of all modules of type M that the given module directly depends on with a depends-on dependency.

See also

directFriendDependenciesOfType

A list of all modules of type M that the given module directly depends on with a friend dependency.

See also

directRegularDependenciesOfType

A list of all modules of type M that the given module directly depends on with a regular dependency.

See also