[AA K2] implement symbol pointers for enum entry members without psi
^KT-54311
This commit is contained in:
committed by
Space Team
parent
1dfca7aca9
commit
897a5b085d
+3
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2022 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.
|
||||
*/
|
||||
|
||||
@@ -83,12 +83,11 @@ internal class KtFirSymbolContainingDeclarationProvider(
|
||||
withSymbolAttachment("symbolForContainingPsi", symbol, analysisSession)
|
||||
}
|
||||
|
||||
KtFakeSourceElementKind.ImplicitConstructor ->
|
||||
return source.psi as KtDeclaration
|
||||
|
||||
KtFakeSourceElementKind.ImplicitConstructor -> return source.psi as KtDeclaration
|
||||
KtFakeSourceElementKind.PropertyFromParameter -> return source.psi?.parentOfType<KtPrimaryConstructor>()!!
|
||||
KtFakeSourceElementKind.DefaultAccessor -> return source.psi as KtProperty
|
||||
KtFakeSourceElementKind.ItLambdaParameter -> return source.psi as KtFunctionLiteral
|
||||
KtFakeSourceElementKind.EnumInitializer -> return source.psi as KtEnumEntry
|
||||
KtRealSourceElementKind -> source.psi!!
|
||||
else ->
|
||||
buildErrorWithAttachment("errorWithAttachment FirSourceElement: kind=${source.kind} element=${source.psi!!::class.simpleName}") {
|
||||
|
||||
+9
-2
@@ -6,9 +6,12 @@
|
||||
package org.jetbrains.kotlin.analysis.api.fir.symbols
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.KtFakeSourceElementKind
|
||||
import org.jetbrains.kotlin.analysis.api.fir.KtSymbolByFirBuilder
|
||||
import org.jetbrains.kotlin.analysis.api.fir.annotations.KtFirAnnotationListForDeclaration
|
||||
import org.jetbrains.kotlin.analysis.api.fir.findPsi
|
||||
import org.jetbrains.kotlin.analysis.api.fir.symbols.pointers.KtFirEnumEntryInitializerSymbolPointer
|
||||
import org.jetbrains.kotlin.analysis.api.fir.symbols.pointers.requireOwnerPointer
|
||||
import org.jetbrains.kotlin.analysis.api.fir.utils.cached
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.KtLifetimeToken
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||
@@ -35,8 +38,12 @@ internal class KtFirAnonymousObjectSymbol(
|
||||
override val superTypes: List<KtType> by cached { firSymbol.superTypesList(builder) }
|
||||
|
||||
override fun createPointer(): KtSymbolPointer<KtAnonymousObjectSymbol> = withValidityAssertion {
|
||||
KtPsiBasedSymbolPointer.createForSymbolFromSource(this)
|
||||
?: throw CanNotCreateSymbolPointerForLocalLibraryDeclarationException("Cannot create pointer for KtFirAnonymousObjectSymbol")
|
||||
KtPsiBasedSymbolPointer.createForSymbolFromSource(this)?.let { return it }
|
||||
if (firSymbol.source?.kind == KtFakeSourceElementKind.EnumInitializer) {
|
||||
return KtFirEnumEntryInitializerSymbolPointer(requireOwnerPointer())
|
||||
}
|
||||
|
||||
throw CanNotCreateSymbolPointerForLocalLibraryDeclarationException("Cannot create pointer for KtFirAnonymousObjectSymbol")
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean = symbolEquals(other)
|
||||
|
||||
+1
-1
@@ -135,7 +135,7 @@ internal class KtFirKotlinPropertySymbol(
|
||||
KtFirMemberPropertySymbolPointer(
|
||||
requireOwnerPointer(),
|
||||
firSymbol.name,
|
||||
firSymbol.createSignature()
|
||||
firSymbol.createSignature(),
|
||||
)
|
||||
|
||||
else -> throw UnsupportedSymbolKind(this::class, kind)
|
||||
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2010-2022 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.analysis.api.fir.symbols.pointers
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.fir.KtFirAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.fir.utils.firSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtAnonymousObjectSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtEnumEntrySymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtSymbolPointer
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnonymousObjectExpression
|
||||
|
||||
internal class KtFirEnumEntryInitializerSymbolPointer(
|
||||
private val ownerPointer: KtSymbolPointer<KtEnumEntrySymbol>,
|
||||
) : KtSymbolPointer<KtAnonymousObjectSymbol>() {
|
||||
@Deprecated("Consider using org.jetbrains.kotlin.analysis.api.KtAnalysisSession.restoreSymbol")
|
||||
override fun restoreSymbol(analysisSession: KtAnalysisSession): KtAnonymousObjectSymbol? {
|
||||
require(analysisSession is KtFirAnalysisSession)
|
||||
val owner = with(analysisSession) {
|
||||
ownerPointer.restoreSymbol()
|
||||
}
|
||||
|
||||
val initializer = owner?.firSymbol?.fir?.initializer as? FirAnonymousObjectExpression ?: return null
|
||||
return analysisSession.firSymbolBuilder.classifierBuilder.buildAnonymousObjectSymbol(initializer.anonymousObject.symbol)
|
||||
}
|
||||
}
|
||||
+4
-2
@@ -24,8 +24,10 @@ internal class KtFirMemberPropertySymbolPointer(
|
||||
candidates: FirScope,
|
||||
firSession: FirSession
|
||||
): KtKotlinPropertySymbol? {
|
||||
val firProperty = candidates.findDeclarationWithSignature<FirProperty>(signature, firSession) { processPropertiesByName(name, it) }
|
||||
?: return null
|
||||
val firProperty = candidates.findDeclarationWithSignature<FirProperty>(signature, firSession) {
|
||||
processPropertiesByName(name, it)
|
||||
} ?: return null
|
||||
|
||||
return firSymbolBuilder.variableLikeBuilder.buildVariableSymbol(firProperty.symbol) as? KtKotlinPropertySymbol
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -29,10 +29,11 @@ internal inline fun <reified D : FirDeclaration> FirScope.findDeclarationWithSig
|
||||
var foundSymbol: D? = null
|
||||
processor { symbol ->
|
||||
val declaration = symbol.fir
|
||||
if (declaration is D && signatureComposer.composeSignature(declaration) == signature) {
|
||||
if (declaration is D && signatureComposer.composeSignature(declaration, allowLocalClasses = true) == signature) {
|
||||
foundSymbol = declaration
|
||||
}
|
||||
}
|
||||
|
||||
return foundSymbol
|
||||
}
|
||||
|
||||
@@ -66,7 +67,7 @@ internal fun FirBasedSymbol<*>.createSignature(): IdSignature =
|
||||
|
||||
internal fun FirDeclaration.createSignature(): IdSignature {
|
||||
val signatureComposer = moduleData.session.ideSessionComponents.signatureComposer
|
||||
return signatureComposer.composeSignature(this)
|
||||
return signatureComposer.composeSignature(this, allowLocalClasses = true)
|
||||
?: error("Could not compose signature for ${this.renderWithType()}, looks like it is private or local")
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE
|
||||
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE_K1
|
||||
package test
|
||||
|
||||
enum class E {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE
|
||||
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE_K1
|
||||
|
||||
enum class MyEnumClass {
|
||||
FirstEntry {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE
|
||||
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE_K1
|
||||
|
||||
enum class MyEnumClass {
|
||||
FirstEntry {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE
|
||||
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE_K1
|
||||
|
||||
enum class MyEnumClass {
|
||||
FirstEntry {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE
|
||||
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE_K1
|
||||
|
||||
enum class Style(val value: String) {
|
||||
SHEET("foo") {
|
||||
override val exitAnimation: String
|
||||
|
||||
Reference in New Issue
Block a user