br.com.jarch.apt.processor.JsfNoCdiProcessor Maven / Gradle / Ivy
The newest version!
package br.com.jarch.apt.processor;
import br.com.jarch.apt.util.ProcessorUtils;
import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.SessionScoped;
import javax.faces.bean.ViewScoped;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
import java.util.Set;
@SupportedAnnotationTypes({"javax.faces.bean.ViewScoped",
"javax.faces.bean.RequestScoped",
"javax.faces.bean.SessionScoped",
"javax.faces.bean.ApplicationScoped"})
public class JsfNoCdiProcessor extends AbstractProcessor {
@Override
public boolean process(final Set extends TypeElement> annotations, final RoundEnvironment roundEnv) {
try {
ProcessorUtils.processingEnvironment = processingEnv;
ProcessorUtils.messageNote("Analyzing: " + getClass().getSimpleName());
roundEnv
.getRootElements()
.stream()
.filter(e -> e.getAnnotation(RequestScoped.class) != null
|| e.getAnnotation(ViewScoped.class) != null
|| e.getAnnotation(SessionScoped.class) != null
|| e.getAnnotation(ApplicationScoped.class) != null)
.forEach(element -> {
ProcessorUtils.messageAnalyzing(getClass(), element);
advertencia(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();
}
private void advertencia(Element element) {
final TypeElement classeElement = (TypeElement) element;
ProcessorUtils.messageWarning(getClass().getSimpleName() + ": JARCH WARNING: Utilize o escopo do CDI no lugar do JSF na classe " + classeElement.getQualifiedName().toString(), element);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy