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

uk.autores.handling.Reporting Maven / Gradle / Ivy

There is a newer version: 11.0.35-beta
Show newest version
// 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);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy