本文整理汇总了Java中java.lang.reflect.AnnotatedElement.getAnnotations方法的典型用法代码示例。如果您正苦于以下问题:Java AnnotatedElement.getAnnotations方法的具体用法?Java AnnotatedElement.getAnnotations怎么用?Java AnnotatedElement.getAnnotations使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.lang.reflect.AnnotatedElement
的用法示例。
在下文中一共展示了AnnotatedElement.getAnnotations方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getMethodAnnotations
import java.lang.reflect.AnnotatedElement; //导入方法依赖的package包/类
private <T extends Annotation> List<T> getMethodAnnotations(AnnotatedElement ae,
Class<T> annotationType) {
List<T> anns = new ArrayList<T>(2);
// look for raw annotation
T ann = ae.getAnnotation(annotationType);
if (ann != null) {
anns.add(ann);
}
// look for meta-annotations
for (Annotation metaAnn : ae.getAnnotations()) {
ann = metaAnn.annotationType().getAnnotation(annotationType);
if (ann != null) {
anns.add(ann);
}
}
return (anns.isEmpty() ? null : anns);
}
示例2: getAnnotations
import java.lang.reflect.AnnotatedElement; //导入方法依赖的package包/类
private <T extends Annotation> Collection<T> getAnnotations(AnnotatedElement ae, Class<T> annotationType) {
Collection<T> anns = new ArrayList<T>(2);
// look at raw annotation
T ann = ae.getAnnotation(annotationType);
if (ann != null) {
anns.add(ann);
}
// scan meta-annotations
for (Annotation metaAnn : ae.getAnnotations()) {
ann = metaAnn.annotationType().getAnnotation(annotationType);
if (ann != null) {
anns.add(ann);
}
}
return (anns.isEmpty() ? null : anns);
}
示例3: findAnnotations
import java.lang.reflect.AnnotatedElement; //导入方法依赖的package包/类
/**
* Find the annotations of given <code>annotationType</code> on given element and stores them in given
* <code>accumulator</code>.
* @param accumulator Accumulator
* @param element Annotated element
* @param annotationType Annotation type to lookup
* @param repeatableContainerType Optional repeteable annotation type
*/
private static <A extends Annotation> void findAnnotations(List<A> accumulator, AnnotatedElement element,
Class<A> annotationType, Class<? extends Annotation> repeatableContainerType) {
// direct lookup
A[] as = element.getAnnotationsByType(annotationType);
if (as.length > 0) {
for (A a : as) {
accumulator.add(a);
}
}
// check meta-annotations
Annotation[] all = element.getAnnotations();
if (all.length > 0) {
for (Annotation annotation : all) {
if (!isInJavaLangAnnotationPackage(annotation) && !annotation.annotationType().equals(annotationType)
&& (repeatableContainerType == null
|| !annotation.annotationType().equals(repeatableContainerType))) {
findAnnotations(accumulator, annotation.annotationType(), annotationType, repeatableContainerType);
}
}
}
}
示例4: Annotations
import java.lang.reflect.AnnotatedElement; //导入方法依赖的package包/类
public Annotations(AnnotatedElement... elements) {
for (AnnotatedElement element : elements) {
for (Annotation annotation : element.getAnnotations()) {
annotations.put(annotation.annotationType(), annotation);
}
}
}
示例5: AnnotatedElementAdapter
import java.lang.reflect.AnnotatedElement; //导入方法依赖的package包/类
public AnnotatedElementAdapter(AnnotatedElement... elements) {
for (AnnotatedElement element : elements) {
for (Annotation annotation : element.getAnnotations()) {
annotations.put(annotation.annotationType(), annotation);
}
}
}
示例6: checkAnnotations
import java.lang.reflect.AnnotatedElement; //导入方法依赖的package包/类
private static void checkAnnotations(AnnotatedElement el, AnnotatableWrapper aw) throws Exception {
for (Annotation ann : el.getAnnotations()) {
Annotation wrapper = aw.getAnnotation(ann.annotationType());
assertNotNull(ann.annotationType().getName(), wrapper);
checkAnnotation(ann, wrapper);
}
}
示例7: isAction
import java.lang.reflect.AnnotatedElement; //导入方法依赖的package包/类
public static boolean isAction(AnnotatedElement element) {
if (element.getAnnotation(Action.class) != null) {
return true;
}
for (Annotation anno : element.getAnnotations()) {
if (AnnotationUtil.isActionAnnotation(anno)) {
return true;
}
}
return false;
}
示例8: getBindingAnnotations
import java.lang.reflect.AnnotatedElement; //导入方法依赖的package包/类
private static List<Annotation> getBindingAnnotations(AnnotatedElement element) {
List<Annotation> annotations = new ArrayList<>();
for (Annotation annotation : element.getAnnotations()) {
if (isBindingAnnotation(annotation)) {
annotations.add(annotation);
}
}
return annotations;
}
示例9: descriptorForElement
import java.lang.reflect.AnnotatedElement; //导入方法依赖的package包/类
public static Descriptor descriptorForElement(final AnnotatedElement elmt) {
if (elmt == null)
return ImmutableDescriptor.EMPTY_DESCRIPTOR;
final Annotation[] annots = elmt.getAnnotations();
return descriptorForAnnotations(annots);
}