br.com.jarch.apt.processor.JArchGenerateLogicMasterSubDetailProcessor Maven / Gradle / Ivy
package br.com.jarch.apt.processor;
import br.com.jarch.annotation.JArchGenerateLogicMasterSubDetail;
import br.com.jarch.util.ProcessorUtils;
import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.ProcessingEnvironment;
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.annotation.JArchGenerateLogicMasterSubDetail", "br.com.jarch.annotation.JArchGenerateLogicMasterSubDetail.List"})
public class JArchGenerateLogicMasterSubDetailProcessor extends AbstractProcessor {
@Override
public boolean process(Set extends TypeElement> annotations, RoundEnvironment roundEnv) {
ProcessorUtils.processingEnvironment = jbUnwrap(ProcessingEnvironment.class, processingEnv);
ProcessorUtils.messageMandatoryWarning("Processando: " + getClass().getSimpleName());
roundEnv
.getElementsAnnotatedWithAny(Set.of(JArchGenerateLogicMasterSubDetail.class, JArchGenerateLogicMasterSubDetail.List.class))
.forEach(element -> new LogicMasterDetailSubDetail(element).generate());
return false;
}
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latest();
}
private static T jbUnwrap(Class extends T> 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