Skip to content

Commit d7213d2

Browse files
committed
Only convert KClass -> Class in annotation context
1 parent 2fd8e61 commit d7213d2

4 files changed

Lines changed: 14 additions & 13 deletions

File tree

java/kotlin-extractor/src/main/kotlin/KotlinFileExtractor.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -512,14 +512,14 @@ open class KotlinFileExtractor(
512512
is IrClassReference -> {
513513
val classRefId = exprId()
514514
val typeAccessId = tw.getLabelFor<DbUnannotatedtypeaccess>("@\"annotationExpr;{$classRefId};0\"")
515-
extractClassReference(v, parent, idx, null, null, overrideId = classRefId, typeAccessOverrideId = typeAccessId, useUnboundType = true)
515+
extractClassReference(v, parent, idx, null, null, overrideId = classRefId, typeAccessOverrideId = typeAccessId, useJavaLangClassType = true)
516516
}
517517
is IrConstructorCall -> {
518518
extractAnnotation(v, parent, idx, contextLabel)
519519
}
520520
is IrVararg -> {
521521
tw.getLabelFor<DbArrayinit>("@\"annotationarray;{${parent}};$contextLabel\"").also { arrayId ->
522-
val type = useType(v.type)
522+
val type = useType(kClassToJavaClass(v.type))
523523
tw.writeExprs_arrayinit(arrayId, type.javaResult.id, parent, idx)
524524
tw.writeExprsKotlinType(arrayId, type.kotlinResult.id)
525525
tw.writeHasLocation(arrayId, tw.getLocation(v))
@@ -4195,11 +4195,12 @@ open class KotlinFileExtractor(
41954195
enclosingStmt: Label<out DbStmt>?,
41964196
overrideId: Label<out DbExpr>? = null,
41974197
typeAccessOverrideId: Label<out DbExpr>? = null,
4198-
useUnboundType: Boolean = false
4198+
useJavaLangClassType: Boolean = false
41994199
) =
42004200
exprIdOrFresh<DbTypeliteral>(overrideId).also { id ->
42014201
val locId = tw.getLocation(e)
4202-
val type = useType(if (useUnboundType) toUnbound(e.type) else e.type)
4202+
val jlcType = if (useJavaLangClassType) this.javaLangClass?.let { it.typeWith() } else null
4203+
val type = useType(jlcType ?: e.type)
42034204
tw.writeExprs_typeliteral(id, type.javaResult.id, parent, idx)
42044205
tw.writeExprsKotlinType(id, type.kotlinResult.id)
42054206
extractExprContext(id, locId, enclosingCallable, enclosingStmt)

java/kotlin-extractor/src/main/kotlin/utils/ClassNames.kt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,4 @@ fun getContainingClassOrSelf(decl: IrDeclaration): IrClass? {
120120
}
121121

122122
fun getJavaEquivalentClassId(c: IrClass) =
123-
c.fqNameWhenAvailable?.toUnsafe()?.let {
124-
if (it.asString() == "kotlin.reflect.KClass") {
125-
ClassId.fromString("java.lang.Class")
126-
} else {
127-
JavaToKotlinClassMap.mapKotlinToJava(it)
128-
}
129-
}
123+
c.fqNameWhenAvailable?.toUnsafe()?.let { JavaToKotlinClassMap.mapKotlinToJava(it) }

java/ql/integration-tests/all-platforms/kotlin/annotation-id-consistency/PrintAst.expected

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ test.kt:
2828
# 5| 2: [Method] w
2929
# 5| 3: [Method] v
3030
# 5| 4: [Method] u
31+
# 5| 5: [Method] t
3132
# 7| 3: [Interface] Ann3
3233
# 7| 1: [Method] a
3334
# 9| 4: [Class] Annotated
@@ -47,6 +48,11 @@ test.kt:
4748
# 0| 1: [IntegerLiteral] 1
4849
# 0| 1: [Annotation] Ann3
4950
# 0| 1: [IntegerLiteral] 2
51+
# 0| 1: [ArrayInit] {...}
52+
# 0| 1: [TypeLiteral] String.class
53+
# 0| 0: [TypeAccess] String
54+
# 0| 1: [TypeLiteral] int.class
55+
# 0| 0: [TypeAccess] int
5056
# 10| 1: [Constructor] Annotated
5157
# 9| 5: [BlockStmt] { ... }
5258
# 9| 0: [SuperConstructorInvocationStmt] super(...)

java/ql/integration-tests/all-platforms/kotlin/annotation-id-consistency/test.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import kotlin.reflect.KClass
22

33
annotation class Ann1(val x: Int, val y: Ann2) { }
44

5-
annotation class Ann2(val z: String, val w: KClass<*>, val v: IntArray, val u: Array<Ann3>) { }
5+
annotation class Ann2(val z: String, val w: KClass<*>, val v: IntArray, val u: Array<Ann3>, val t: Array<KClass<*>>) { }
66

77
annotation class Ann3(val a: Int) { }
88

9-
@Ann1(1, Ann2("Hello", String::class, intArrayOf(1, 2, 3), arrayOf(Ann3(1), Ann3(2))))
9+
@Ann1(1, Ann2("Hello", String::class, intArrayOf(1, 2, 3), arrayOf(Ann3(1), Ann3(2)), arrayOf(String::class, Int::class)))
1010
class Annotated { }

0 commit comments

Comments
 (0)