net.chestmc.common.annotations.StandardProcessor.kt Maven / Gradle / Ivy
package net.chestmc.common.annotations
import javax.annotation.processing.AbstractProcessor
import javax.annotation.processing.Filer
import javax.annotation.processing.Messager
import javax.lang.model.util.Elements
import javax.lang.model.util.Types
import javax.tools.Diagnostic
/**
* A standard processor is a [AbstractProcessor] with some
* useful functions when creating new annotation processors.
*/
abstract class StandardProcessor : AbstractProcessor() {
/**
* A shortcut to get the messager of the [processingEnv].
*/
val messager: Messager get() = processingEnv.messager
/**
* A shortcut to get the elements utils of the [processingEnv].
*/
val elements: Elements get() = processingEnv.elementUtils
/**
* A shortcut to get the filer of the [processingEnv].
*/
val filer: Filer get() = processingEnv.filer
/**
* A shortcut to get the type utils of the [processingEnv].
*/
val types: Types get() = processingEnv.typeUtils
/**
* Prints a message by the specified kind in the messager.
*/
fun print(kind: Diagnostic.Kind, message: Any) = messager.printMessage(kind, "$message")
/**
* Prints a error message in the messager.
*/
fun error(message: Any): Boolean {
print(Diagnostic.Kind.ERROR, message)
return false
}
/**
* Prints a note message in the messager.
*/
fun note(message: Any) = print(Diagnostic.Kind.NOTE, message)
/**
* Prints a warning message in the messager.
*/
fun warning(message: Any) = print(Diagnostic.Kind.WARNING, message)
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy