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

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

There is a newer version: 24.9.0
Show newest version
package br.com.jarch.apt.processor;


import br.com.jarch.annotation.JArchConfiguration;
import br.com.jarch.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.TypeElement;
import javax.persistence.SequenceGenerator;
import java.util.Set;


@SupportedAnnotationTypes("javax.persistence.SequenceGenerator")
public class SequenceGeneratorProcessor extends AbstractProcessor {

    public static final int MIN_SIZE = 3;
    public static final int POSITION_UNDERLINE = 2;

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

        try {
            roundEnv
                    .getElementsAnnotatedWith(SequenceGenerator.class)
                    .stream()
                    .filter(element -> element.getAnnotation(JArchConfiguration.class) == null || !element.getAnnotation(JArchConfiguration.class).ignorePatternsObjetcsDataBase())
                    .filter(element -> element.getEnclosingElement().getAnnotation(JArchConfiguration.class) == null || !element.getEnclosingElement().getAnnotation(JArchConfiguration.class).ignorePatternsObjetcsDataBase())
                    .forEach(element -> {
                        ProcessorUtils.messageAnalyzing(getClass(), element);

                        final SequenceGenerator anotacao = element.getAnnotation(SequenceGenerator.class);

                        if (anotacao.sequenceName().isEmpty()) {
                            ProcessorUtils.messageError("JARCH ERROR: @SequenceGenerator com sequenceName vazio não permitido. Informar nome da sequence", element);
                        }

                        if (anotacao.sequenceName().length() < MIN_SIZE
                                || anotacao.sequenceName().toCharArray()[POSITION_UNDERLINE] != '_') {
                            ProcessorUtils.messageError("JARCH ERROR: @SequenceGenerator com name fora do padrão. Informar nome da sequence da tabela conforme padronização", element);
                        }

                        if (anotacao.sequenceName().length() > 30) {
                            ProcessorUtils.messageError("JARCH ERROR: @SequenceGenerator com atributo sequenceName superior a 30 caracteres. Informar nome da sequence da tabela com no máximo 30 caracteres", 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();
    }

}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy