diff --git a/analysis/analysis-api-fe10/src/org/jetbrains/kotlin/analysis/api/descriptors/components/KtFe10ScopeProvider.kt b/analysis/analysis-api-fe10/src/org/jetbrains/kotlin/analysis/api/descriptors/components/KtFe10ScopeProvider.kt index 10e7d814e81..d416b589ed2 100644 --- a/analysis/analysis-api-fe10/src/org/jetbrains/kotlin/analysis/api/descriptors/components/KtFe10ScopeProvider.kt +++ b/analysis/analysis-api-fe10/src/org/jetbrains/kotlin/analysis/api/descriptors/components/KtFe10ScopeProvider.kt @@ -6,9 +6,7 @@ package org.jetbrains.kotlin.analysis.api.descriptors.components import com.intellij.openapi.diagnostic.Logger -import org.jetbrains.kotlin.analysis.api.components.KtImplicitReceiver -import org.jetbrains.kotlin.analysis.api.components.KtScopeContext -import org.jetbrains.kotlin.analysis.api.components.KtScopeProvider +import org.jetbrains.kotlin.analysis.api.components.* import org.jetbrains.kotlin.analysis.api.descriptors.KtFe10AnalysisSession import org.jetbrains.kotlin.analysis.api.descriptors.components.base.Fe10KtAnalysisSessionComponent import org.jetbrains.kotlin.analysis.api.descriptors.scopes.KtFe10FileScope @@ -200,15 +198,16 @@ internal class KtFe10ScopeProvider( val elementToAnalyze = positionInFakeFile.containingNonLocalDeclaration() ?: originalFile val bindingContext = analysisContext.analyze(elementToAnalyze) + val scopeKind = KtScopeKind.LocalScope(0) // TODO val lexicalScope = positionInFakeFile.getResolutionScope(bindingContext) if (lexicalScope != null) { val compositeScope = KtCompositeScope(listOf(KtFe10ScopeLexical(lexicalScope, analysisContext)), token) - return KtScopeContext(compositeScope, collectImplicitReceivers(lexicalScope), token) + return KtScopeContext(listOf(KtScopeWithKind(compositeScope, scopeKind, token)), collectImplicitReceivers(lexicalScope), token) } val fileScope = analysisContext.resolveSession.fileScopeProvider.getFileResolutionScope(originalFile) val compositeScope = KtCompositeScope(listOf(KtFe10ScopeLexical(fileScope, analysisContext)), token) - return KtScopeContext(compositeScope, collectImplicitReceivers(fileScope), token) + return KtScopeContext(listOf(KtScopeWithKind(compositeScope, scopeKind, token)), collectImplicitReceivers(fileScope), token) } private inline fun getDescriptor(symbol: KtSymbol): T? { @@ -225,7 +224,7 @@ internal class KtFe10ScopeProvider( private fun collectImplicitReceivers(scope: LexicalScope): MutableList { val result = mutableListOf() - for (implicitReceiver in scope.getImplicitReceiversHierarchy()) { + for ((index, implicitReceiver) in scope.getImplicitReceiversHierarchy().withIndex()) { val type = implicitReceiver.type.toKtType(analysisContext) val ownerDescriptor = implicitReceiver.containingDeclaration val owner = ownerDescriptor.toKtSymbol(analysisContext) @@ -235,7 +234,7 @@ internal class KtFe10ScopeProvider( continue } - result += KtImplicitReceiver(token, type, owner) + result += KtImplicitReceiver(token, type, owner, index) } return result diff --git a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/components/KtFirScopeProvider.kt b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/components/KtFirScopeProvider.kt index e85a39a71e7..0455db0f7e8 100644 --- a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/components/KtFirScopeProvider.kt +++ b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/components/KtFirScopeProvider.kt @@ -6,9 +6,7 @@ package org.jetbrains.kotlin.analysis.api.fir.components import com.intellij.openapi.project.Project -import org.jetbrains.kotlin.analysis.api.components.KtImplicitReceiver -import org.jetbrains.kotlin.analysis.api.components.KtScopeContext -import org.jetbrains.kotlin.analysis.api.components.KtScopeProvider +import org.jetbrains.kotlin.analysis.api.components.* import org.jetbrains.kotlin.analysis.api.fir.KtFirAnalysisSession import org.jetbrains.kotlin.analysis.api.fir.KtSymbolByFirBuilder import org.jetbrains.kotlin.analysis.api.fir.scopes.* @@ -28,6 +26,7 @@ import org.jetbrains.kotlin.analysis.api.symbols.KtPackageSymbol import org.jetbrains.kotlin.analysis.api.symbols.markers.KtSymbolWithMembers import org.jetbrains.kotlin.analysis.api.types.KtType import org.jetbrains.kotlin.analysis.low.level.api.fir.api.LLFirResolveSession +import org.jetbrains.kotlin.analysis.utils.errors.unexpectedElementError import org.jetbrains.kotlin.analysis.utils.printer.getElementTextInContext import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.declarations.FirClass @@ -142,7 +141,7 @@ internal class KtFirScopeProvider( } override fun getFileScope(fileSymbol: KtFileSymbol): KtScope { - check(fileSymbol is KtFirFileSymbol) { "KtFirScopeProvider can only work with KtFirFileSymbol, but ${fileSymbol::class} was provided" } + check(fileSymbol is KtFirFileSymbol) { "KtFirScopeProvider can only work with KtFirFileSymbol, but ${fileSymbol::class} was provided" } return KtFirFileScope(fileSymbol, builder) } @@ -178,31 +177,29 @@ internal class KtFirScopeProvider( val towerDataContext = analysisSession.firResolveSession.getTowerContextProvider(originalFile).getClosestAvailableParentContext(positionInFakeFile) ?: error("Cannot find enclosing declaration for ${positionInFakeFile.getElementTextInContext()}") + val towerDataElementsIndexed = towerDataContext.towerDataElements.asReversed().withIndex() - val implicitReceivers = towerDataContext.nonLocalTowerDataElements.mapNotNull { it.implicitReceiver }.distinct() - val implicitKtReceivers = implicitReceivers.map { receiver -> - KtImplicitReceiver( - token, - builder.typeBuilder.buildKtType(receiver.type), - builder.buildSymbol(receiver.boundSymbol.fir), - ) + val implicitReceivers = towerDataElementsIndexed.flatMap { (index, towerDataElement) -> + val receivers = listOfNotNull(towerDataElement.implicitReceiver) + towerDataElement.contextReceiverGroup.orEmpty() + + receivers.map { receiver -> + KtImplicitReceiver( + token, + builder.typeBuilder.buildKtType(receiver.type), + builder.buildSymbol(receiver.boundSymbol.fir), + index + ) + } } - val implicitReceiverScopes = implicitReceivers.mapNotNull { it.implicitScope } - val nonLocalScopes = towerDataContext.nonLocalTowerDataElements.mapNotNull { it.scope }.distinct() - val firLocalScopes = towerDataContext.localScopes - - val allKtScopes = buildList { - implicitReceiverScopes.mapTo(this, ::convertToKtScope) - nonLocalScopes.mapTo(this, ::convertToKtScope) - firLocalScopes.mapTo(this, ::convertToKtScope) + val firScopes = towerDataElementsIndexed.flatMap { (index, towerDataElement) -> + towerDataElement.getAvailableScopes().map { IndexedValue(index, it) } + } + val scopes = firScopes.map { (index, firScope) -> + KtScopeWithKind(convertToKtScope(firScope), getScopeKind(firScope, index), token) } - return KtScopeContext( - getCompositeScope(allKtScopes.asReversed()), - implicitKtReceivers.asReversed(), - token - ) + return KtScopeContext(scopes, implicitReceivers, token) } private fun convertToKtScope(firScope: FirScope): KtScope { @@ -215,6 +212,28 @@ internal class KtFirScopeProvider( } } + private fun getScopeKind(firScope: FirScope, indexInTower: Int): KtScopeKind = when (firScope) { + is FirNameAwareOnlyCallablesScope -> getScopeKind(firScope.delegate, indexInTower) + is FirNameAwareOnlyClassifiersScope -> getScopeKind(firScope.delegate, indexInTower) + + is FirLocalScope -> KtScopeKind.LocalScope(indexInTower) + is FirTypeScope -> KtScopeKind.SimpleTypeScope(indexInTower) + is FirTypeParameterScope -> KtScopeKind.TypeParameterScope(indexInTower) + is FirPackageMemberScope -> KtScopeKind.PackageMemberScope(indexInTower) + + is FirNestedClassifierScope -> KtScopeKind.StaticMemberScope(indexInTower) + is FirNestedClassifierScopeWithSubstitution -> KtScopeKind.StaticMemberScope(indexInTower) + is FirLazyNestedClassifierScope -> KtScopeKind.StaticMemberScope(indexInTower) + is FirStaticScope -> KtScopeKind.StaticMemberScope(indexInTower) + + is FirExplicitSimpleImportingScope -> KtScopeKind.ExplicitSimpleImportingScope(indexInTower) + is FirExplicitStarImportingScope -> KtScopeKind.ExplicitStarImportingScope(indexInTower) + is FirDefaultSimpleImportingScope -> KtScopeKind.DefaultSimpleImportingScope(indexInTower) + is FirDefaultStarImportingScope -> KtScopeKind.DefaultStarImportingScope(indexInTower) + + else -> unexpectedElementError("scope", firScope) + } + private fun createPackageScope(fqName: FqName): KtFirPackageScope { return KtFirPackageScope( fqName, diff --git a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/components/KtFirSymbolContainingDeclarationProvider.kt b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/components/KtFirSymbolContainingDeclarationProvider.kt index 2ae6c118a23..c1f8ce00d37 100644 --- a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/components/KtFirSymbolContainingDeclarationProvider.kt +++ b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/components/KtFirSymbolContainingDeclarationProvider.kt @@ -18,6 +18,7 @@ import org.jetbrains.kotlin.analysis.api.symbols.* import org.jetbrains.kotlin.analysis.api.symbols.markers.KtSymbolKind import org.jetbrains.kotlin.analysis.api.symbols.markers.KtSymbolWithKind import org.jetbrains.kotlin.analysis.low.level.api.fir.sessions.llFirSession +import org.jetbrains.kotlin.analysis.low.level.api.fir.util.originalDeclaration import org.jetbrains.kotlin.analysis.project.structure.KtModule import org.jetbrains.kotlin.analysis.utils.errors.buildErrorWithAttachment import org.jetbrains.kotlin.analysis.utils.printer.parentOfType @@ -113,5 +114,5 @@ internal class KtFirSymbolContainingDeclarationProvider( when (val container = this.parentOfType()) { is KtDestructuringDeclaration -> container.parentOfType() else -> container - } + }?.let { it.originalDeclaration ?: it } } diff --git a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/references/KDocReferenceResolver.kt b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/references/KDocReferenceResolver.kt index 022cdb4eb19..86a207675fd 100644 --- a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/references/KDocReferenceResolver.kt +++ b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/references/KDocReferenceResolver.kt @@ -50,7 +50,7 @@ internal object KDocReferenceResolver { context(KtAnalysisSession) private fun MutableCollection.collectSymbolsFromPositionScopes(owner: KtDeclaration, fqName: FqName) { - val initialScope = owner.containingKtFile.getScopeContextForPosition(owner).scopes + val initialScope = owner.containingKtFile.getScopeContextForPosition(owner).getCompositeScope() val scope = fqName.pathSegments() .dropLast(1) diff --git a/analysis/analysis-api-fir/tests-gen/org/jetbrains/kotlin/analysis/api/fir/test/cases/generated/cases/scopes/FirIdeDependentAnalysisSourceModuleScopeContextForPositionTestGenerated.java b/analysis/analysis-api-fir/tests-gen/org/jetbrains/kotlin/analysis/api/fir/test/cases/generated/cases/scopes/FirIdeDependentAnalysisSourceModuleScopeContextForPositionTestGenerated.java new file mode 100644 index 00000000000..6f3c33cacb5 --- /dev/null +++ b/analysis/analysis-api-fir/tests-gen/org/jetbrains/kotlin/analysis/api/fir/test/cases/generated/cases/scopes/FirIdeDependentAnalysisSourceModuleScopeContextForPositionTestGenerated.java @@ -0,0 +1,78 @@ +/* + * Copyright 2010-2023 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.test.cases.generated.cases.scopes; + +import com.intellij.testFramework.TestDataPath; +import org.jetbrains.kotlin.test.util.KtTestUtil; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.kotlin.analysis.api.fir.test.configurators.AnalysisApiFirTestConfiguratorFactory; +import org.jetbrains.kotlin.analysis.test.framework.test.configurators.AnalysisApiTestConfiguratorFactoryData; +import org.jetbrains.kotlin.analysis.test.framework.test.configurators.AnalysisApiTestConfigurator; +import org.jetbrains.kotlin.analysis.test.framework.test.configurators.TestModuleKind; +import org.jetbrains.kotlin.analysis.test.framework.test.configurators.FrontendKind; +import org.jetbrains.kotlin.analysis.test.framework.test.configurators.AnalysisSessionMode; +import org.jetbrains.kotlin.analysis.test.framework.test.configurators.AnalysisApiMode; +import org.jetbrains.kotlin.analysis.api.impl.base.test.cases.scopes.AbstractScopeContextForPositionTest; +import org.jetbrains.kotlin.test.TestMetadata; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; + +import java.io.File; +import java.util.regex.Pattern; + +/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.analysis.api.GenerateAnalysisApiTestsKt}. DO NOT MODIFY MANUALLY */ +@SuppressWarnings("all") +@TestMetadata("analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition") +@TestDataPath("$PROJECT_ROOT") +public class FirIdeDependentAnalysisSourceModuleScopeContextForPositionTestGenerated extends AbstractScopeContextForPositionTest { + @NotNull + @Override + public AnalysisApiTestConfigurator getConfigurator() { + return AnalysisApiFirTestConfiguratorFactory.INSTANCE.createConfigurator( + new AnalysisApiTestConfiguratorFactoryData( + FrontendKind.Fir, + TestModuleKind.Source, + AnalysisSessionMode.Dependent, + AnalysisApiMode.Ide + ) + ); + } + + @Test + public void testAllFilesPresentInScopeContextForPosition() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition"), Pattern.compile("^(.+)\\.kt$"), null, true); + } + + @Test + @TestMetadata("contextReceiver.kt") + public void testContextReceiver() throws Exception { + runTest("analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/contextReceiver.kt"); + } + + @Test + @TestMetadata("enumEntry.kt") + public void testEnumEntry() throws Exception { + runTest("analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/enumEntry.kt"); + } + + @Test + @TestMetadata("errorType.kt") + public void testErrorType() throws Exception { + runTest("analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/errorType.kt"); + } + + @Test + @TestMetadata("localTypeScope.kt") + public void testLocalTypeScope() throws Exception { + runTest("analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/localTypeScope.kt"); + } + + @Test + @TestMetadata("simpleScopeContextForPosition.kt") + public void testSimpleScopeContextForPosition() throws Exception { + runTest("analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/simpleScopeContextForPosition.kt"); + } +} diff --git a/analysis/analysis-api-fir/tests-gen/org/jetbrains/kotlin/analysis/api/fir/test/cases/generated/cases/scopes/FirIdeNormalAnalysisSourceModuleScopeContextForPositionTestGenerated.java b/analysis/analysis-api-fir/tests-gen/org/jetbrains/kotlin/analysis/api/fir/test/cases/generated/cases/scopes/FirIdeNormalAnalysisSourceModuleScopeContextForPositionTestGenerated.java new file mode 100644 index 00000000000..3d88c1f14ed --- /dev/null +++ b/analysis/analysis-api-fir/tests-gen/org/jetbrains/kotlin/analysis/api/fir/test/cases/generated/cases/scopes/FirIdeNormalAnalysisSourceModuleScopeContextForPositionTestGenerated.java @@ -0,0 +1,78 @@ +/* + * Copyright 2010-2023 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.test.cases.generated.cases.scopes; + +import com.intellij.testFramework.TestDataPath; +import org.jetbrains.kotlin.test.util.KtTestUtil; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.kotlin.analysis.api.fir.test.configurators.AnalysisApiFirTestConfiguratorFactory; +import org.jetbrains.kotlin.analysis.test.framework.test.configurators.AnalysisApiTestConfiguratorFactoryData; +import org.jetbrains.kotlin.analysis.test.framework.test.configurators.AnalysisApiTestConfigurator; +import org.jetbrains.kotlin.analysis.test.framework.test.configurators.TestModuleKind; +import org.jetbrains.kotlin.analysis.test.framework.test.configurators.FrontendKind; +import org.jetbrains.kotlin.analysis.test.framework.test.configurators.AnalysisSessionMode; +import org.jetbrains.kotlin.analysis.test.framework.test.configurators.AnalysisApiMode; +import org.jetbrains.kotlin.analysis.api.impl.base.test.cases.scopes.AbstractScopeContextForPositionTest; +import org.jetbrains.kotlin.test.TestMetadata; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; + +import java.io.File; +import java.util.regex.Pattern; + +/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.analysis.api.GenerateAnalysisApiTestsKt}. DO NOT MODIFY MANUALLY */ +@SuppressWarnings("all") +@TestMetadata("analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition") +@TestDataPath("$PROJECT_ROOT") +public class FirIdeNormalAnalysisSourceModuleScopeContextForPositionTestGenerated extends AbstractScopeContextForPositionTest { + @NotNull + @Override + public AnalysisApiTestConfigurator getConfigurator() { + return AnalysisApiFirTestConfiguratorFactory.INSTANCE.createConfigurator( + new AnalysisApiTestConfiguratorFactoryData( + FrontendKind.Fir, + TestModuleKind.Source, + AnalysisSessionMode.Normal, + AnalysisApiMode.Ide + ) + ); + } + + @Test + public void testAllFilesPresentInScopeContextForPosition() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition"), Pattern.compile("^(.+)\\.kt$"), null, true); + } + + @Test + @TestMetadata("contextReceiver.kt") + public void testContextReceiver() throws Exception { + runTest("analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/contextReceiver.kt"); + } + + @Test + @TestMetadata("enumEntry.kt") + public void testEnumEntry() throws Exception { + runTest("analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/enumEntry.kt"); + } + + @Test + @TestMetadata("errorType.kt") + public void testErrorType() throws Exception { + runTest("analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/errorType.kt"); + } + + @Test + @TestMetadata("localTypeScope.kt") + public void testLocalTypeScope() throws Exception { + runTest("analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/localTypeScope.kt"); + } + + @Test + @TestMetadata("simpleScopeContextForPosition.kt") + public void testSimpleScopeContextForPosition() throws Exception { + runTest("analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/simpleScopeContextForPosition.kt"); + } +} diff --git a/analysis/analysis-api-impl-base/tests/org/jetbrains/kotlin/analysis/api/impl/base/test/cases/scopes/AbstractScopeContextForPositionTest.kt b/analysis/analysis-api-impl-base/tests/org/jetbrains/kotlin/analysis/api/impl/base/test/cases/scopes/AbstractScopeContextForPositionTest.kt new file mode 100644 index 00000000000..4c8cebf95f0 --- /dev/null +++ b/analysis/analysis-api-impl-base/tests/org/jetbrains/kotlin/analysis/api/impl/base/test/cases/scopes/AbstractScopeContextForPositionTest.kt @@ -0,0 +1,117 @@ +/* + * Copyright 2010-2023 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.impl.base.test.cases.scopes + +import org.jetbrains.kotlin.analysis.api.KtAnalysisSession +import org.jetbrains.kotlin.analysis.api.components.KtScopeContext +import org.jetbrains.kotlin.analysis.api.components.KtScopeKind +import org.jetbrains.kotlin.analysis.api.renderer.base.annotations.KtRendererAnnotationsFilter +import org.jetbrains.kotlin.analysis.api.renderer.declarations.impl.KtDeclarationRendererForSource +import org.jetbrains.kotlin.analysis.api.renderer.declarations.modifiers.renderers.KtRendererModifierFilter +import org.jetbrains.kotlin.analysis.api.renderer.types.impl.KtTypeRendererForSource +import org.jetbrains.kotlin.analysis.api.renderer.types.renderers.KtTypeErrorTypeRenderer +import org.jetbrains.kotlin.analysis.api.scopes.KtScope +import org.jetbrains.kotlin.analysis.api.symbols.DebugSymbolRenderer +import org.jetbrains.kotlin.analysis.api.symbols.KtDeclarationSymbol +import org.jetbrains.kotlin.analysis.api.types.KtType +import org.jetbrains.kotlin.analysis.test.framework.base.AbstractAnalysisApiBasedSingleModuleTest +import org.jetbrains.kotlin.analysis.test.framework.services.expressionMarkerProvider +import org.jetbrains.kotlin.analysis.utils.printer.prettyPrint +import org.jetbrains.kotlin.psi.KtElement +import org.jetbrains.kotlin.psi.KtFile +import org.jetbrains.kotlin.test.model.TestModule +import org.jetbrains.kotlin.test.services.TestServices +import org.jetbrains.kotlin.test.services.assertions + +abstract class AbstractScopeContextForPositionTest : AbstractAnalysisApiBasedSingleModuleTest() { + override fun doTestByFileStructure(ktFiles: List, module: TestModule, testServices: TestServices) { + val ktFile = ktFiles.first() + val element = testServices.expressionMarkerProvider.getSelectedElementOfType(ktFile) + + analyseForTest(element) { elementToAnalyze -> + val scopeContext = ktFile.getScopeContextForPosition(elementToAnalyze) + + val scopeContextStringRepresentation = renderForTests(elementToAnalyze, scopeContext) + val scopeContextStringRepresentationPretty = renderForTests(elementToAnalyze, scopeContext, printPretty = true) + + testServices.assertions.assertEqualsToTestDataFileSibling(scopeContextStringRepresentation) + testServices.assertions.assertEqualsToTestDataFileSibling(scopeContextStringRepresentationPretty, extension = ".pretty.txt") + } + } + + private fun KtAnalysisSession.renderForTests( + element: KtElement, + scopeContext: KtScopeContext, + printPretty: Boolean = false + ): String = prettyPrint { + appendLine("element: ${element.text}") + appendLine("implicit receivers:") + + withIndent { + for (implicitReceiver in scopeContext.implicitReceivers) { + val type = implicitReceiver.type + appendLine("type: ${renderType(type, printPretty)}") + appendLine("owner symbol: ${implicitReceiver.ownerSymbol::class.simpleName}") + appendLine() + } + } + appendLine("scopes:") + withIndent { + for (scopeWithKind in scopeContext.scopes) { + appendLine(renderForTests(scopeWithKind.scope, scopeWithKind.kind, printPretty)) + } + } + } + + private fun KtAnalysisSession.renderForTests(scope: KtScope, scopeKind: KtScopeKind, printPretty: Boolean): String = prettyPrint { + append("${scopeKind::class.simpleName}, index = ${scopeKind.indexInTower}") + + if (scopeKind is KtScopeKind.DefaultSimpleImportingScope || scopeKind is KtScopeKind.DefaultStarImportingScope) { + appendLine() + return@prettyPrint + } + + val callables = scope.getCallableSymbols().toList() + val classifiers = scope.getClassifierSymbols().toList() + val isEmpty = callables.isEmpty() && classifiers.isEmpty() + if (isEmpty) { + appendLine(", empty") + } else { + appendLine() + withIndent { + appendLine("classifiers: ${classifiers.size}") + withIndent { classifiers.forEach { appendLine(renderSymbol(it, printPretty)) } } + appendLine("callables: ${callables.size}") + withIndent { callables.forEach { appendLine(renderSymbol(it, printPretty)) } } + } + } + } + + private fun KtAnalysisSession.renderType( + type: KtType, + printPretty: Boolean + ): String = prettyPrint { + if (printPretty) prettyPrintTypeRenderer.renderType(type, this) else append(debugRenderer.renderType(type)) + } + + + private fun KtAnalysisSession.renderSymbol( + symbol: KtDeclarationSymbol, + printPretty: Boolean + ): String = if (printPretty) symbol.render(prettyPrintSymbolRenderer) else debugRenderer.render(symbol) + + companion object { + private val debugRenderer = DebugSymbolRenderer() + + private val prettyPrintTypeRenderer = KtTypeRendererForSource.WITH_QUALIFIED_NAMES.with { + typeErrorTypeRenderer = KtTypeErrorTypeRenderer.WITH_ERROR_MESSAGE + } + private val prettyPrintSymbolRenderer = KtDeclarationRendererForSource.WITH_QUALIFIED_NAMES.with { + annotationRenderer = annotationRenderer.with { annotationFilter = KtRendererAnnotationsFilter.NONE } + modifiersRenderer = modifiersRenderer.with { modifierFilter = KtRendererModifierFilter.NONE } + } + } +} diff --git a/analysis/analysis-api-standalone/tests-gen/org/jetbrains/kotlin/analysis/api/standalone/fir/test/cases/generated/cases/scopes/FirStandaloneNormalAnalysisSourceModuleScopeContextForPositionTestGenerated.java b/analysis/analysis-api-standalone/tests-gen/org/jetbrains/kotlin/analysis/api/standalone/fir/test/cases/generated/cases/scopes/FirStandaloneNormalAnalysisSourceModuleScopeContextForPositionTestGenerated.java new file mode 100644 index 00000000000..cc5c7c6505a --- /dev/null +++ b/analysis/analysis-api-standalone/tests-gen/org/jetbrains/kotlin/analysis/api/standalone/fir/test/cases/generated/cases/scopes/FirStandaloneNormalAnalysisSourceModuleScopeContextForPositionTestGenerated.java @@ -0,0 +1,78 @@ +/* + * Copyright 2010-2023 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.standalone.fir.test.cases.generated.cases.scopes; + +import com.intellij.testFramework.TestDataPath; +import org.jetbrains.kotlin.test.util.KtTestUtil; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.kotlin.analysis.api.standalone.fir.test.AnalysisApiFirStandaloneModeTestConfiguratorFactory; +import org.jetbrains.kotlin.analysis.test.framework.test.configurators.AnalysisApiTestConfiguratorFactoryData; +import org.jetbrains.kotlin.analysis.test.framework.test.configurators.AnalysisApiTestConfigurator; +import org.jetbrains.kotlin.analysis.test.framework.test.configurators.TestModuleKind; +import org.jetbrains.kotlin.analysis.test.framework.test.configurators.FrontendKind; +import org.jetbrains.kotlin.analysis.test.framework.test.configurators.AnalysisSessionMode; +import org.jetbrains.kotlin.analysis.test.framework.test.configurators.AnalysisApiMode; +import org.jetbrains.kotlin.analysis.api.impl.base.test.cases.scopes.AbstractScopeContextForPositionTest; +import org.jetbrains.kotlin.test.TestMetadata; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; + +import java.io.File; +import java.util.regex.Pattern; + +/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.analysis.api.GenerateAnalysisApiTestsKt}. DO NOT MODIFY MANUALLY */ +@SuppressWarnings("all") +@TestMetadata("analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition") +@TestDataPath("$PROJECT_ROOT") +public class FirStandaloneNormalAnalysisSourceModuleScopeContextForPositionTestGenerated extends AbstractScopeContextForPositionTest { + @NotNull + @Override + public AnalysisApiTestConfigurator getConfigurator() { + return AnalysisApiFirStandaloneModeTestConfiguratorFactory.INSTANCE.createConfigurator( + new AnalysisApiTestConfiguratorFactoryData( + FrontendKind.Fir, + TestModuleKind.Source, + AnalysisSessionMode.Normal, + AnalysisApiMode.Standalone + ) + ); + } + + @Test + public void testAllFilesPresentInScopeContextForPosition() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition"), Pattern.compile("^(.+)\\.kt$"), null, true); + } + + @Test + @TestMetadata("contextReceiver.kt") + public void testContextReceiver() throws Exception { + runTest("analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/contextReceiver.kt"); + } + + @Test + @TestMetadata("enumEntry.kt") + public void testEnumEntry() throws Exception { + runTest("analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/enumEntry.kt"); + } + + @Test + @TestMetadata("errorType.kt") + public void testErrorType() throws Exception { + runTest("analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/errorType.kt"); + } + + @Test + @TestMetadata("localTypeScope.kt") + public void testLocalTypeScope() throws Exception { + runTest("analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/localTypeScope.kt"); + } + + @Test + @TestMetadata("simpleScopeContextForPosition.kt") + public void testSimpleScopeContextForPosition() throws Exception { + runTest("analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/simpleScopeContextForPosition.kt"); + } +} diff --git a/analysis/analysis-api/src/org/jetbrains/kotlin/analysis/api/components/KtScopeProvider.kt b/analysis/analysis-api/src/org/jetbrains/kotlin/analysis/api/components/KtScopeProvider.kt index fa87e38a14a..975cff729c3 100644 --- a/analysis/analysis-api/src/org/jetbrains/kotlin/analysis/api/components/KtScopeProvider.kt +++ b/analysis/analysis-api/src/org/jetbrains/kotlin/analysis/api/components/KtScopeProvider.kt @@ -105,28 +105,124 @@ public interface KtScopeProviderMixIn : KtAnalysisSessionMixIn { /** * Scopes in returned [KtScopeContext] don't include synthetic Java properties. * To get such properties use [getSyntheticJavaPropertiesScope]. + * + * For each scope in [KtScopeContext] an index is calculated. The indexes are relative to position, and they are only known for + * scopes obtained with [getScopeContextForPosition]. */ public fun KtFile.getScopeContextForPosition(positionInFakeFile: KtElement): KtScopeContext = withValidityAssertion { analysisSession.scopeProvider.getScopeContextForPosition(this, positionInFakeFile) } public fun KtFile.getScopeContextForFile(): KtScopeContext = withValidityAssertion { analysisSession.scopeProvider.getScopeContextForPosition(this, this) } + + /** + * Returns single scope, containing declarations from all scopes that satisfy [filter]. The order of declarations corresponds to the + * order of their containing scopes, which are sorted according to their indexes in scope tower. + */ + public fun KtScopeContext.getCompositeScope(filter: (KtScopeKind) -> Boolean = { true }): KtScope = withValidityAssertion { + val subScopes = scopes.filter { filter(it.kind) }.map { it.scope } + subScopes.asCompositeScope() + } } public class KtScopeContext( - private val _scopes: KtScope, + private val _scopes: List, private val _implicitReceivers: List, override val token: KtLifetimeToken ) : KtLifetimeOwner { public val implicitReceivers: List get() = withValidityAssertion { _implicitReceivers } - public val scopes: KtScope get() = withValidityAssertion { _scopes } + + /** + * Scopes for position, sorted according to their indexes in scope tower, i.e. the first scope is the closest one to position. + */ + public val scopes: List get() = withValidityAssertion { _scopes } } public class KtImplicitReceiver( override val token: KtLifetimeToken, private val _type: KtType, - private val _ownerSymbol: KtSymbol + private val _ownerSymbol: KtSymbol, + private val _receiverScopeIndexInTower: Int ) : KtLifetimeOwner { public val ownerSymbol: KtSymbol get() = withValidityAssertion { _ownerSymbol } public val type: KtType get() = withValidityAssertion { _type } + public val scopeIndexInTower: Int get() = withValidityAssertion { _receiverScopeIndexInTower } +} + + +public sealed class KtScopeKind { + /** + * Index in scope tower. For example: + * ``` + * fun f(a: A, b: B) { // local scope: indexInTower = 2 + * with(a) { // type scope for A: indexInTower = 1 + * with(b) { // type scope for B: indexInTower = 0 + * + * } + * } + * } + * ``` + */ + public abstract val indexInTower: Int + + public class LocalScope(override val indexInTower: Int) : KtScopeKind() + + public sealed class TypeScope : KtScopeKind() + + /** + * Represents [KtTypeScope], which doesn't include synthetic Java properties of corresponding type. + */ + public class SimpleTypeScope(override val indexInTower: Int) : TypeScope() + public class SyntheticJavaPropertiesScope(override val indexInTower: Int) : TypeScope() + + public sealed class NonLocalScope : KtScopeKind() + + /** + * Represents [KtScope] containing type parameters. + */ + public class TypeParameterScope(override val indexInTower: Int) : NonLocalScope() + + /** + * Represents [KtScope] containing declarations from package. + */ + public class PackageMemberScope(override val indexInTower: Int) : NonLocalScope() + + /** + * Represents [KtScope] containing declarations from imports. + */ + public sealed class ImportingScope : NonLocalScope() + + /** + * Represents [KtScope] containing declarations from explicit non-star imports. + */ + public class ExplicitSimpleImportingScope(override val indexInTower: Int) : ImportingScope() + + /** + * Represents [KtScope] containing declarations from explicit star imports. + */ + public class ExplicitStarImportingScope(override val indexInTower: Int) : ImportingScope() + + /** + * Represents [KtScope] containing declarations from non-star imports which are not declared explicitly and are added by default. + */ + public class DefaultSimpleImportingScope(override val indexInTower: Int) : ImportingScope() + + /** + * Represents [KtScope] containing declarations from star imports which are not declared explicitly and are added by default. + */ + public class DefaultStarImportingScope(override val indexInTower: Int) : ImportingScope() + + /** + * Represents [KtScope] containing static members of a classifier. + */ + public class StaticMemberScope(override val indexInTower: Int) : NonLocalScope() +} + +public data class KtScopeWithKind( + private val _scope: KtScope, + private val _kind: KtScopeKind, + override val token: KtLifetimeToken +) : KtLifetimeOwner { + public val scope: KtScope get() = withValidityAssertion { _scope } + public val kind: KtScopeKind get() = withValidityAssertion { _kind } } diff --git a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/contextReceiver.kt b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/contextReceiver.kt new file mode 100644 index 00000000000..39b10ebb087 --- /dev/null +++ b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/contextReceiver.kt @@ -0,0 +1,7 @@ +class Context { + fun memberInContext() {} +} +context(Context) +fun test() { + e +} \ No newline at end of file diff --git a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/contextReceiver.pretty.txt b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/contextReceiver.pretty.txt new file mode 100644 index 00000000000..cc70b142e54 --- /dev/null +++ b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/contextReceiver.pretty.txt @@ -0,0 +1,38 @@ +element: e +implicit receivers: + type: Context + owner symbol: KtFirFunctionSymbol + +scopes: + LocalScope, index = 0, empty + + SimpleTypeScope, index = 1 + classifiers: 0 + callables: 4 + fun memberInContext() + fun equals(other: kotlin.Any?): kotlin.Boolean + fun hashCode(): kotlin.Int + fun toString(): kotlin.String + + LocalScope, index = 2, empty + + ExplicitSimpleImportingScope, index = 3, empty + + PackageMemberScope, index = 4 + classifiers: 1 + class Context + callables: 1 + context(Context) + fun test() + + DefaultSimpleImportingScope, index = 5 + + DefaultSimpleImportingScope, index = 6 + + ExplicitStarImportingScope, index = 7, empty + + DefaultSimpleImportingScope, index = 8 + + DefaultStarImportingScope, index = 9 + + DefaultStarImportingScope, index = 10 diff --git a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/contextReceiver.txt b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/contextReceiver.txt new file mode 100644 index 00000000000..6c581382e33 --- /dev/null +++ b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/contextReceiver.txt @@ -0,0 +1,220 @@ +element: e +implicit receivers: + type: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: Context + owner symbol: KtFirFunctionSymbol + +scopes: + LocalScope, index = 0, empty + + SimpleTypeScope, index = 1 + classifiers: 0 + callables: 4 + KtFunctionSymbol: + annotationsList: [] + callableIdIfNonLocal: /Context.memberInContext + contextReceivers: [] + contractEffects: [] + hasStableParameterNames: true + isBuiltinFunctionInvoke: false + isExtension: false + isExternal: false + isInfix: false + isInline: false + isOperator: false + isOverride: false + isStatic: false + isSuspend: false + modality: FINAL + name: memberInContext + origin: SOURCE + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Unit + symbolKind: CLASS_MEMBER + typeParameters: [] + valueParameters: [] + visibility: Public + KtFunctionSymbol: + annotationsList: [] + callableIdIfNonLocal: kotlin/Any.equals + contextReceivers: [] + contractEffects: [] + hasStableParameterNames: true + isBuiltinFunctionInvoke: false + isExtension: false + isExternal: false + isInfix: false + isInline: false + isOperator: true + isOverride: false + isStatic: false + isSuspend: false + modality: OPEN + name: equals + origin: LIBRARY + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Boolean + symbolKind: CLASS_MEMBER + typeParameters: [] + valueParameters: [ + KtValueParameterSymbol: + annotationsList: [] + callableIdIfNonLocal: null + contextReceivers: [] + generatedPrimaryConstructorProperty: null + hasDefaultValue: false + isCrossinline: false + isExtension: false + isImplicitLambdaParameter: false + isNoinline: false + isVararg: false + name: other + origin: LIBRARY + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Any? + symbolKind: LOCAL + typeParameters: [] + ] + visibility: Public + KtFunctionSymbol: + annotationsList: [] + callableIdIfNonLocal: kotlin/Any.hashCode + contextReceivers: [] + contractEffects: [] + hasStableParameterNames: true + isBuiltinFunctionInvoke: false + isExtension: false + isExternal: false + isInfix: false + isInline: false + isOperator: false + isOverride: false + isStatic: false + isSuspend: false + modality: OPEN + name: hashCode + origin: LIBRARY + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Int + symbolKind: CLASS_MEMBER + typeParameters: [] + valueParameters: [] + visibility: Public + KtFunctionSymbol: + annotationsList: [] + callableIdIfNonLocal: kotlin/Any.toString + contextReceivers: [] + contractEffects: [] + hasStableParameterNames: true + isBuiltinFunctionInvoke: false + isExtension: false + isExternal: false + isInfix: false + isInline: false + isOperator: false + isOverride: false + isStatic: false + isSuspend: false + modality: OPEN + name: toString + origin: LIBRARY + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/String + symbolKind: CLASS_MEMBER + typeParameters: [] + valueParameters: [] + visibility: Public + + LocalScope, index = 2, empty + + ExplicitSimpleImportingScope, index = 3, empty + + PackageMemberScope, index = 4 + classifiers: 1 + KtNamedClassOrObjectSymbol: + annotationsList: [] + classIdIfNonLocal: Context + classKind: CLASS + companionObject: null + contextReceivers: [] + isData: false + isExternal: false + isFun: false + isInline: false + isInner: false + modality: FINAL + name: Context + origin: SOURCE + superTypes: [ + KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Any + ] + symbolKind: TOP_LEVEL + typeParameters: [] + visibility: Public + callables: 1 + KtFunctionSymbol: + annotationsList: [] + callableIdIfNonLocal: /test + contextReceivers: [ + KtContextReceiver: + label: null + type: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: Context + ] + contractEffects: [] + hasStableParameterNames: true + isBuiltinFunctionInvoke: false + isExtension: false + isExternal: false + isInfix: false + isInline: false + isOperator: false + isOverride: false + isStatic: false + isSuspend: false + modality: FINAL + name: test + origin: SOURCE + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Unit + symbolKind: TOP_LEVEL + typeParameters: [] + valueParameters: [] + visibility: Public + + DefaultSimpleImportingScope, index = 5 + + DefaultSimpleImportingScope, index = 6 + + ExplicitStarImportingScope, index = 7, empty + + DefaultSimpleImportingScope, index = 8 + + DefaultStarImportingScope, index = 9 + + DefaultStarImportingScope, index = 10 diff --git a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/enumEntry.kt b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/enumEntry.kt new file mode 100644 index 00000000000..1abbb5f2c57 --- /dev/null +++ b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/enumEntry.kt @@ -0,0 +1,8 @@ +enum class E { + A { + val x: String = "" + fun foo() { + e + } + } +} diff --git a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/enumEntry.pretty.txt b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/enumEntry.pretty.txt new file mode 100644 index 00000000000..102edd43142 --- /dev/null +++ b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/enumEntry.pretty.txt @@ -0,0 +1,65 @@ +element: e +implicit receivers: + type: `` + owner symbol: KtFirAnonymousObjectSymbol + + type: kotlin.Enum.Companion + owner symbol: KtFirNamedClassOrObjectSymbol + +scopes: + LocalScope, index = 0, empty + + LocalScope, index = 1, empty + + SimpleTypeScope, index = 2 + classifiers: 1 + companion object + callables: 9 + val x: kotlin.String + fun foo() + fun clone(): kotlin.Any + fun compareTo(other: E): kotlin.Int + fun equals(other: kotlin.Any?): kotlin.Boolean + fun hashCode(): kotlin.Int + fun toString(): kotlin.String + val name: kotlin.String + val ordinal: kotlin.Int + + StaticMemberScope, index = 3 + classifiers: 0 + callables: 4 + A + fun values(): kotlin.Array + fun valueOf(value: kotlin.String): E + val entries: kotlin.enums.EnumEntries + + StaticMemberScope, index = 4 + classifiers: 1 + companion object + callables: 0 + + SimpleTypeScope, index = 5 + classifiers: 0 + callables: 3 + fun equals(other: kotlin.Any?): kotlin.Boolean + fun hashCode(): kotlin.Int + fun toString(): kotlin.String + + ExplicitSimpleImportingScope, index = 6, empty + + PackageMemberScope, index = 7 + classifiers: 1 + enum class E + callables: 0 + + DefaultSimpleImportingScope, index = 8 + + DefaultSimpleImportingScope, index = 9 + + ExplicitStarImportingScope, index = 10, empty + + DefaultSimpleImportingScope, index = 11 + + DefaultStarImportingScope, index = 12 + + DefaultStarImportingScope, index = 13 diff --git a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/enumEntry.txt b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/enumEntry.txt new file mode 100644 index 00000000000..9c50c587cce --- /dev/null +++ b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/enumEntry.txt @@ -0,0 +1,736 @@ +element: e +implicit receivers: + type: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: + owner symbol: KtFirAnonymousObjectSymbol + + type: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Enum.Companion + owner symbol: KtFirNamedClassOrObjectSymbol + +scopes: + LocalScope, index = 0, empty + + LocalScope, index = 1, empty + + SimpleTypeScope, index = 2 + classifiers: 1 + KtNamedClassOrObjectSymbol: + annotationsList: [] + classIdIfNonLocal: kotlin/Enum.Companion + classKind: COMPANION_OBJECT + companionObject: null + contextReceivers: [] + isData: false + isExternal: false + isFun: false + isInline: false + isInner: false + modality: FINAL + name: Companion + origin: LIBRARY + superTypes: [ + KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Any + ] + symbolKind: CLASS_MEMBER + typeParameters: [] + visibility: Public + callables: 9 + KtKotlinPropertySymbol: + annotationsList: [] + callableIdIfNonLocal: null + contextReceivers: [] + getter: KtPropertyGetterSymbol: + annotationsList: [] + callableIdIfNonLocal: null + contextReceivers: [] + hasBody: false + hasStableParameterNames: true + isDefault: true + isExtension: false + isInline: false + isOverride: false + modality: FINAL + origin: SOURCE + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/String + symbolKind: ACCESSOR + typeParameters: [] + valueParameters: [] + visibility: Public + hasBackingField: true + hasGetter: true + hasSetter: false + initializer: KtConstantInitializerValue("") + isConst: false + isDelegatedProperty: false + isExtension: false + isFromPrimaryConstructor: false + isLateInit: false + isOverride: false + isStatic: false + isVal: true + modality: FINAL + name: x + origin: SOURCE + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/String + setter: null + symbolKind: CLASS_MEMBER + typeParameters: [] + visibility: Public + KtFunctionSymbol: + annotationsList: [] + callableIdIfNonLocal: null + contextReceivers: [] + contractEffects: [] + hasStableParameterNames: true + isBuiltinFunctionInvoke: false + isExtension: false + isExternal: false + isInfix: false + isInline: false + isOperator: false + isOverride: false + isStatic: false + isSuspend: false + modality: FINAL + name: foo + origin: SOURCE + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Unit + symbolKind: CLASS_MEMBER + typeParameters: [] + valueParameters: [] + visibility: Public + KtFunctionSymbol: + annotationsList: [] + callableIdIfNonLocal: kotlin/Enum.clone + contextReceivers: [] + contractEffects: [] + hasStableParameterNames: true + isBuiltinFunctionInvoke: false + isExtension: false + isExternal: false + isInfix: false + isInline: false + isOperator: false + isOverride: false + isStatic: false + isSuspend: false + modality: FINAL + name: clone + origin: LIBRARY + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Any + symbolKind: CLASS_MEMBER + typeParameters: [] + valueParameters: [] + visibility: Protected + KtFunctionSymbol: + annotationsList: [] + callableIdIfNonLocal: /E.compareTo + contextReceivers: [] + contractEffects: [] + hasStableParameterNames: true + isBuiltinFunctionInvoke: false + isExtension: false + isExternal: false + isInfix: false + isInline: false + isOperator: true + isOverride: false + isStatic: false + isSuspend: false + modality: FINAL + name: compareTo + origin: SUBSTITUTION_OVERRIDE + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Int + symbolKind: CLASS_MEMBER + typeParameters: [] + valueParameters: [ + KtValueParameterSymbol: + annotationsList: [] + callableIdIfNonLocal: null + contextReceivers: [] + generatedPrimaryConstructorProperty: null + hasDefaultValue: false + isCrossinline: false + isExtension: false + isImplicitLambdaParameter: false + isNoinline: false + isVararg: false + name: other + origin: SUBSTITUTION_OVERRIDE + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: E + symbolKind: LOCAL + typeParameters: [] + ] + visibility: Public + KtFunctionSymbol: + annotationsList: [] + callableIdIfNonLocal: kotlin/Enum.equals + contextReceivers: [] + contractEffects: [] + hasStableParameterNames: true + isBuiltinFunctionInvoke: false + isExtension: false + isExternal: false + isInfix: false + isInline: false + isOperator: true + isOverride: false + isStatic: false + isSuspend: false + modality: FINAL + name: equals + origin: LIBRARY + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Boolean + symbolKind: CLASS_MEMBER + typeParameters: [] + valueParameters: [ + KtValueParameterSymbol: + annotationsList: [] + callableIdIfNonLocal: null + contextReceivers: [] + generatedPrimaryConstructorProperty: null + hasDefaultValue: false + isCrossinline: false + isExtension: false + isImplicitLambdaParameter: false + isNoinline: false + isVararg: false + name: other + origin: LIBRARY + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Any? + symbolKind: LOCAL + typeParameters: [] + ] + visibility: Public + KtFunctionSymbol: + annotationsList: [] + callableIdIfNonLocal: kotlin/Enum.hashCode + contextReceivers: [] + contractEffects: [] + hasStableParameterNames: true + isBuiltinFunctionInvoke: false + isExtension: false + isExternal: false + isInfix: false + isInline: false + isOperator: false + isOverride: false + isStatic: false + isSuspend: false + modality: FINAL + name: hashCode + origin: LIBRARY + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Int + symbolKind: CLASS_MEMBER + typeParameters: [] + valueParameters: [] + visibility: Public + KtFunctionSymbol: + annotationsList: [] + callableIdIfNonLocal: kotlin/Enum.toString + contextReceivers: [] + contractEffects: [] + hasStableParameterNames: true + isBuiltinFunctionInvoke: false + isExtension: false + isExternal: false + isInfix: false + isInline: false + isOperator: false + isOverride: false + isStatic: false + isSuspend: false + modality: OPEN + name: toString + origin: LIBRARY + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/String + symbolKind: CLASS_MEMBER + typeParameters: [] + valueParameters: [] + visibility: Public + KtKotlinPropertySymbol: + annotationsList: [ + kotlin/internal/IntrinsicConstEvaluation() + psi: null + ] + callableIdIfNonLocal: kotlin/Enum.name + contextReceivers: [] + getter: KtPropertyGetterSymbol: + annotationsList: [] + callableIdIfNonLocal: null + contextReceivers: [] + hasBody: false + hasStableParameterNames: true + isDefault: true + isExtension: false + isInline: false + isOverride: false + modality: FINAL + origin: LIBRARY + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/String + symbolKind: ACCESSOR + typeParameters: [] + valueParameters: [] + visibility: Public + hasBackingField: true + hasGetter: true + hasSetter: false + initializer: null + isConst: false + isDelegatedProperty: false + isExtension: false + isFromPrimaryConstructor: false + isLateInit: false + isOverride: false + isStatic: false + isVal: true + modality: FINAL + name: name + origin: LIBRARY + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/String + setter: null + symbolKind: CLASS_MEMBER + typeParameters: [] + visibility: Public + KtKotlinPropertySymbol: + annotationsList: [] + callableIdIfNonLocal: kotlin/Enum.ordinal + contextReceivers: [] + getter: KtPropertyGetterSymbol: + annotationsList: [] + callableIdIfNonLocal: null + contextReceivers: [] + hasBody: false + hasStableParameterNames: true + isDefault: true + isExtension: false + isInline: false + isOverride: false + modality: FINAL + origin: LIBRARY + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Int + symbolKind: ACCESSOR + typeParameters: [] + valueParameters: [] + visibility: Public + hasBackingField: true + hasGetter: true + hasSetter: false + initializer: null + isConst: false + isDelegatedProperty: false + isExtension: false + isFromPrimaryConstructor: false + isLateInit: false + isOverride: false + isStatic: false + isVal: true + modality: FINAL + name: ordinal + origin: LIBRARY + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Int + setter: null + symbolKind: CLASS_MEMBER + typeParameters: [] + visibility: Public + + StaticMemberScope, index = 3 + classifiers: 0 + callables: 4 + KtEnumEntrySymbol: + annotationsList: [] + callableIdIfNonLocal: /E.A + containingEnumClassIdIfNonLocal: E + contextReceivers: [] + isExtension: false + name: A + origin: SOURCE + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: E + symbolKind: CLASS_MEMBER + typeParameters: [] + KtFunctionSymbol: + annotationsList: [] + callableIdIfNonLocal: /E.values + contextReceivers: [] + contractEffects: [] + hasStableParameterNames: true + isBuiltinFunctionInvoke: false + isExtension: false + isExternal: false + isInfix: false + isInline: false + isOperator: false + isOverride: false + isStatic: true + isSuspend: false + modality: FINAL + name: values + origin: SOURCE_MEMBER_GENERATED + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [ + KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: E + ] + type: kotlin/Array + symbolKind: CLASS_MEMBER + typeParameters: [] + valueParameters: [] + visibility: Public + KtFunctionSymbol: + annotationsList: [] + callableIdIfNonLocal: /E.valueOf + contextReceivers: [] + contractEffects: [] + hasStableParameterNames: true + isBuiltinFunctionInvoke: false + isExtension: false + isExternal: false + isInfix: false + isInline: false + isOperator: false + isOverride: false + isStatic: true + isSuspend: false + modality: FINAL + name: valueOf + origin: SOURCE_MEMBER_GENERATED + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: E + symbolKind: CLASS_MEMBER + typeParameters: [] + valueParameters: [ + KtValueParameterSymbol: + annotationsList: [] + callableIdIfNonLocal: null + contextReceivers: [] + generatedPrimaryConstructorProperty: null + hasDefaultValue: false + isCrossinline: false + isExtension: false + isImplicitLambdaParameter: false + isNoinline: false + isVararg: false + name: value + origin: SOURCE_MEMBER_GENERATED + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/String + symbolKind: LOCAL + typeParameters: [] + ] + visibility: Public + KtKotlinPropertySymbol: + annotationsList: [] + callableIdIfNonLocal: /E.entries + contextReceivers: [] + getter: KtPropertyGetterSymbol: + annotationsList: [] + callableIdIfNonLocal: null + contextReceivers: [] + hasBody: false + hasStableParameterNames: true + isDefault: true + isExtension: false + isInline: false + isOverride: false + modality: FINAL + origin: SOURCE_MEMBER_GENERATED + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [ + KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: E + ] + type: kotlin/enums/EnumEntries + symbolKind: ACCESSOR + typeParameters: [] + valueParameters: [] + visibility: Public + hasBackingField: false + hasGetter: true + hasSetter: false + initializer: null + isConst: false + isDelegatedProperty: false + isExtension: false + isFromPrimaryConstructor: false + isLateInit: false + isOverride: false + isStatic: true + isVal: true + modality: FINAL + name: entries + origin: SOURCE_MEMBER_GENERATED + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [ + KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: E + ] + type: kotlin/enums/EnumEntries + setter: null + symbolKind: CLASS_MEMBER + typeParameters: [] + visibility: Public + + StaticMemberScope, index = 4 + classifiers: 1 + KtNamedClassOrObjectSymbol: + annotationsList: [] + classIdIfNonLocal: kotlin/Enum.Companion + classKind: COMPANION_OBJECT + companionObject: null + contextReceivers: [] + isData: false + isExternal: false + isFun: false + isInline: false + isInner: false + modality: FINAL + name: Companion + origin: LIBRARY + superTypes: [ + KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Any + ] + symbolKind: CLASS_MEMBER + typeParameters: [] + visibility: Public + callables: 0 + + SimpleTypeScope, index = 5 + classifiers: 0 + callables: 3 + KtFunctionSymbol: + annotationsList: [] + callableIdIfNonLocal: kotlin/Any.equals + contextReceivers: [] + contractEffects: [] + hasStableParameterNames: true + isBuiltinFunctionInvoke: false + isExtension: false + isExternal: false + isInfix: false + isInline: false + isOperator: true + isOverride: false + isStatic: false + isSuspend: false + modality: OPEN + name: equals + origin: LIBRARY + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Boolean + symbolKind: CLASS_MEMBER + typeParameters: [] + valueParameters: [ + KtValueParameterSymbol: + annotationsList: [] + callableIdIfNonLocal: null + contextReceivers: [] + generatedPrimaryConstructorProperty: null + hasDefaultValue: false + isCrossinline: false + isExtension: false + isImplicitLambdaParameter: false + isNoinline: false + isVararg: false + name: other + origin: LIBRARY + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Any? + symbolKind: LOCAL + typeParameters: [] + ] + visibility: Public + KtFunctionSymbol: + annotationsList: [] + callableIdIfNonLocal: kotlin/Any.hashCode + contextReceivers: [] + contractEffects: [] + hasStableParameterNames: true + isBuiltinFunctionInvoke: false + isExtension: false + isExternal: false + isInfix: false + isInline: false + isOperator: false + isOverride: false + isStatic: false + isSuspend: false + modality: OPEN + name: hashCode + origin: LIBRARY + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Int + symbolKind: CLASS_MEMBER + typeParameters: [] + valueParameters: [] + visibility: Public + KtFunctionSymbol: + annotationsList: [] + callableIdIfNonLocal: kotlin/Any.toString + contextReceivers: [] + contractEffects: [] + hasStableParameterNames: true + isBuiltinFunctionInvoke: false + isExtension: false + isExternal: false + isInfix: false + isInline: false + isOperator: false + isOverride: false + isStatic: false + isSuspend: false + modality: OPEN + name: toString + origin: LIBRARY + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/String + symbolKind: CLASS_MEMBER + typeParameters: [] + valueParameters: [] + visibility: Public + + ExplicitSimpleImportingScope, index = 6, empty + + PackageMemberScope, index = 7 + classifiers: 1 + KtNamedClassOrObjectSymbol: + annotationsList: [] + classIdIfNonLocal: E + classKind: ENUM_CLASS + companionObject: null + contextReceivers: [] + isData: false + isExternal: false + isFun: false + isInline: false + isInner: false + modality: FINAL + name: E + origin: SOURCE + superTypes: [ + KtUsualClassType: + annotationsList: [] + ownTypeArguments: [ + KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: E + ] + type: kotlin/Enum + ] + symbolKind: TOP_LEVEL + typeParameters: [] + visibility: Public + callables: 0 + + DefaultSimpleImportingScope, index = 8 + + DefaultSimpleImportingScope, index = 9 + + ExplicitStarImportingScope, index = 10, empty + + DefaultSimpleImportingScope, index = 11 + + DefaultStarImportingScope, index = 12 + + DefaultStarImportingScope, index = 13 diff --git a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/errorType.kt b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/errorType.kt new file mode 100644 index 00000000000..ba8aab59aae --- /dev/null +++ b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/errorType.kt @@ -0,0 +1,14 @@ +interface List { + fun add(e: T) + fun get(index: Int): T +} + +inline fun buildList(f: List.() -> Unit): List = l + +fun test() { + buildList { + with(this.get(0)) { + e + } + } +} \ No newline at end of file diff --git a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/errorType.pretty.txt b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/errorType.pretty.txt new file mode 100644 index 00000000000..f08f22c4af1 --- /dev/null +++ b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/errorType.pretty.txt @@ -0,0 +1,50 @@ +element: e +implicit receivers: + type: ERROR(Cannot infer argument for type parameter E) + owner symbol: KtFirAnonymousFunctionSymbol + + type: List + owner symbol: KtFirAnonymousFunctionSymbol + +scopes: + SimpleTypeScope, index = 0, empty + + LocalScope, index = 1, empty + + LocalScope, index = 2, empty + + SimpleTypeScope, index = 3 + classifiers: 0 + callables: 5 + fun add(e: T) + fun get(index: kotlin.Int): T + fun equals(other: kotlin.Any?): kotlin.Boolean + fun hashCode(): kotlin.Int + fun toString(): kotlin.String + + LocalScope, index = 4, empty + + LocalScope, index = 5, empty + + LocalScope, index = 6, empty + + ExplicitSimpleImportingScope, index = 7, empty + + PackageMemberScope, index = 8 + classifiers: 1 + interface List + callables: 2 + fun buildList(f: List.() -> kotlin.Unit): List + fun test() + + DefaultSimpleImportingScope, index = 9 + + DefaultSimpleImportingScope, index = 10 + + ExplicitStarImportingScope, index = 11, empty + + DefaultSimpleImportingScope, index = 12 + + DefaultStarImportingScope, index = 13 + + DefaultStarImportingScope, index = 14 diff --git a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/errorType.txt b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/errorType.txt new file mode 100644 index 00000000000..e68b8c26506 --- /dev/null +++ b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/errorType.txt @@ -0,0 +1,366 @@ +element: e +implicit receivers: + type: KtTypeErrorType: + annotationsList: [] + type: ERROR CLASS: Cannot infer argument for type parameter E + owner symbol: KtFirAnonymousFunctionSymbol + + type: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [ + KtTypeErrorType: + annotationsList: [] + type: ERROR CLASS: Cannot infer argument for type parameter E + ] + type: List + owner symbol: KtFirAnonymousFunctionSymbol + +scopes: + SimpleTypeScope, index = 0, empty + + LocalScope, index = 1, empty + + LocalScope, index = 2, empty + + SimpleTypeScope, index = 3 + classifiers: 0 + callables: 5 + KtFunctionSymbol: + annotationsList: [] + callableIdIfNonLocal: /List.add + contextReceivers: [] + contractEffects: [] + hasStableParameterNames: true + isBuiltinFunctionInvoke: false + isExtension: false + isExternal: false + isInfix: false + isInline: false + isOperator: false + isOverride: false + isStatic: false + isSuspend: false + modality: ABSTRACT + name: add + origin: SOURCE + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Unit + symbolKind: CLASS_MEMBER + typeParameters: [] + valueParameters: [ + KtValueParameterSymbol: + annotationsList: [] + callableIdIfNonLocal: null + contextReceivers: [] + generatedPrimaryConstructorProperty: null + hasDefaultValue: false + isCrossinline: false + isExtension: false + isImplicitLambdaParameter: false + isNoinline: false + isVararg: false + name: e + origin: SOURCE + receiverParameter: null + returnType: KtTypeParameterType: + annotationsList: [] + type: T + symbolKind: LOCAL + typeParameters: [] + ] + visibility: Public + KtFunctionSymbol: + annotationsList: [] + callableIdIfNonLocal: /List.get + contextReceivers: [] + contractEffects: [] + hasStableParameterNames: true + isBuiltinFunctionInvoke: false + isExtension: false + isExternal: false + isInfix: false + isInline: false + isOperator: false + isOverride: false + isStatic: false + isSuspend: false + modality: ABSTRACT + name: get + origin: SOURCE + receiverParameter: null + returnType: KtTypeParameterType: + annotationsList: [] + type: T + symbolKind: CLASS_MEMBER + typeParameters: [] + valueParameters: [ + KtValueParameterSymbol: + annotationsList: [] + callableIdIfNonLocal: null + contextReceivers: [] + generatedPrimaryConstructorProperty: null + hasDefaultValue: false + isCrossinline: false + isExtension: false + isImplicitLambdaParameter: false + isNoinline: false + isVararg: false + name: index + origin: SOURCE + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Int + symbolKind: LOCAL + typeParameters: [] + ] + visibility: Public + KtFunctionSymbol: + annotationsList: [] + callableIdIfNonLocal: kotlin/Any.equals + contextReceivers: [] + contractEffects: [] + hasStableParameterNames: true + isBuiltinFunctionInvoke: false + isExtension: false + isExternal: false + isInfix: false + isInline: false + isOperator: true + isOverride: false + isStatic: false + isSuspend: false + modality: OPEN + name: equals + origin: LIBRARY + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Boolean + symbolKind: CLASS_MEMBER + typeParameters: [] + valueParameters: [ + KtValueParameterSymbol: + annotationsList: [] + callableIdIfNonLocal: null + contextReceivers: [] + generatedPrimaryConstructorProperty: null + hasDefaultValue: false + isCrossinline: false + isExtension: false + isImplicitLambdaParameter: false + isNoinline: false + isVararg: false + name: other + origin: LIBRARY + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Any? + symbolKind: LOCAL + typeParameters: [] + ] + visibility: Public + KtFunctionSymbol: + annotationsList: [] + callableIdIfNonLocal: kotlin/Any.hashCode + contextReceivers: [] + contractEffects: [] + hasStableParameterNames: true + isBuiltinFunctionInvoke: false + isExtension: false + isExternal: false + isInfix: false + isInline: false + isOperator: false + isOverride: false + isStatic: false + isSuspend: false + modality: OPEN + name: hashCode + origin: LIBRARY + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Int + symbolKind: CLASS_MEMBER + typeParameters: [] + valueParameters: [] + visibility: Public + KtFunctionSymbol: + annotationsList: [] + callableIdIfNonLocal: kotlin/Any.toString + contextReceivers: [] + contractEffects: [] + hasStableParameterNames: true + isBuiltinFunctionInvoke: false + isExtension: false + isExternal: false + isInfix: false + isInline: false + isOperator: false + isOverride: false + isStatic: false + isSuspend: false + modality: OPEN + name: toString + origin: LIBRARY + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/String + symbolKind: CLASS_MEMBER + typeParameters: [] + valueParameters: [] + visibility: Public + + LocalScope, index = 4, empty + + LocalScope, index = 5, empty + + LocalScope, index = 6, empty + + ExplicitSimpleImportingScope, index = 7, empty + + PackageMemberScope, index = 8 + classifiers: 1 + KtNamedClassOrObjectSymbol: + annotationsList: [] + classIdIfNonLocal: List + classKind: INTERFACE + companionObject: null + contextReceivers: [] + isData: false + isExternal: false + isFun: false + isInline: false + isInner: false + modality: ABSTRACT + name: List + origin: SOURCE + superTypes: [ + KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Any + ] + symbolKind: TOP_LEVEL + typeParameters: [ + KtTypeParameterSymbol(T) + ] + visibility: Public + callables: 2 + KtFunctionSymbol: + annotationsList: [] + callableIdIfNonLocal: /buildList + contextReceivers: [] + contractEffects: [] + hasStableParameterNames: true + isBuiltinFunctionInvoke: false + isExtension: false + isExternal: false + isInfix: false + isInline: true + isOperator: false + isOverride: false + isStatic: false + isSuspend: false + modality: FINAL + name: buildList + origin: SOURCE + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [ + KtTypeParameterType: + annotationsList: [] + type: E + ] + type: List + symbolKind: TOP_LEVEL + typeParameters: [ + KtTypeParameterSymbol(E) + ] + valueParameters: [ + KtValueParameterSymbol: + annotationsList: [] + callableIdIfNonLocal: null + contextReceivers: [] + generatedPrimaryConstructorProperty: null + hasDefaultValue: false + isCrossinline: false + isExtension: false + isImplicitLambdaParameter: false + isNoinline: false + isVararg: false + name: f + origin: SOURCE + receiverParameter: null + returnType: KtFunctionalType: + annotationsList: [] + ownTypeArguments: [ + KtUsualClassType: + annotationsList: [] + ownTypeArguments: [ + KtTypeParameterType: + annotationsList: [] + type: E + ] + type: List + KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Unit + ] + type: @ExtensionFunctionType kotlin/Function1, kotlin/Unit> + symbolKind: LOCAL + typeParameters: [] + ] + visibility: Public + KtFunctionSymbol: + annotationsList: [] + callableIdIfNonLocal: /test + contextReceivers: [] + contractEffects: [] + hasStableParameterNames: true + isBuiltinFunctionInvoke: false + isExtension: false + isExternal: false + isInfix: false + isInline: false + isOperator: false + isOverride: false + isStatic: false + isSuspend: false + modality: FINAL + name: test + origin: SOURCE + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Unit + symbolKind: TOP_LEVEL + typeParameters: [] + valueParameters: [] + visibility: Public + + DefaultSimpleImportingScope, index = 9 + + DefaultSimpleImportingScope, index = 10 + + ExplicitStarImportingScope, index = 11, empty + + DefaultSimpleImportingScope, index = 12 + + DefaultStarImportingScope, index = 13 + + DefaultStarImportingScope, index = 14 diff --git a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/localTypeScope.kt b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/localTypeScope.kt new file mode 100644 index 00000000000..a561ea4d4c7 --- /dev/null +++ b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/localTypeScope.kt @@ -0,0 +1,10 @@ +fun z() { + val localInZ = 3 + class Y { + val propertyInY = 2 + fun x() { + val localInX = 1 + e + } + } +} \ No newline at end of file diff --git a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/localTypeScope.pretty.txt b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/localTypeScope.pretty.txt new file mode 100644 index 00000000000..98dcde227ef --- /dev/null +++ b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/localTypeScope.pretty.txt @@ -0,0 +1,49 @@ +element: e +implicit receivers: + type: Y + owner symbol: KtFirNamedClassOrObjectSymbol + +scopes: + LocalScope, index = 0 + classifiers: 0 + callables: 1 + val localInX: kotlin.Int + + LocalScope, index = 1, empty + + SimpleTypeScope, index = 2 + classifiers: 0 + callables: 5 + val propertyInY: kotlin.Int + fun x() + fun equals(other: kotlin.Any?): kotlin.Boolean + fun hashCode(): kotlin.Int + fun toString(): kotlin.String + + LocalScope, index = 3 + classifiers: 1 + class Y + callables: 1 + val localInZ: kotlin.Int + + LocalScope, index = 4, empty + + ExplicitSimpleImportingScope, index = 5, empty + + PackageMemberScope, index = 6 + classifiers: 0 + callables: 1 + fun z() + + DefaultSimpleImportingScope, index = 7 + + DefaultSimpleImportingScope, index = 8 + + ExplicitStarImportingScope, index = 9, empty + + DefaultSimpleImportingScope, index = 10 + + DefaultStarImportingScope, index = 11 + + DefaultStarImportingScope, index = 12 + diff --git a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/localTypeScope.txt b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/localTypeScope.txt new file mode 100644 index 00000000000..94241136c5f --- /dev/null +++ b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/localTypeScope.txt @@ -0,0 +1,301 @@ +element: e +implicit receivers: + type: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: Y + owner symbol: KtFirNamedClassOrObjectSymbol + +scopes: + LocalScope, index = 0 + classifiers: 0 + callables: 1 + KtLocalVariableSymbol: + annotationsList: [] + callableIdIfNonLocal: null + contextReceivers: [] + isExtension: false + isVal: true + name: localInX + origin: SOURCE + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Int + symbolKind: LOCAL + typeParameters: [] + + LocalScope, index = 1, empty + + SimpleTypeScope, index = 2 + classifiers: 0 + callables: 5 + KtKotlinPropertySymbol: + annotationsList: [] + callableIdIfNonLocal: null + contextReceivers: [] + getter: KtPropertyGetterSymbol: + annotationsList: [] + callableIdIfNonLocal: null + contextReceivers: [] + hasBody: false + hasStableParameterNames: true + isDefault: true + isExtension: false + isInline: false + isOverride: false + modality: FINAL + origin: SOURCE + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Int + symbolKind: ACCESSOR + typeParameters: [] + valueParameters: [] + visibility: Public + hasBackingField: true + hasGetter: true + hasSetter: false + initializer: KtConstantInitializerValue(2) + isConst: false + isDelegatedProperty: false + isExtension: false + isFromPrimaryConstructor: false + isLateInit: false + isOverride: false + isStatic: false + isVal: true + modality: FINAL + name: propertyInY + origin: SOURCE + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Int + setter: null + symbolKind: CLASS_MEMBER + typeParameters: [] + visibility: Public + KtFunctionSymbol: + annotationsList: [] + callableIdIfNonLocal: null + contextReceivers: [] + contractEffects: [] + hasStableParameterNames: true + isBuiltinFunctionInvoke: false + isExtension: false + isExternal: false + isInfix: false + isInline: false + isOperator: false + isOverride: false + isStatic: false + isSuspend: false + modality: FINAL + name: x + origin: SOURCE + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Unit + symbolKind: CLASS_MEMBER + typeParameters: [] + valueParameters: [] + visibility: Public + KtFunctionSymbol: + annotationsList: [] + callableIdIfNonLocal: kotlin/Any.equals + contextReceivers: [] + contractEffects: [] + hasStableParameterNames: true + isBuiltinFunctionInvoke: false + isExtension: false + isExternal: false + isInfix: false + isInline: false + isOperator: true + isOverride: false + isStatic: false + isSuspend: false + modality: OPEN + name: equals + origin: LIBRARY + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Boolean + symbolKind: CLASS_MEMBER + typeParameters: [] + valueParameters: [ + KtValueParameterSymbol: + annotationsList: [] + callableIdIfNonLocal: null + contextReceivers: [] + generatedPrimaryConstructorProperty: null + hasDefaultValue: false + isCrossinline: false + isExtension: false + isImplicitLambdaParameter: false + isNoinline: false + isVararg: false + name: other + origin: LIBRARY + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Any? + symbolKind: LOCAL + typeParameters: [] + ] + visibility: Public + KtFunctionSymbol: + annotationsList: [] + callableIdIfNonLocal: kotlin/Any.hashCode + contextReceivers: [] + contractEffects: [] + hasStableParameterNames: true + isBuiltinFunctionInvoke: false + isExtension: false + isExternal: false + isInfix: false + isInline: false + isOperator: false + isOverride: false + isStatic: false + isSuspend: false + modality: OPEN + name: hashCode + origin: LIBRARY + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Int + symbolKind: CLASS_MEMBER + typeParameters: [] + valueParameters: [] + visibility: Public + KtFunctionSymbol: + annotationsList: [] + callableIdIfNonLocal: kotlin/Any.toString + contextReceivers: [] + contractEffects: [] + hasStableParameterNames: true + isBuiltinFunctionInvoke: false + isExtension: false + isExternal: false + isInfix: false + isInline: false + isOperator: false + isOverride: false + isStatic: false + isSuspend: false + modality: OPEN + name: toString + origin: LIBRARY + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/String + symbolKind: CLASS_MEMBER + typeParameters: [] + valueParameters: [] + visibility: Public + + LocalScope, index = 3 + classifiers: 1 + KtNamedClassOrObjectSymbol: + annotationsList: [] + classIdIfNonLocal: null + classKind: CLASS + companionObject: null + contextReceivers: [] + isData: false + isExternal: false + isFun: false + isInline: false + isInner: false + modality: FINAL + name: Y + origin: SOURCE + superTypes: [ + KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Any + ] + symbolKind: LOCAL + typeParameters: [] + visibility: Local + callables: 1 + KtLocalVariableSymbol: + annotationsList: [] + callableIdIfNonLocal: null + contextReceivers: [] + isExtension: false + isVal: true + name: localInZ + origin: SOURCE + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Int + symbolKind: LOCAL + typeParameters: [] + + LocalScope, index = 4, empty + + ExplicitSimpleImportingScope, index = 5, empty + + PackageMemberScope, index = 6 + classifiers: 0 + callables: 1 + KtFunctionSymbol: + annotationsList: [] + callableIdIfNonLocal: /z + contextReceivers: [] + contractEffects: [] + hasStableParameterNames: true + isBuiltinFunctionInvoke: false + isExtension: false + isExternal: false + isInfix: false + isInline: false + isOperator: false + isOverride: false + isStatic: false + isSuspend: false + modality: FINAL + name: z + origin: SOURCE + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Unit + symbolKind: TOP_LEVEL + typeParameters: [] + valueParameters: [] + visibility: Public + + DefaultSimpleImportingScope, index = 7 + + DefaultSimpleImportingScope, index = 8 + + ExplicitStarImportingScope, index = 9, empty + + DefaultSimpleImportingScope, index = 10 + + DefaultStarImportingScope, index = 11 + + DefaultStarImportingScope, index = 12 + diff --git a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/simpleScopeContextForPosition.kt b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/simpleScopeContextForPosition.kt new file mode 100644 index 00000000000..677d4f873d8 --- /dev/null +++ b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/simpleScopeContextForPosition.kt @@ -0,0 +1,39 @@ +// FILE: JavaClass.java +public class JavaClass { + class NestedInJavaClass { + } +} + +// FILE: main.kt +class A { + fun memberInA() {} +} + +class B { + fun memberInB() {} +} + +fun withA(f: A.() -> Unit) {} + +fun withB(f: B.() -> Unit) {} + +fun withJavaClass(f: JavaClass.() -> Unit) {} + +fun topLevel() = 1 + +class C: JavaClass() { + fun methodInC(param: String?) { + val localVarB = 2 + fun localFunB() {} + param?.let { lambdaArg -> + val localVarA = 1 + withB { + withA { + e + } + } + } + } + + class NestedInC +} \ No newline at end of file diff --git a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/simpleScopeContextForPosition.pretty.txt b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/simpleScopeContextForPosition.pretty.txt new file mode 100644 index 00000000000..a116dc9be56 --- /dev/null +++ b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/simpleScopeContextForPosition.pretty.txt @@ -0,0 +1,105 @@ +element: e +implicit receivers: + type: A + owner symbol: KtFirAnonymousFunctionSymbol + + type: B + owner symbol: KtFirAnonymousFunctionSymbol + + type: C + owner symbol: KtFirNamedClassOrObjectSymbol + +scopes: + SimpleTypeScope, index = 0 + classifiers: 0 + callables: 4 + fun memberInA() + fun equals(other: kotlin.Any?): kotlin.Boolean + fun hashCode(): kotlin.Int + fun toString(): kotlin.String + + LocalScope, index = 1, empty + + LocalScope, index = 2, empty + + SimpleTypeScope, index = 3 + classifiers: 0 + callables: 4 + fun memberInB() + fun equals(other: kotlin.Any?): kotlin.Boolean + fun hashCode(): kotlin.Int + fun toString(): kotlin.String + + LocalScope, index = 4, empty + + LocalScope, index = 5 + classifiers: 0 + callables: 1 + val localVarA: kotlin.Int + + LocalScope, index = 6 + classifiers: 0 + callables: 1 + lambdaArg: kotlin.String + + LocalScope, index = 7 + classifiers: 0 + callables: 2 + val localVarB: kotlin.Int + fun localFunB() + + LocalScope, index = 8 + classifiers: 0 + callables: 1 + param: kotlin.String? + + TypeParameterScope, index = 9 + classifiers: 1 + T + callables: 0 + + SimpleTypeScope, index = 10 + classifiers: 2 + class NestedInC + class NestedInJavaClass + callables: 4 + fun methodInC(param: kotlin.String?) + fun equals(other: kotlin.Any?): kotlin.Boolean + fun hashCode(): kotlin.Int + fun toString(): kotlin.String + + StaticMemberScope, index = 11 + classifiers: 1 + class NestedInC + callables: 0 + + StaticMemberScope, index = 12 + classifiers: 1 + class NestedInJavaClass + callables: 0 + + ExplicitSimpleImportingScope, index = 13, empty + + PackageMemberScope, index = 14 + classifiers: 3 + class C : JavaClass() + class B + class A + callables: 4 + fun withJavaClass(f: JavaClass.() -> kotlin.Unit) + fun topLevel(): kotlin.Int + fun withB(f: B.() -> kotlin.Unit) + fun withA(f: A.() -> kotlin.Unit) + + DefaultSimpleImportingScope, index = 15 + + DefaultSimpleImportingScope, index = 16 + + ExplicitStarImportingScope, index = 17, empty + + DefaultSimpleImportingScope, index = 18 + + DefaultStarImportingScope, index = 19 + + DefaultStarImportingScope, index = 20 + diff --git a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/simpleScopeContextForPosition.txt b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/simpleScopeContextForPosition.txt new file mode 100644 index 00000000000..69bb6fcd8e9 --- /dev/null +++ b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/simpleScopeContextForPosition.txt @@ -0,0 +1,959 @@ +element: e +implicit receivers: + type: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: A + owner symbol: KtFirAnonymousFunctionSymbol + + type: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: B + owner symbol: KtFirAnonymousFunctionSymbol + + type: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: C + owner symbol: KtFirNamedClassOrObjectSymbol + +scopes: + SimpleTypeScope, index = 0 + classifiers: 0 + callables: 4 + KtFunctionSymbol: + annotationsList: [] + callableIdIfNonLocal: /A.memberInA + contextReceivers: [] + contractEffects: [] + hasStableParameterNames: true + isBuiltinFunctionInvoke: false + isExtension: false + isExternal: false + isInfix: false + isInline: false + isOperator: false + isOverride: false + isStatic: false + isSuspend: false + modality: FINAL + name: memberInA + origin: SOURCE + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Unit + symbolKind: CLASS_MEMBER + typeParameters: [] + valueParameters: [] + visibility: Public + KtFunctionSymbol: + annotationsList: [] + callableIdIfNonLocal: kotlin/Any.equals + contextReceivers: [] + contractEffects: [] + hasStableParameterNames: true + isBuiltinFunctionInvoke: false + isExtension: false + isExternal: false + isInfix: false + isInline: false + isOperator: true + isOverride: false + isStatic: false + isSuspend: false + modality: OPEN + name: equals + origin: LIBRARY + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Boolean + symbolKind: CLASS_MEMBER + typeParameters: [] + valueParameters: [ + KtValueParameterSymbol: + annotationsList: [] + callableIdIfNonLocal: null + contextReceivers: [] + generatedPrimaryConstructorProperty: null + hasDefaultValue: false + isCrossinline: false + isExtension: false + isImplicitLambdaParameter: false + isNoinline: false + isVararg: false + name: other + origin: LIBRARY + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Any? + symbolKind: LOCAL + typeParameters: [] + ] + visibility: Public + KtFunctionSymbol: + annotationsList: [] + callableIdIfNonLocal: kotlin/Any.hashCode + contextReceivers: [] + contractEffects: [] + hasStableParameterNames: true + isBuiltinFunctionInvoke: false + isExtension: false + isExternal: false + isInfix: false + isInline: false + isOperator: false + isOverride: false + isStatic: false + isSuspend: false + modality: OPEN + name: hashCode + origin: LIBRARY + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Int + symbolKind: CLASS_MEMBER + typeParameters: [] + valueParameters: [] + visibility: Public + KtFunctionSymbol: + annotationsList: [] + callableIdIfNonLocal: kotlin/Any.toString + contextReceivers: [] + contractEffects: [] + hasStableParameterNames: true + isBuiltinFunctionInvoke: false + isExtension: false + isExternal: false + isInfix: false + isInline: false + isOperator: false + isOverride: false + isStatic: false + isSuspend: false + modality: OPEN + name: toString + origin: LIBRARY + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/String + symbolKind: CLASS_MEMBER + typeParameters: [] + valueParameters: [] + visibility: Public + + LocalScope, index = 1, empty + + LocalScope, index = 2, empty + + SimpleTypeScope, index = 3 + classifiers: 0 + callables: 4 + KtFunctionSymbol: + annotationsList: [] + callableIdIfNonLocal: /B.memberInB + contextReceivers: [] + contractEffects: [] + hasStableParameterNames: true + isBuiltinFunctionInvoke: false + isExtension: false + isExternal: false + isInfix: false + isInline: false + isOperator: false + isOverride: false + isStatic: false + isSuspend: false + modality: FINAL + name: memberInB + origin: SOURCE + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Unit + symbolKind: CLASS_MEMBER + typeParameters: [] + valueParameters: [] + visibility: Public + KtFunctionSymbol: + annotationsList: [] + callableIdIfNonLocal: kotlin/Any.equals + contextReceivers: [] + contractEffects: [] + hasStableParameterNames: true + isBuiltinFunctionInvoke: false + isExtension: false + isExternal: false + isInfix: false + isInline: false + isOperator: true + isOverride: false + isStatic: false + isSuspend: false + modality: OPEN + name: equals + origin: LIBRARY + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Boolean + symbolKind: CLASS_MEMBER + typeParameters: [] + valueParameters: [ + KtValueParameterSymbol: + annotationsList: [] + callableIdIfNonLocal: null + contextReceivers: [] + generatedPrimaryConstructorProperty: null + hasDefaultValue: false + isCrossinline: false + isExtension: false + isImplicitLambdaParameter: false + isNoinline: false + isVararg: false + name: other + origin: LIBRARY + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Any? + symbolKind: LOCAL + typeParameters: [] + ] + visibility: Public + KtFunctionSymbol: + annotationsList: [] + callableIdIfNonLocal: kotlin/Any.hashCode + contextReceivers: [] + contractEffects: [] + hasStableParameterNames: true + isBuiltinFunctionInvoke: false + isExtension: false + isExternal: false + isInfix: false + isInline: false + isOperator: false + isOverride: false + isStatic: false + isSuspend: false + modality: OPEN + name: hashCode + origin: LIBRARY + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Int + symbolKind: CLASS_MEMBER + typeParameters: [] + valueParameters: [] + visibility: Public + KtFunctionSymbol: + annotationsList: [] + callableIdIfNonLocal: kotlin/Any.toString + contextReceivers: [] + contractEffects: [] + hasStableParameterNames: true + isBuiltinFunctionInvoke: false + isExtension: false + isExternal: false + isInfix: false + isInline: false + isOperator: false + isOverride: false + isStatic: false + isSuspend: false + modality: OPEN + name: toString + origin: LIBRARY + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/String + symbolKind: CLASS_MEMBER + typeParameters: [] + valueParameters: [] + visibility: Public + + LocalScope, index = 4, empty + + LocalScope, index = 5 + classifiers: 0 + callables: 1 + KtLocalVariableSymbol: + annotationsList: [] + callableIdIfNonLocal: null + contextReceivers: [] + isExtension: false + isVal: true + name: localVarA + origin: SOURCE + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Int + symbolKind: LOCAL + typeParameters: [] + + LocalScope, index = 6 + classifiers: 0 + callables: 1 + KtValueParameterSymbol: + annotationsList: [] + callableIdIfNonLocal: null + contextReceivers: [] + generatedPrimaryConstructorProperty: null + hasDefaultValue: false + isCrossinline: false + isExtension: false + isImplicitLambdaParameter: false + isNoinline: false + isVararg: false + name: lambdaArg + origin: SOURCE + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/String + symbolKind: LOCAL + typeParameters: [] + + LocalScope, index = 7 + classifiers: 0 + callables: 2 + KtLocalVariableSymbol: + annotationsList: [] + callableIdIfNonLocal: null + contextReceivers: [] + isExtension: false + isVal: true + name: localVarB + origin: SOURCE + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Int + symbolKind: LOCAL + typeParameters: [] + KtFunctionSymbol: + annotationsList: [] + callableIdIfNonLocal: null + contextReceivers: [] + contractEffects: [] + hasStableParameterNames: true + isBuiltinFunctionInvoke: false + isExtension: false + isExternal: false + isInfix: false + isInline: false + isOperator: false + isOverride: false + isStatic: false + isSuspend: false + modality: FINAL + name: localFunB + origin: SOURCE + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Unit + symbolKind: LOCAL + typeParameters: [] + valueParameters: [] + visibility: Local + + LocalScope, index = 8 + classifiers: 0 + callables: 1 + KtValueParameterSymbol: + annotationsList: [] + callableIdIfNonLocal: null + contextReceivers: [] + generatedPrimaryConstructorProperty: null + hasDefaultValue: false + isCrossinline: false + isExtension: false + isImplicitLambdaParameter: false + isNoinline: false + isVararg: false + name: param + origin: SOURCE + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/String? + symbolKind: LOCAL + typeParameters: [] + + TypeParameterScope, index = 9 + classifiers: 1 + KtTypeParameterSymbol: + annotationsList: [] + isReified: false + name: T + origin: SOURCE + typeParameters: [] + upperBounds: [] + variance: INVARIANT + callables: 0 + + SimpleTypeScope, index = 10 + classifiers: 2 + KtNamedClassOrObjectSymbol: + annotationsList: [] + classIdIfNonLocal: C.NestedInC + classKind: CLASS + companionObject: null + contextReceivers: [] + isData: false + isExternal: false + isFun: false + isInline: false + isInner: false + modality: FINAL + name: NestedInC + origin: SOURCE + superTypes: [ + KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Any + ] + symbolKind: CLASS_MEMBER + typeParameters: [] + visibility: Public + KtNamedClassOrObjectSymbol: + annotationsList: [] + classIdIfNonLocal: JavaClass.NestedInJavaClass + classKind: CLASS + companionObject: null + contextReceivers: [] + isData: false + isExternal: false + isFun: false + isInline: false + isInner: true + modality: OPEN + name: NestedInJavaClass + origin: JAVA + superTypes: [ + KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Any + ] + symbolKind: CLASS_MEMBER + typeParameters: [] + visibility: PackageVisibility + callables: 4 + KtFunctionSymbol: + annotationsList: [] + callableIdIfNonLocal: /C.methodInC + contextReceivers: [] + contractEffects: [] + hasStableParameterNames: true + isBuiltinFunctionInvoke: false + isExtension: false + isExternal: false + isInfix: false + isInline: false + isOperator: false + isOverride: false + isStatic: false + isSuspend: false + modality: FINAL + name: methodInC + origin: SOURCE + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Unit + symbolKind: CLASS_MEMBER + typeParameters: [ + KtTypeParameterSymbol(T) + ] + valueParameters: [ + KtValueParameterSymbol: + annotationsList: [] + callableIdIfNonLocal: null + contextReceivers: [] + generatedPrimaryConstructorProperty: null + hasDefaultValue: false + isCrossinline: false + isExtension: false + isImplicitLambdaParameter: false + isNoinline: false + isVararg: false + name: param + origin: SOURCE + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/String? + symbolKind: LOCAL + typeParameters: [] + ] + visibility: Public + KtFunctionSymbol: + annotationsList: [] + callableIdIfNonLocal: kotlin/Any.equals + contextReceivers: [] + contractEffects: [] + hasStableParameterNames: true + isBuiltinFunctionInvoke: false + isExtension: false + isExternal: false + isInfix: false + isInline: false + isOperator: true + isOverride: false + isStatic: false + isSuspend: false + modality: OPEN + name: equals + origin: LIBRARY + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Boolean + symbolKind: CLASS_MEMBER + typeParameters: [] + valueParameters: [ + KtValueParameterSymbol: + annotationsList: [] + callableIdIfNonLocal: null + contextReceivers: [] + generatedPrimaryConstructorProperty: null + hasDefaultValue: false + isCrossinline: false + isExtension: false + isImplicitLambdaParameter: false + isNoinline: false + isVararg: false + name: other + origin: LIBRARY + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Any? + symbolKind: LOCAL + typeParameters: [] + ] + visibility: Public + KtFunctionSymbol: + annotationsList: [] + callableIdIfNonLocal: kotlin/Any.hashCode + contextReceivers: [] + contractEffects: [] + hasStableParameterNames: true + isBuiltinFunctionInvoke: false + isExtension: false + isExternal: false + isInfix: false + isInline: false + isOperator: false + isOverride: false + isStatic: false + isSuspend: false + modality: OPEN + name: hashCode + origin: LIBRARY + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Int + symbolKind: CLASS_MEMBER + typeParameters: [] + valueParameters: [] + visibility: Public + KtFunctionSymbol: + annotationsList: [] + callableIdIfNonLocal: kotlin/Any.toString + contextReceivers: [] + contractEffects: [] + hasStableParameterNames: true + isBuiltinFunctionInvoke: false + isExtension: false + isExternal: false + isInfix: false + isInline: false + isOperator: false + isOverride: false + isStatic: false + isSuspend: false + modality: OPEN + name: toString + origin: LIBRARY + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/String + symbolKind: CLASS_MEMBER + typeParameters: [] + valueParameters: [] + visibility: Public + + StaticMemberScope, index = 11 + classifiers: 1 + KtNamedClassOrObjectSymbol: + annotationsList: [] + classIdIfNonLocal: C.NestedInC + classKind: CLASS + companionObject: null + contextReceivers: [] + isData: false + isExternal: false + isFun: false + isInline: false + isInner: false + modality: FINAL + name: NestedInC + origin: SOURCE + superTypes: [ + KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Any + ] + symbolKind: CLASS_MEMBER + typeParameters: [] + visibility: Public + callables: 0 + + StaticMemberScope, index = 12 + classifiers: 1 + KtNamedClassOrObjectSymbol: + annotationsList: [] + classIdIfNonLocal: JavaClass.NestedInJavaClass + classKind: CLASS + companionObject: null + contextReceivers: [] + isData: false + isExternal: false + isFun: false + isInline: false + isInner: true + modality: OPEN + name: NestedInJavaClass + origin: JAVA + superTypes: [ + KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Any + ] + symbolKind: CLASS_MEMBER + typeParameters: [] + visibility: PackageVisibility + callables: 0 + + ExplicitSimpleImportingScope, index = 13, empty + + PackageMemberScope, index = 14 + classifiers: 3 + KtNamedClassOrObjectSymbol: + annotationsList: [] + classIdIfNonLocal: C + classKind: CLASS + companionObject: null + contextReceivers: [] + isData: false + isExternal: false + isFun: false + isInline: false + isInner: false + modality: FINAL + name: C + origin: SOURCE + superTypes: [ + KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: JavaClass + ] + symbolKind: TOP_LEVEL + typeParameters: [] + visibility: Public + KtNamedClassOrObjectSymbol: + annotationsList: [] + classIdIfNonLocal: B + classKind: CLASS + companionObject: null + contextReceivers: [] + isData: false + isExternal: false + isFun: false + isInline: false + isInner: false + modality: FINAL + name: B + origin: SOURCE + superTypes: [ + KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Any + ] + symbolKind: TOP_LEVEL + typeParameters: [] + visibility: Public + KtNamedClassOrObjectSymbol: + annotationsList: [] + classIdIfNonLocal: A + classKind: CLASS + companionObject: null + contextReceivers: [] + isData: false + isExternal: false + isFun: false + isInline: false + isInner: false + modality: FINAL + name: A + origin: SOURCE + superTypes: [ + KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Any + ] + symbolKind: TOP_LEVEL + typeParameters: [] + visibility: Public + callables: 4 + KtFunctionSymbol: + annotationsList: [] + callableIdIfNonLocal: /withJavaClass + contextReceivers: [] + contractEffects: [] + hasStableParameterNames: true + isBuiltinFunctionInvoke: false + isExtension: false + isExternal: false + isInfix: false + isInline: false + isOperator: false + isOverride: false + isStatic: false + isSuspend: false + modality: FINAL + name: withJavaClass + origin: SOURCE + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Unit + symbolKind: TOP_LEVEL + typeParameters: [] + valueParameters: [ + KtValueParameterSymbol: + annotationsList: [] + callableIdIfNonLocal: null + contextReceivers: [] + generatedPrimaryConstructorProperty: null + hasDefaultValue: false + isCrossinline: false + isExtension: false + isImplicitLambdaParameter: false + isNoinline: false + isVararg: false + name: f + origin: SOURCE + receiverParameter: null + returnType: KtFunctionalType: + annotationsList: [] + ownTypeArguments: [ + KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: JavaClass + KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Unit + ] + type: @ExtensionFunctionType kotlin/Function1 + symbolKind: LOCAL + typeParameters: [] + ] + visibility: Public + KtFunctionSymbol: + annotationsList: [] + callableIdIfNonLocal: /topLevel + contextReceivers: [] + contractEffects: [] + hasStableParameterNames: true + isBuiltinFunctionInvoke: false + isExtension: false + isExternal: false + isInfix: false + isInline: false + isOperator: false + isOverride: false + isStatic: false + isSuspend: false + modality: FINAL + name: topLevel + origin: SOURCE + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Int + symbolKind: TOP_LEVEL + typeParameters: [] + valueParameters: [] + visibility: Public + KtFunctionSymbol: + annotationsList: [] + callableIdIfNonLocal: /withB + contextReceivers: [] + contractEffects: [] + hasStableParameterNames: true + isBuiltinFunctionInvoke: false + isExtension: false + isExternal: false + isInfix: false + isInline: false + isOperator: false + isOverride: false + isStatic: false + isSuspend: false + modality: FINAL + name: withB + origin: SOURCE + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Unit + symbolKind: TOP_LEVEL + typeParameters: [] + valueParameters: [ + KtValueParameterSymbol: + annotationsList: [] + callableIdIfNonLocal: null + contextReceivers: [] + generatedPrimaryConstructorProperty: null + hasDefaultValue: false + isCrossinline: false + isExtension: false + isImplicitLambdaParameter: false + isNoinline: false + isVararg: false + name: f + origin: SOURCE + receiverParameter: null + returnType: KtFunctionalType: + annotationsList: [] + ownTypeArguments: [ + KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: B + KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Unit + ] + type: @ExtensionFunctionType kotlin/Function1 + symbolKind: LOCAL + typeParameters: [] + ] + visibility: Public + KtFunctionSymbol: + annotationsList: [] + callableIdIfNonLocal: /withA + contextReceivers: [] + contractEffects: [] + hasStableParameterNames: true + isBuiltinFunctionInvoke: false + isExtension: false + isExternal: false + isInfix: false + isInline: false + isOperator: false + isOverride: false + isStatic: false + isSuspend: false + modality: FINAL + name: withA + origin: SOURCE + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Unit + symbolKind: TOP_LEVEL + typeParameters: [] + valueParameters: [ + KtValueParameterSymbol: + annotationsList: [] + callableIdIfNonLocal: null + contextReceivers: [] + generatedPrimaryConstructorProperty: null + hasDefaultValue: false + isCrossinline: false + isExtension: false + isImplicitLambdaParameter: false + isNoinline: false + isVararg: false + name: f + origin: SOURCE + receiverParameter: null + returnType: KtFunctionalType: + annotationsList: [] + ownTypeArguments: [ + KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: A + KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Unit + ] + type: @ExtensionFunctionType kotlin/Function1 + symbolKind: LOCAL + typeParameters: [] + ] + visibility: Public + + DefaultSimpleImportingScope, index = 15 + + DefaultSimpleImportingScope, index = 16 + + ExplicitStarImportingScope, index = 17, empty + + DefaultSimpleImportingScope, index = 18 + + DefaultStarImportingScope, index = 19 + + DefaultStarImportingScope, index = 20 + diff --git a/analysis/analysis-test-framework/tests/org/jetbrains/kotlin/analysis/test/framework/base/AbstractAnalysisApiBasedTest.kt b/analysis/analysis-test-framework/tests/org/jetbrains/kotlin/analysis/test/framework/base/AbstractAnalysisApiBasedTest.kt index 14b0b09a720..5fe5e5dd4d9 100644 --- a/analysis/analysis-test-framework/tests/org/jetbrains/kotlin/analysis/test/framework/base/AbstractAnalysisApiBasedTest.kt +++ b/analysis/analysis-test-framework/tests/org/jetbrains/kotlin/analysis/test/framework/base/AbstractAnalysisApiBasedTest.kt @@ -177,17 +177,18 @@ abstract class AbstractAnalysisApiBasedTest : TestWithDisposable() { private fun isFirDisabledForTheTest(): Boolean = AnalysisApiTestDirectives.IGNORE_FIR in testServices.moduleStructure.allDirectives - protected fun analyseForTest(contextElement: KtElement, action: KtAnalysisSession.() -> R): R { + protected fun analyseForTest(contextElement: KtElement, action: KtAnalysisSession.(KtElement) -> R): R { return if (configurator.analyseInDependentSession) { val originalContainingFile = contextElement.containingKtFile val fileCopy = originalContainingFile.copy() as KtFile + val sameElementInCopy = PsiTreeUtil.findSameElementInCopy(contextElement, fileCopy) analyzeInDependedAnalysisSession( originalContainingFile, - PsiTreeUtil.findSameElementInCopy(contextElement, fileCopy), - action = action + sameElementInCopy, + action = { action(sameElementInCopy) } ) } else { - analyze(contextElement, action = action) + analyze(contextElement, action = { action(contextElement) }) } } diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirNestedClassifierScopeWithSubstitution.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirNestedClassifierScopeWithSubstitution.kt index 1f83b076d60..1dabb20fabe 100644 --- a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirNestedClassifierScopeWithSubstitution.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirNestedClassifierScopeWithSubstitution.kt @@ -15,7 +15,7 @@ import org.jetbrains.kotlin.fir.symbols.impl.* import org.jetbrains.kotlin.fir.types.ConeClassLikeType import org.jetbrains.kotlin.name.Name -private class FirNestedClassifierScopeWithSubstitution( +class FirNestedClassifierScopeWithSubstitution internal constructor( private val scope: FirContainingNamesAwareScope, private val substitutor: ConeSubstitutor ) : FirContainingNamesAwareScope() { diff --git a/generators/analysis-api-generator/tests/org/jetbrains/kotlin/generators/tests/analysis/api/analysisApi.kt b/generators/analysis-api-generator/tests/org/jetbrains/kotlin/generators/tests/analysis/api/analysisApi.kt index 144b37a0d89..889b1ebec3f 100644 --- a/generators/analysis-api-generator/tests/org/jetbrains/kotlin/generators/tests/analysis/api/analysisApi.kt +++ b/generators/analysis-api-generator/tests/org/jetbrains/kotlin/generators/tests/analysis/api/analysisApi.kt @@ -416,5 +416,11 @@ private fun AnalysisApiTestGroup.generateAnalysisApiComponentsTests() { model("typeScope") } } + + group(filter = frontendIs(FrontendKind.Fir)) { + test(AbstractScopeContextForPositionTest::class) { + model("scopeContextForPosition") + } + } } }