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