All Downloads are FREE. Search and download functionalities are using the official Maven repository.

o_utils.ksp.generator.0.22.6.source-code.WalkOnKSFiles.kt Maven / Gradle / Ivy

There is a newer version: 0.23.0
Show newest version
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 {
    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): Sequence {
    return files.flatMap {
        findSubClasses(it)
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy