Add more annotation tests, add KClass to Class substitution

This commit is contained in:
Tamas Vajk
2022-04-13 09:59:26 +02:00
committed by Chris Smowton
parent f465dd5362
commit 3e1d4a7400
5 changed files with 76 additions and 18 deletions

View File

@@ -14,6 +14,7 @@ import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.util.fqNameWhenAvailable
import org.jetbrains.kotlin.ir.util.parentClassOrNull
import org.jetbrains.kotlin.load.kotlin.JvmPackagePartSource
import org.jetbrains.kotlin.name.ClassId
// Adapted from Kotlin's interpreter/Utils.kt function 'internalName'
// Translates class names into their JLS section 13.1 binary name,
@@ -119,4 +120,10 @@ fun getContainingClassOrSelf(decl: IrDeclaration): IrClass? {
}
fun getJavaEquivalentClassId(c: IrClass) =
c.fqNameWhenAvailable?.toUnsafe()?.let { JavaToKotlinClassMap.mapKotlinToJava(it) }
c.fqNameWhenAvailable?.toUnsafe()?.let {
if (it.asString() == "kotlin.reflect.KClass") {
ClassId.fromString("java.lang.Class")
} else {
JavaToKotlinClassMap.mapKotlinToJava(it)
}
}

View File

@@ -22,15 +22,15 @@ Annot1j.java:
def.kt:
# 0| [CompilationUnit] def
# 0| 1: [Class] DefKt
# 23| 1: [Method] fn
# 25| 1: [Method] fn
#-----| 4: (Parameters)
# 23| 0: [Parameter] a
# 23| 5: [BlockStmt] { ... }
# 24| 0: [ExprStmt] <Expr>;
# 24| 0: [MethodAccess] println(...)
# 24| -1: [TypeAccess] ConsoleKt
# 24| 0: [MethodAccess] a(...)
# 24| -1: [VarAccess] a
# 25| 0: [Parameter] a
# 25| 5: [BlockStmt] { ... }
# 26| 0: [ExprStmt] <Expr>;
# 26| 0: [MethodAccess] println(...)
# 26| -1: [TypeAccess] ConsoleKt
# 26| 0: [MethodAccess] a(...)
# 26| -1: [VarAccess] a
# 3| 2: [Interface] Annot0k
# 3| 1: [Method] a
# 5| 3: [Interface] Annot1k
@@ -72,10 +72,21 @@ def.kt:
# 0| 1: [VarAccess] A
# 0| 1: [Annotation] Annot0k
# 0| 1: [IntegerLiteral] 1
# 21| 1: [Constructor] Z
# 21| 3: [Annotation] Annot0j
# 0| 1: [IntegerLiteral] 1
# 22| 4: [Annotation] Annot1j
# 0| 1: [ErrorExpr] <error expr>
# 0| 1: [ErrorExpr] <error expr>
# 0| 1: [ErrorExpr] <error expr>
# 0| 1: [VarAccess] B
# 0| 1: [ArrayInit] {...}
# 0| 1: [VarAccess] C
# 0| 1: [VarAccess] A
# 0| 1: [ErrorExpr] <error expr>
# 23| 1: [Constructor] Z
# 19| 5: [BlockStmt] { ... }
# 19| 0: [SuperConstructorInvocationStmt] super(...)
# 21| 1: [BlockStmt] { ... }
# 23| 1: [BlockStmt] { ... }
use.java:
# 0| [CompilationUnit] use
# 1| 1: [Class] use
@@ -97,7 +108,7 @@ use.java:
# 6| 5: [BlockStmt] { ... }
# 7| 0: [ReturnStmt] return ...
# 7| 0: [NullLiteral] null
# 12| 4: [Class] Z
# 14| 4: [Class] Z
#-----| -3: (Annotations)
# 10| 1: [Annotation] Annot0j
# 10| 1: [IntegerLiteral] 1
@@ -115,3 +126,19 @@ use.java:
# 11| -1: [TypeAccess] Y
# 11| 6: [Annotation] Annot0j
# 11| 1: [IntegerLiteral] 2
# 12| 3: [Annotation] Annot0k
# 12| 1: [IntegerLiteral] 1
# 13| 4: [Annotation] Annot1k
# 13| 1: [IntegerLiteral] 1
# 13| 2: [StringLiteral] "ac"
# 13| 3: [TypeLiteral] X.class
# 13| 0: [TypeAccess] X
# 13| 4: [VarAccess] Y.B
# 13| -1: [TypeAccess] Y
# 13| 5: [ArrayInit] {...}
# 13| 3: [VarAccess] Y.C
# 13| -1: [TypeAccess] Y
# 13| 4: [VarAccess] Y.A
# 13| -1: [TypeAccess] Y
# 13| 6: [Annotation] Annot0k
# 13| 1: [IntegerLiteral] 2

View File

@@ -15,11 +15,16 @@ annotationDeclarations
| def.kt:5:1:12:1 | Annot1k | def.kt:11:5:11:31 | f |
annotations
| def.kt:0:0:0:0 | Annot0k | def.kt:20:1:20:40 | Annot1k | def.kt:3:1:3:60 | Annot0k |
| def.kt:19:1:19:17 | Annot0k | def.kt:19:1:21:10 | Z | def.kt:3:1:3:60 | Annot0k |
| def.kt:20:1:20:40 | Annot1k | def.kt:19:1:21:10 | Z | def.kt:5:1:12:1 | Annot1k |
| use.java:10:5:10:21 | Annot0j | use.java:12:18:12:18 | Z | Annot0j.java:1:19:1:25 | Annot0j |
| use.java:11:5:11:90 | Annot1j | use.java:12:18:12:18 | Z | Annot1j.java:1:19:1:25 | Annot1j |
| def.kt:19:1:19:17 | Annot0k | def.kt:19:1:23:10 | Z | def.kt:3:1:3:60 | Annot0k |
| def.kt:20:1:20:40 | Annot1k | def.kt:19:1:23:10 | Z | def.kt:5:1:12:1 | Annot1k |
| def.kt:21:1:21:17 | Annot0j | def.kt:19:1:23:10 | Z | Annot0j.java:1:19:1:25 | Annot0j |
| def.kt:22:1:22:40 | Annot1j | def.kt:19:1:23:10 | Z | Annot1j.java:1:19:1:25 | Annot1j |
| use.java:10:5:10:21 | Annot0j | use.java:14:18:14:18 | Z | Annot0j.java:1:19:1:25 | Annot0j |
| use.java:11:5:11:90 | Annot1j | use.java:14:18:14:18 | Z | Annot1j.java:1:19:1:25 | Annot1j |
| use.java:11:73:11:89 | Annot0j | use.java:11:5:11:90 | Annot1j | Annot0j.java:1:19:1:25 | Annot0j |
| use.java:12:5:12:19 | Annot0k | use.java:14:18:14:18 | Z | def.kt:3:1:3:60 | Annot0k |
| use.java:13:5:13:88 | Annot1k | use.java:14:18:14:18 | Z | def.kt:5:1:12:1 | Annot1k |
| use.java:13:73:13:87 | Annot0k | use.java:13:5:13:88 | Annot1k | def.kt:3:1:3:60 | Annot0k |
annotationValues
| def.kt:0:0:0:0 | Annot0k | def.kt:0:0:0:0 | 1 |
| def.kt:19:1:19:17 | Annot0k | def.kt:0:0:0:0 | 1 |
@@ -29,6 +34,13 @@ annotationValues
| def.kt:20:1:20:40 | Annot1k | def.kt:0:0:0:0 | X.class |
| def.kt:20:1:20:40 | Annot1k | def.kt:0:0:0:0 | ab |
| def.kt:20:1:20:40 | Annot1k | def.kt:0:0:0:0 | {...} |
| def.kt:21:1:21:17 | Annot0j | def.kt:0:0:0:0 | 1 |
| def.kt:22:1:22:40 | Annot1j | def.kt:0:0:0:0 | <error expr> |
| def.kt:22:1:22:40 | Annot1j | def.kt:0:0:0:0 | <error expr> |
| def.kt:22:1:22:40 | Annot1j | def.kt:0:0:0:0 | <error expr> |
| def.kt:22:1:22:40 | Annot1j | def.kt:0:0:0:0 | <error expr> |
| def.kt:22:1:22:40 | Annot1j | def.kt:0:0:0:0 | B |
| def.kt:22:1:22:40 | Annot1j | def.kt:0:0:0:0 | {...} |
| use.java:10:5:10:21 | Annot0j | use.java:10:20:10:20 | 1 |
| use.java:11:5:11:90 | Annot1j | use.java:11:18:11:18 | 1 |
| use.java:11:5:11:90 | Annot1j | use.java:11:25:11:28 | "ac" |
@@ -37,6 +49,14 @@ annotationValues
| use.java:11:5:11:90 | Annot1j | use.java:11:57:11:66 | {...} |
| use.java:11:5:11:90 | Annot1j | use.java:11:73:11:89 | Annot0j |
| use.java:11:73:11:89 | Annot0j | use.java:11:88:11:88 | 2 |
| use.java:12:5:12:19 | Annot0k | use.java:12:18:12:18 | 1 |
| use.java:13:5:13:88 | Annot1k | use.java:13:18:13:18 | 1 |
| use.java:13:5:13:88 | Annot1k | use.java:13:25:13:28 | "ac" |
| use.java:13:5:13:88 | Annot1k | use.java:13:35:13:41 | X.class |
| use.java:13:5:13:88 | Annot1k | use.java:13:48:13:50 | Y.B |
| use.java:13:5:13:88 | Annot1k | use.java:13:57:13:66 | {...} |
| use.java:13:5:13:88 | Annot1k | use.java:13:73:13:87 | Annot0k |
| use.java:13:73:13:87 | Annot0k | use.java:13:86:13:86 | 2 |
#select
| Annot0j.java:1:19:1:25 | Annot0j | Interface |
| Annot1j.java:1:19:1:25 | Annot1j | Interface |
@@ -45,6 +65,6 @@ annotationValues
| def.kt:5:1:12:1 | Annot1k | Interface |
| def.kt:14:1:14:10 | X | Class |
| def.kt:15:1:17:1 | Y | Class |
| def.kt:19:1:21:10 | Z | Class |
| def.kt:19:1:23:10 | Z | Class |
| use.java:1:14:1:16 | use | Class |
| use.java:12:18:12:18 | Z | Class |
| use.java:14:18:14:18 | Z | Class |

View File

@@ -18,6 +18,8 @@ enum class Y {
@Annot0k(abc = 1)
@Annot1k(d = Y.B, e = arrayOf(Y.C, Y.A))
@Annot0j(abc = 1)
@Annot1j(d = Y.B, e = arrayOf(Y.C, Y.A))
class Z {}
fun fn(a: Annot0k) {

View File

@@ -9,5 +9,7 @@ public class use implements Annot0k {
@Annot0j(abc = 1)
@Annot1j(a = 1, b = "ac", c = X.class, d = Y.B, e = {Y.C, Y.A}, f = @Annot0j(abc = 2))
@Annot0k(a = 1)
@Annot1k(a = 1, b = "ac", c = X.class, d = Y.B, e = {Y.C, Y.A}, f = @Annot0k(a = 2))
public class Z { }
}