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:easymvp.compiler.EasyMVPProcessor.java

private Map<TypeElement, DelegateClassGenerator> makeDelegates(RoundEnvironment roundEnv) {
    //Key is view class as TypeElement
    Map<TypeElement, DelegateClassGenerator> delegateClassMap = new LinkedHashMap<>();

    for (Element element : roundEnv.getElementsAnnotatedWith(ActivityView.class)) {
        parseActivityView(element, delegateClassMap);
    }/*w  w w  .ja  va2s  .com*/
    for (Element element : roundEnv.getElementsAnnotatedWith(FragmentView.class)) {
        parseFragmentView(element, delegateClassMap);
    }
    for (Element element : roundEnv.getElementsAnnotatedWith(CustomView.class)) {
        parseCustomView(element, delegateClassMap);
    }
    for (Element element : roundEnv.getElementsAnnotatedWith(Presenter.class)) {
        parsePresenterInjection(element, delegateClassMap);
    }
    return delegateClassMap;
}

From source file:info.archinnov.achilles.internals.apt.processors.meta.AchillesProcessor.java

private List<EntityMetaSignature> discoverAndValidateTablesAndViews(Set<? extends TypeElement> annotations,
        RoundEnvironment roundEnv, GlobalParsingContext parsingContext) {
    final List<TypeElement> tableTypes = annotations.stream()
            .filter(annotation -> isAnnotationOfType(annotation, Table.class))
            .flatMap(annotation -> roundEnv.getElementsAnnotatedWith(annotation).stream())
            .map(MoreElements::asType).collect(toList());

    final List<TypeElement> viewTypes = annotations.stream()
            .filter(annotation -> isAnnotationOfType(annotation, MaterializedView.class))
            .flatMap(annotation -> roundEnv.getElementsAnnotatedWith(annotation).stream())
            .map(MoreElements::asType).collect(toList());

    final List<TypeElement> types = CollectionsHelper.appendAll(tableTypes, viewTypes);

    validateEntityNames(types);//ww w .  j a v  a  2 s.  c om

    final List<EntityMetaSignature> tableSignatures = tableTypes.stream()
            .map(x -> entityParser.parseEntity(x, parsingContext)).collect(toList());

    final List<EntityMetaSignature> viewSignatures = viewTypes.stream()
            .map(x -> entityParser.parseView(x, parsingContext)).collect(toList());

    final List<EntityMetaSignature> tableAndViewSignatures = CollectionsHelper.appendAll(tableSignatures,
            viewSignatures);

    validateViewsAgainstBaseTable(aptUtils, viewSignatures, tableSignatures);
    return tableAndViewSignatures;
}

From source file:org.shredzone.commons.taglib.processor.TaglibProcessor.java

@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    taglib = new TaglibBean();

    try {/*from w  w w  .j  a v a2  s  .  c  om*/
        for (Element e : roundEnv.getElementsAnnotatedWith(Tag.class)) {
            processTag(e);
        }

        for (Element e : roundEnv.getElementsAnnotatedWith(TagInfo.class)) {
            processTagInfo(e);
        }

        for (Element e : roundEnv.getElementsAnnotatedWith(BeanFactoryReference.class)) {
            processBeanFactoryReference(e);
        }

        for (Element e : roundEnv.getElementsAnnotatedWith(TagParameter.class)) {
            processTagParameter(e);
        }

        for (Element e : roundEnv.getElementsAnnotatedWith(TagLib.class)) {
            processTagLib(e);
        }

        if (!taglib.getTags().isEmpty()) {
            for (TagBean tag : taglib.getTags()) {
                generateProxyClass(tag);
            }
            generateTaglibTld(taglib.getTldName());
        }

    } catch (ProcessorException | IOException ex) {
        Messager messager = processingEnv.getMessager();
        messager.printMessage(Diagnostic.Kind.ERROR, ex.getMessage());
        return false;

    } finally {
        taglib = null;
        taglibSet = false;
    }

    return true;
}

From source file:info.archinnov.achilles.internals.apt.processors.meta.AchillesProcessor.java

private FunctionsContext parseAndValidateFunctionRegistry(GlobalParsingContext context,
        Set<? extends TypeElement> annotations, RoundEnvironment roundEnv,
        List<EntityMetaSignature> tableAndViewSignatures) {
    final List<FunctionSignature> udfSignatures = annotations.stream()
            .filter(annotation -> isAnnotationOfType(annotation, FunctionRegistry.class))
            .flatMap(annotation -> roundEnv.getElementsAnnotatedWith(annotation).stream())
            .map(MoreElements::asType)/* www.j  av a  2  s .c om*/
            .flatMap(x -> FunctionParser.parseFunctionRegistryAndValidateTypes(aptUtils, x, context).stream())
            .collect(toList());

    FunctionParser.validateNoDuplicateDeclaration(aptUtils, udfSignatures);

    final Set<TypeName> functionParameterTypes = udfSignatures.stream()
            .flatMap(x -> x.sourceParameterTypes.stream().map(TypeName::box)).collect(toSet());

    final Set<TypeName> functionReturnTypes = udfSignatures.stream().map(x -> x.sourceReturnType.box())
            .collect(toSet());

    final Set<TypeName> entityColumnTargetTypes = tableAndViewSignatures.stream()
            .filter(EntityMetaSignature::isTable).flatMap(x -> x.fieldMetaSignatures.stream())
            .map(x -> x.sourceType)
            //.map(TypeUtils::mapToNativeCassandraType)
            .collect(toSet());

    return new FunctionsContext(udfSignatures, CollectionsHelper.appendAll(functionParameterTypes,
            functionReturnTypes, entityColumnTargetTypes, NATIVE_TYPES));
}

From source file:pt.ist.vaadinframework.annotation.EmbeddedAnnotationProcessor.java

@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {

    final Set<String> actions = new HashSet<String>();

    final File file = new File(LOG_FILENAME);
    if (file.exists()) {
        try {/*  ww w  .  j av a  2 s .c om*/
            final String contents = FileUtils.readFileToString(file);
            for (final String line : contents.split(ENTRY_SEPERATOR)) {
                actions.add(line);
            }
        } catch (final IOException e) {
            e.printStackTrace();
        }
    }

    final Set<? extends Element> elements = roundEnv.getElementsAnnotatedWith(EmbeddedComponent.class);
    for (final Element element : elements) {
        if (element instanceof TypeElement) {
            final TypeElement typeElement = (TypeElement) element;
            actions.add(typeElement.getQualifiedName().toString());
        } else {
            System.out.println("Skipping processing of element: " + element.getClass().getName()
                    + ", this type was not expected!");
        }
    }

    FileWriter fileWriter = null;
    try {
        fileWriter = new FileWriter(LOG_FILENAME, false);
        for (final String action : actions) {
            fileWriter.append(action);
            fileWriter.write(ENTRY_SEPERATOR);
        }
    } catch (final IOException e) {
        e.printStackTrace();
    } finally {
        if (fileWriter != null) {
            try {
                fileWriter.close();
            } catch (final IOException e) {
                e.printStackTrace();
            }
        }
    }

    return true;
}

From source file:com.contentful.vault.compiler.Processor.java

private Set<Injection> findAndParseTargets(RoundEnvironment env) {
    Map<TypeElement, ModelInjection> models = new LinkedHashMap<>();
    Map<TypeElement, FieldsInjection> fields = new LinkedHashMap<>();
    Map<TypeElement, SpaceInjection> spaces = new LinkedHashMap<>();

    // Parse ContentType bindings
    for (Element element : env.getElementsAnnotatedWith(ContentType.class)) {
        try {/*from ww  w . ja v a2  s . c  o m*/
            parseContentType((TypeElement) element, models);
        } catch (Exception e) {
            parsingError(element, ContentType.class, e);
        }
    }

    // Parse Space bindings
    for (Element element : env.getElementsAnnotatedWith(Space.class)) {
        try {
            parseSpace((TypeElement) element, spaces, models);
        } catch (Exception e) {
            parsingError(element, Space.class, e);
        }
    }

    // Prepare FieldsInjection targets
    for (ModelInjection modelInjection : models.values()) {
        fields.put(modelInjection.originatingElement, createFieldsInjection(modelInjection));
    }

    Set<Injection> result = new LinkedHashSet<>();
    result.addAll(models.values());
    result.addAll(fields.values());
    result.addAll(spaces.values());
    return result;
}

From source file:ch.rasc.constgen.ConstAnnotationProcessor.java

@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {

    this.processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE,
            "Running " + getClass().getSimpleName());

    if (roundEnv.processingOver() || annotations.size() == 0) {
        return ALLOW_OTHER_PROCESSORS_TO_CLAIM_ANNOTATIONS;
    }//from w w  w. j  a  v  a  2  s  .  c  om

    if (roundEnv.getRootElements() == null || roundEnv.getRootElements().isEmpty()) {
        this.processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "No sources to process");
        return ALLOW_OTHER_PROCESSORS_TO_CLAIM_ANNOTATIONS;
    }

    for (TypeElement annotation : annotations) {
        Set<? extends Element> elements = roundEnv.getElementsAnnotatedWith(annotation);
        boolean bsoncodecProject = annotation.getQualifiedName()
                .contentEquals("ch.rasc.bsoncodec.annotation.BsonDocument");
        for (Element element : elements) {

            try {
                TypeElement typeElement = (TypeElement) element;

                CodeGenerator codeGen = new CodeGenerator(typeElement, this.processingEnv.getElementUtils(),
                        bsoncodecProject);

                JavaFileObject jfo = this.processingEnv.getFiler()
                        .createSourceFile(codeGen.getPackageName() + "." + codeGen.getClassName());
                try (Writer writer = jfo.openWriter()) {
                    codeGen.generate(writer);
                }

            } catch (Exception e) {
                this.processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, e.getMessage());
            }

        }
    }

    return ALLOW_OTHER_PROCESSORS_TO_CLAIM_ANNOTATIONS;
}

From source file:com.predic8.membrane.annot.SpringConfigurationXSDGeneratingAnnotationProcessor.java

private Set<? extends Element> getCachedElementsAnnotatedWith(RoundEnvironment roundEnv,
        Class<? extends Annotation> annotation) {
    //FileObject o = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "META-INF", "membrane.cache");
    if (cache == null)
        read();/*  w w w .jav a2 s .c  om*/

    HashSet<Element> result = cache.get(annotation);
    if (result == null) {
        // update cache
        cache.put(annotation, result = new HashSet<Element>(roundEnv.getElementsAnnotatedWith(annotation)));
    } else {
        for (Element e : roundEnv.getElementsAnnotatedWith(annotation)) {
            result.remove(e);
            result.add(e);
        }
    }

    return result;
}

From source file:com.thoratou.exact.processors.ExactProcessor.java

private void readAnnotations(RoundEnvironment roundEnv, HashMap<String, ArrayList<Item>> itemMap,
        HashMap<String, ArrayList<ExtensionItem>> extItemMap) throws Exception {
    //retrieve all classes with @ExactNode annotation
    for (TypeElement typeElement : ElementFilter.typesIn(roundEnv.getElementsAnnotatedWith(ExactNode.class))) {
        Name qualifiedName = typeElement.getQualifiedName();
        String className = qualifiedName.toString();
        logger.info("Exact class : " + className);
        classMap.put(className, typeElement);

        for (ExecutableElement methodElement : ElementFilter.methodsIn(typeElement.getEnclosedElements())) {
            {/*w  w  w .j  a v a  2s  .  c o  m*/
                ExactPath annotation = methodElement.getAnnotation(ExactPath.class);
                if (annotation != null) {
                    String methodName = methodElement.getSimpleName().toString();
                    String returnType = methodElement.getReturnType().toString();
                    String xPathString = annotation.value();

                    logger.info(
                            "Exact method : " + methodName + " , " + annotation.value() + " , " + returnType);

                    XPathParser parser = new XPathParser(xPathString);
                    XPathPathExpr xPathPathExpr = parser.parse();

                    logger.info("XPath value = " + xPathPathExpr.toString());

                    Item item = new Item();
                    item.setxPathPathExpr(xPathPathExpr);
                    item.setMethodName(methodName);
                    item.setReturnType(returnType);

                    if (itemMap.containsKey(className)) {
                        ArrayList<Item> items = itemMap.get(className);
                        items.add(item);
                    } else {
                        ArrayList<Item> items = new ArrayList<Item>();
                        items.add(item);
                        itemMap.put(className, items);
                    }

                    methodMap.put(new Pair<String, String>(className, methodName), methodElement);
                }
            }

            {
                ExactExtension annotation = methodElement.getAnnotation(ExactExtension.class);
                if (annotation != null) {
                    String methodName = methodElement.getSimpleName().toString();
                    String returnType = methodElement.getReturnType().toString();
                    String name = annotation.name();
                    String element = annotation.element();
                    String filter = annotation.filter();

                    logger.info("Exact extension : " + methodName + " , " + returnType + " , " + name + " , "
                            + element + " , " + filter);

                    XPathParser elementParser = new XPathParser(element);
                    XPathPathExpr elementXPathPathExpr = elementParser.parse();
                    logger.info("XPath element = " + elementXPathPathExpr.toString());

                    XPathParser filterParser = new XPathParser(filter);
                    XPathPathExpr filterXPathPathExpr = filterParser.parse();
                    logger.info("XPath filter = " + filterXPathPathExpr.toString());

                    ExtensionItem item = new ExtensionItem();
                    item.setName(name);
                    item.setElement(elementXPathPathExpr);
                    item.setFilter(filterXPathPathExpr);
                    item.setMethodName(methodName);
                    item.setReturnType(returnType);

                    if (extItemMap.containsKey(className)) {
                        ArrayList<ExtensionItem> items = extItemMap.get(className);
                        items.add(item);
                    } else {
                        ArrayList<ExtensionItem> items = new ArrayList<ExtensionItem>();
                        items.add(item);
                        extItemMap.put(className, items);
                    }
                }
            }
        }
    }
}

From source file:auto.parse.processor.AutoParseProcessor.java

private void process(RoundEnvironment roundEnv) {
    Collection<? extends Element> annotatedElements = roundEnv.getElementsAnnotatedWith(AutoParse.class);
    Collection<? extends TypeElement> types = ElementFilter.typesIn(annotatedElements);
    for (TypeElement type : types) {
        try {//from w  w  w  .j  a va2  s.c  o m
            processType(type);
        } catch (CompileException e) {
            // We abandoned this type, but continue with the next.
        } catch (RuntimeException e) {
            // Don't propagate this exception, which will confusingly crash the compiler.
            reportError("@AutoParse processor threw an exception: " + e, type);
        }
    }
}