Skip to content

Commit

Permalink
fix special class name resolution for class literal annotation value
Browse files Browse the repository at this point in the history
(cherry picked from commit 5083a96)
  • Loading branch information
neetopia authored and KSP Auto Pick committed Jan 16, 2024
1 parent a01ada6 commit 9ba7a39
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,10 @@ class KSAnnotationDescriptorImpl private constructor(
}

private fun ClassId.findKSClassDeclaration(): KSClassDeclaration? {
val ksName = KSNameImpl.getCached(this.asSingleFqName().asString().replace("$", "."))
return ResolverImpl.instance!!.getClassDeclarationByName(ksName)
return ResolverImpl.instance!!.getClassDeclarationByName(this.asSingleFqName().asString()) ?: run {
val ksName = KSNameImpl.getCached(asSingleFqName().asString().replace("$", "."))
ResolverImpl.instance!!.getClassDeclarationByName(ksName)
}
}

private fun ClassId.findKSType(): KSType? = findKSClassDeclaration()?.asStarProjectedType()
Expand Down
6 changes: 6 additions & 0 deletions test-utils/testData/api/annotationValue_kt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
// TEST PROCESSOR: AnnotationArgumentProcessor
// EXPECTED:
// defaultInNested
// SomeClass$WithDollarSign
// Str
// 42
// Foo
Expand Down Expand Up @@ -49,6 +50,10 @@ class ThrowsClass {
annotation class Foo(val s: Int) {
annotation class Nested(val nestedDefault:String = "defaultInNested")
}
class `SomeClass$WithDollarSign`

annotation class MyAnnotation(val clazz: KClass<*>)


annotation class Bar(
val argStr: String,
Expand All @@ -68,6 +73,7 @@ annotation class Bar(

fun Fun() {
@Foo.Nested
@MyAnnotation(`SomeClass$WithDollarSign`::class)
@Bar(
"Str",
40 + 2,
Expand Down

0 comments on commit 9ba7a39

Please sign in to comment.