com.bennyhuo.kotlin.processor.module.ksp.KspIndexLoader.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ksp-module-support Show documentation
Show all versions of ksp-module-support Show documentation
Compile-time trim indent for Kotlin String literals.
The newest version!
package com.bennyhuo.kotlin.processor.module.ksp
import com.bennyhuo.kotlin.processor.module.LibraryIndex
import com.bennyhuo.kotlin.processor.module.common.IndexLoader
import com.bennyhuo.kotlin.processor.module.common.UniElement
import com.bennyhuo.kotlin.processor.module.common.UniTypeElement
import com.bennyhuo.kotlin.processor.module.utils.PACKAGE_NAME
import com.google.devtools.ksp.getAnnotationsByType
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.KSClassDeclaration
/**
* Created by benny.
*/
internal class KspIndexLoader(
private val resolver: Resolver,
override val annotations: Set
) : IndexLoader {
override fun findAnnotatedElementsByTypeName(enclosingTypeName: String): Collection> {
val declarationName = DeclarationName.parse(enclosingTypeName)
return resolver.getDeclarations(declarationName).flatMap {
findAnnotatedElements(it.toUniElement())
}
}
override fun getTypeElement(typeName: String): UniTypeElement? {
return resolver.getClassDeclarationByName(typeName)?.toUniElement()
}
override fun getIndexes(): List {
return resolver.getDeclarationsFromPackage(PACKAGE_NAME)
.filterIsInstance()
.mapNotNull {
it.getAnnotationsByType(LibraryIndex::class).firstOrNull()
}.toList()
}
fun loadUnwrapped() = load().mapValues {
it.value.map { it.unwrap() }.toSet()
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy