當前位置: 首頁>>代碼示例>>Java>>正文


Java Element.getAnnotationsByType方法代碼示例

本文整理匯總了Java中javax.lang.model.element.Element.getAnnotationsByType方法的典型用法代碼示例。如果您正苦於以下問題:Java Element.getAnnotationsByType方法的具體用法?Java Element.getAnnotationsByType怎麽用?Java Element.getAnnotationsByType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.lang.model.element.Element的用法示例。


在下文中一共展示了Element.getAnnotationsByType方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: processBaseAnnotatins

import javax.lang.model.element.Element; //導入方法依賴的package包/類
private void processBaseAnnotatins(Element element) {
	Requires[] requires = element.getAnnotationsByType(Requires.class);
	for (Requires r : requires) {
		RequiresBuilder rb = new ContractBuilder.RequiresBuilder().from(r);
		requrements.add(processTemplate(element, rb.build()));
	}

	Provides[] provides = element.getAnnotationsByType(Provides.class);
	for (Provides p : provides) {
		ProvidesBuilder pb = new ContractBuilder.ProvidesBuilder().from(p);
		capabilities.add(processTemplate(element, pb.build()));

	}
}
 
開發者ID:commsen,項目名稱:EM,代碼行數:15,代碼來源:ContractsAnnotationProcessor.java

示例2: process

import javax.lang.model.element.Element; //導入方法依賴的package包/類
/**
 * 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;
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:45,代碼來源:PluginChecker.java

示例3: processMatchableNode

import javax.lang.model.element.Element; //導入方法依賴的package包/類
/**
 * 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);
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:31,代碼來源:MatchProcessor.java


注:本文中的javax.lang.model.element.Element.getAnnotationsByType方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。