javax.lang.model.element.Element#getAnnotationsByType ( )源码实例Demo

下面列出了javax.lang.model.element.Element#getAnnotationsByType ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: dragonwell8_jdk   文件: PluginChecker.java
/**
 * Processes @Require annotations and checks that Device meets requirements.
 *
 * {@inheritDoc}
 */
@Override
public boolean process(Set<? extends TypeElement> annotations,
        RoundEnvironment roundEnv) {
    for (Element el : roundEnv.getElementsAnnotatedWith(RequireContainer.class)) {
        for (Require req : el.getAnnotationsByType(Require.class)) {
            //for every Require annotation checks if device has module of required version.
            Integer version = device.getSupportedModules().get(req.value());

            if (version == null
                    || version < req.minVersion()
                    || version > req.maxVersion()) {
                //if module is optional then show only warning not error
                if (req.optional()) {
                    processingEnv.getMessager()
                            .printMessage(Diagnostic.Kind.WARNING,
                                    "Plugin [" + el + "] requires " + req
                                    + "\n but device " + (version == null
                                    ? "doesn't have such module."
                                    + " This module is optional."
                                    + " So plugin will work but miss"
                                    + " some functionality"
                                    : "has " + version
                                    + " version of that module"));
                } else {
                    processingEnv.getMessager()
                            .printMessage(Diagnostic.Kind.ERROR,
                                    "Plugin [" + el + "] requires " + req
                                    + "\n but device "
                                    + (version == null
                                    ? "doesn't have such module"
                                    : "has " + version
                                    + " version of that module"));
                }
            }
        }
        return true;
    }
    return false;
}
 
源代码2 项目: TencentKona-8   文件: PluginChecker.java
/**
 * Processes @Require annotations and checks that Device meets requirements.
 *
 * {@inheritDoc}
 */
@Override
public boolean process(Set<? extends TypeElement> annotations,
        RoundEnvironment roundEnv) {
    for (Element el : roundEnv.getElementsAnnotatedWith(RequireContainer.class)) {
        for (Require req : el.getAnnotationsByType(Require.class)) {
            //for every Require annotation checks if device has module of required version.
            Integer version = device.getSupportedModules().get(req.value());

            if (version == null
                    || version < req.minVersion()
                    || version > req.maxVersion()) {
                //if module is optional then show only warning not error
                if (req.optional()) {
                    processingEnv.getMessager()
                            .printMessage(Diagnostic.Kind.WARNING,
                                    "Plugin [" + el + "] requires " + req
                                    + "\n but device " + (version == null
                                    ? "doesn't have such module."
                                    + " This module is optional."
                                    + " So plugin will work but miss"
                                    + " some functionality"
                                    : "has " + version
                                    + " version of that module"));
                } else {
                    processingEnv.getMessager()
                            .printMessage(Diagnostic.Kind.ERROR,
                                    "Plugin [" + el + "] requires " + req
                                    + "\n but device "
                                    + (version == null
                                    ? "doesn't have such module"
                                    : "has " + version
                                    + " version of that module"));
                }
            }
        }
        return true;
    }
    return false;
}
 
源代码3 项目: jdk8u60   文件: PluginChecker.java
/**
 * Processes @Require annotations and checks that Device meets requirements.
 *
 * {@inheritDoc}
 */
@Override
public boolean process(Set<? extends TypeElement> annotations,
        RoundEnvironment roundEnv) {
    for (Element el : roundEnv.getElementsAnnotatedWith(RequireContainer.class)) {
        for (Require req : el.getAnnotationsByType(Require.class)) {
            //for every Require annotation checks if device has module of required version.
            Integer version = device.getSupportedModules().get(req.value());

            if (version == null
                    || version < req.minVersion()
                    || version > req.maxVersion()) {
                //if module is optional then show only warning not error
                if (req.optional()) {
                    processingEnv.getMessager()
                            .printMessage(Diagnostic.Kind.WARNING,
                                    "Plugin [" + el + "] requires " + req
                                    + "\n but device " + (version == null
                                    ? "doesn't have such module."
                                    + " This module is optional."
                                    + " So plugin will work but miss"
                                    + " some functionality"
                                    : "has " + version
                                    + " version of that module"));
                } else {
                    processingEnv.getMessager()
                            .printMessage(Diagnostic.Kind.ERROR,
                                    "Plugin [" + el + "] requires " + req
                                    + "\n but device "
                                    + (version == null
                                    ? "doesn't have such module"
                                    : "has " + version
                                    + " version of that module"));
                }
            }
        }
        return true;
    }
    return false;
}
 
源代码4 项目: openjdk-jdk8u   文件: PluginChecker.java
/**
 * Processes @Require annotations and checks that Device meets requirements.
 *
 * {@inheritDoc}
 */
@Override
public boolean process(Set<? extends TypeElement> annotations,
        RoundEnvironment roundEnv) {
    for (Element el : roundEnv.getElementsAnnotatedWith(RequireContainer.class)) {
        for (Require req : el.getAnnotationsByType(Require.class)) {
            //for every Require annotation checks if device has module of required version.
            Integer version = device.getSupportedModules().get(req.value());

            if (version == null
                    || version < req.minVersion()
                    || version > req.maxVersion()) {
                //if module is optional then show only warning not error
                if (req.optional()) {
                    processingEnv.getMessager()
                            .printMessage(Diagnostic.Kind.WARNING,
                                    "Plugin [" + el + "] requires " + req
                                    + "\n but device " + (version == null
                                    ? "doesn't have such module."
                                    + " This module is optional."
                                    + " So plugin will work but miss"
                                    + " some functionality"
                                    : "has " + version
                                    + " version of that module"));
                } else {
                    processingEnv.getMessager()
                            .printMessage(Diagnostic.Kind.ERROR,
                                    "Plugin [" + el + "] requires " + req
                                    + "\n but device "
                                    + (version == null
                                    ? "doesn't have such module"
                                    : "has " + version
                                    + " version of that module"));
                }
            }
        }
        return true;
    }
    return false;
}
 
源代码5 项目: openjdk-jdk8u-backup   文件: PluginChecker.java
/**
 * Processes @Require annotations and checks that Device meets requirements.
 *
 * {@inheritDoc}
 */
@Override
public boolean process(Set<? extends TypeElement> annotations,
        RoundEnvironment roundEnv) {
    for (Element el : roundEnv.getElementsAnnotatedWith(RequireContainer.class)) {
        for (Require req : el.getAnnotationsByType(Require.class)) {
            //for every Require annotation checks if device has module of required version.
            Integer version = device.getSupportedModules().get(req.value());

            if (version == null
                    || version < req.minVersion()
                    || version > req.maxVersion()) {
                //if module is optional then show only warning not error
                if (req.optional()) {
                    processingEnv.getMessager()
                            .printMessage(Diagnostic.Kind.WARNING,
                                    "Plugin [" + el + "] requires " + req
                                    + "\n but device " + (version == null
                                    ? "doesn't have such module."
                                    + " This module is optional."
                                    + " So plugin will work but miss"
                                    + " some functionality"
                                    : "has " + version
                                    + " version of that module"));
                } else {
                    processingEnv.getMessager()
                            .printMessage(Diagnostic.Kind.ERROR,
                                    "Plugin [" + el + "] requires " + req
                                    + "\n but device "
                                    + (version == null
                                    ? "doesn't have such module"
                                    : "has " + version
                                    + " version of that module"));
                }
            }
        }
        return true;
    }
    return false;
}
 
源代码6 项目: openjdk-jdk9   文件: MatchProcessor.java
/**
 * Build up the type table to be used during parsing of the MatchRule.
 */
private void processMatchableNode(Element element) {
    if (!processedMatchableNode.contains(element)) {
        try {
            processedMatchableNode.add(element);

            AnnotationMirror mirror = findAnnotationMirror(element, matchableNodesTypeMirror);
            if (mirror == null) {
                mirror = findAnnotationMirror(element, matchableNodeTypeMirror);
            }
            if (mirror == null) {
                return;
            }
            TypeElement topDeclaringType = topDeclaringType(element);
            List<AnnotationMirror> mirrors = null;
            if (typeUtils().isSameType(mirror.getAnnotationType(), matchableNodesTypeMirror)) {
                // Unpack the mirrors for a repeatable annotation
                mirrors = getAnnotationValueList(AnnotationMirror.class, mirror, "value");
            }
            int i = 0;
            for (MatchableNode matchableNode : element.getAnnotationsByType(MatchableNode.class)) {
                processMatchableNode(element, topDeclaringType, matchableNode, mirrors != null ? mirrors.get(i++) : mirror);
            }
        } catch (Throwable t) {
            reportExceptionThrow(element, t);
        }
    }
}
 
源代码7 项目: jdk8u-jdk   文件: PluginChecker.java
/**
 * Processes @Require annotations and checks that Device meets requirements.
 *
 * {@inheritDoc}
 */
@Override
public boolean process(Set<? extends TypeElement> annotations,
        RoundEnvironment roundEnv) {
    for (Element el : roundEnv.getElementsAnnotatedWith(RequireContainer.class)) {
        for (Require req : el.getAnnotationsByType(Require.class)) {
            //for every Require annotation checks if device has module of required version.
            Integer version = device.getSupportedModules().get(req.value());

            if (version == null
                    || version < req.minVersion()
                    || version > req.maxVersion()) {
                //if module is optional then show only warning not error
                if (req.optional()) {
                    processingEnv.getMessager()
                            .printMessage(Diagnostic.Kind.WARNING,
                                    "Plugin [" + el + "] requires " + req
                                    + "\n but device " + (version == null
                                    ? "doesn't have such module."
                                    + " This module is optional."
                                    + " So plugin will work but miss"
                                    + " some functionality"
                                    : "has " + version
                                    + " version of that module"));
                } else {
                    processingEnv.getMessager()
                            .printMessage(Diagnostic.Kind.ERROR,
                                    "Plugin [" + el + "] requires " + req
                                    + "\n but device "
                                    + (version == null
                                    ? "doesn't have such module"
                                    : "has " + version
                                    + " version of that module"));
                }
            }
        }
        return true;
    }
    return false;
}
 
源代码8 项目: hottub   文件: PluginChecker.java
/**
 * Processes @Require annotations and checks that Device meets requirements.
 *
 * {@inheritDoc}
 */
@Override
public boolean process(Set<? extends TypeElement> annotations,
        RoundEnvironment roundEnv) {
    for (Element el : roundEnv.getElementsAnnotatedWith(RequireContainer.class)) {
        for (Require req : el.getAnnotationsByType(Require.class)) {
            //for every Require annotation checks if device has module of required version.
            Integer version = device.getSupportedModules().get(req.value());

            if (version == null
                    || version < req.minVersion()
                    || version > req.maxVersion()) {
                //if module is optional then show only warning not error
                if (req.optional()) {
                    processingEnv.getMessager()
                            .printMessage(Diagnostic.Kind.WARNING,
                                    "Plugin [" + el + "] requires " + req
                                    + "\n but device " + (version == null
                                    ? "doesn't have such module."
                                    + " This module is optional."
                                    + " So plugin will work but miss"
                                    + " some functionality"
                                    : "has " + version
                                    + " version of that module"));
                } else {
                    processingEnv.getMessager()
                            .printMessage(Diagnostic.Kind.ERROR,
                                    "Plugin [" + el + "] requires " + req
                                    + "\n but device "
                                    + (version == null
                                    ? "doesn't have such module"
                                    : "has " + version
                                    + " version of that module"));
                }
            }
        }
        return true;
    }
    return false;
}
 
源代码9 项目: openjdk-8-source   文件: PluginChecker.java
/**
 * Processes @Require annotations and checks that Device meets requirements.
 *
 * {@inheritDoc}
 */
@Override
public boolean process(Set<? extends TypeElement> annotations,
        RoundEnvironment roundEnv) {
    for (Element el : roundEnv.getElementsAnnotatedWith(RequireContainer.class)) {
        for (Require req : el.getAnnotationsByType(Require.class)) {
            //for every Require annotation checks if device has module of required version.
            Integer version = device.getSupportedModules().get(req.value());

            if (version == null
                    || version < req.minVersion()
                    || version > req.maxVersion()) {
                //if module is optional then show only warning not error
                if (req.optional()) {
                    processingEnv.getMessager()
                            .printMessage(Diagnostic.Kind.WARNING,
                                    "Plugin [" + el + "] requires " + req
                                    + "\n but device " + (version == null
                                    ? "doesn't have such module."
                                    + " This module is optional."
                                    + " So plugin will work but miss"
                                    + " some functionality"
                                    : "has " + version
                                    + " version of that module"));
                } else {
                    processingEnv.getMessager()
                            .printMessage(Diagnostic.Kind.ERROR,
                                    "Plugin [" + el + "] requires " + req
                                    + "\n but device "
                                    + (version == null
                                    ? "doesn't have such module"
                                    : "has " + version
                                    + " version of that module"));
                }
            }
        }
        return true;
    }
    return false;
}
 
源代码10 项目: openjdk-8   文件: PluginChecker.java
/**
 * Processes @Require annotations and checks that Device meets requirements.
 *
 * {@inheritDoc}
 */
@Override
public boolean process(Set<? extends TypeElement> annotations,
        RoundEnvironment roundEnv) {
    for (Element el : roundEnv.getElementsAnnotatedWith(RequireContainer.class)) {
        for (Require req : el.getAnnotationsByType(Require.class)) {
            //for every Require annotation checks if device has module of required version.
            Integer version = device.getSupportedModules().get(req.value());

            if (version == null
                    || version < req.minVersion()
                    || version > req.maxVersion()) {
                //if module is optional then show only warning not error
                if (req.optional()) {
                    processingEnv.getMessager()
                            .printMessage(Diagnostic.Kind.WARNING,
                                    "Plugin [" + el + "] requires " + req
                                    + "\n but device " + (version == null
                                    ? "doesn't have such module."
                                    + " This module is optional."
                                    + " So plugin will work but miss"
                                    + " some functionality"
                                    : "has " + version
                                    + " version of that module"));
                } else {
                    processingEnv.getMessager()
                            .printMessage(Diagnostic.Kind.ERROR,
                                    "Plugin [" + el + "] requires " + req
                                    + "\n but device "
                                    + (version == null
                                    ? "doesn't have such module"
                                    : "has " + version
                                    + " version of that module"));
                }
            }
        }
        return true;
    }
    return false;
}
 
源代码11 项目: jdk8u_jdk   文件: PluginChecker.java
/**
 * Processes @Require annotations and checks that Device meets requirements.
 *
 * {@inheritDoc}
 */
@Override
public boolean process(Set<? extends TypeElement> annotations,
        RoundEnvironment roundEnv) {
    for (Element el : roundEnv.getElementsAnnotatedWith(RequireContainer.class)) {
        for (Require req : el.getAnnotationsByType(Require.class)) {
            //for every Require annotation checks if device has module of required version.
            Integer version = device.getSupportedModules().get(req.value());

            if (version == null
                    || version < req.minVersion()
                    || version > req.maxVersion()) {
                //if module is optional then show only warning not error
                if (req.optional()) {
                    processingEnv.getMessager()
                            .printMessage(Diagnostic.Kind.WARNING,
                                    "Plugin [" + el + "] requires " + req
                                    + "\n but device " + (version == null
                                    ? "doesn't have such module."
                                    + " This module is optional."
                                    + " So plugin will work but miss"
                                    + " some functionality"
                                    : "has " + version
                                    + " version of that module"));
                } else {
                    processingEnv.getMessager()
                            .printMessage(Diagnostic.Kind.ERROR,
                                    "Plugin [" + el + "] requires " + req
                                    + "\n but device "
                                    + (version == null
                                    ? "doesn't have such module"
                                    : "has " + version
                                    + " version of that module"));
                }
            }
        }
        return true;
    }
    return false;
}
 
源代码12 项目: jdk8u-jdk   文件: PluginChecker.java
/**
 * Processes @Require annotations and checks that Device meets requirements.
 *
 * {@inheritDoc}
 */
@Override
public boolean process(Set<? extends TypeElement> annotations,
        RoundEnvironment roundEnv) {
    for (Element el : roundEnv.getElementsAnnotatedWith(RequireContainer.class)) {
        for (Require req : el.getAnnotationsByType(Require.class)) {
            //for every Require annotation checks if device has module of required version.
            Integer version = device.getSupportedModules().get(req.value());

            if (version == null
                    || version < req.minVersion()
                    || version > req.maxVersion()) {
                //if module is optional then show only warning not error
                if (req.optional()) {
                    processingEnv.getMessager()
                            .printMessage(Diagnostic.Kind.WARNING,
                                    "Plugin [" + el + "] requires " + req
                                    + "\n but device " + (version == null
                                    ? "doesn't have such module."
                                    + " This module is optional."
                                    + " So plugin will work but miss"
                                    + " some functionality"
                                    : "has " + version
                                    + " version of that module"));
                } else {
                    processingEnv.getMessager()
                            .printMessage(Diagnostic.Kind.ERROR,
                                    "Plugin [" + el + "] requires " + req
                                    + "\n but device "
                                    + (version == null
                                    ? "doesn't have such module"
                                    : "has " + version
                                    + " version of that module"));
                }
            }
        }
        return true;
    }
    return false;
}
 
源代码13 项目: jdk8u-dev-jdk   文件: PluginChecker.java
/**
 * Processes @Require annotations and checks that Device meets requirements.
 *
 * {@inheritDoc}
 */
@Override
public boolean process(Set<? extends TypeElement> annotations,
        RoundEnvironment roundEnv) {
    for (Element el : roundEnv.getElementsAnnotatedWith(RequireContainer.class)) {
        for (Require req : el.getAnnotationsByType(Require.class)) {
            //for every Require annotation checks if device has module of required version.
            Integer version = device.getSupportedModules().get(req.value());

            if (version == null
                    || version < req.minVersion()
                    || version > req.maxVersion()) {
                //if module is optional then show only warning not error
                if (req.optional()) {
                    processingEnv.getMessager()
                            .printMessage(Diagnostic.Kind.WARNING,
                                    "Plugin [" + el + "] requires " + req
                                    + "\n but device " + (version == null
                                    ? "doesn't have such module."
                                    + " This module is optional."
                                    + " So plugin will work but miss"
                                    + " some functionality"
                                    : "has " + version
                                    + " version of that module"));
                } else {
                    processingEnv.getMessager()
                            .printMessage(Diagnostic.Kind.ERROR,
                                    "Plugin [" + el + "] requires " + req
                                    + "\n but device "
                                    + (version == null
                                    ? "doesn't have such module"
                                    : "has " + version
                                    + " version of that module"));
                }
            }
        }
        return true;
    }
    return false;
}
 
源代码14 项目: syndesis   文件: ActionProcessor.java
/**
 * Add action properties to the global properties.
 */
private void addActionProperties(ObjectNode root, Element element) throws InvocationTargetException, IllegalAccessException {

    Annotation[] annotations = element.getAnnotationsByType(propertyAnnotationClass);
    for (int i = 0; i < annotations.length; i++) {
        Annotation annotation = annotations[i];
        ObjectNode propertyNode = mapper.createObjectNode();

        gatherProperties(propertyNode, annotation);

        if (element.getKind() == ElementKind.FIELD) {
            VariableElement field = (VariableElement)element;

            TypeMirror typeMirror = field.asType();
            TypeElement typeElement = processingEnv.getElementUtils().getTypeElement(typeMirror.toString());
            String javaType = typeMirror.toString();
            String type = propertyNode.get("type").asText();

            final boolean doesntHaveEnums = !propertyNode.has("enums");
            final boolean typeIsEnum = typeElement != null && typeElement.getKind() == ElementKind.ENUM;
            if (doesntHaveEnums && typeIsEnum) {
                // don't auto detect enum if enums are set through
                // annotations
                for (Element enumElement : typeElement.getEnclosedElements()) {
                    if (enumElement.getKind() == ElementKind.ENUM_CONSTANT) {
                        ObjectNode enumNode = mapper.createObjectNode();

                        writeIfNotEmpty(enumNode, "label", enumElement.toString());
                        writeIfNotEmpty(enumNode, "value", enumElement.toString());

                        propertyNode.withArray("enums").add(enumNode);
                    }
                }

                javaType = String.class.getName();
                type = String.class.getName();
            }

            if (type == null || "".equals(type.trim())){
                if (String.class.getName().equals(type)) {
                    type = "string";
                } else if (Boolean.class.getName().equals(type)) {
                    type = "boolean";
                } else if (Integer.class.getName().equals(type)) {
                    type = "int";
                } else if (Float.class.getName().equals(type)) {
                    type = "float";
                } else if (Double.class.getName().equals(type)) {
                    type = "double";
                }
            }

            writeIfNotEmpty(propertyNode, "javaType", javaType);
            writeIfNotEmpty(propertyNode, "type", type);
        }

        root.withArray("properties").add(propertyNode);
    }
}
 
源代码15 项目: Chimera   文件: Resolver.java
@Override
public <A extends Annotation> A[] all(Element element, Class<A> annotation) {
    return element.getAnnotationsByType(annotation);
}