br.com.jarch.apt.processor.FacesConverterProcessor Maven / Gradle / Ivy
package br.com.jarch.apt.processor;
import br.com.jarch.util.ProcessorUtils;
import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.faces.convert.FacesConverter;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.*;
import javax.lang.model.type.TypeMirror;
import java.util.List;
import java.util.Map;
import java.util.Set;
@SupportedAnnotationTypes({"javax.faces.convert.FacesConverter"})
public class FacesConverterProcessor extends AbstractProcessor {
@Override
public boolean process(Set extends TypeElement> annotations, RoundEnvironment roundEnv) {
ProcessorUtils.processingEnvironment = processingEnv;
ProcessorUtils.messageMandatoryWarning("Processando: " + getClass().getSimpleName());
try {
for (Element element : roundEnv.getElementsAnnotatedWith(FacesConverter.class)) {
ProcessorUtils.messageAnalyzing(getClass(), element);
// Get the annotation element from the type element
List extends AnnotationMirror> annotationMirrors = element.getAnnotationMirrors();
for (AnnotationMirror annotationMirror : annotationMirrors) {
String attributeValue = "";
String attributeForClass = "";
// Get the ExecutableElement:AnnotationValue pairs from the annotation element
Map extends ExecutableElement, ? extends AnnotationValue> elementValues
= annotationMirror.getElementValues();
for (Map.Entry extends ExecutableElement, ? extends AnnotationValue> entry
: elementValues.entrySet()) {
String key = entry.getKey().getSimpleName().toString();
Object value = entry.getValue().getValue();
switch (key) {
case "value":
attributeValue = (String) value;
break;
case "forClass":
TypeMirror typeMirror = (TypeMirror) value;
attributeForClass = typeMirror.toString();
break;
}
}
if (attributeValue.isEmpty()
&& attributeForClass.isEmpty()) {
ProcessorUtils.messageError("JARCH ERROR: @FacesConverter sem definição para os atributos value e forClass", element);
}
}
}
} catch (Exception ex) {
ProcessorUtils.messageError("JARCH ERROR: Erro no APT " + getClass().getSimpleName() + " Mensagem: " + ex.getMessage());
}
return false;
}
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latest();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy