本文整理匯總了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()));
}
}
示例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;
}
示例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);
}
}
}