KT-65425 [SLC] Correctly compute getQualifiedName for generated classes

Since the declarations generated by compiler plugins do not have proper
PSI (`classOrObjectDeclaration` in this case), we need to resort to
symbols for such declarations to compute the proper qualified name

^KT-65425 Fixed
This commit is contained in:
Roman Golyshev
2024-01-31 10:18:14 +01:00
committed by Space Team
parent 6271f5cbe5
commit a55b8d30fd
12 changed files with 89 additions and 1 deletions
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.analysis.api.impl.base.test.configurators.AnalysisAp
import org.jetbrains.kotlin.analysis.api.impl.base.test.configurators.AnalysisApiLibraryBaseTestServiceRegistrar
import org.jetbrains.kotlin.analysis.api.standalone.base.project.structure.KtModuleProjectStructure
import org.jetbrains.kotlin.analysis.low.level.api.fir.test.base.AnalysisApiFirTestServiceRegistrar
import org.jetbrains.kotlin.analysis.low.level.api.fir.test.base.configureOptionalTestCompilerPlugin
import org.jetbrains.kotlin.analysis.test.framework.project.structure.KtLibraryBinaryModuleFactory
import org.jetbrains.kotlin.analysis.test.framework.project.structure.KtModuleFactory
import org.jetbrains.kotlin.analysis.test.framework.project.structure.TestModuleStructureFactory
@@ -34,6 +35,7 @@ object AnalysisApiFirLibraryBinaryTestConfigurator : AnalysisApiTestConfigurator
builder.apply {
useAdditionalService<KtModuleFactory> { KtLibraryBinaryModuleFactory }
configureLibraryCompilationSupport(this)
configureOptionalTestCompilerPlugin()
}
}
@@ -158,7 +158,12 @@ abstract class SymbolLightClassForClassLike<SType : KtClassOrObjectSymbol> prote
override val originKind: LightClassOriginKind get() = LightClassOriginKind.SOURCE
override fun getQualifiedName(): String? = classOrObjectDeclaration?.fqName?.asString()
override fun getQualifiedName(): String? {
val classOrObjectFqName = classOrObjectDeclaration?.fqName
?: withClassOrObjectSymbol { s -> s.classIdIfNonLocal?.asSingleFqName() }
return classOrObjectFqName?.toString()
}
override fun getInterfaces(): Array<PsiClass> = PsiClassImplUtil.getInterfaces(this)
override fun getSuperClass(): PsiClass? = PsiClassImplUtil.getSuperClass(this)
@@ -616,5 +616,11 @@ public class SymbolLightClassesByFqNameForLibraryTestGenerated extends AbstractS
public void testAllOpen() throws Exception {
runTest("compiler/testData/asJava/lightClasses/lightClassByFqName/withTestCompilerPluginEnabled/allOpen.kt");
}
@Test
@TestMetadata("companionWithFoo_companionTypeUsedInJava_ReferenceFromKotlin.kt")
public void testCompanionWithFoo_companionTypeUsedInJava_ReferenceFromKotlin() throws Exception {
runTest("compiler/testData/asJava/lightClasses/lightClassByFqName/withTestCompilerPluginEnabled/companionWithFoo_companionTypeUsedInJava_ReferenceFromKotlin.kt");
}
}
}
@@ -616,5 +616,11 @@ public class SymbolLightClassesEqualityByFqNameForLibraryTestGenerated extends A
public void testAllOpen() throws Exception {
runTest("compiler/testData/asJava/lightClasses/lightClassByFqName/withTestCompilerPluginEnabled/allOpen.kt");
}
@Test
@TestMetadata("companionWithFoo_companionTypeUsedInJava_ReferenceFromKotlin.kt")
public void testCompanionWithFoo_companionTypeUsedInJava_ReferenceFromKotlin() throws Exception {
runTest("compiler/testData/asJava/lightClasses/lightClassByFqName/withTestCompilerPluginEnabled/companionWithFoo_companionTypeUsedInJava_ReferenceFromKotlin.kt");
}
}
}
@@ -616,5 +616,11 @@ public class SymbolLightClassesParentingByFqNameForLibraryTestGenerated extends
public void testAllOpen() throws Exception {
runTest("compiler/testData/asJava/lightClasses/lightClassByFqName/withTestCompilerPluginEnabled/allOpen.kt");
}
@Test
@TestMetadata("companionWithFoo_companionTypeUsedInJava_ReferenceFromKotlin.kt")
public void testCompanionWithFoo_companionTypeUsedInJava_ReferenceFromKotlin() throws Exception {
runTest("compiler/testData/asJava/lightClasses/lightClassByFqName/withTestCompilerPluginEnabled/companionWithFoo_companionTypeUsedInJava_ReferenceFromKotlin.kt");
}
}
}
@@ -806,5 +806,11 @@ public class SymbolLightClassesByFqNameForSourceTestGenerated extends AbstractSy
public void testAllOpen() throws Exception {
runTest("compiler/testData/asJava/lightClasses/lightClassByFqName/withTestCompilerPluginEnabled/allOpen.kt");
}
@Test
@TestMetadata("companionWithFoo_companionTypeUsedInJava_ReferenceFromKotlin.kt")
public void testCompanionWithFoo_companionTypeUsedInJava_ReferenceFromKotlin() throws Exception {
runTest("compiler/testData/asJava/lightClasses/lightClassByFqName/withTestCompilerPluginEnabled/companionWithFoo_companionTypeUsedInJava_ReferenceFromKotlin.kt");
}
}
}
@@ -806,5 +806,11 @@ public class SymbolLightClassesEqualityByFqNameForSourceTestGenerated extends Ab
public void testAllOpen() throws Exception {
runTest("compiler/testData/asJava/lightClasses/lightClassByFqName/withTestCompilerPluginEnabled/allOpen.kt");
}
@Test
@TestMetadata("companionWithFoo_companionTypeUsedInJava_ReferenceFromKotlin.kt")
public void testCompanionWithFoo_companionTypeUsedInJava_ReferenceFromKotlin() throws Exception {
runTest("compiler/testData/asJava/lightClasses/lightClassByFqName/withTestCompilerPluginEnabled/companionWithFoo_companionTypeUsedInJava_ReferenceFromKotlin.kt");
}
}
}
@@ -806,5 +806,11 @@ public class SymbolLightClassesParentingByFqNameForSourceTestGenerated extends A
public void testAllOpen() throws Exception {
runTest("compiler/testData/asJava/lightClasses/lightClassByFqName/withTestCompilerPluginEnabled/allOpen.kt");
}
@Test
@TestMetadata("companionWithFoo_companionTypeUsedInJava_ReferenceFromKotlin.kt")
public void testCompanionWithFoo_companionTypeUsedInJava_ReferenceFromKotlin() throws Exception {
runTest("compiler/testData/asJava/lightClasses/lightClassByFqName/withTestCompilerPluginEnabled/companionWithFoo_companionTypeUsedInJava_ReferenceFromKotlin.kt");
}
}
}
@@ -0,0 +1,7 @@
public final class TestClass /* test.TestClass*/ {
private final error.NonExistentClass usage;
public TestClass();// .ctor()
public final error.NonExistentClass getUsage();// getUsage()
}
@@ -0,0 +1,7 @@
public final class TestClass /* test.TestClass*/ {
private final MyClass.Companion usage;
public TestClass();// .ctor()
public final MyClass.Companion getUsage();// getUsage()
}
@@ -0,0 +1,26 @@
// test.TestClass
// Java code does not see declarations generated by compiler plugins, see KT-65454
// COMPILATION_ERRORS
// WITH_FIR_TEST_COMPILER_PLUGIN
// FILE: main.kt
package test
import org.jetbrains.kotlin.fir.plugin.CompanionWithFoo
@CompanionWithFoo
class MyClass
class TestClass {
val usage = CompanionProvider.provide()
}
// FILE: test/JavaClass.java
package test;
public class CompanionProvider {
// generated MyClass.Companion type reference in java
public static MyClass.Companion provide() { return null; }
}
@@ -670,5 +670,10 @@ public class CompilerLightClassTestGenerated extends AbstractCompilerLightClassT
public void testAllOpen() throws Exception {
runTest("compiler/testData/asJava/lightClasses/lightClassByFqName/withTestCompilerPluginEnabled/allOpen.kt");
}
@TestMetadata("companionWithFoo_companionTypeUsedInJava_ReferenceFromKotlin.kt")
public void testCompanionWithFoo_companionTypeUsedInJava_ReferenceFromKotlin() throws Exception {
runTest("compiler/testData/asJava/lightClasses/lightClassByFqName/withTestCompilerPluginEnabled/companionWithFoo_companionTypeUsedInJava_ReferenceFromKotlin.kt");
}
}
}