FIR IDE: forbid analysis session to be stored in a variable
This commit is contained in:
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.diagnostics.Diagnostic
|
|||||||
import org.jetbrains.kotlin.idea.frontend.api.scopes.KtScopeProvider
|
import org.jetbrains.kotlin.idea.frontend.api.scopes.KtScopeProvider
|
||||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.*
|
import org.jetbrains.kotlin.idea.frontend.api.symbols.*
|
||||||
import org.jetbrains.kotlin.idea.frontend.api.types.KtType
|
import org.jetbrains.kotlin.idea.frontend.api.types.KtType
|
||||||
|
import org.jetbrains.kotlin.idea.frontend.api.types.KtTypeRenderer
|
||||||
import org.jetbrains.kotlin.name.ClassId
|
import org.jetbrains.kotlin.name.ClassId
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
|
|
||||||
@@ -17,6 +18,7 @@ import org.jetbrains.kotlin.psi.*
|
|||||||
* - Should not be accessed from event dispatch thread
|
* - Should not be accessed from event dispatch thread
|
||||||
* - Should not be accessed outside read action
|
* - Should not be accessed outside read action
|
||||||
* - Should not be leaked outside read action it was created in
|
* - 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 [analyze] context
|
||||||
* - All entities retrieved from analysis facade should not be leaked outside the read action KtAnalysisSession was created in
|
* - All entities retrieved from analysis facade should not be leaked outside the read action KtAnalysisSession was created in
|
||||||
*
|
*
|
||||||
* To pass a symbol from one read action to another use [KtSymbolPointer] which can be created from a symbol by [KtSymbol.createPointer]
|
* To pass a symbol from one read action to another use [KtSymbolPointer] which can be created from a symbol by [KtSymbol.createPointer]
|
||||||
|
|||||||
+6
@@ -13,9 +13,15 @@ abstract class KtAnalysisSessionProvider {
|
|||||||
abstract fun getAnalysisSessionFor(contextElement: KtElement): KtAnalysisSession
|
abstract fun getAnalysisSessionFor(contextElement: KtElement): KtAnalysisSession
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("DeprecatedCallableAddReplaceWith")
|
||||||
|
@Deprecated(
|
||||||
|
"Should not be directly used as it is not allowed to store KtAnalysisSession in a variable, consider using `analyze` instead",
|
||||||
|
level = DeprecationLevel.WARNING,
|
||||||
|
)
|
||||||
fun getAnalysisSessionFor(contextElement: KtElement): KtAnalysisSession =
|
fun getAnalysisSessionFor(contextElement: KtElement): KtAnalysisSession =
|
||||||
contextElement.project.service<KtAnalysisSessionProvider>().getAnalysisSessionFor(contextElement)
|
contextElement.project.service<KtAnalysisSessionProvider>().getAnalysisSessionFor(contextElement)
|
||||||
|
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
inline fun <R> analyze(contextElement: KtElement, action: KtAnalysisSession.() -> R): R =
|
inline fun <R> analyze(contextElement: KtElement, action: KtAnalysisSession.() -> R): R =
|
||||||
getAnalysisSessionFor(contextElement).action()
|
getAnalysisSessionFor(contextElement).action()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user