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

com.fluxtion.compiler.generation.annotationprocessor.ValidateOnParentUpdateHandlerAnnotations Maven / Gradle / Ivy

package com.fluxtion.compiler.generation.annotationprocessor;

import com.fluxtion.runtime.annotations.OnParentUpdate;
import com.google.auto.service.AutoService;

import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.Processor;
import javax.annotation.processing.RoundEnvironment;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.Element;
import javax.lang.model.element.Modifier;
import javax.lang.model.element.TypeElement;
import javax.lang.model.type.ExecutableType;
import javax.tools.Diagnostic;
import java.util.HashSet;
import java.util.Set;
import java.util.stream.Collectors;

@AutoService(Processor.class)
public class ValidateOnParentUpdateHandlerAnnotations extends AbstractProcessor {
    @Override
    public boolean process(Set annotations, RoundEnvironment roundEnv) {
        for (TypeElement annotation : annotations) {
            Set annotatedElements = roundEnv.getElementsAnnotatedWith(annotation);
            Set typeElements = annotatedElements.stream()
                    .filter(element ->
                            ((ExecutableType) element.asType()).getParameterTypes().size() != 1
                                    || !element.getModifiers().contains(Modifier.PUBLIC)
                    )
                    .collect(Collectors.toSet());

            typeElements.forEach(element ->
                    processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR,
                            "OnParentUpdate should be public method accepting a single parameter, "
                                    + "failing method:" + element.getSimpleName(), element));
        }
        return false;
    }

    @Override
    public SourceVersion getSupportedSourceVersion() {
        return SourceVersion.latestSupported();
    }

    @Override
    public Set getSupportedAnnotationTypes() {
        Set supportedAnnotations = new HashSet<>();
        supportedAnnotations.add(OnParentUpdate.class.getCanonicalName());
        return supportedAnnotations;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy