Skip to content

Commit

Permalink
Test annotation value of annotation type
Browse files Browse the repository at this point in the history
  • Loading branch information
kuanyingchou committed Mar 18, 2024
1 parent e8d42f8 commit 10d1eb4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package com.google.devtools.ksp.processor
import com.google.devtools.ksp.getClassDeclarationByName
import com.google.devtools.ksp.processing.Resolver
import com.google.devtools.ksp.symbol.KSAnnotated
import com.google.devtools.ksp.symbol.KSAnnotation
import com.google.devtools.ksp.symbol.KSType
import com.google.devtools.ksp.symbol.KSValueArgument
import com.google.devtools.ksp.symbol.KSVisitorVoid
Expand Down Expand Up @@ -52,10 +53,17 @@ class AnnotationArgumentProcessor : AbstractTestProcessor() {

inner class ArgumentVisitor : KSVisitorVoid() {
override fun visitValueArgument(valueArgument: KSValueArgument, data: Unit) {
if (valueArgument.value is KSType) {
results.add((valueArgument.value as KSType).declaration.toString())
} else {
results.add(valueArgument.value.toString())
valueArgument.value.also {
if (it is KSType) {
results.add(it.declaration.toString())
} else {
results.add(it.toString())
if (it is KSAnnotation) {
it.arguments.forEach {
it.accept(this, Unit)
}
}
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions test-utils/testData/api/annotationValue_java.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
// Error type synthetic declaration
// Array
// @Foo
// 17
// @Suppress
// [name1, name2]
// G
// ONE
// 31
Expand Down
2 changes: 2 additions & 0 deletions test-utils/testData/api/annotationValue_kt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
// Error type synthetic declaration
// [<ERROR TYPE>, Foo]
// @Foo
// 17
// @Suppress
// [name1, name2]
// G
// ONE
// 31
Expand Down

0 comments on commit 10d1eb4

Please sign in to comment.