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

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

The newest version!
package br.com.jarch.apt.processor;

import br.com.jarch.apt.generate.GenerateCrud;
import br.com.jarch.apt.util.ProcessorUtils;
import br.com.jarch.core.annotation.JArchGenerateCrud;

import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.TypeElement;
import java.lang.reflect.Method;
import java.util.Set;

@SupportedAnnotationTypes({"br.com.jarch.core.annotation.JArchGenerateCrud", "br.com.jarch.core.annotation.JArchGenerateCrud.List"})
public class GenerateCrudProcessor extends AbstractProcessor {

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

            roundEnv
                    .getElementsAnnotatedWithAny(Set.of(JArchGenerateCrud.class, JArchGenerateCrud.List.class))
                    .forEach(element -> new GenerateCrud(element).generate());

        } 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 static  T jbUnwrap(Class iface, T wrapper) {
        T unwrapped = null;
        try {
            final Class apiWrappers = wrapper.getClass().getClassLoader().loadClass("org.jetbrains.jps.javac.APIWrappers");
            final Method unwrapMethod = apiWrappers.getDeclaredMethod("unwrap", Class.class, Object.class);
            unwrapped = iface.cast(unwrapMethod.invoke(null, iface, wrapper));
        } catch (Throwable ignored) {
        }
        return unwrapped != null ? unwrapped : wrapper;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy