br.com.jarch.apt.processor.ExclusiveProcessor Maven / Gradle / Ivy
package br.com.jarch.apt.processor;
import br.com.jarch.annotation.JArchValidExclusive;
import br.com.jarch.annotation.JArchValidExclusives;
import br.com.jarch.util.ProcessorUtils;
import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.Completion;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.Element;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.TypeElement;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
@SupportedAnnotationTypes("br.com.jarch.annotation.JArchValidExclusive")
public class ExclusiveProcessor extends AbstractProcessor {
private final List listaAtributos = new ArrayList<>();
@Override
public boolean process(final Set extends TypeElement> annotations, final RoundEnvironment roundEnv) {
ProcessorUtils.processingEnvironment = processingEnv;
ProcessorUtils.messageMandatoryWarning("Processando: " + getClass().getSimpleName());
try {
roundEnv
.getElementsAnnotatedWith(JArchValidExclusive.class)
.stream()
.forEach(element -> {
ProcessorUtils.messageAnalyzing(getClass(), element);
if ("id".equalsIgnoreCase(element.getSimpleName().toString())) {
ProcessorUtils.messageError("JARCH ERROR: @JArchValidExclusive não pode ser utilizado no atributo id", 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();
}
@Override
public Iterable extends Completion> getCompletions(Element element, AnnotationMirror annotation, ExecutableElement member, String userText) {
listaAtributos.clear();
final TypeElement classeElement = (TypeElement) element;
final JArchValidExclusives anotacao = element.getAnnotation(JArchValidExclusives.class);
if (member.getSimpleName().toString().contains("value")) {
String[] fields = anotacao.fields();
for (String field : fields) {
listaAtributos.add(new MyCmpl(field)); //Completions.of(field, "Mensagem para" + field));
ProcessorUtils.messageError("JARCH ERROR: Atributo " + field + " não localizado na anotação @JArchValidExclusives da classe " + classeElement.getQualifiedName().toString(), element);
}
return listaAtributos;
}
return super.getCompletions(element, annotation, member, userText);
}
private static final class MyCmpl implements Completion {
private final String protocol;
public MyCmpl(String protocol) {
this.protocol = protocol;
}
@Override
public String getValue() {
return '"' + protocol;
}
// @Override
// @NbBundle.Messages({
// "# {0} - name of the URL protocol",
// "MSG_GENERATE_PROTOCOL=Your favorite protocol {0}"
// })
public String getMessage() {
// return Bundle.MSG_GENERATE_PROTOCOL(protocol);
return "DEUS E FIEL !!!";
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy