package com.ekino.lesaint.dozerannihilation.processor.impl;

import java.io.IOException;
import java.lang.annotation.Annotation;
import java.util.Set;
import javax.annotation.processing.ProcessingEnvironment;
import javax.annotation.processing.RoundEnvironment;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
import javax.tools.Diagnostic;

/**
 * AbstractAnnotationProcessor -
 *
 * @author lesaint
 */
public abstract class AbstractAnnotationProcessor<T extends Annotation> implements AnnotationProcessor {
    protected final ProcessingEnvironment processingEnv;
    private final Class<T> annotationType;

    protected AbstractAnnotationProcessor(ProcessingEnvironment processingEnv, Class<T> annotationType) {
        this.processingEnv = processingEnv;
        this.annotationType = annotationType;
    }

    @Override
    public void processAll(TypeElement annotation, RoundEnvironment roundEnv) {
        Set<? extends Element> elementsAnnotatedWith = roundEnv.getElementsAnnotatedWith(annotationType);
//        System.out.println("Elements retrieved " + elementsAnnotatedWith);
        for (Element element : elementsAnnotatedWith) {
            try {
                process(element, roundEnv);
            } catch (IOException e) {
                e.printStackTrace();
                processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "TODO", element);
            }
        }
    }

    protected abstract void process(Element element, RoundEnvironment roundEnv) throws IOException;
}

@@ -1426,46 +1426,249 @@
 age(
-Diagnostic.Kind.ERROR, %22TODO%22, element
+%0A                        Diagnostic.Kind.ERROR,%0A                        %22Processing of elements annotated with %22 + annotationType.getCanonicalName() + %22 failed for %22 + element.getSimpleName(),%0A                        element%0A                
 );%0A 

fix TODO error message