FIR IDE: introduce symbol pointers for restoring symbols in another read action

fix pointer
This commit is contained in:
Ilya Kirillov
2020-06-29 17:20:28 +03:00
parent f88ebed1a3
commit 5cfac8fa3f
20 changed files with 180 additions and 11 deletions
@@ -5,6 +5,8 @@
package org.jetbrains.kotlin.idea.frontend.api
import org.jetbrains.kotlin.idea.frontend.api.types.KtType
data class ImplicitReceiverSmartCast(val types: Collection<KtType>, val kind: ImplicitReceiverSmartcastKind)
enum class ImplicitReceiverSmartcastKind {
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.idea.frontend.api
import com.intellij.openapi.project.Project
import org.jetbrains.kotlin.diagnostics.Diagnostic
import org.jetbrains.kotlin.idea.frontend.api.symbols.*
import org.jetbrains.kotlin.idea.frontend.api.types.KtType
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.psi.*
@@ -5,6 +5,8 @@
package org.jetbrains.kotlin.idea.frontend.api
import org.jetbrains.kotlin.idea.frontend.api.types.KtType
sealed class KtTypeArgument
object KtStarProjectionTypeArgument : KtTypeArgument()
@@ -5,7 +5,7 @@
package org.jetbrains.kotlin.idea.frontend.api.symbols
import org.jetbrains.kotlin.idea.frontend.api.KtType
import org.jetbrains.kotlin.idea.frontend.api.types.KtType
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
@@ -18,6 +18,8 @@ abstract class KtTypeAliasSymbol : KtClassLikeSymbol() {
abstract class KtClassOrObjectSymbol : KtClassLikeSymbol(), KtSymbolWithTypeParameters, KtSymbolWithModality<KtSymbolModality> {
abstract val classKind: KtClassKind
abstract override fun createPointer(): KtSymbolPointer<KtClassOrObjectSymbol>
}
enum class KtClassKind {
@@ -32,4 +32,6 @@ abstract class KtConstructorSymbol : KtFunctionLikeSymbol() {
abstract override val valueParameters: List<KtConstructorParameterSymbol>
abstract val isPrimary: Boolean
abstract val owner: KtClassOrObjectSymbol
abstract override fun createPointer(): KtSymbolPointer<KtConstructorSymbol>
}
@@ -9,4 +9,6 @@ import org.jetbrains.kotlin.name.FqName
abstract class KtPackageSymbol : KtSymbol {
abstract val fqName: FqName
abstract override fun createPointer(): KtSymbolPointer<KtPackageSymbol>
}
@@ -11,6 +11,8 @@ import org.jetbrains.kotlin.idea.frontend.api.ValidityOwner
interface KtSymbol : ValidityOwner {
val origin: KtSymbolOrigin
val psi: PsiElement?
fun createPointer(): KtSymbolPointer<KtSymbol> = NonRestorableKtSymbolPointer
}
enum class KtSymbolOrigin {
@@ -0,0 +1,35 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.idea.frontend.api.symbols
import org.jetbrains.kotlin.idea.frontend.api.KtAnalysisSession
/**
* `KtSymbol` is valid only during read action it was created in
* To pass the symbol from one read action to another the KtSymbolPointer should be used
*
* We can restore the symbol
* * for function & property symbol if its signature was not changed
* * for local variable symbol if code block it was declared in was not changed
* * for class & type alias symbols if its qualified name was not changed
* * for package symbol if the package is still exists
*
* @see org.jetbrains.kotlin.idea.frontend.api.ReadActionConfinementValidityToken
*/
interface KtSymbolPointer<out S : KtSymbol> {
/**
* @return restored symbol (possibly the new symbol instance) if one is still valid, `null` otherwise
*/
fun restoreSymbol(analysisSession: KtAnalysisSession): S?
}
object NonRestorableKtSymbolPointer : KtSymbolPointer<Nothing> {
override fun restoreSymbol(analysisSession: KtAnalysisSession): Nothing? = null
}
inline fun <S : KtSymbol> symbolPointer(crossinline getSymbol: (KtAnalysisSession) -> S?) = object : KtSymbolPointer<S> {
override fun restoreSymbol(analysisSession: KtAnalysisSession): S? = getSymbol(analysisSession)
}
@@ -5,7 +5,7 @@
package org.jetbrains.kotlin.idea.frontend.api.symbols
import org.jetbrains.kotlin.idea.frontend.api.KtType
import org.jetbrains.kotlin.idea.frontend.api.types.KtType
import org.jetbrains.kotlin.name.Name
interface KtNamedSymbol : KtSymbol {
@@ -3,8 +3,10 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.idea.frontend.api
package org.jetbrains.kotlin.idea.frontend.api.types
import org.jetbrains.kotlin.idea.frontend.api.KtTypeArgument
import org.jetbrains.kotlin.idea.frontend.api.ValidityOwner
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtClassLikeSymbol
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtTypeParameterSymbol
import org.jetbrains.kotlin.name.ClassId