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


Java AnnotatedElement.getDeclaredAnnotations方法代碼示例

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


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

示例1: getTesterAnnotations

import java.lang.reflect.AnnotatedElement; //導入方法依賴的package包/類
/**
 * Find all the tester annotations declared on a tester class or method.
 * @param classOrMethod a class or method whose tester annotations to find
 * @return an iterable sequence of tester annotations on the class
 */
public static Iterable<Annotation> getTesterAnnotations(AnnotatedElement classOrMethod) {
  synchronized (annotationCache) {
    List<Annotation> annotations = annotationCache.get(classOrMethod);
    if (annotations == null) {
      annotations = new ArrayList<Annotation>();
      for (Annotation a : classOrMethod.getDeclaredAnnotations()) {
        if (a.annotationType().isAnnotationPresent(TesterAnnotation.class)) {
          annotations.add(a);
        }
      }
      annotations = Collections.unmodifiableList(annotations);
      annotationCache.put(classOrMethod, annotations);
    }
    return annotations;
  }
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:22,代碼來源:FeatureUtil.java

示例2: findAnnotation

import java.lang.reflect.AnnotatedElement; //導入方法依賴的package包/類
/**
 * The default implementation performs a simple search for a declared annotation matching the search type.
 * Spring provides a more sophisticated annotation search utility that matches on meta-annotations as well.
 *
 * @param annotatedElement The element to search.
 * @param annotationType The annotation type class.
 * @param <A> Annotation type to search for.
 * @return
 */
@SuppressWarnings("unchecked")
default <A extends Annotation> A findAnnotation(AnnotatedElement annotatedElement, Class<A> annotationType) {
    Annotation[] anns = annotatedElement.getDeclaredAnnotations();
    for (Annotation ann : anns) {
        if (ann.annotationType() == annotationType) {
            return (A) ann;
        }
    }
    return null;
}
 
開發者ID:micrometer-metrics,項目名稱:micrometer,代碼行數:20,代碼來源:AnnotationFinder.java


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