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

br.com.jarch.apt.processor.NamedProcessor 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.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) {
        try {
            ProcessorUtils.processingEnvironment = processingEnv;
            ProcessorUtils.messageNote("Analyzing: " + getClass().getSimpleName());

            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