Skip to content

Commit

Permalink
Test asMemberOf
Browse files Browse the repository at this point in the history
  • Loading branch information
kuanyingchou committed Aug 23, 2024
1 parent 429f173 commit 3644ab9
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,15 @@ class Sub implements @B(a = @A(i = 42)) Parent {}
// FILE: TestJavaLib.java
@JavaAnnotationWithDefaults
class TestJavaLib {}

// FILE: foo/bar/Test.java
package foo.bar;
import java.util.List;
class Test {
List<String> f() { throw new RuntimeException(); }
}
// FILE: foo/bar/Test.kt
package foo.bar
class KTest {
fun f(): List<String> = TODO()
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,29 @@ class AnnotationArgumentProcessor : AbstractTestProcessor() {
val visitor = ArgumentVisitor()

override fun process(resolver: Resolver): List<KSAnnotated> {
listOf("foo.bar.Test", "foo.bar.KTest").forEach { cls ->
resolver.getClassDeclarationByName(cls)!!.let { test ->
test.getAllFunctions().single { it.simpleName.asString() == "f" }.let { f ->
val resolvedReturnType = f.returnType!!.resolve()
val iterator = (resolvedReturnType.declaration as KSClassDeclaration).getAllFunctions().single {
it.simpleName.asString() == "iterator"
}
// Prints
// ```
// MutableIterator<E>
// Iterator<String>
// ```
// with KSP2 but is
// ```
// MutableIterator<(String..String?)>
// Iterator<String>
// ```
// with KSP1.
println(iterator.asMemberOf(resolvedReturnType).returnType)
}
}
}

listOf("MyClass", "MyClassInLib").forEach { clsName ->
resolver.getClassDeclarationByName(clsName)?.let { cls ->
cls.annotations.single().arguments.forEach {
Expand Down
12 changes: 12 additions & 0 deletions test-utils/testData/api/annotationValue_java.kt
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,15 @@ class Sub implements @B(a = @A(i = 42)) Parent {}
// FILE: TestJavaLib.java
@JavaAnnotationWithDefaults
class TestJavaLib {}

// FILE: foo/bar/Test.java
package foo.bar;
import java.util.List;
class Test {
List<String> f() { throw new RuntimeException(); }
}
// FILE: foo/bar/Test.kt
package foo.bar
class KTest {
fun f(): List<String> = TODO()
}

0 comments on commit 3644ab9

Please sign in to comment.