summaryrefslogtreecommitdiff
path: root/plugins/kotlin/analysis-api-providers-ide-impl/test
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/kotlin/analysis-api-providers-ide-impl/test')
-rw-r--r--plugins/kotlin/analysis-api-providers-ide-impl/test/org/jetbrains/kotlin/idea/fir/analysis/providers/AbstractKotlinIdeAnnotationsResolverTest.kt57
-rw-r--r--plugins/kotlin/analysis-api-providers-ide-impl/test/org/jetbrains/kotlin/idea/fir/analysis/providers/KotlinIdeAnnotationsResolverTestGenerated.java96
-rw-r--r--plugins/kotlin/analysis-api-providers-ide-impl/test/org/jetbrains/kotlin/idea/fir/analysis/providers/sessions/AbstractSessionsInvalidationTest.kt14
-rw-r--r--plugins/kotlin/analysis-api-providers-ide-impl/test/org/jetbrains/kotlin/idea/fir/analysis/providers/sessions/SessionsInvalidationTestGenerated.java2
-rw-r--r--plugins/kotlin/analysis-api-providers-ide-impl/test/org/jetbrains/kotlin/idea/fir/analysis/providers/trackers/ProjectWideOutOfBlockKotlinModificationTrackerTestGenerated.java2
5 files changed, 162 insertions, 9 deletions
diff --git a/plugins/kotlin/analysis-api-providers-ide-impl/test/org/jetbrains/kotlin/idea/fir/analysis/providers/AbstractKotlinIdeAnnotationsResolverTest.kt b/plugins/kotlin/analysis-api-providers-ide-impl/test/org/jetbrains/kotlin/idea/fir/analysis/providers/AbstractKotlinIdeAnnotationsResolverTest.kt
new file mode 100644
index 000000000000..e247ae9e3125
--- /dev/null
+++ b/plugins/kotlin/analysis-api-providers-ide-impl/test/org/jetbrains/kotlin/idea/fir/analysis/providers/AbstractKotlinIdeAnnotationsResolverTest.kt
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2010-2022 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.fir.analysis.providers
+
+import com.intellij.openapi.components.service
+import com.intellij.psi.search.GlobalSearchScope
+import com.intellij.psi.util.parentOfType
+import org.jetbrains.kotlin.analysis.providers.KotlinAnnotationsResolver
+import org.jetbrains.kotlin.analysis.providers.KotlinAnnotationsResolverFactory
+import org.jetbrains.kotlin.idea.test.InTextDirectivesUtils
+import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
+import org.jetbrains.kotlin.psi.KtAnnotated
+import org.jetbrains.kotlin.psi.psiUtil.getElementTextWithContext
+import java.io.File
+
+abstract class AbstractKotlinIdeAnnotationsResolverTest : KotlinLightCodeInsightFixtureTestCase() {
+ private val expectedAnnotationsDirective: String = "// ANNOTATION:"
+
+ private val annotationsResolver: KotlinAnnotationsResolver
+ get() = project.service<KotlinAnnotationsResolverFactory>().createAnnotationResolver(GlobalSearchScope.projectScope(project))
+
+ fun doTest(path: String) {
+ val mainTestFile = File(path)
+ val allTestFiles = listOf(mainTestFile) + resolveDependencyFiles(mainTestFile)
+
+ myFixture.configureByFiles(*allTestFiles.toTypedArray())
+
+ val annotatedElement = myFixture.elementAtCaret.parentOfType<KtAnnotated>(withSelf = true)
+ ?: error("Expected KtAnnotation element at the caret: ${myFixture.elementAtCaret.getElementTextWithContext()}")
+
+ val actualAnnotations = annotationsResolver.annotationsOnDeclaration(annotatedElement).sortedBy { it.toString() }
+ val expectedAnnotations = InTextDirectivesUtils.findListWithPrefixes(
+ myFixture.editor.document.text,
+ expectedAnnotationsDirective
+ ).filter { it.isNotEmpty() }
+
+ assertEquals(
+ "Expected annotations not found on the element under the caret:",
+ expectedAnnotations,
+ actualAnnotations.map { it.toString() }
+ )
+ }
+
+ private fun resolveDependencyFiles(mainFile: File): List<File> {
+ val dependencySuffixes = listOf(".dependency.kt", ".dependency1.kt", ".dependency2.kt")
+
+ return dependencySuffixes
+ .map { suffix -> mainFile.resolveSiblingWithDifferentExtension(suffix) }
+ .filter { it.exists() }
+ }
+
+ private fun File.resolveSiblingWithDifferentExtension(newExtension: String): File =
+ resolveSibling("$nameWithoutExtension$newExtension")
+}
+
diff --git a/plugins/kotlin/analysis-api-providers-ide-impl/test/org/jetbrains/kotlin/idea/fir/analysis/providers/KotlinIdeAnnotationsResolverTestGenerated.java b/plugins/kotlin/analysis-api-providers-ide-impl/test/org/jetbrains/kotlin/idea/fir/analysis/providers/KotlinIdeAnnotationsResolverTestGenerated.java
new file mode 100644
index 000000000000..dc07f1a93437
--- /dev/null
+++ b/plugins/kotlin/analysis-api-providers-ide-impl/test/org/jetbrains/kotlin/idea/fir/analysis/providers/KotlinIdeAnnotationsResolverTestGenerated.java
@@ -0,0 +1,96 @@
+// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+
+package org.jetbrains.kotlin.idea.fir.analysis.providers;
+
+import com.intellij.testFramework.TestDataPath;
+import org.jetbrains.kotlin.idea.test.JUnit3RunnerWithInners;
+import org.jetbrains.kotlin.idea.test.KotlinTestUtils;
+import org.jetbrains.kotlin.test.TestMetadata;
+import org.jetbrains.kotlin.idea.test.TestRoot;
+import org.junit.runner.RunWith;
+
+/**
+ * This class is generated by {@link org.jetbrains.kotlin.testGenerator.generator.TestGenerator}.
+ * DO NOT MODIFY MANUALLY.
+ */
+@SuppressWarnings("all")
+@TestRoot("analysis-api-providers-ide-impl")
+@TestDataPath("$CONTENT_ROOT")
+@RunWith(JUnit3RunnerWithInners.class)
+@TestMetadata("testData/annotationsResolver")
+public class KotlinIdeAnnotationsResolverTestGenerated extends AbstractKotlinIdeAnnotationsResolverTest {
+ private void runTest(String testDataFilePath) throws Exception {
+ KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
+ }
+
+ @TestMetadata("annotations_in_brackets_syntax.kt")
+ public void testAnnotations_in_brackets_syntax() throws Exception {
+ runTest("testData/annotationsResolver/annotations_in_brackets_syntax.kt");
+ }
+
+ @TestMetadata("different_package_fqname.kt")
+ public void testDifferent_package_fqname() throws Exception {
+ runTest("testData/annotationsResolver/different_package_fqname.kt");
+ }
+
+ @TestMetadata("different_package_short_name_full_import.kt")
+ public void testDifferent_package_short_name_full_import() throws Exception {
+ runTest("testData/annotationsResolver/different_package_short_name_full_import.kt");
+ }
+
+ @TestMetadata("different_package_short_name_no_import.kt")
+ public void testDifferent_package_short_name_no_import() throws Exception {
+ runTest("testData/annotationsResolver/different_package_short_name_no_import.kt");
+ }
+
+ @TestMetadata("different_package_short_name_star_import.kt")
+ public void testDifferent_package_short_name_star_import() throws Exception {
+ runTest("testData/annotationsResolver/different_package_short_name_star_import.kt");
+ }
+
+ @TestMetadata("same_package_fqname.kt")
+ public void testSame_package_fqname() throws Exception {
+ runTest("testData/annotationsResolver/same_package_fqname.kt");
+ }
+
+ @TestMetadata("same_package_short_name.kt")
+ public void testSame_package_short_name() throws Exception {
+ runTest("testData/annotationsResolver/same_package_short_name.kt");
+ }
+
+ @RunWith(JUnit3RunnerWithInners.class)
+ @TestMetadata("testData/annotationsResolver/ambiguity")
+ public static class Ambiguity extends AbstractKotlinIdeAnnotationsResolverTest {
+ private void runTest(String testDataFilePath) throws Exception {
+ KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
+ }
+
+ @TestMetadata("full_import_different_packages.kt")
+ public void testFull_import_different_packages() throws Exception {
+ runTest("testData/annotationsResolver/ambiguity/full_import_different_packages.kt");
+ }
+
+ @TestMetadata("star_import_different_packages.kt")
+ public void testStar_import_different_packages() throws Exception {
+ runTest("testData/annotationsResolver/ambiguity/star_import_different_packages.kt");
+ }
+ }
+
+ @RunWith(JUnit3RunnerWithInners.class)
+ @TestMetadata("testData/annotationsResolver/priority")
+ public static class Priority extends AbstractKotlinIdeAnnotationsResolverTest {
+ private void runTest(String testDataFilePath) throws Exception {
+ KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
+ }
+
+ @TestMetadata("full_import_beats_star_import.kt")
+ public void testFull_import_beats_star_import() throws Exception {
+ runTest("testData/annotationsResolver/priority/full_import_beats_star_import.kt");
+ }
+
+ @TestMetadata("star_import_beats_package_import.kt")
+ public void testStar_import_beats_package_import() throws Exception {
+ runTest("testData/annotationsResolver/priority/star_import_beats_package_import.kt");
+ }
+ }
+}
diff --git a/plugins/kotlin/analysis-api-providers-ide-impl/test/org/jetbrains/kotlin/idea/fir/analysis/providers/sessions/AbstractSessionsInvalidationTest.kt b/plugins/kotlin/analysis-api-providers-ide-impl/test/org/jetbrains/kotlin/idea/fir/analysis/providers/sessions/AbstractSessionsInvalidationTest.kt
index a77e2dc86d2d..50f65b833758 100644
--- a/plugins/kotlin/analysis-api-providers-ide-impl/test/org/jetbrains/kotlin/idea/fir/analysis/providers/sessions/AbstractSessionsInvalidationTest.kt
+++ b/plugins/kotlin/analysis-api-providers-ide-impl/test/org/jetbrains/kotlin/idea/fir/analysis/providers/sessions/AbstractSessionsInvalidationTest.kt
@@ -7,9 +7,9 @@ import com.intellij.openapi.module.Module
import com.intellij.openapi.vfs.LocalFileSystem
import com.intellij.testFramework.PsiTestUtil
import junit.framework.Assert
-import org.jetbrains.kotlin.analysis.low.level.api.fir.sessions.FirIdeModuleSession
-import org.jetbrains.kotlin.analysis.low.level.api.fir.sessions.FirIdeSession
-import org.jetbrains.kotlin.analysis.low.level.api.fir.sessions.FirIdeSessionProviderStorage
+import org.jetbrains.kotlin.analysis.low.level.api.fir.sessions.LLFirModuleSession
+import org.jetbrains.kotlin.analysis.low.level.api.fir.sessions.LLFirSession
+import org.jetbrains.kotlin.analysis.low.level.api.fir.sessions.LLFirSessionProviderStorage
import org.jetbrains.kotlin.analysis.project.structure.KtSourceModule
import org.jetbrains.kotlin.idea.fir.analysis.project.structure.getMainKtSourceModule
import org.jetbrains.kotlin.idea.fir.analysis.providers.TestProjectModule
@@ -50,7 +50,7 @@ abstract class AbstractSessionsInvalidationTest : AbstractMultiModuleTest() {
val rootModuleSourceInfo = rootModule.getMainKtSourceModule()!!
- val storage = FirIdeSessionProviderStorage(project)
+ val storage = LLFirSessionProviderStorage(project)
val initialSessions = storage.getFirSessions(rootModuleSourceInfo)
modulesToMakeOOBM.forEach { it.incModificationTracker() }
@@ -62,7 +62,7 @@ abstract class AbstractSessionsInvalidationTest : AbstractMultiModuleTest() {
changedSessions.removeAll(intersection)
val changedSessionsModulesNamesSorted = changedSessions
.map { session ->
- val moduleSession = session as FirIdeModuleSession
+ val moduleSession = session as LLFirModuleSession
val module = moduleSession.module as KtSourceModule
module.moduleName
}
@@ -72,9 +72,9 @@ abstract class AbstractSessionsInvalidationTest : AbstractMultiModuleTest() {
Assert.assertEquals(testStructure.expectedInvalidatedModules, changedSessionsModulesNamesSorted)
}
- private fun FirIdeSessionProviderStorage.getFirSessions(module: KtSourceModule): Set<FirIdeSession> {
+ private fun LLFirSessionProviderStorage.getFirSessions(module: KtSourceModule): Set<LLFirSession> {
val sessionProvider = getSessionProvider(module)
- return sessionProvider.sessions.values.toSet()
+ return sessionProvider.allSessions.toSet()
}
private fun createEmptyModule(name: String): Module {
diff --git a/plugins/kotlin/analysis-api-providers-ide-impl/test/org/jetbrains/kotlin/idea/fir/analysis/providers/sessions/SessionsInvalidationTestGenerated.java b/plugins/kotlin/analysis-api-providers-ide-impl/test/org/jetbrains/kotlin/idea/fir/analysis/providers/sessions/SessionsInvalidationTestGenerated.java
index be7bc209a9ed..416e8403b734 100644
--- a/plugins/kotlin/analysis-api-providers-ide-impl/test/org/jetbrains/kotlin/idea/fir/analysis/providers/sessions/SessionsInvalidationTestGenerated.java
+++ b/plugins/kotlin/analysis-api-providers-ide-impl/test/org/jetbrains/kotlin/idea/fir/analysis/providers/sessions/SessionsInvalidationTestGenerated.java
@@ -1,4 +1,4 @@
-// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.kotlin.idea.fir.analysis.providers.sessions;
diff --git a/plugins/kotlin/analysis-api-providers-ide-impl/test/org/jetbrains/kotlin/idea/fir/analysis/providers/trackers/ProjectWideOutOfBlockKotlinModificationTrackerTestGenerated.java b/plugins/kotlin/analysis-api-providers-ide-impl/test/org/jetbrains/kotlin/idea/fir/analysis/providers/trackers/ProjectWideOutOfBlockKotlinModificationTrackerTestGenerated.java
index 53a48c4de6b8..0455c30fddd3 100644
--- a/plugins/kotlin/analysis-api-providers-ide-impl/test/org/jetbrains/kotlin/idea/fir/analysis/providers/trackers/ProjectWideOutOfBlockKotlinModificationTrackerTestGenerated.java
+++ b/plugins/kotlin/analysis-api-providers-ide-impl/test/org/jetbrains/kotlin/idea/fir/analysis/providers/trackers/ProjectWideOutOfBlockKotlinModificationTrackerTestGenerated.java
@@ -1,4 +1,4 @@
-// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.kotlin.idea.fir.analysis.providers.trackers;