[Assign plugin] Use FqName to match annotations in FirAssignAnnotationMatchingService
All other compiler plugins accept "pkg1.pkg2.Class1" classes notation
and correctly match against it
But Assignment plugin used `ClassId` on such qualified names and got
`ClassId("/pkg1.pkg2.Class1")` instead of `ClassId("pkg1/pkg2/Class1")`,
and that lead to unexpected problems
This commit fixes that by using `FqName` instead of `ClassId`
^KT-57406 Fixed
This commit is contained in:
committed by
Space Team
parent
f035f80ad5
commit
4e0b68b516
+5
-5
@@ -15,16 +15,16 @@ import org.jetbrains.kotlin.fir.extensions.FirExtensionSessionComponent.Factory
|
||||
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol
|
||||
import org.jetbrains.kotlin.fir.types.toRegularClassSymbol
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
|
||||
internal class FirAssignAnnotationMatchingService(
|
||||
session: FirSession,
|
||||
private val annotationClassIds: List<ClassId>
|
||||
private val annotationClassIds: List<FqName>
|
||||
) : FirExtensionSessionComponent(session) {
|
||||
|
||||
companion object {
|
||||
fun getFactory(annotations: List<String>): Factory {
|
||||
return Factory { session -> FirAssignAnnotationMatchingService(session, annotations.map { ClassId.fromString(it) }) }
|
||||
return Factory { session -> FirAssignAnnotationMatchingService(session, annotations.map { FqName(it) }) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,10 +40,10 @@ internal class FirAssignAnnotationMatchingService(
|
||||
}
|
||||
|
||||
private fun FirRegularClassSymbol.annotated(): Boolean {
|
||||
if (this.annotations.any { it.toAnnotationClassId(session) in annotationClassIds }) return true
|
||||
if (this.annotations.any { it.toAnnotationClassId(session)?.asSingleFqName() in annotationClassIds }) return true
|
||||
return resolvedSuperTypeRefs.any { superTypeRef ->
|
||||
val symbol = superTypeRef.type.fullyExpandedType(session).toRegularClassSymbol(session) ?: return@any false
|
||||
symbol.annotations.any { it.toAnnotationClassId(session) in annotationClassIds }
|
||||
symbol.annotations.any { it.toAnnotationClassId(session)?.asSingleFqName() in annotationClassIds }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-1
@@ -72,7 +72,10 @@ fun TestConfigurationBuilder.configureDiagnostics() {
|
||||
|
||||
class AssignmentPluginEnvironmentConfigurator(testServices: TestServices) : EnvironmentConfigurator(testServices) {
|
||||
companion object {
|
||||
private val TEST_ANNOTATIONS = listOf("ValueContainer")
|
||||
private val TEST_ANNOTATIONS = listOf(
|
||||
"ValueContainer",
|
||||
"qualified.ValueContainer",
|
||||
)
|
||||
}
|
||||
|
||||
@OptIn(InternalNonStableExtensionPoints::class)
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
// FILE: annotation.kt
|
||||
package qualified
|
||||
|
||||
annotation class ValueContainer
|
||||
|
||||
// FILE: main.kt
|
||||
import qualified.ValueContainer
|
||||
|
||||
@ValueContainer
|
||||
class StringProperty(var v: String) {
|
||||
fun assign(v: String) {
|
||||
this.v = v
|
||||
}
|
||||
}
|
||||
|
||||
val property = StringProperty("Initial")
|
||||
|
||||
fun box(): String {
|
||||
property = "OK"
|
||||
|
||||
return property.v
|
||||
}
|
||||
+6
@@ -43,6 +43,12 @@ public class FirLightTreeBlackBoxCodegenTestForAssignmentPluginGenerated extends
|
||||
runTest("plugins/assign-plugin/testData/codegen/plusAssignPrecedence.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("qualifiedAnnotation.kt")
|
||||
public void testQualifiedAnnotation() throws Exception {
|
||||
runTest("plugins/assign-plugin/testData/codegen/qualifiedAnnotation.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("supportedUsage.kt")
|
||||
public void testSupportedUsage() throws Exception {
|
||||
|
||||
+6
@@ -43,6 +43,12 @@ public class IrBlackBoxCodegenTestAssignmentPluginGenerated extends AbstractIrBl
|
||||
runTest("plugins/assign-plugin/testData/codegen/plusAssignPrecedence.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("qualifiedAnnotation.kt")
|
||||
public void testQualifiedAnnotation() throws Exception {
|
||||
runTest("plugins/assign-plugin/testData/codegen/qualifiedAnnotation.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("supportedUsage.kt")
|
||||
public void testSupportedUsage() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user