KT-63096 [LL] Add test for using annotation from other module for compiler plugin
This commit is contained in:
+10
@@ -45,4 +45,14 @@ public class FirIdeNormalAnalysisScriptSourceModuleMultiModuleResolveCallTestGen
|
||||
public void testAllFilesPresentInResolveCall() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/analysis-api/testData/components/multiModuleCallResolver/resolveCall"), Pattern.compile("^(.+)\\.kts$"), null, true);
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("analysis/analysis-api/testData/components/multiModuleCallResolver/resolveCall/withTestCompilerPluginEnabled")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
public class WithTestCompilerPluginEnabled {
|
||||
@Test
|
||||
public void testAllFilesPresentInWithTestCompilerPluginEnabled() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/analysis-api/testData/components/multiModuleCallResolver/resolveCall/withTestCompilerPluginEnabled"), Pattern.compile("^(.+)\\.kts$"), null, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+16
@@ -57,4 +57,20 @@ public class FirIdeNormalAnalysisSourceModuleMultiModuleResolveCallTestGenerated
|
||||
public void testUnitTypeFromOtherModule() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/multiModuleCallResolver/resolveCall/unitTypeFromOtherModule.kt");
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("analysis/analysis-api/testData/components/multiModuleCallResolver/resolveCall/withTestCompilerPluginEnabled")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
public class WithTestCompilerPluginEnabled {
|
||||
@Test
|
||||
public void testAllFilesPresentInWithTestCompilerPluginEnabled() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/analysis-api/testData/components/multiModuleCallResolver/resolveCall/withTestCompilerPluginEnabled"), Pattern.compile("^(.+)\\.kt$"), null, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("annotationFromOtherModule.kt")
|
||||
public void testAnnotationFromOtherModule() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/multiModuleCallResolver/resolveCall/withTestCompilerPluginEnabled/annotationFromOtherModule.kt");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+16
@@ -57,4 +57,20 @@ public class FirStandaloneNormalAnalysisSourceModuleMultiModuleResolveCallTestGe
|
||||
public void testUnitTypeFromOtherModule() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/multiModuleCallResolver/resolveCall/unitTypeFromOtherModule.kt");
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("analysis/analysis-api/testData/components/multiModuleCallResolver/resolveCall/withTestCompilerPluginEnabled")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
public class WithTestCompilerPluginEnabled {
|
||||
@Test
|
||||
public void testAllFilesPresentInWithTestCompilerPluginEnabled() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/analysis-api/testData/components/multiModuleCallResolver/resolveCall/withTestCompilerPluginEnabled"), Pattern.compile("^(.+)\\.kt$"), null, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("annotationFromOtherModule.kt")
|
||||
public void testAnnotationFromOtherModule() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/multiModuleCallResolver/resolveCall/withTestCompilerPluginEnabled/annotationFromOtherModule.kt");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
@@ -9,6 +9,7 @@ import com.intellij.openapi.Disposable
|
||||
import com.intellij.openapi.project.Project
|
||||
import org.jetbrains.kotlin.analysis.api.standalone.base.project.structure.KtModuleProjectStructure
|
||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.compiler.based.SealedClassesInheritorsCaclulatorPreAnalysisHandler
|
||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.test.base.configureOptionalTestCompilerPlugin
|
||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.test.configurators.AnalysisApiFirSourceTestConfigurator
|
||||
import org.jetbrains.kotlin.analysis.test.framework.project.structure.KtModuleFactory
|
||||
import org.jetbrains.kotlin.analysis.test.framework.project.structure.KtSourceModuleFactory
|
||||
@@ -33,6 +34,7 @@ object StandaloneModeConfigurator : AnalysisApiTestConfigurator() {
|
||||
useAdditionalService<KtModuleFactory> { KtSourceModuleFactory() }
|
||||
useDirectives(SealedClassesInheritorsCaclulatorPreAnalysisHandler.Directives)
|
||||
usePreAnalysisHandlers(::SealedClassesInheritorsCaclulatorPreAnalysisHandler)
|
||||
configureOptionalTestCompilerPlugin()
|
||||
useConfigurators(::ExternalAnnotationsEnvironmentConfigurator)
|
||||
useSourcePreprocessor(::ExternalAnnotationsSourcePreprocessor)
|
||||
}
|
||||
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// WITH_FIR_TEST_COMPILER_PLUGIN
|
||||
// MODULE: lib
|
||||
|
||||
// FILE: foo/MyAnnotation.kt
|
||||
package foo
|
||||
|
||||
annotation class MyAnnotation
|
||||
|
||||
// MODULE: main(lib)
|
||||
|
||||
// FILE: test/main.kt
|
||||
package test
|
||||
|
||||
@foo.MyAnnotation
|
||||
class MyClass
|
||||
|
||||
fun test(myClass: MyClass) {
|
||||
myClass.mater<caret>ialize()
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
KtSuccessCallInfo:
|
||||
call = KtSimpleFunctionCall:
|
||||
isImplicitInvoke = false
|
||||
partiallyAppliedSymbol = KtPartiallyAppliedSymbol:
|
||||
dispatchReceiver = KtExplicitReceiverValue:
|
||||
expression = myClass
|
||||
isSafeNavigation = false
|
||||
type = test.MyClass
|
||||
extensionReceiver = null
|
||||
signature = KtFunctionLikeSignature:
|
||||
receiverType = null
|
||||
returnType = test.MyClass
|
||||
symbol = test/MyClass.materialize(<dispatch receiver>: test.MyClass): test.MyClass
|
||||
valueParameters = []
|
||||
callableIdIfNonLocal = test/MyClass.materialize
|
||||
typeArgumentsMapping = {}
|
||||
argumentMapping = {}
|
||||
+1
-1
@@ -29,7 +29,7 @@ private object CompilerPluginsDirectives : SimpleDirectivesContainer() {
|
||||
)
|
||||
}
|
||||
|
||||
internal fun TestConfigurationBuilder.configureOptionalTestCompilerPlugin() {
|
||||
fun TestConfigurationBuilder.configureOptionalTestCompilerPlugin() {
|
||||
useDirectives(CompilerPluginsDirectives)
|
||||
|
||||
useConfigurators(
|
||||
|
||||
+12
-1
@@ -29,7 +29,18 @@ class AdditionalMembersGenerator(session: FirSession) : FirDeclarationGeneration
|
||||
private val MATERIALIZE_NAME = Name.identifier("materialize")
|
||||
private val NESTED_NAME = Name.identifier("Nested")
|
||||
|
||||
private val PREDICATE = LookupPredicate.create { annotated("NestedClassAndMaterializeMember".fqn()) }
|
||||
/**
|
||||
* This annotation does not exist in 'plugin-annotations' module/jar; instead,
|
||||
* it's supposed to be defined in the user's (or test case) code.
|
||||
*
|
||||
* We need this to test that the generation extensions and annotation resolvers
|
||||
* properly work with such annotations and with the declarations marked by them.
|
||||
*/
|
||||
private val MY_ANNOTATION = AnnotationFqn("foo.MyAnnotation")
|
||||
|
||||
private val PREDICATE = LookupPredicate.create {
|
||||
annotated("NestedClassAndMaterializeMember".fqn()) or annotated(MY_ANNOTATION)
|
||||
}
|
||||
}
|
||||
|
||||
private val predicateBasedProvider = session.predicateBasedProvider
|
||||
|
||||
Reference in New Issue
Block a user