From 11e94c1de1c7805823d58bde8a81c4bafd7d82a0 Mon Sep 17 00:00:00 2001 From: Ilya Kirillov Date: Thu, 5 Nov 2020 08:52:21 +0300 Subject: [PATCH] FIR IDE: fix building of local declaration symbols --- .../level/api/FirModuleResolveStateImpl.kt | 4 ++ .../symbolsByPsi/localDeclarations.kt | 69 +++++++++++++++++++ .../SymbolsByPsiBuildingTestGenerated.java | 5 ++ 3 files changed, 78 insertions(+) create mode 100644 idea/idea-frontend-fir/testData/symbolsByPsi/localDeclarations.kt diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/FirModuleResolveStateImpl.kt b/idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/FirModuleResolveStateImpl.kt index 3ffdd11f705..9ff93bb26a1 100644 --- a/idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/FirModuleResolveStateImpl.kt +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/FirModuleResolveStateImpl.kt @@ -97,6 +97,10 @@ internal class FirModuleResolveStateImpl( rootModuleSession.firIdeProvider.symbolProvider, sessionProvider.getModuleCache(ktDeclaration.getModuleInfo() as ModuleSourceInfo) ) + if (container.resolvePhase < FirResolvePhase.BODY_RESOLVE) { + val cache = (container.session as FirIdeSourcesSession).cache + firLazyDeclarationResolver.lazyResolveDeclaration(container, cache, FirResolvePhase.BODY_RESOLVE, checkPCE = false /*TODO*/) + } val firDeclaration = FirElementFinder.findElementIn(container) { firDeclaration -> firDeclaration.psi == ktDeclaration } diff --git a/idea/idea-frontend-fir/testData/symbolsByPsi/localDeclarations.kt b/idea/idea-frontend-fir/testData/symbolsByPsi/localDeclarations.kt new file mode 100644 index 00000000000..1eb884277e7 --- /dev/null +++ b/idea/idea-frontend-fir/testData/symbolsByPsi/localDeclarations.kt @@ -0,0 +1,69 @@ +fun yyy() { + val q = 10 + fun aaa() {} + + class F {} +} + +// SYMBOLS: +/* +KtFirLocalVariableSymbol: + isVal: true + name: q + origin: SOURCE + symbolKind: LOCAL + type: kotlin/Int + +KtFirFunctionSymbol: + annotations: [] + callableIdIfNonLocal: null + isExtension: false + isExternal: false + isInline: false + isOperator: false + isOverride: false + isSuspend: false + modality: FINAL + name: aaa + origin: SOURCE + receiverType: null + symbolKind: LOCAL + type: kotlin/Unit + typeParameters: [] + valueParameters: [] + visibility: LOCAL + +KtFirClassOrObjectSymbol: + annotations: [] + classIdIfNonLocal: null + classKind: CLASS + companionObject: null + isInner: false + modality: FINAL + name: F + origin: SOURCE + primaryConstructor: KtFirConstructorSymbol() + superTypes: [kotlin/Any] + symbolKind: LOCAL + typeParameters: [] + visibility: LOCAL + +KtFirFunctionSymbol: + annotations: [] + callableIdIfNonLocal: yyy + isExtension: false + isExternal: false + isInline: false + isOperator: false + isOverride: false + isSuspend: false + modality: FINAL + name: yyy + origin: SOURCE + receiverType: null + symbolKind: TOP_LEVEL + type: kotlin/Unit + typeParameters: [] + valueParameters: [] + visibility: PUBLIC +*/ diff --git a/idea/idea-frontend-fir/tests/org/jetbrains/kotlin/idea/frontend/api/symbols/SymbolsByPsiBuildingTestGenerated.java b/idea/idea-frontend-fir/tests/org/jetbrains/kotlin/idea/frontend/api/symbols/SymbolsByPsiBuildingTestGenerated.java index c9c56fa67b1..fa7930de2e2 100644 --- a/idea/idea-frontend-fir/tests/org/jetbrains/kotlin/idea/frontend/api/symbols/SymbolsByPsiBuildingTestGenerated.java +++ b/idea/idea-frontend-fir/tests/org/jetbrains/kotlin/idea/frontend/api/symbols/SymbolsByPsiBuildingTestGenerated.java @@ -67,4 +67,9 @@ public class SymbolsByPsiBuildingTestGenerated extends AbstractSymbolsByPsiBuild public void testImplicitReturn() throws Exception { runTest("idea/idea-frontend-fir/testData/symbolsByPsi/implicitReturn.kt"); } + + @TestMetadata("localDeclarations.kt") + public void testLocalDeclarations() throws Exception { + runTest("idea/idea-frontend-fir/testData/symbolsByPsi/localDeclarations.kt"); + } }