forked from google/ksp
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add experimental KSDeclarationContainer.declarationsInSourceOrder
which is same as KSDeclarationContainer.declarations, except that the order of retrived declarations match their positions in source. This is adapted from google#260, which is authored by Yigit Boyar <yboyar@google.com>.
- Loading branch information
Showing
5 changed files
with
392 additions
and
0 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
45 changes: 45 additions & 0 deletions
45
...ler-plugin/src/test/kotlin/com/google/devtools/ksp/processor/DeclarationOrderProcessor.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,45 @@ | ||
package com.google.devtools.ksp.processor | ||
|
||
import com.google.devtools.ksp.KspExperimental | ||
import com.google.devtools.ksp.getClassDeclarationByName | ||
import com.google.devtools.ksp.processing.Resolver | ||
import com.google.devtools.ksp.symbol.KSAnnotated | ||
import com.google.devtools.ksp.symbol.KSDeclaration | ||
import com.google.devtools.ksp.symbol.KSFunctionDeclaration | ||
import com.google.devtools.ksp.symbol.KSPropertyDeclaration | ||
import com.google.devtools.ksp.symbol.impl.declarationsInSourceOrder | ||
|
||
@KspExperimental | ||
class DeclarationOrderProcessor : AbstractTestProcessor() { | ||
private val result = mutableListOf<String>() | ||
override fun toResult() = result | ||
|
||
override fun process(resolver: Resolver): List<KSAnnotated> { | ||
val classNames = listOf( | ||
"lib.KotlinClass", "lib.JavaClass", | ||
"KotlinClass", "JavaClass" | ||
) | ||
classNames.map { | ||
checkNotNull(resolver.getClassDeclarationByName(it)) { | ||
"cannot find $it" | ||
} | ||
}.forEach { klass -> | ||
result.add(klass.qualifiedName!!.asString()) | ||
result.addAll( | ||
klass.declarationsInSourceOrder.filterIsInstance<KSPropertyDeclaration>().map { | ||
it.toSignature(resolver) | ||
} | ||
) | ||
result.addAll( | ||
klass.declarationsInSourceOrder.filterIsInstance<KSFunctionDeclaration>().map { | ||
it.toSignature(resolver) | ||
} | ||
) | ||
} | ||
return emptyList() | ||
} | ||
|
||
private fun KSDeclaration.toSignature( | ||
resolver: Resolver | ||
) = "${simpleName.asString()}:${resolver.mapToJvmSignature(this)}" | ||
} |
Oops, something went wrong.