KotlinRestrictedAnalysisService¶
Allows the platform to communicate to the Analysis API about restricted analysis. When analysis is restricted, the platform typically lacks full, up-to-date information about the project. For example, declaration providers might return incomplete results. In addition, the available information might change without associated modification events.
As a consequence, results returned by the Analysis API might be incomplete or incorrect. Handling such results is the responsibility of the Analysis API user. The user should be aware of the platform's conventions around its restricted analysis mode and develop accordingly.
During restricted analysis, the platform might require accesses of affected data (such as indices) to be wrapped in a specific handler, see withRestrictedDataAccess.
In IntelliJ, restricted analysis mode is synonymous with its dumb mode, which is typically enabled when files are being re-indexed.
Any exceptions which occur during restricted analysis are wrapped in KaRestrictedAnalysisException (see its KDoc for more information).
If KotlinRestrictedAnalysisService is not registered, it's assumed that the platform has no conception of restricted analysis. When there is a restricted analysis mode, but analysis should be disallowed during the mode, KotlinRestrictedAnalysisService should still be implemented, setting isRestrictedAnalysisAllowed to false.
Implementation notes¶
It is the responsibility of the platform to ensure that declaration providers and package providers are adapted to restricted analysis. This also extends to other platform components which might be affected by restricted analysis.
The platform must ensure that modification events are published when entering and exiting restricted analysis mode:
-
The platform must publish modification events for all
KaModules which might be affected by incomplete, inconsistent, or changing information when entering restricted analysis mode. The kind of modification event (module state modification, out-of-block modification) to publish depends on the event which triggered the restricted analysis mode. -
- Generally, the usual modification events published by the platform in reaction to project changes should be sufficient to cover this requirement.
-
A
global module state modification eventmust be published when exiting restricted analysis mode, to mitigate potential issues with inconsistent cache states that accumulated during restricted analysis.
Types¶
Companion¶
object Companion
Properties¶
isAnalysisRestricted¶
abstract val isAnalysisRestricted: Boolean
Whether the Analysis API platform is currently in restricted analysis mode.
isRestrictedAnalysisAllowed¶
abstract val isRestrictedAnalysisAllowed: Boolean
Whether Analysis API access during restricted analysis mode is allowed by the platform. Such analysis activity is also called simply restricted analysis.
Depending on this setting, the Analysis API will act differently during restricted analysis mode:
-
When restricted analysis is allowed, requests to the Analysis API will be accepted, and analysis will be performed according to the rules of restricted analysis (see
KotlinRestrictedAnalysisService). -
Otherwise, the Analysis API will reject the request using
rejectRestrictedAnalysis.
Functions¶
rejectRestrictedAnalysis¶
abstract fun rejectRestrictedAnalysis(): Nothing
Throws an exception after Analysis API access was rejected during restricted analysis mode.
runWithRestrictedDataAccess¶
abstract fun <R> runWithRestrictedDataAccess(action: () -> R): R
Runs action in a context where the platform allows access to the data affected by restricted analysis mode.
On the client side, please use withRestrictedDataAccess instead.
withRestrictedDataAccess¶
inline fun <R> KotlinRestrictedAnalysisService?.withRestrictedDataAccess(crossinline action: () -> R): R
Runs action with KotlinRestrictedAnalysisService.runWithRestrictedDataAccess if deemed necessary and applicable.