Skip to content

Commit

Permalink
Test defaults in nested annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
kuanyingchou committed Sep 2, 2024
1 parent 6af7077 commit 28add76
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@
// 31
// [warning1, warning 2]
// Sub: [i:42]
// TestJavaLib: OtherAnnotation
// TestNestedAnnotationDefaults: def
// TestNestedAnnotationDefaults: hij
// TestNestedAnnotationDefaults: def
// TestNestedAnnotationDefaults: hij
// END
// MODULE: module1
// FILE: placeholder.kt
Expand Down Expand Up @@ -73,6 +76,9 @@ public @interface JavaAnnotationWithDefaults {
OtherAnnotation otherAnnotationVal() default @OtherAnnotation("def");
}

// FILE: KotlinAnnotationWithDefaults.kt
annotation class KotlinAnnotationWithDefaults(val otherAnnotation: OtherAnnotation = OtherAnnotation("hij"))

// MODULE: main(module1)
// FILE: Test.java
@MyAnnotation(stringParam = "2") class MyClass implements MyInterface {}
Expand Down Expand Up @@ -136,6 +142,17 @@ import java.lang.annotation.Target;
interface Parent {}
class Sub implements @B(a = @A(i = 42)) Parent {}

// FILE: TestJavaLib.java
// FILE: JavaAnnotationWithDefaultsInSource.java
public @interface JavaAnnotationWithDefaultsInSource {
OtherAnnotation otherAnnotationVal() default @OtherAnnotation("def");
}

// FILE: KotlinAnnotationWithDefaults.kt
annotation class KotlinAnnotationWithDefaultsInSource(val otherAnnotation: OtherAnnotation = OtherAnnotation("hij"))

// FILE: TestNestedAnnotationDefaults.java
@JavaAnnotationWithDefaultsInSource
@KotlinAnnotationWithDefaultsInSource
@JavaAnnotationWithDefaults
class TestJavaLib {}
@KotlinAnnotationWithDefaults
class TestNestedAnnotationDefaults {}
23 changes: 20 additions & 3 deletions kotlin-analysis-api/testData/annotationValue/annotationValue_kt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@
// Sub: [i:42]
// Cls: argToA: b
// Cls: argToB: 42
// TestJavaLib: OtherAnnotation
// TestNestedAnnotationDefaults: def
// TestNestedAnnotationDefaults: hij
// TestNestedAnnotationDefaults: def
// TestNestedAnnotationDefaults: hij
// END
// MODULE: module1
// FILE: placeholder.kt
Expand Down Expand Up @@ -72,6 +75,9 @@ public @interface JavaAnnotationWithDefaults {
OtherAnnotation otherAnnotationVal() default @OtherAnnotation("def");
}

// FILE: KotlinAnnotationWithDefaults.kt
annotation class KotlinAnnotationWithDefaults(val otherAnnotation: OtherAnnotation = OtherAnnotation("hij"))

// MODULE: main(module1)
// FILE: a.kt

Expand Down Expand Up @@ -147,6 +153,17 @@ interface Parent

class Sub : @B(a = A(i = 42)) Parent

// FILE: TestJavaLib.kt
// FILE: JavaAnnotationWithDefaultsInSource.java
public @interface JavaAnnotationWithDefaultsInSource {
OtherAnnotation otherAnnotationVal() default @OtherAnnotation("def");
}

// FILE: KotlinAnnotationWithDefaults.kt
annotation class KotlinAnnotationWithDefaultsInSource(val otherAnnotation: OtherAnnotation = OtherAnnotation("hij"))

// FILE: KotlinClient.kt
@JavaAnnotationWithDefaultsInSource
@KotlinAnnotationWithDefaultsInSource
@JavaAnnotationWithDefaults
class TestJavaLib
@KotlinAnnotationWithDefaults
class TestNestedAnnotationDefaults
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,10 @@ class AnnotationArgumentProcessor : AbstractTestProcessor() {
}
}

resolver.getClassDeclarationByName("TestJavaLib")?.let { cls ->
cls.annotations.single().arguments.single().let { ksValueArg ->
results.add("TestJavaLib: " + (ksValueArg.value as KSAnnotation).shortName.asString())
resolver.getClassDeclarationByName("TestNestedAnnotationDefaults")?.let { cls ->
cls.annotations.forEach { annotation ->
val annotationArg = annotation.arguments.single().value as KSAnnotation
results.add("${cls.simpleName.asString()}: ${annotationArg.arguments.single().value}")
}
}

Expand Down
23 changes: 20 additions & 3 deletions test-utils/testData/api/annotationValue_java.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@
// 31
// [warning1, warning 2]
// Sub: [i:42]
// TestJavaLib: OtherAnnotation
// TestNestedAnnotationDefaults: def
// TestNestedAnnotationDefaults: hij
// TestNestedAnnotationDefaults: def
// TestNestedAnnotationDefaults: hij
// END
// MODULE: module1
// FILE: placeholder.kt
Expand Down Expand Up @@ -65,6 +68,9 @@ public @interface JavaAnnotationWithDefaults {
OtherAnnotation otherAnnotationVal() default @OtherAnnotation("def");
}

// FILE: KotlinAnnotationWithDefaults.kt
annotation class KotlinAnnotationWithDefaults(val otherAnnotation: OtherAnnotation = OtherAnnotation("hij"))

// MODULE: main(module1)
// FILE: Test.java
@MyAnnotation(stringParam = "2") class MyClass implements MyInterface {}
Expand Down Expand Up @@ -127,6 +133,17 @@ import java.lang.annotation.Target;
interface Parent {}
class Sub implements @B(a = @A(i = 42)) Parent {}

// FILE: TestJavaLib.java
// FILE: JavaAnnotationWithDefaultsInSource.java
public @interface JavaAnnotationWithDefaultsInSource {
OtherAnnotation otherAnnotationVal() default @OtherAnnotation("def");
}

// FILE: KotlinAnnotationWithDefaults.kt
annotation class KotlinAnnotationWithDefaultsInSource(val otherAnnotation: OtherAnnotation = OtherAnnotation("hij"))

// FILE: TestNestedAnnotationDefaults.java
@JavaAnnotationWithDefaultsInSource
@KotlinAnnotationWithDefaultsInSource
@JavaAnnotationWithDefaults
class TestJavaLib {}
@KotlinAnnotationWithDefaults
class TestNestedAnnotationDefaults {}
24 changes: 24 additions & 0 deletions test-utils/testData/api/annotationValue_kt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
// ONE
// 31
// Throws
// TestNestedAnnotationDefaults: def
// TestNestedAnnotationDefaults: hij
// TestNestedAnnotationDefaults: def
// TestNestedAnnotationDefaults: hij
// END
// MODULE: module1
// FILE: placeholder.kt
Expand All @@ -49,6 +53,10 @@ public @interface JavaAnnotationWithDefaults {
OtherAnnotation otherAnnotationVal() default @OtherAnnotation("def");
}

// FILE: KotlinAnnotationWithDefaults.kt
annotation class KotlinAnnotationWithDefaults(val otherAnnotation: OtherAnnotation = OtherAnnotation("hij"))


// MODULE: main(module1)
// FILE: a.kt

Expand Down Expand Up @@ -109,3 +117,19 @@ fun Fun() {
// FILE: JavaEnum.java

enum JavaEnum { ONE, TWO, THREE }

// FILE: JavaAnnotationWithDefaultsInSource.java
public @interface JavaAnnotationWithDefaultsInSource {
OtherAnnotation otherAnnotationVal() default @OtherAnnotation("def");
}

// FILE: KotlinAnnotationWithDefaults.kt
annotation class KotlinAnnotationWithDefaultsInSource(val otherAnnotation: OtherAnnotation = OtherAnnotation("hij"))

// FILE: KotlinClient.kt
@JavaAnnotationWithDefaultsInSource
@KotlinAnnotationWithDefaultsInSource
@JavaAnnotationWithDefaults
@KotlinAnnotationWithDefaults
class TestNestedAnnotationDefaults

0 comments on commit 28add76

Please sign in to comment.