diff options
author | Jiaxiang Chen <jiaxiang@google.com> | 2022-09-09 13:53:37 -0700 |
---|---|---|
committer | Jiaxiang Chen <roaringacw@gmail.com> | 2022-09-13 16:54:47 -0700 |
commit | 3d29c22e2396a6575919aa28ddc9038e631be97f (patch) | |
tree | e9178b9b44362c20617e17fecfe526f91f2c7a0a /test-utils/src | |
parent | 35a12d6148ddd3ffb42b4d6ae0a99395485bde62 (diff) | |
download | ksp-3d29c22e2396a6575919aa28ddc9038e631be97f.tar.gz |
retrieve annotations for KSType from KotlinType instead of KSTypeReference
Diffstat (limited to 'test-utils/src')
2 files changed, 36 insertions, 2 deletions
diff --git a/test-utils/src/main/kotlin/com/google/devtools/ksp/processor/FunctionTypeAnnotationProcessor.kt b/test-utils/src/main/kotlin/com/google/devtools/ksp/processor/FunctionTypeAnnotationProcessor.kt new file mode 100644 index 00000000..c35d156e --- /dev/null +++ b/test-utils/src/main/kotlin/com/google/devtools/ksp/processor/FunctionTypeAnnotationProcessor.kt @@ -0,0 +1,36 @@ +package com.google.devtools.ksp.processor + +import com.google.devtools.ksp.processing.Resolver +import com.google.devtools.ksp.symbol.KSAnnotated +import com.google.devtools.ksp.symbol.KSNode +import com.google.devtools.ksp.symbol.KSPropertyDeclaration +import com.google.devtools.ksp.visitor.KSTopDownVisitor + +class FunctionTypeAnnotationProcessor : AbstractTestProcessor() { + val results = mutableListOf<String>() + + override fun toResult(): List<String> { + return results + } + + override fun process(resolver: Resolver): List<KSAnnotated> { + val files = resolver.getNewFiles() + + files.forEach { + it.accept( + object : KSTopDownVisitor<Unit, Unit>() { + override fun defaultHandler(node: KSNode, data: Unit) = Unit + + override fun visitPropertyDeclaration(property: KSPropertyDeclaration, data: Unit) { + val type = property.type.resolve() + val propertyName = property.simpleName.asString() + val typeName = type.declaration.simpleName.asString() + results.add("$propertyName: $typeName ${type.annotations.joinToString { it.toString() }}") + } + }, + Unit + ) + } + return emptyList() + } +} diff --git a/test-utils/src/main/kotlin/com/google/devtools/ksp/processor/FunctionTypeProcessor.kt b/test-utils/src/main/kotlin/com/google/devtools/ksp/processor/FunctionTypeProcessor.kt index 4e5f4e07..f361599b 100644 --- a/test-utils/src/main/kotlin/com/google/devtools/ksp/processor/FunctionTypeProcessor.kt +++ b/test-utils/src/main/kotlin/com/google/devtools/ksp/processor/FunctionTypeProcessor.kt @@ -23,12 +23,10 @@ import com.google.devtools.ksp.visitor.KSTopDownVisitor open class FunctionTypeProcessor : AbstractTestProcessor() { val results = mutableListOf<String>() - val typeCollector = TypeCollector() val types = mutableSetOf<KSType>() override fun process(resolver: Resolver): List<KSAnnotated> { val files = resolver.getNewFiles() - val ignoredNames = mutableSetOf<String>() files.forEach { it.accept( |