Skip to content

Commit

Permalink
Test nested type annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
kuanyingchou committed Apr 11, 2024
1 parent cf3b401 commit 372a234
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
13 changes: 13 additions & 0 deletions kotlin-analysis-api/testData/annotationValue/java.kt
Expand Up @@ -31,6 +31,19 @@
// 31
// [warning1, warning 2]
// END
// FILE: Test.java
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
@Target({ElementType.TYPE, ElementType.TYPE_USE})
@interface A {
int i();
}
@Target({ElementType.TYPE, ElementType.TYPE_USE})
@interface B {
A a();
}
interface Parent {}
class Sub implements @B(a = @A(i = 42)) Parent {}
// FILE: a.kt

enum class RGB {
Expand Down
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 All @@ -29,6 +30,12 @@ class AnnotationArgumentProcessor : AbstractTestProcessor() {
val visitor = ArgumentVisitor()

override fun process(resolver: Resolver): List<KSAnnotated> {
resolver.getClassDeclarationByName("Sub")!!.let { cls ->
cls.superTypes.single().annotations.single().let { typeAnnotation ->
val a = typeAnnotation.arguments.single().value as KSAnnotation
println(a.arguments)
}
}
resolver.getSymbolsWithAnnotation("Bar", true).forEach {
it.annotations.forEach { it.arguments.forEach { it.accept(visitor, Unit) } }
}
Expand Down
13 changes: 13 additions & 0 deletions test-utils/testData/api/annotationValue_java.kt
Expand Up @@ -31,6 +31,19 @@
// 31
// [warning1, warning 2]
// END
// FILE: Test.java
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
@Target({ElementType.TYPE, ElementType.TYPE_USE})
@interface A {
int i();
}
@Target({ElementType.TYPE, ElementType.TYPE_USE})
@interface B {
A a();
}
interface Parent {}
class Sub implements @B(a = @A(i = 42)) Parent {}
// FILE: a.kt

enum class RGB {
Expand Down

0 comments on commit 372a234

Please sign in to comment.