From 25a19002c43edb5767d10ea81100eae3f89b72b0 Mon Sep 17 00:00:00 2001 From: Kuan-Ying Chou Date: Fri, 26 Apr 2024 18:02:41 +0100 Subject: [PATCH] Test type var bounds --- .../devtools/ksp/processor/AnnotatedUtilProcessor.kt | 11 +++++++++++ test-utils/testData/api/annotatedUtil.kt | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/test-utils/src/main/kotlin/com/google/devtools/ksp/processor/AnnotatedUtilProcessor.kt b/test-utils/src/main/kotlin/com/google/devtools/ksp/processor/AnnotatedUtilProcessor.kt index 954feb432b..24aa04b280 100644 --- a/test-utils/src/main/kotlin/com/google/devtools/ksp/processor/AnnotatedUtilProcessor.kt +++ b/test-utils/src/main/kotlin/com/google/devtools/ksp/processor/AnnotatedUtilProcessor.kt @@ -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 @@ -37,6 +39,15 @@ class AnnotatedUtilProcessor : AbstractTestProcessor() { private val visitors = listOf(IsAnnotationPresentVisitor(), GetAnnotationsByTypeVisitor()) override fun process(resolver: Resolver): List { + + 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) } diff --git a/test-utils/testData/api/annotatedUtil.kt b/test-utils/testData/api/annotatedUtil.kt index bbd0578519..fcb281f736 100644 --- a/test-utils/testData/api/annotatedUtil.kt +++ b/test-utils/testData/api/annotatedUtil.kt @@ -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

method10(): P where P: Collection<*>, P: Foo = TODO() +} + // FILE: com/google/devtools/ksp/processor/a.kt package com.google.devtools.ksp.processor