Skip to content

Commit

Permalink
Test type var bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
kuanyingchou committed Apr 26, 2024
1 parent c262051 commit 25a1900
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Expand Up @@ -19,6 +19,8 @@ package com.google.devtools.ksp.processor

import com.google.devtools.ksp.KspExperimental
import com.google.devtools.ksp.getAnnotationsByType
import com.google.devtools.ksp.getClassDeclarationByName
import com.google.devtools.ksp.getDeclaredFunctions
import com.google.devtools.ksp.isAnnotationPresent
import com.google.devtools.ksp.processing.Resolver
import com.google.devtools.ksp.symbol.KSAnnotated
Expand All @@ -37,6 +39,15 @@ class AnnotatedUtilProcessor : AbstractTestProcessor() {
private val visitors = listOf(IsAnnotationPresentVisitor(), GetAnnotationsByTypeVisitor())

override fun process(resolver: Resolver): List<KSAnnotated> {

resolver.getClassDeclarationByName("MyTest")!!.let { cls ->
cls.getDeclaredFunctions().forEach { f ->
if (f.typeParameters.isNotEmpty()) {
println(f.typeParameters.single().bounds.toList())
}
}
}

resolver.getSymbolsWithAnnotation("com.google.devtools.ksp.processor.Test", true).forEach {
results.add("Test: $it")
visitors.forEach { visitor -> it.accept(visitor, results) }
Expand Down
5 changes: 5 additions & 0 deletions test-utils/testData/api/annotatedUtil.kt
Expand Up @@ -37,6 +37,11 @@
// ByType: com.google.devtools.ksp.processor.OuterAnnotation[innerAnnotation=com.google.devtools.ksp.processor.InnerAnnotation[value=hello from the other side]]
// END
// MODULE: annotations
// FILE: MyTest.kt
class MyTest {
fun <P> method10(): P where P: Collection<*>, P: Foo = TODO()
}

// FILE: com/google/devtools/ksp/processor/a.kt
package com.google.devtools.ksp.processor

Expand Down

0 comments on commit 25a1900

Please sign in to comment.