[AA] Edit documentation of analyze and related classes

This commit is contained in:
Marco Pennekamp
2023-08-08 23:25:40 +02:00
committed by Space Team
parent 7dbfe4bfb1
commit ed13d6b3a4
3 changed files with 21 additions and 16 deletions
@@ -17,16 +17,18 @@ import org.jetbrains.kotlin.psi.KtElement
import org.jetbrains.kotlin.psi.KtFile
/**
* The entry point into all frontend-related work. Has the following contracts:
* - Should not be accessed from event dispatch thread
* - Should not be accessed outside read action
* - Should not be leaked outside read action it was created in
* - To be sure that session is not leaked it is forbidden to store it in a variable, consider working with it only in [analyse] context
* - All entities retrieved from analysis session should not be leaked outside the read action KtAnalysisSession was created in
* [KtAnalysisSession] is the entry point into all frontend-related work. It has the following contracts:
*
* To pass a symbol from one read action to another use [KtSymbolPointer] which can be created from a symbol by [KtSymbol.createPointer]
* - It should not be accessed from event dispatch thread.
* - It should not be accessed outside a read action.
* - It should not be leaked outside the read action it was created in.
* - To be sure that an analysis session is not leaked, it is forbidden to store it in a variable. Consider working with it only inside
* [analyze] blocks, and pass it to functions via context receivers (e.g. `context(KtAnalysisSession)`).
* - All entities retrieved from an analysis session should not be leaked outside the read action the analysis session was created in.
*
* To create analysis session consider using [analyse]
* To pass a symbol from one read action to another use [KtSymbolPointer], which can be created from a symbol by [KtSymbol.createPointer].
*
* To create a [KtAnalysisSession], please use [analyze] or one of its siblings.
*/
@OptIn(KtAnalysisApiInternals::class)
@Suppress("AnalysisApiMissingLifetimeCheck")
@@ -7,15 +7,16 @@
package org.jetbrains.kotlin.analysis.api
import org.jetbrains.kotlin.analysis.api.lifetime.KtLifetimeTokenFactory
import org.jetbrains.kotlin.analysis.api.session.KtAnalysisSessionProvider
import org.jetbrains.kotlin.analysis.project.structure.KtModule
import org.jetbrains.kotlin.psi.KtElement
import org.jetbrains.kotlin.psi.KtFile
/**
* Execute given [action] in [KtAnalysisSession] context
* Uses [useSiteKtElement] as an [KtElement] which containing module is a use-site module,
* i.e, the module from which perspective the project will be analyzed.
* Executes the given [action] in a [KtAnalysisSession] context.
*
* The project will be analyzed from the perspective of [useSiteKtElement]'s module, also called the use-site module.
*
* @see KtAnalysisSession
*/
@@ -26,10 +27,10 @@ public inline fun <R> analyze(
KtAnalysisSessionProvider.getInstance(useSiteKtElement.project)
.analyse(useSiteKtElement, action)
/**
* Execute given [action] in [KtAnalysisSession] context
* Uses [useSiteKtModule] as use-site module, i.e, the module from which perspective the project will be analyzed.
* Executes the given [action] in a [KtAnalysisSession] context.
*
* The project will be analyzed from the perspective of the given [useSiteKtModule].
*
* @see KtAnalysisSession
* @see KtLifetimeTokenFactory
@@ -18,8 +18,10 @@ import org.jetbrains.kotlin.psi.KtElement
import org.jetbrains.kotlin.psi.KtFile
/**
* Provides [KtAnalysisSession] by [contextElement]
* Should not be used directly, consider using [analyse]/[analyzeWithReadAction]/[analyzeInModalWindow] instead
* Provides [KtAnalysisSession]s by use-site [KtElement]s or [KtModule]s.
*
* This provider should not be used directly. Please use [analyze][org.jetbrains.kotlin.analysis.api.analyze] or
* [analyzeInDependedAnalysisSession][org.jetbrains.kotlin.analysis.api.analyzeInDependedAnalysisSession] instead.
*/
@OptIn(KtAnalysisApiInternals::class)
public abstract class KtAnalysisSessionProvider(public val project: Project) : Disposable {