uk.autores.handling.Reporting Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of annotations Show documentation
Show all versions of annotations Show documentation
Annotation driven library for handling embedded resources
// Copyright 2023 https://github.com/autores-uk/autores/blob/main/LICENSE.txt
// SPDX-License-Identifier: Apache-2.0
package uk.autores.handling;
import javax.annotation.processing.Messager;
import javax.lang.model.element.Element;
import javax.tools.Diagnostic;
import java.util.function.Consumer;
/** Utility type to aid in optional error reporting. */
final class Reporting {
private Reporting() {}
static Consumer reporter(Context context, ConfigDef def) {
String action = context.option(def).orElse("error");
if ("ignore".equals(action)) {
return (m) -> {};
}
Messager messager = context.env().getMessager();
Element annotated = context.annotated();
if ("warn".equals(action)) {
return m -> messager.printMessage(Diagnostic.Kind.WARNING, m, annotated);
}
return m -> messager.printMessage(Diagnostic.Kind.ERROR, m, annotated);
}
}