Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
retrieve annotations for KSType from KotlinType instead of KSTypeRefe…
…rence
- Loading branch information
Showing
6 changed files
with
88 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
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
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,33 @@ | ||
/* | ||
* Copyright 2022 Google LLC | ||
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
|
||
// WITH_RUNTIME | ||
// TEST PROCESSOR: FunctionTypeAnnotationProcessor | ||
// EXPECTED: | ||
// strExt0: Function1 @ExtensionFunctionType | ||
// strExt1: Function2 @ExtensionFunctionType | ||
// strWithAnnoExt0: Function1 @A, @ExtensionFunctionType | ||
// strWithAnnoExt1: Function2 @A, @ExtensionFunctionType | ||
// END | ||
// FILE: a.kt | ||
annotation class A | ||
|
||
val strExt0: String.() -> Unit = TODO() | ||
val strExt1: String.(Int) -> Unit = TODO() | ||
val strWithAnnoExt0: @A String.() -> Unit = TODO() | ||
val strWithAnnoExt1: @A String.(@A Int) -> Unit = TODO() |
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
36 changes: 36 additions & 0 deletions
36
...tils/src/main/kotlin/com/google/devtools/ksp/processor/FunctionTypeAnnotationProcessor.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,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() | ||
} | ||
} |
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