-
Notifications
You must be signed in to change notification settings - Fork 287
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
map java types to kotlin types when parsing annotation class referenc…
…e values (cherry picked from commit 386fe47)
- Loading branch information
Showing
4 changed files
with
62 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
kotlin-analysis-api/testData/annotationValue/defaultKClassValue.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// TEST PROCESSOR: DefaultKClassValueProcessor | ||
// EXPECTED: | ||
// kotlin.String | ||
// kotlin.String | ||
// kotlin.String | ||
// kotlin.Int | ||
// END | ||
// MODULE: lib1 | ||
// FILE: lib1.kt | ||
annotation class ExampleAnnotation(val value: kotlin.reflect.KClass<*> = java.lang.String::class) | ||
|
||
// MODULE: main(lib1) | ||
// FILE: a.kt | ||
|
||
@ExampleAnnotation(String::class) | ||
class Example | ||
|
||
@ExampleAnnotation(Int::class) | ||
class Example2 | ||
|
28 changes: 28 additions & 0 deletions
28
test-utils/src/main/kotlin/com/google/devtools/ksp/processor/DefaultKClassValueProcessor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.google.devtools.ksp.processor | ||
|
||
import com.google.devtools.ksp.getClassDeclarationByName | ||
import com.google.devtools.ksp.impl.symbol.kotlin.KSTypeImpl | ||
import com.google.devtools.ksp.processing.Resolver | ||
import com.google.devtools.ksp.symbol.KSAnnotated | ||
|
||
class DefaultKClassValueProcessor : AbstractTestProcessor() { | ||
val results = mutableListOf<String>() | ||
|
||
override fun toResult(): List<String> { | ||
return results | ||
} | ||
|
||
override fun process(resolver: Resolver): List<KSAnnotated> { | ||
val example1 = resolver.getClassDeclarationByName("Example")!!.annotations.first() | ||
val example2 = resolver.getClassDeclarationByName("Example2")!!.annotations.first() | ||
val arg1 = (example1.arguments.single().value as KSTypeImpl).declaration.qualifiedName!! | ||
val defaultArg1 = (example1.defaultArguments.single().value as KSTypeImpl).declaration.qualifiedName!! | ||
results.add(defaultArg1.asString()) | ||
results.add(arg1.asString()) | ||
val arg2 = (example2.arguments.single().value as KSTypeImpl).declaration.qualifiedName!! | ||
val defaultArg2 = (example2.defaultArguments.single().value as KSTypeImpl).declaration.qualifiedName!! | ||
results.add(defaultArg2.asString()) | ||
results.add(arg2.asString()) | ||
return emptyList() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters