Example usage for javax.annotation.processing RoundEnvironment getElementsAnnotatedWith

List of usage examples for javax.annotation.processing RoundEnvironment getElementsAnnotatedWith

Introduction

In this page you can find the example usage for javax.annotation.processing RoundEnvironment getElementsAnnotatedWith.

Prototype

Set<? extends Element> getElementsAnnotatedWith(Class<? extends Annotation> a);

Source Link

Document

Returns the elements annotated with the given annotation type.

Usage

From source file:com.github.pellaton.jazoon2012.JazoonProcessor.java

/**
 * Process one round./*w  w  w  .j a  v  a 2s  . c o  m*/
 * 
 * @see AbstractProcessor#process(Set, RoundEnvironment)
 */
private void processRound(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    for (TypeElement annotation : annotations) {
        for (Element element : roundEnv.getElementsAnnotatedWith(annotation)) {
            if (element instanceof TypeElement) {
                processElement((TypeElement) element);
            }
        }
    }
}

From source file:org.squashtest.tm.tools.annotation.processor.DynamicComponentProcessor.java

private void enqueueComponents(RoundEnvironment roundEnvironment) {
    for (Element annotated : roundEnvironment.getElementsAnnotatedWith(annotationClass())) {
        //         messager.printMessage(Kind.NOTE, "INFO Enqueued dynamic component " + annotationClass().getSimpleName(),
        //               annotated);

        if (checkTarget(annotationClass(), annotated)) {
            dynamicComponents.add(annotated);
        }/*from w w  w .  j  a v a  2  s . c  o  m*/
    }
}

From source file:net.pkhsolutions.ceres.common.builder.processor.BuildableAP.java

@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    for (Element element : roundEnv.getElementsAnnotatedWith(Buildable.class)) {
        processType((TypeElement) element);
    }//from w w w . ja v a 2s .  c o m
    return true;
}

From source file:com.webguys.djinn.marid.util.BuiltinAnnotationProcessor.java

@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    try {/* w w w.  j  av  a 2s .c  o m*/
        for (TypeElement annotation : annotations) {
            this.elements.addAll(roundEnv.getElementsAnnotatedWith(annotation));
        }

        if (roundEnv.processingOver()) {
            if (this.shouldGenerate()) {
                if (null == this.sourceFile) {
                    this.sourceFile = this.processingEnv.getFiler().createSourceFile(CLASSNAME);
                }

                this.processingEnv.getMessager().printMessage(Kind.NOTE, "generating builtin repository.");
                this.generate();
            } else {
                this.processingEnv.getMessager().printMessage(Kind.NOTE, "NOT generating builtin repository.");
            }
        }
    } catch (Exception e) {
        String message = String.format("Unable to generate the code (%s).", e.getMessage());
        this.processingEnv.getMessager().printMessage(Kind.ERROR, message);
    }

    return true;
}

From source file:blue.lapis.pore.ap.event.EventVerifierProcessor.java

@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    if (!roundEnv.processingOver()) {
        for (TypeElement anno : annotations) {
            for (Element e : roundEnv.getElementsAnnotatedWith(anno)) {
                if (e.getKind() != ElementKind.CLASS) {
                    processingEnv.getMessager().printMessage(ERROR, "Found @" + anno.getSimpleName()
                            + " annotation on a " + e.getKind().name() + " element instead of a class element",
                            e);/*from   w w w  .  j a  va2 s. c  o m*/
                    continue;
                }

                TypeElement type = (TypeElement) e;

                verifySuperClass(type);
                verifyPackage(type);
                verifyName(type);
                verifyEnclosedElements(type);
            }
        }
    }

    return false;
}

From source file:com.github.pellaton.springconfigvalidation.SpringConfigurationValidationProcessor.java

private void processRound(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    for (TypeElement annotation : annotations) {
        for (Element element : roundEnv.getElementsAnnotatedWith(annotation)) {
            processElement(element);//from  w  w w .j  a  va 2  s.  c o  m
        }
    }
}

From source file:de.adorsys.beanval2json.converter.BeanvalConverter.java

/**
 * Searches for all properties which are annotated with given TypeElement and
 * updates the constraintsMap with the according constraints
 *//*from   ww  w  .  j  a  v  a 2s . com*/
public void addConstraints(TypeElement typeElement, RoundEnvironment roundEnv,
        Map<String, Constraints> constraintsMap) throws ProcessingException {
    for (Element element : roundEnv.getElementsAnnotatedWith(typeElement)) {
        String name = getFqn(element);
        if (ctx.ignoreProperty(name)) {
            continue;
        }
        for (AnnotationMirror annotationMirror : element.getAnnotationMirrors()) {
            if (!ctx.getTypeUtils().isSameType(typeElement.asType(), annotationMirror.getAnnotationType())) {
                continue;
            }
            Constraint constraint = convertConstraint(annotationMirror);
            Constraints constraints = getConstraints(constraintsMap, name);
            try {
                String methodName = String.format("%s%s", IDENTIFIER_SETTER, typeElement.getSimpleName());
                constraints.getClass().getMethod(methodName, constraint.getClass()).invoke(constraints,
                        constraint);
            } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException
                    | NoSuchMethodException | SecurityException ex) {
                throw new ProcessingException(String.format("Could not add %s-Constraint from %s: %s",
                        typeElement.getSimpleName(), element.getSimpleName(), ex.getMessage()));
            }
        }
    }
}

From source file:org.ez18n.apt.processor.GwtXmlProcessor.java

@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    if (roundEnv.processingOver()) {
        return true;
    }/*w w  w . jav  a 2  s .  com*/

    final List<TypeElement> bundleTypes = new ArrayList<TypeElement>();
    for (Element element : roundEnv.getElementsAnnotatedWith(MessageBundle.class)) {
        if (element.getKind() != ElementKind.INTERFACE) {
            continue;
        }
        final TypeElement bundleType = (TypeElement) element;
        bundleTypes.add(bundleType);
    }

    if (bundleTypes.isEmpty()) {
        return true;
    }

    String packageName = null;
    for (TypeElement typeElement : bundleTypes) {
        String typeElementPackage = typeElement.getEnclosingElement().toString();
        if (packageName == null) {
            packageName = typeElementPackage;
        } else {
            packageName = intersectPackage(packageName, typeElementPackage);
        }
    }

    try {
        final FileObject file = processingEnv.getFiler().createResource(SOURCE_OUTPUT,
                packageName == null ? "net.courtanet.b2c" : packageName, "Generated.gwt.xml");
        final Writer writer = file.openWriter();
        writer.write(getCode(bundleTypes));
        writer.close();
    } catch (FilerException e) {
        return false;
    } catch (IOException e) {
        processingEnv.getMessager().printMessage(Kind.ERROR, e.getMessage());
    }
    return false;
}

From source file:org.ez18n.apt.processor.LabelBundleProcessor.java

@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    if (roundEnv.processingOver()) {
        return true;
    }//  www  .  jav  a2  s.  co  m
    final List<LabelTemplateMethod> methods = new ArrayList<LabelTemplateMethod>();
    for (Element element : roundEnv.getElementsAnnotatedWith(MessageBundle.class)) {
        if (element.getKind() != ElementKind.INTERFACE) {
            continue;
        }
        final TypeElement bundleType = (TypeElement) element;
        processLabels(bundleType, methods);
        try {

            FileObject file = null;
            switch (generationType) {
            case SOURCE:
                file = processingEnv.getFiler().createSourceFile(getTargetClassName(bundleType), bundleType);
                break;

            case RESSOURCE:
                file = processingEnv.getFiler().createResource(SOURCE_OUTPUT,
                        bundleType.getEnclosingElement().toString(),
                        getTargetSimpleName(bundleType) + ".properties");
                break;
            }

            final Writer writer = file.openWriter();
            writer.write(getCode(bundleType, methods));
            writer.close();
        } catch (IOException e) {
            processingEnv.getMessager().printMessage(Kind.ERROR, e.getMessage(), bundleType);
        } finally {
            methods.clear();
        }
    }
    return false;
}

From source file:com.rgeldmacher.leash.LeashAnnotationProcessor.java

@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    Set<? extends Element> elements = roundEnv.getElementsAnnotatedWith(Retain.class);
    Map<TypeElement, Set<Element>> fieldsByType = getFieldsByType(elements);

    for (Map.Entry<TypeElement, Set<Element>> entry : fieldsByType.entrySet()) {
        try {/* www.  j a  v  a2s.co m*/
            writeJavaFile(entry.getKey(), entry.getValue());
        } catch (IOException e) {
            error(entry.getKey(), "Could not create leash support class", e);
        }
    }

    return true;
}