Skip to content

KotlinContentScopeRefiner

A contributor to KaModule.contentScope.

This extension point allows extending and restricting content scopes inside KaModule. All the refiners are lazily applied to KaModule.baseContentScope to build KaModule.contentScope. The computation of the refined content scope happens inside KaContentScopeProvider.

For example, this allows extensions providing synthetic non-Kotlin sources to bring those source files into the relevant module, library, or SDK scopes and shadow existing sources in a backend-agnostic manner.

Note that implementations of KotlinContentScopeRefiner cannot access KaModule.contentScope, as it's not yet built when getEnlargementScopes/getRestrictionScopes are called. Furthermore, implementations must not use KotlinProjectStructureProvider, as the content scope may be accessed during KaModule computation.

Types

Companion

object Companion

Functions

getEnlargementScopes

open fun getEnlargementScopes(module: KaModule): List<GlobalSearchScope>

Given a KaModule, getEnlargementScopes returns GlobalSearchScopes which enlarge KaModule.baseContentScope to form KaModule.contentScope. An enlargement expands the base content scope with the files contained in the enlargement scope.

If some file contained in getEnlargementScopes is also already contained in KaModule.baseContentScope, the enlargement scope will have no additional effect with respect to this file.

If the refiner doesn't provide any enlargements, emptyList is expected to be returned.

getRestrictionScopes

open fun getRestrictionScopes(module: KaModule): List<GlobalSearchScope>

Given a KaModule, getRestrictionScopes returns GlobalSearchScopes which restrict KaModule.baseContentScope to form KaModule.contentScope. A restriction limits the base content scope to the files contained in the restriction scope.

If some file not contained in getRestrictionScopes is also not contained in KaModule.baseContentScope, the restriction scope will have no additional effect with respect to this file.

If the refiner doesn't provide any restrictions, emptyList is expected to be returned.