arrow.higherkinds.HigherKindsProcessor.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of arrow-meta Show documentation
Show all versions of arrow-meta Show documentation
Functional companion to Kotlin's Standard Library
package arrow.higherkinds
import com.google.auto.service.AutoService
import arrow.common.utils.AbstractProcessor
import arrow.common.utils.knownError
import java.io.File
import javax.annotation.processing.Processor
import javax.annotation.processing.RoundEnvironment
import javax.lang.model.SourceVersion
import javax.lang.model.element.ElementKind
import javax.lang.model.element.TypeElement
@AutoService(Processor::class)
class HigherKindsProcessor : AbstractProcessor() {
private val annotatedList: MutableList = mutableListOf()
override fun getSupportedSourceVersion(): SourceVersion = SourceVersion.latestSupported()
override fun getSupportedAnnotationTypes(): Set = setOf(higherKindsAnnotationClass.canonicalName)
/**
* Processor entry point
*/
override fun onProcess(annotations: Set, roundEnv: RoundEnvironment) {
annotatedList += roundEnv
.getElementsAnnotatedWith(higherKindsAnnotationClass)
.map { element ->
when (element.kind) {
ElementKind.CLASS -> processClass(element as TypeElement)
ElementKind.INTERFACE -> processClass(element as TypeElement)
else -> knownError("$higherKindsAnnotationName can only be used on classes")
}
}
if (roundEnv.processingOver()) {
val generatedDir = File(this.generatedDir!!, higherKindsAnnotationClass.simpleName).also { it.mkdirs() }
HigherKindsFileGenerator(generatedDir, annotatedList).generate()
}
}
private fun processClass(element: TypeElement): AnnotatedHigherKind {
val proto = getClassOrPackageDataWrapper(element)
return AnnotatedHigherKind(element, proto)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy