[Analysis API] add tests for getImportingScopeContext

^KT-57966
This commit is contained in:
Ilya Kirillov
2023-05-01 12:27:25 +02:00
committed by Space Team
parent 20f921c0bf
commit eeac3f53b4
20 changed files with 616 additions and 0 deletions
@@ -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.components.scopeProvider;
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.components.scopeProvider.AbstractFileImportingScopeContextTest;
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/importingScopeContext")
@TestDataPath("$PROJECT_ROOT")
public class FirIdeDependentAnalysisSourceModuleFileImportingScopeContextTestGenerated extends AbstractFileImportingScopeContextTest {
@NotNull
@Override
public AnalysisApiTestConfigurator getConfigurator() {
return AnalysisApiFirTestConfiguratorFactory.INSTANCE.createConfigurator(
new AnalysisApiTestConfiguratorFactoryData(
FrontendKind.Fir,
TestModuleKind.Source,
AnalysisSessionMode.Dependent,
AnalysisApiMode.Ide
)
);
}
@Test
public void testAllFilesPresentInImportingScopeContext() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/analysis-api/testData/components/scopeProvider/importingScopeContext"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
@Test
@TestMetadata("errorImport.kt")
public void testErrorImport() throws Exception {
runTest("analysis/analysis-api/testData/components/scopeProvider/importingScopeContext/errorImport.kt");
}
@Test
@TestMetadata("importAlias.kt")
public void testImportAlias() throws Exception {
runTest("analysis/analysis-api/testData/components/scopeProvider/importingScopeContext/importAlias.kt");
}
@Test
@TestMetadata("noImports.kt")
public void testNoImports() throws Exception {
runTest("analysis/analysis-api/testData/components/scopeProvider/importingScopeContext/noImports.kt");
}
@Test
@TestMetadata("simpleImport.kt")
public void testSimpleImport() throws Exception {
runTest("analysis/analysis-api/testData/components/scopeProvider/importingScopeContext/simpleImport.kt");
}
@Test
@TestMetadata("starImport.kt")
public void testStarImport() throws Exception {
runTest("analysis/analysis-api/testData/components/scopeProvider/importingScopeContext/starImport.kt");
}
}
@@ -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.components.scopeProvider;
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.components.scopeProvider.AbstractFileImportingScopeContextTest;
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/importingScopeContext")
@TestDataPath("$PROJECT_ROOT")
public class FirIdeNormalAnalysisSourceModuleFileImportingScopeContextTestGenerated extends AbstractFileImportingScopeContextTest {
@NotNull
@Override
public AnalysisApiTestConfigurator getConfigurator() {
return AnalysisApiFirTestConfiguratorFactory.INSTANCE.createConfigurator(
new AnalysisApiTestConfiguratorFactoryData(
FrontendKind.Fir,
TestModuleKind.Source,
AnalysisSessionMode.Normal,
AnalysisApiMode.Ide
)
);
}
@Test
public void testAllFilesPresentInImportingScopeContext() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/analysis-api/testData/components/scopeProvider/importingScopeContext"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
@Test
@TestMetadata("errorImport.kt")
public void testErrorImport() throws Exception {
runTest("analysis/analysis-api/testData/components/scopeProvider/importingScopeContext/errorImport.kt");
}
@Test
@TestMetadata("importAlias.kt")
public void testImportAlias() throws Exception {
runTest("analysis/analysis-api/testData/components/scopeProvider/importingScopeContext/importAlias.kt");
}
@Test
@TestMetadata("noImports.kt")
public void testNoImports() throws Exception {
runTest("analysis/analysis-api/testData/components/scopeProvider/importingScopeContext/noImports.kt");
}
@Test
@TestMetadata("simpleImport.kt")
public void testSimpleImport() throws Exception {
runTest("analysis/analysis-api/testData/components/scopeProvider/importingScopeContext/simpleImport.kt");
}
@Test
@TestMetadata("starImport.kt")
public void testStarImport() throws Exception {
runTest("analysis/analysis-api/testData/components/scopeProvider/importingScopeContext/starImport.kt");
}
}
@@ -0,0 +1,56 @@
/*
* 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.components.scopeProvider
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.impl.base.test.cases.components.scopeProvider.TestScopeRenderer.renderForTests
import org.jetbrains.kotlin.analysis.test.framework.base.AbstractAnalysisApiBasedSingleModuleTest
import org.jetbrains.kotlin.analysis.utils.printer.prettyPrint
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.test.directives.model.SimpleDirectivesContainer
import org.jetbrains.kotlin.test.model.TestModule
import org.jetbrains.kotlin.test.services.TestServices
import org.jetbrains.kotlin.test.services.assertions
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstance
abstract class AbstractFileImportingScopeContextTest : AbstractAnalysisApiBasedSingleModuleTest() {
override fun doTestByFileStructure(ktFiles: List<KtFile>, module: TestModule, testServices: TestServices) {
val ktFile = ktFiles.first()
val renderDefaultImportingScope = Directives.RENDER_DEFAULT_IMPORTING_SCOPE in module.directives
analyseForTest(ktFile.children.firstIsInstance()) {
val ktScopeContext = ktFile.getImportingScopeContext()
val scopeContextStringRepresentation = render(ktScopeContext, renderDefaultImportingScope)
val scopeContextStringRepresentationPretty = render(ktScopeContext, renderDefaultImportingScope, printPretty = true)
testServices.assertions.assertEqualsToTestDataFileSibling(scopeContextStringRepresentation)
testServices.assertions.assertEqualsToTestDataFileSibling(scopeContextStringRepresentationPretty, extension = ".pretty.txt")
}
}
context(KtAnalysisSession)
private fun render(
importingScope: KtScopeContext,
renderDefaultImportingScope: Boolean,
printPretty: Boolean = false
): String = prettyPrint {
renderForTests(importingScope, printPretty) { ktScopeKind ->
when (ktScopeKind) {
is KtScopeKind.PackageMemberScope -> false
is KtScopeKind.DefaultSimpleImportingScope -> renderDefaultImportingScope
is KtScopeKind.DefaultStarImportingScope -> renderDefaultImportingScope
else -> true
}
}
}
private object Directives : SimpleDirectivesContainer() {
val RENDER_DEFAULT_IMPORTING_SCOPE by directive("render default importing scope in test output")
}
}
@@ -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.components.scopeProvider;
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.components.scopeProvider.AbstractFileImportingScopeContextTest;
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/importingScopeContext")
@TestDataPath("$PROJECT_ROOT")
public class FirStandaloneNormalAnalysisSourceModuleFileImportingScopeContextTestGenerated extends AbstractFileImportingScopeContextTest {
@NotNull
@Override
public AnalysisApiTestConfigurator getConfigurator() {
return AnalysisApiFirStandaloneModeTestConfiguratorFactory.INSTANCE.createConfigurator(
new AnalysisApiTestConfiguratorFactoryData(
FrontendKind.Fir,
TestModuleKind.Source,
AnalysisSessionMode.Normal,
AnalysisApiMode.Standalone
)
);
}
@Test
public void testAllFilesPresentInImportingScopeContext() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/analysis-api/testData/components/scopeProvider/importingScopeContext"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
@Test
@TestMetadata("errorImport.kt")
public void testErrorImport() throws Exception {
runTest("analysis/analysis-api/testData/components/scopeProvider/importingScopeContext/errorImport.kt");
}
@Test
@TestMetadata("importAlias.kt")
public void testImportAlias() throws Exception {
runTest("analysis/analysis-api/testData/components/scopeProvider/importingScopeContext/importAlias.kt");
}
@Test
@TestMetadata("noImports.kt")
public void testNoImports() throws Exception {
runTest("analysis/analysis-api/testData/components/scopeProvider/importingScopeContext/noImports.kt");
}
@Test
@TestMetadata("simpleImport.kt")
public void testSimpleImport() throws Exception {
runTest("analysis/analysis-api/testData/components/scopeProvider/importingScopeContext/simpleImport.kt");
}
@Test
@TestMetadata("starImport.kt")
public void testStarImport() throws Exception {
runTest("analysis/analysis-api/testData/components/scopeProvider/importingScopeContext/starImport.kt");
}
}
@@ -0,0 +1,4 @@
import c.b
val a = 5 // some KtElement to analyze in the air against
@@ -0,0 +1,17 @@
implicit receivers:
scopes:
DefaultStarImportingScope, index = 0
DefaultStarImportingScope, index = 1
DefaultSimpleImportingScope, index = 2
ExplicitStarImportingScope, index = 3, empty
DefaultSimpleImportingScope, index = 4
DefaultSimpleImportingScope, index = 5
PackageMemberScope, index = 6
ExplicitSimpleImportingScope, index = 7, empty
@@ -0,0 +1,18 @@
implicit receivers:
scopes:
DefaultStarImportingScope, index = 0
DefaultStarImportingScope, index = 1
DefaultSimpleImportingScope, index = 2
ExplicitStarImportingScope, index = 3, empty
DefaultSimpleImportingScope, index = 4
DefaultSimpleImportingScope, index = 5
PackageMemberScope, index = 6
ExplicitSimpleImportingScope, index = 7, empty
@@ -0,0 +1,9 @@
// FILE: main.kt
import other.A as AAA
val a = 5 // some KtElement to analyze in the air against
// FILE: other/other.kt
package other
class A
@@ -0,0 +1,20 @@
implicit receivers:
scopes:
DefaultStarImportingScope, index = 0
DefaultStarImportingScope, index = 1
DefaultSimpleImportingScope, index = 2
ExplicitStarImportingScope, index = 3, empty
DefaultSimpleImportingScope, index = 4
DefaultSimpleImportingScope, index = 5
PackageMemberScope, index = 6
ExplicitSimpleImportingScope, index = 7
classifiers: 1
class A
callables: 0
@@ -0,0 +1,43 @@
implicit receivers:
scopes:
DefaultStarImportingScope, index = 0
DefaultStarImportingScope, index = 1
DefaultSimpleImportingScope, index = 2
ExplicitStarImportingScope, index = 3, empty
DefaultSimpleImportingScope, index = 4
DefaultSimpleImportingScope, index = 5
PackageMemberScope, index = 6
ExplicitSimpleImportingScope, index = 7
classifiers: 1
KtNamedClassOrObjectSymbol:
annotationsList: []
classIdIfNonLocal: other/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: 0
@@ -0,0 +1,3 @@
// RENDER_DEFAULT_IMPORTING_SCOPE
val a = 5 // some KtElement to analyze in the air against
@@ -0,0 +1,17 @@
implicit receivers:
scopes:
DefaultStarImportingScope, index = 0
DefaultStarImportingScope, index = 1
DefaultSimpleImportingScope, index = 2
ExplicitStarImportingScope, index = 3, empty
DefaultSimpleImportingScope, index = 4
DefaultSimpleImportingScope, index = 5
PackageMemberScope, index = 6
ExplicitSimpleImportingScope, index = 7, empty
@@ -0,0 +1,18 @@
implicit receivers:
scopes:
DefaultStarImportingScope, index = 0
DefaultStarImportingScope, index = 1
DefaultSimpleImportingScope, index = 2
ExplicitStarImportingScope, index = 3, empty
DefaultSimpleImportingScope, index = 4
DefaultSimpleImportingScope, index = 5
PackageMemberScope, index = 6
ExplicitSimpleImportingScope, index = 7, empty
@@ -0,0 +1,9 @@
// FILE: main.kt
import other.A
val a = 5 // some KtElement to analyze in the air against
// FILE: other/other.kt
package other
class A
@@ -0,0 +1,20 @@
implicit receivers:
scopes:
DefaultStarImportingScope, index = 0
DefaultStarImportingScope, index = 1
DefaultSimpleImportingScope, index = 2
ExplicitStarImportingScope, index = 3, empty
DefaultSimpleImportingScope, index = 4
DefaultSimpleImportingScope, index = 5
PackageMemberScope, index = 6
ExplicitSimpleImportingScope, index = 7
classifiers: 1
class A
callables: 0
@@ -0,0 +1,43 @@
implicit receivers:
scopes:
DefaultStarImportingScope, index = 0
DefaultStarImportingScope, index = 1
DefaultSimpleImportingScope, index = 2
ExplicitStarImportingScope, index = 3, empty
DefaultSimpleImportingScope, index = 4
DefaultSimpleImportingScope, index = 5
PackageMemberScope, index = 6
ExplicitSimpleImportingScope, index = 7
classifiers: 1
KtNamedClassOrObjectSymbol:
annotationsList: []
classIdIfNonLocal: other/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: 0
@@ -0,0 +1,10 @@
// FILE: main.kt
import other.*
val a = 5 // some KtElement to analyze in the air against
// FILE: other/other.kt
package other
class A
fun b() {}
@@ -0,0 +1,21 @@
implicit receivers:
scopes:
DefaultStarImportingScope, index = 0
DefaultStarImportingScope, index = 1
DefaultSimpleImportingScope, index = 2
ExplicitStarImportingScope, index = 3
classifiers: 1
class A
callables: 1
fun b()
DefaultSimpleImportingScope, index = 4
DefaultSimpleImportingScope, index = 5
PackageMemberScope, index = 6
ExplicitSimpleImportingScope, index = 7, empty
@@ -0,0 +1,70 @@
implicit receivers:
scopes:
DefaultStarImportingScope, index = 0
DefaultStarImportingScope, index = 1
DefaultSimpleImportingScope, index = 2
ExplicitStarImportingScope, index = 3
classifiers: 1
KtNamedClassOrObjectSymbol:
annotationsList: []
classIdIfNonLocal: other/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: 1
KtFunctionSymbol:
annotationsList: []
callableIdIfNonLocal: other/b
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: b
origin: SOURCE
receiverParameter: null
returnType: KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: kotlin/Unit
symbolKind: TOP_LEVEL
typeParameters: []
valueParameters: []
visibility: Public
DefaultSimpleImportingScope, index = 4
DefaultSimpleImportingScope, index = 5
PackageMemberScope, index = 6
ExplicitSimpleImportingScope, index = 7, empty
@@ -399,6 +399,10 @@ private fun AnalysisApiTestGroup.generateAnalysisApiComponentsTests() {
test(AbstractScopeContextForPositionTest::class) {
model("scopeContextForPosition")
}
test(AbstractFileImportingScopeContextTest::class) {
model("importingScopeContext")
}
}
group(filter = analysisSessionModeIs(AnalysisSessionMode.Normal)) {