br.com.jarch.apt.processor.LookupProcessor Maven / Gradle / Ivy
package br.com.jarch.apt.processor;
import br.com.jarch.annotation.JArchLookup;
import br.com.jarch.util.ProcessorUtils;
import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.Completion;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.Element;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.TypeElement;
import java.util.Set;
@SupportedAnnotationTypes("br.com.jarch.annotation.JArchLookup")
public class LookupProcessor extends AbstractProcessor {
@Override
public boolean process(final Set extends TypeElement> annotations, final RoundEnvironment roundEnv) {
ProcessorUtils.processingEnvironment = processingEnv;
ProcessorUtils.messageMandatoryWarning("Processando: " + getClass().getSimpleName());
try {
for (Element element : roundEnv.getElementsAnnotatedWith(JArchLookup.class)) {
ProcessorUtils.messageAnalyzing(getClass(), element);
final JArchLookup anotacao = element.getAnnotation(JArchLookup.class);
if (anotacao.ignoreProcessor()) {
continue;
}
final TypeElement classeElement = (TypeElement) element;
existsFieldLookup(element, classeElement, anotacao.codeAttribute());
existsFieldLookup(element, classeElement, anotacao.descriptionAttribute());
}
} catch (Exception ex) {
ProcessorUtils.messageError("JARCH ERROR: Erro no APT " + getClass().getSimpleName() + " Mensagem: " + ex.getMessage());
}
return false;
}
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latest();
}
private static void existsFieldLookup(Element elementAtual, TypeElement classeElement, String field) {
if (!ProcessorUtils.existsField(classeElement, field)) {
ProcessorUtils.messageError("JARCH ERROR: Atributo " + field + " não localizado na anotação @JArchLookup da classe " + classeElement.getQualifiedName().toString(), elementAtual);
}
}
@Override
public Iterable extends Completion> getCompletions(Element element, AnnotationMirror annotation, ExecutableElement member, String userText) {
return super.getCompletions(element, annotation, member, userText);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy