mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2025-09-15 05:19:23 +00:00
improve sealed workaround generation
This commit is contained in:
30
ksp/generator/src/main/kotlin/WalkOnKSFiles.kt
Normal file
30
ksp/generator/src/main/kotlin/WalkOnKSFiles.kt
Normal file
@@ -0,0 +1,30 @@
|
||||
package dev.inmo.micro_ksp.generator
|
||||
|
||||
import com.google.devtools.ksp.getAllSuperTypes
|
||||
import com.google.devtools.ksp.symbol.KSAnnotated
|
||||
import com.google.devtools.ksp.symbol.KSClassDeclaration
|
||||
import com.google.devtools.ksp.symbol.KSDeclarationContainer
|
||||
import com.google.devtools.ksp.symbol.KSFile
|
||||
|
||||
fun KSClassDeclaration.findSubClasses(subSymbol: KSAnnotated): Sequence<KSClassDeclaration> {
|
||||
return when (subSymbol) {
|
||||
is KSClassDeclaration -> if (subSymbol.getAllSuperTypes().map { it.declaration }.contains(this)) {
|
||||
sequenceOf(subSymbol)
|
||||
} else {
|
||||
sequenceOf()
|
||||
}
|
||||
else -> sequenceOf()
|
||||
} + if (subSymbol is KSDeclarationContainer) {
|
||||
subSymbol.declarations.flatMap {
|
||||
findSubClasses(it)
|
||||
}
|
||||
} else {
|
||||
sequenceOf()
|
||||
}
|
||||
}
|
||||
|
||||
fun KSClassDeclaration.findSubClasses(files: Sequence<KSAnnotated>): Sequence<KSClassDeclaration> {
|
||||
return files.flatMap {
|
||||
findSubClasses(it)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user