[FIR] Support typealiases in FirAssignAnnotationMatchingService
This commit is contained in:
committed by
Space Team
parent
0c00e79024
commit
6a1c9e9279
+5
-5
@@ -9,7 +9,7 @@ import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.caches.FirCache
|
||||
import org.jetbrains.kotlin.fir.caches.firCachesFactory
|
||||
import org.jetbrains.kotlin.fir.caches.getValue
|
||||
import org.jetbrains.kotlin.fir.expressions.classId
|
||||
import org.jetbrains.kotlin.fir.declarations.toAnnotationClassId
|
||||
import org.jetbrains.kotlin.fir.extensions.FirExtensionSessionComponent
|
||||
import org.jetbrains.kotlin.fir.extensions.FirExtensionSessionComponent.Factory
|
||||
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
|
||||
@@ -40,10 +40,10 @@ internal class FirAssignAnnotationMatchingService(
|
||||
}
|
||||
|
||||
private fun FirRegularClassSymbol.annotated(): Boolean {
|
||||
if (this.annotations.any { it.classId in annotationClassIds }) return true
|
||||
return resolvedSuperTypeRefs.any {
|
||||
val symbol = it.type.fullyExpandedType(session).toRegularClassSymbol(session) ?: return@any false
|
||||
symbol.annotations.any { it.classId in annotationClassIds }
|
||||
if (this.annotations.any { it.toAnnotationClassId(session) 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 }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
// FILE: test.kt
|
||||
annotation class ValueContainer
|
||||
|
||||
typealias VC = ValueContainer
|
||||
|
||||
@VC
|
||||
interface KotlinProperty<T> {
|
||||
fun assign(argument: T);
|
||||
fun get(): T;
|
||||
}
|
||||
|
||||
data class KotlinStringProperty(private var v: String): KotlinProperty<String> {
|
||||
override fun assign(v: String) {
|
||||
this.v = v
|
||||
}
|
||||
override fun get() = this.v
|
||||
}
|
||||
|
||||
@VC
|
||||
data class KotlinClassStringProperty(private var v: String) {
|
||||
fun assign(v: String) {
|
||||
this.v = v
|
||||
}
|
||||
fun get(): String {
|
||||
return v
|
||||
}
|
||||
}
|
||||
|
||||
fun `should work with annotation on Kotlin interface`(): String {
|
||||
data class Task(val input: KotlinStringProperty)
|
||||
val task = Task(KotlinStringProperty("Fail"))
|
||||
task.input = "OK"
|
||||
|
||||
return if (task.input.get() != "OK") {
|
||||
"Fail: ${task.input.get()}"
|
||||
} else {
|
||||
"OK"
|
||||
}
|
||||
}
|
||||
|
||||
fun `should work with annotation on Kotlin class`(): String {
|
||||
data class Task(val input: KotlinClassStringProperty)
|
||||
val task = Task(KotlinClassStringProperty("Fail"))
|
||||
task.input = "OK"
|
||||
|
||||
return if (task.input.get() != "OK") {
|
||||
"Fail: ${task.input.get()}"
|
||||
} else {
|
||||
"OK"
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var result = `should work with annotation on Kotlin interface`()
|
||||
if (result != "OK") return result
|
||||
|
||||
result = `should work with annotation on Kotlin class`()
|
||||
if (result != "OK") return result
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+6
@@ -49,6 +49,12 @@ public class FirBlackBoxCodegenTestForAssignmentPluginGenerated extends Abstract
|
||||
runTest("plugins/assign-plugin/testData/codegen/supportedUsage.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("typealias.kt")
|
||||
public void testTypealias() throws Exception {
|
||||
runTest("plugins/assign-plugin/testData/codegen/typealias.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("varBehaviour.kt")
|
||||
public void testVarBehaviour() throws Exception {
|
||||
|
||||
+6
@@ -49,6 +49,12 @@ public class IrBlackBoxCodegenTestAssignmentPluginGenerated extends AbstractIrBl
|
||||
runTest("plugins/assign-plugin/testData/codegen/supportedUsage.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("typealias.kt")
|
||||
public void testTypealias() throws Exception {
|
||||
runTest("plugins/assign-plugin/testData/codegen/typealias.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("varBehaviour.kt")
|
||||
public void testVarBehaviour() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user