br.com.jarch.apt.processor.ManagedBeanProcessor 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.enterprise.context.ApplicationScoped;
import javax.enterprise.context.RequestScoped;
import javax.enterprise.context.SessionScoped;
import javax.faces.bean.ManagedBean;
import javax.faces.view.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.ManagedBean")
public class ManagedBeanProcessor extends AbstractProcessor {
public static final String MESSAGE_ERROR = "JARCH ERROR: @ManagedBean do JSF com escopo do CDI encontrado na classe ";
@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(ManagedBean.class)) {
ProcessorUtils.messageAnalyzing(getClass(), element);
if (!element.getKind().isClass()) {
continue;
}
validWithCdi(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 validWithCdi(Element element) {
final TypeElement classeElement = (TypeElement) element;
if (element.getAnnotation(RequestScoped.class) != null) {
ProcessorUtils.messageError(MESSAGE_ERROR + classeElement.getQualifiedName().toString(), element);
}
if (element.getAnnotation(ViewScoped.class) != null) {
ProcessorUtils.messageError(MESSAGE_ERROR + classeElement.getQualifiedName().toString(), element);
}
if (element.getAnnotation(SessionScoped.class) != null) {
ProcessorUtils.messageError(MESSAGE_ERROR + classeElement.getQualifiedName().toString(), element);
}
if (element.getAnnotation(ApplicationScoped.class) != null) {
ProcessorUtils.messageError(MESSAGE_ERROR + classeElement.getQualifiedName().toString(), element);
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy