br.com.jarch.apt.processor.RequiredProcessor Maven / Gradle / Ivy
The newest version!
package br.com.jarch.apt.processor;
import br.com.jarch.core.annotation.JArchValidRequired;
import br.com.jarch.apt.util.ProcessorUtils;
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.Element;
import javax.lang.model.element.TypeElement;
import java.util.Set;
@SupportedAnnotationTypes({"br.com.jarch.core.annotation.JArchValidRequired"/*, "br.com.jarch.core.annotation.JArchValidRequired.List"*/})
public class RequiredProcessor extends AbstractProcessor {
@Override
public boolean process(final Set extends TypeElement> annotations, final RoundEnvironment roundEnv) {
try {
ProcessorUtils.processingEnvironment = processingEnv;
ProcessorUtils.messageNote("Analyzing: " + getClass().getSimpleName());
roundEnv
.getElementsAnnotatedWithAny(Set.of(JArchValidRequired.class/*, JArchValidRequired.List.class*/))
.stream()
.forEach(element -> {
ProcessorUtils.messageAnalyzing(getClass(), element);
validRequired(element);
});
return false;
} 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 validRequired(Element element) {
for (JArchValidRequired anotacao : element.getAnnotationsByType(JArchValidRequired.class)) {
if (!anotacao.value().isEmpty()
&& !anotacao.value().startsWith("label.")
&& !anotacao.value().startsWith("message.")
&& !anotacao.value().startsWith("required.")) {
ProcessorUtils.messageError("JARCH ERROR: @JArchValidRequired com value igual " + anotacao.value() + " fora do padrao para uma chave do bundle. Utilizar o seguinte prefixo: \"label.\" ou \"message.\" ou \"required.\" .", element);
}
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy