[FIR-IDE] Add DestructuringDeclarationEntry to SymbolProvider

This commit is contained in:
Kristoffer Andersen
2022-05-10 14:11:39 +02:00
committed by Ilya Kirillov
parent b6371a5b9a
commit 3af0e57406
11 changed files with 203 additions and 4 deletions
@@ -126,4 +126,8 @@ internal class KtFe10SymbolProvider(
.filter { it.name == name }
.mapNotNull { it.toKtSymbol(analysisContext) as? KtCallableSymbol }
}
override fun getDestructuringDeclarationEntrySymbol(psi: KtDestructuringDeclarationEntry): KtLocalVariableSymbol {
return KtFe10PsiLocalVariableSymbol(psi, analysisContext)
}
}
@@ -112,6 +112,12 @@ public class Fe10IdeNormalAnalysisSourceModuleSymbolByPsiTestGenerated extends A
runTest("analysis/analysis-api/testData/symbols/symbolByPsi/deprecated.kt");
}
@Test
@TestMetadata("destructuringDeclaration.kt")
public void testDestructuringDeclaration() throws Exception {
runTest("analysis/analysis-api/testData/symbols/symbolByPsi/destructuringDeclaration.kt");
}
@Test
@TestMetadata("dynamic.kt")
public void testDynamic() throws Exception {
@@ -122,14 +122,14 @@ internal class KtFirSymbolProvider(
// A KtClassOrObject may also map to an FirEnumEntry. Hence, we need to return null in this case.
if (psi is KtEnumEntry) return null
return firSymbolBuilder.classifierBuilder.buildNamedClassOrObjectSymbol(
psi.resolveToFirSymbolOfType<FirRegularClassSymbol>(firResolveSession)
)
psi.resolveToFirSymbolOfType<FirRegularClassSymbol>(firResolveSession))
}
override fun getPropertyAccessorSymbol(psi: KtPropertyAccessor): KtPropertyAccessorSymbol {
return firSymbolBuilder.callableBuilder.buildPropertyAccessorSymbol(
psi.resolveToFirSymbolOfType<FirPropertyAccessorSymbol>(firResolveSession)
)
psi.resolveToFirSymbolOfType<FirPropertyAccessorSymbol>(firResolveSession))
}
override fun getClassInitializerSymbol(psi: KtClassInitializer): KtClassInitializerSymbol {
@@ -149,4 +149,12 @@ internal class KtFirSymbolProvider(
}
override val ROOT_PACKAGE_SYMBOL: KtPackageSymbol = KtFirPackageSymbol(FqName.ROOT, firResolveSession.project, token)
override fun getDestructuringDeclarationEntrySymbol(psi: KtDestructuringDeclarationEntry): KtLocalVariableSymbol {
return firSymbolBuilder.variableLikeBuilder.buildLocalVariableSymbol(
psi.resolveToFirSymbolOfType<FirPropertySymbol>(
firResolveSession
)
)
}
}
@@ -112,6 +112,12 @@ public class FirIdeNormalAnalysisSourceModuleSymbolByPsiTestGenerated extends Ab
runTest("analysis/analysis-api/testData/symbols/symbolByPsi/deprecated.kt");
}
@Test
@TestMetadata("destructuringDeclaration.kt")
public void testDestructuringDeclaration() throws Exception {
runTest("analysis/analysis-api/testData/symbols/symbolByPsi/destructuringDeclaration.kt");
}
@Test
@TestMetadata("dynamic.kt")
public void testDynamic() throws Exception {
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.analysis.api.impl.base.test.cases.symbols
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
import org.jetbrains.kotlin.psi.KtBackingField
import org.jetbrains.kotlin.psi.KtDeclaration
import org.jetbrains.kotlin.psi.KtDestructuringDeclaration
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.psi.KtParameter
import org.jetbrains.kotlin.psi.psiUtil.collectDescendantsOfType
@@ -30,6 +31,7 @@ abstract class AbstractSymbolByPsiTest : AbstractSymbolTest() {
get() =
when (this) {
is KtBackingField -> false
is KtDestructuringDeclaration -> false
is KtParameter -> !this.isFunctionTypeParameter
else -> true
}
@@ -112,6 +112,12 @@ public class FirStandaloneNormalAnalysisSourceModuleSymbolByPsiTestGenerated ext
runTest("analysis/analysis-api/testData/symbols/symbolByPsi/deprecated.kt");
}
@Test
@TestMetadata("destructuringDeclaration.kt")
public void testDestructuringDeclaration() throws Exception {
runTest("analysis/analysis-api/testData/symbols/symbolByPsi/destructuringDeclaration.kt");
}
@Test
@TestMetadata("dynamic.kt")
public void testDynamic() throws Exception {
@@ -30,6 +30,7 @@ public abstract class KtSymbolProvider : KtAnalysisSessionComponent() {
}
is KtPropertyAccessor -> getPropertyAccessorSymbol(psi)
is KtClassInitializer -> getClassInitializerSymbol(psi)
is KtDestructuringDeclarationEntry -> getDestructuringDeclarationEntrySymbol(psi)
else -> error("Cannot build symbol for ${psi::class}")
}
@@ -48,6 +49,7 @@ public abstract class KtSymbolProvider : KtAnalysisSessionComponent() {
public abstract fun getNamedClassOrObjectSymbol(psi: KtClassOrObject): KtNamedClassOrObjectSymbol?
public abstract fun getPropertyAccessorSymbol(psi: KtPropertyAccessor): KtPropertyAccessorSymbol
public abstract fun getClassInitializerSymbol(psi: KtClassInitializer): KtClassInitializerSymbol
public abstract fun getDestructuringDeclarationEntrySymbol(psi: KtDestructuringDeclarationEntry): KtLocalVariableSymbol
public abstract fun getClassOrObjectSymbolByClassId(classId: ClassId): KtClassOrObjectSymbol?
@@ -133,6 +135,13 @@ public interface KtSymbolProviderMixIn : KtAnalysisSessionMixIn {
public fun FqName.getContainingCallableSymbolsWithName(name: Name): Sequence<KtSymbol> =
withValidityAssertion { analysisSession.symbolProvider.getTopLevelCallableSymbols(this, name) }
/**
* @return symbol corresponding to the local variable introduced by individual destructuring declaration entries.
* E.g. `val (x, y) = p` has two declaration entries, one corresponding to `x`, one to `y`.
*/
public fun KtDestructuringDeclarationEntry.getDestructuringDeclarationEntrySymbol(): KtLocalVariableSymbol =
analysisSession.symbolProvider.getDestructuringDeclarationEntrySymbol(this)
@Suppress("PropertyName")
public val ROOT_PACKAGE_SYMBOL: KtPackageSymbol
get() = withValidityAssertion { analysisSession.symbolProvider.ROOT_PACKAGE_SYMBOL }
@@ -0,0 +1,9 @@
fun destruct(): kotlin.Int
data class P {
constructor(x: kotlin.Int, y: kotlin.Int)
val x: kotlin.Int
val y: kotlin.Int
}
@@ -0,0 +1,6 @@
data class P(val x: Int, val y: Int)
fun destruct(): Int {
val (l, r) = P(1, 2)
return l + r
}
@@ -0,0 +1,15 @@
fun destruct(): kotlin.Int
class P {
constructor(x: kotlin.Int, y: kotlin.Int)
val x: kotlin.Int
val y: kotlin.Int
operator fun component1(): kotlin.Int
operator fun component2(): kotlin.Int
fun copy(x: kotlin.Int = ..., y: kotlin.Int = ...): P
}
@@ -0,0 +1,128 @@
KtValueParameterSymbol:
annotationsList: []
callableIdIfNonLocal: null
generatedPrimaryConstructorProperty: KtKotlinPropertySymbol(/P.x)
hasDefaultValue: false
isExtension: false
isImplicitLambdaParameter: false
isVararg: false
name: x
origin: SOURCE
receiverType: null
returnType: kotlin/Int
symbolKind: LOCAL
typeParameters: []
getContainingModule: KtSourceModule "Sources of main"
deprecationStatus: null
KtValueParameterSymbol:
annotationsList: []
callableIdIfNonLocal: null
generatedPrimaryConstructorProperty: KtKotlinPropertySymbol(/P.y)
hasDefaultValue: false
isExtension: false
isImplicitLambdaParameter: false
isVararg: false
name: y
origin: SOURCE
receiverType: null
returnType: kotlin/Int
symbolKind: LOCAL
typeParameters: []
getContainingModule: KtSourceModule "Sources of main"
deprecationStatus: null
KtConstructorSymbol:
annotationsList: []
callableIdIfNonLocal: null
containingClassIdIfNonLocal: P
hasStableParameterNames: true
isExtension: false
isPrimary: true
origin: SOURCE
receiverType: null
returnType: P
symbolKind: CLASS_MEMBER
typeParameters: []
valueParameters: [
KtValueParameterSymbol(x)
KtValueParameterSymbol(y)
]
visibility: Public
getContainingModule: KtSourceModule "Sources of main"
deprecationStatus: null
KtNamedClassOrObjectSymbol:
annotationsList: []
classIdIfNonLocal: P
classKind: CLASS
companionObject: null
isData: true
isExternal: false
isFun: false
isInline: false
isInner: false
modality: FINAL
name: P
origin: SOURCE
superTypes: [
kotlin/Any
]
symbolKind: TOP_LEVEL
typeParameters: []
visibility: Public
getContainingModule: KtSourceModule "Sources of main"
deprecationStatus: null
KtLocalVariableSymbol:
annotationsList: []
callableIdIfNonLocal: null
isExtension: false
isVal: true
name: l
origin: SOURCE
receiverType: null
returnType: kotlin/Int
symbolKind: LOCAL
typeParameters: []
getContainingModule: KtSourceModule "Sources of main"
deprecationStatus: null
KtLocalVariableSymbol:
annotationsList: []
callableIdIfNonLocal: null
isExtension: false
isVal: true
name: r
origin: SOURCE
receiverType: null
returnType: kotlin/Int
symbolKind: LOCAL
typeParameters: []
getContainingModule: KtSourceModule "Sources of main"
deprecationStatus: null
KtFunctionSymbol:
annotationsList: []
callableIdIfNonLocal: /destruct
hasStableParameterNames: true
isBuiltinFunctionInvoke: false
isExtension: false
isExternal: false
isInfix: false
isInline: false
isOperator: false
isOverride: false
isStatic: false
isSuspend: false
modality: FINAL
name: destruct
origin: SOURCE
receiverType: null
returnType: kotlin/Int
symbolKind: TOP_LEVEL
typeParameters: []
valueParameters: []
visibility: Public
getContainingModule: KtSourceModule "Sources of main"
deprecationStatus: null