All Downloads are FREE. Search and download functionalities are using the official Maven repository.

br.com.jarch.apt.processor.NamedProcessor Maven / Gradle / Ivy

There is a newer version: 24.9.0
Show newest version
package br.com.jarch.apt.processor;

import br.com.jarch.annotation.JArchViewScoped;
import br.com.jarch.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.inject.Named;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
import java.util.Set;

@SupportedAnnotationTypes({"javax.inject.Named"})
public class NamedProcessor extends AbstractProcessor {

    @Override
    public boolean process(final Set annotations, final RoundEnvironment roundEnv) {
        ProcessorUtils.processingEnvironment = processingEnv;
        ProcessorUtils.messageMandatoryWarning("Processando: " + getClass().getSimpleName());

        try {
            for (Element element : roundEnv.getElementsAnnotatedWith(Named.class)) {
                ProcessorUtils.messageAnalyzing(getClass(), element);

                if (!element.getKind().isClass()) {
                    continue;
                }

                validCdiWithJsf(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 validCdiWithJsf(Element element) {
        final TypeElement classeElement = (TypeElement) element;

//        if (element.getAnnotation(ViewScoped.class) != null) {
//            ProcessorUtils.messageError("JARCH ERROR: @Named do CDI com escopo @ViewScoped do JSF encontrado na classe " + classeElement.getQualifiedName().toString(), element);
//        }
//
//        if (element.getAnnotation(RequestScoped.class) != null) {
//            ProcessorUtils.messageError("JARCH ERROR: @Named do CDI com escopo @RequestScoped do JSF encontrado na classe " + classeElement.getQualifiedName().toString(), element);
//        }
//
//        if (element.getAnnotation(SessionScoped.class) != null) {
//            ProcessorUtils.messageError("JARCH ERROR: @Named do CDI com escopo @SessionScoped do JSF encontrado na classe " + classeElement.getQualifiedName().toString(), element);
//        }
//
//        if (element.getAnnotation(ApplicationScoped.class) != null) {
//            ProcessorUtils.messageError("JARCH ERROR: @Named do CDI com escopo @ApplicationScoped do JSF encontrado na classe " + classeElement.getQualifiedName().toString(), element);
//        }
//
//        if (element.getAnnotation(JArchViewScoped.class) != null) {
//            ProcessorUtils.messageError("JARCH ERROR: @JArchViewScoped é um estereótipo que ja possuí o @Named, remover a anotação @Named da classe " + classeElement.getQualifiedName().toString(), element);
//        }
    }
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy