diff --git a/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt b/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt index b05d4a0f326..6546fe93f51 100644 --- a/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt +++ b/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt @@ -92,6 +92,7 @@ import org.jetbrains.kotlin.idea.folding.AbstractKotlinFoldingTest import org.jetbrains.kotlin.idea.frontend.api.components.AbstractExpectedExpressionTypeTest import org.jetbrains.kotlin.idea.frontend.api.components.AbstractReturnExpressionTargetTest import org.jetbrains.kotlin.idea.frontend.api.fir.AbstractResolveCallTest +import org.jetbrains.kotlin.idea.frontend.api.scopes.AbstractFileScopeTest import org.jetbrains.kotlin.idea.frontend.api.scopes.AbstractMemberScopeByFqNameTest import org.jetbrains.kotlin.idea.frontend.api.symbols.* import org.jetbrains.kotlin.idea.hierarchy.AbstractHierarchyTest @@ -1013,6 +1014,10 @@ fun main(args: Array) { model("memberScopeByFqName", extension = "txt") } + testClass { + model("fileScopeTest", extension = "kt") + } + testClass { model("symbolPointer", extension = "kt") } diff --git a/idea/idea-frontend-fir/testData/fileScopeTest/simpleFileScope.kt b/idea/idea-frontend-fir/testData/fileScopeTest/simpleFileScope.kt new file mode 100644 index 00000000000..0a9c291a6a4 --- /dev/null +++ b/idea/idea-frontend-fir/testData/fileScopeTest/simpleFileScope.kt @@ -0,0 +1,11 @@ +fun test(): Int = 3 + +val testVal: Int = 2 + +class C { + fun r() { + + } +} + +interface I diff --git a/idea/idea-frontend-fir/testData/fileScopeTest/simpleFileScope.kt.result b/idea/idea-frontend-fir/testData/fileScopeTest/simpleFileScope.kt.result new file mode 100644 index 00000000000..02f237af8fd --- /dev/null +++ b/idea/idea-frontend-fir/testData/fileScopeTest/simpleFileScope.kt.result @@ -0,0 +1,83 @@ +FILE SYMBOL: +KtFirFileSymbol: + annotations: [] + origin: SOURCE + +CALLABLE NAMES: +[test, testVal] + +CALLABLE SYMBOLS: +KtFirFunctionSymbol: + annotations: [] + callableIdIfNonLocal: test + isExtension: false + isExternal: false + isInline: false + isOperator: false + isOverride: false + isSuspend: false + modality: FINAL + name: test + origin: SOURCE + receiverTypeAndAnnotations: null + symbolKind: TOP_LEVEL + type: kotlin/Int + typeParameters: [] + valueParameters: [] + visibility: PUBLIC + +KtFirKotlinPropertySymbol: + annotations: [] + callableIdIfNonLocal: testVal + getter: KtFirPropertyGetterSymbol() + hasBackingField: true + hasGetter: true + hasSetter: false + initializer: 2 + isConst: false + isExtension: false + isLateInit: false + isOverride: false + isVal: true + modality: FINAL + name: testVal + origin: SOURCE + receiverTypeAndAnnotations: null + setter: null + symbolKind: TOP_LEVEL + type: kotlin/Int + visibility: PUBLIC + +CLASSIFIER NAMES: +[C, I] + +CLASSIFIER SYMBOLS: +KtFirClassOrObjectSymbol: + annotations: [] + classIdIfNonLocal: C + classKind: CLASS + companionObject: null + isInner: false + modality: FINAL + name: C + origin: SOURCE + primaryConstructor: KtFirConstructorSymbol() + superTypes: [kotlin/Any] + symbolKind: TOP_LEVEL + typeParameters: [] + visibility: PUBLIC + +KtFirClassOrObjectSymbol: + annotations: [] + classIdIfNonLocal: I + classKind: INTERFACE + companionObject: null + isInner: false + modality: ABSTRACT + name: I + origin: SOURCE + primaryConstructor: null + superTypes: [kotlin/Any] + symbolKind: TOP_LEVEL + typeParameters: [] + visibility: PUBLIC diff --git a/idea/idea-frontend-fir/tests/org/jetbrains/kotlin/idea/frontend/api/scopes/AbstractFileScopeTest.kt b/idea/idea-frontend-fir/tests/org/jetbrains/kotlin/idea/frontend/api/scopes/AbstractFileScopeTest.kt new file mode 100644 index 00000000000..43508cd439f --- /dev/null +++ b/idea/idea-frontend-fir/tests/org/jetbrains/kotlin/idea/frontend/api/scopes/AbstractFileScopeTest.kt @@ -0,0 +1,43 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.idea.frontend.api.scopes + +import com.intellij.openapi.util.io.FileUtil +import org.jetbrains.kotlin.idea.executeOnPooledThreadInReadAction +import org.jetbrains.kotlin.idea.frontend.api.analyze +import org.jetbrains.kotlin.idea.frontend.api.symbols.DebugSymbolRenderer +import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase +import org.jetbrains.kotlin.psi.KtFile +import org.jetbrains.kotlin.test.KotlinTestUtils +import java.io.File + +abstract class AbstractFileScopeTest : KotlinLightCodeInsightFixtureTestCase() { + + protected fun doTest(path: String) { + val ktFile = myFixture.configureByText("file.kt", FileUtil.loadFile(File(path))) as KtFile + + val actual = executeOnPooledThreadInReadAction { + analyze(ktFile) { + val symbol = ktFile.getFileSymbol() + val scope = symbol.getFileScope() + + val renderedSymbol = DebugSymbolRenderer.render(symbol) + val callableNames = scope.getCallableNames() + val renderedCallables = scope.getCallableSymbols().map { DebugSymbolRenderer.render(it) } + val classifierNames = scope.getClassifierNames() + val renderedClassifiers = scope.getClassifierSymbols().map { DebugSymbolRenderer.render(it) } + + "FILE SYMBOL:\n" + renderedSymbol + + "\nCALLABLE NAMES:\n" + callableNames.joinToString(prefix = "[", postfix = "]\n", separator = ", ") + + "\nCALLABLE SYMBOLS:\n" + renderedCallables.joinToString(separator = "\n") + + "\nCLASSIFIER NAMES:\n" + classifierNames.joinToString(prefix = "[", postfix = "]\n", separator = ", ") + + "\nCLASSIFIER SYMBOLS:\n" + renderedClassifiers.joinToString(separator = "\n") + } + } + + KotlinTestUtils.assertEqualsToFile(File("$path.result"), actual) + } +} \ No newline at end of file diff --git a/idea/idea-frontend-fir/tests/org/jetbrains/kotlin/idea/frontend/api/scopes/FileScopeTestGenerated.java b/idea/idea-frontend-fir/tests/org/jetbrains/kotlin/idea/frontend/api/scopes/FileScopeTestGenerated.java new file mode 100644 index 00000000000..abd237e6f29 --- /dev/null +++ b/idea/idea-frontend-fir/tests/org/jetbrains/kotlin/idea/frontend/api/scopes/FileScopeTestGenerated.java @@ -0,0 +1,35 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.idea.frontend.api.scopes; + +import com.intellij.testFramework.TestDataPath; +import org.jetbrains.kotlin.test.JUnit3RunnerWithInners; +import org.jetbrains.kotlin.test.KotlinTestUtils; +import org.jetbrains.kotlin.test.TestMetadata; +import org.junit.runner.RunWith; + +import java.io.File; +import java.util.regex.Pattern; + +/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */ +@SuppressWarnings("all") +@TestMetadata("idea/idea-frontend-fir/testData/fileScopeTest") +@TestDataPath("$PROJECT_ROOT") +@RunWith(JUnit3RunnerWithInners.class) +public class FileScopeTestGenerated extends AbstractFileScopeTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInFileScopeTest() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/idea-frontend-fir/testData/fileScopeTest"), Pattern.compile("^(.+)\\.kt$"), null, true); + } + + @TestMetadata("simpleFileScope.kt") + public void testSimpleFileScope() throws Exception { + runTest("idea/idea-frontend-fir/testData/fileScopeTest/simpleFileScope.kt"); + } +}