java.lang.Class.getDeclaredAnnotations()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(7.3k)|赞(0)|评价(0)|浏览(186)

本文整理了Java中java.lang.Class.getDeclaredAnnotations()方法的一些代码示例,展示了Class.getDeclaredAnnotations()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Class.getDeclaredAnnotations()方法的具体详情如下:
包路径:java.lang.Class
类名称:Class
方法名:getDeclaredAnnotations

Class.getDeclaredAnnotations介绍

[英]Returns the annotations that are directly defined on the class represented by this Class. Annotations that are inherited are not included in the result. If there are no annotations at all, an empty array is returned.
[中]返回在此类表示的类上直接定义的注释。继承的注释不包括在结果中。如果根本没有注释,则返回一个空数组。

代码示例

代码示例来源:origin: spring-projects/spring-loaded

public static Annotation[] callGetDeclaredAnnotations(Class thiz)
{
  return thiz.getDeclaredAnnotations();
}

代码示例来源:origin: alibaba/jvm-sandbox

@Override
  protected List<ClassStructure> initialValue() {
    return Collections.unmodifiableList(newInstances(getAnnotationTypeArray(clazz.getDeclaredAnnotations())));
  }
};

代码示例来源:origin: spring-projects/spring-loaded

public List<Annotation> callClassGetDeclaredAnnotations(Class<?> c) {
  return Arrays.asList(c.getDeclaredAnnotations());
}
public boolean callClassIsAnnotationPresent(Class<?> c, Class<? extends Annotation> annotClass) {

代码示例来源:origin: libgdx/libgdx

/** Returns an array of {@link Annotation} objects reflecting all annotations declared by the supplied class, or an empty
 * array if there are none. Does not include inherited annotations. */
static public Annotation[] getDeclaredAnnotations (Class c) {
  java.lang.annotation.Annotation[] annotations = c.getDeclaredAnnotations();
  Annotation[] result = new Annotation[annotations.length];
  for (int i = 0; i < annotations.length; i++) {
    result[i] = new Annotation(annotations[i]);
  }
  return result;
}

代码示例来源:origin: apache/incubator-gobblin

private static boolean isConfigStoreWithStableVersion(ConfigStore cs) {
 for (Annotation annotation : cs.getClass().getDeclaredAnnotations()) {
  if (annotation instanceof ConfigStoreWithStableVersioning) {
   return true;
  }
 }
 return false;
}

代码示例来源:origin: libgdx/libgdx

/** Returns an {@link Annotation} object reflecting the annotation provided, or null if this class doesn't have such an
 * annotation. This is a convenience function if the caller knows already which annotation type he's looking for. */
static public Annotation getDeclaredAnnotation (Class c, Class<? extends java.lang.annotation.Annotation> annotationType) {
  java.lang.annotation.Annotation[] annotations = c.getDeclaredAnnotations();
  for (java.lang.annotation.Annotation annotation : annotations) {
    if (annotation.annotationType().equals(annotationType)) return new Annotation(annotation);
  }
  return null;
}

代码示例来源:origin: libgdx/libgdx

/** Returns an array of {@link Annotation} objects reflecting all annotations declared by the supplied class, or an empty
 * array if there are none. Does not include inherited annotations. */
static public Annotation[] getDeclaredAnnotations (Class c) {
  java.lang.annotation.Annotation[] annotations = c.getDeclaredAnnotations();
  Annotation[] result = new Annotation[annotations.length];
  for (int i = 0; i < annotations.length; i++) {
    result[i] = new Annotation(annotations[i]);
  }
  return result;
}

代码示例来源:origin: libgdx/libgdx

/** Returns an {@link Annotation} object reflecting the annotation provided, or null if this class doesn't have such an
 * annotation. This is a convenience function if the caller knows already which annotation type he's looking for. */
static public Annotation getDeclaredAnnotation (Class c, Class<? extends java.lang.annotation.Annotation> annotationType) {
  java.lang.annotation.Annotation[] annotations = c.getDeclaredAnnotations();
  for (java.lang.annotation.Annotation annotation : annotations) {
    if (annotation.annotationType().equals(annotationType)) return new Annotation(annotation);
  }
  return null;
}

代码示例来源:origin: prestodb/presto

/**
 * @since 2.7
 */
public static Annotation[] findClassAnnotations(Class<?> cls) {
  if (isObjectOrPrimitive(cls)) {
    return NO_ANNOTATIONS;
  }
  return cls.getDeclaredAnnotations();
}

代码示例来源:origin: redisson/redisson

/**
 * @since 2.7
 */
public static Annotation[] findClassAnnotations(Class<?> cls) {
  if (isObjectOrPrimitive(cls)) {
    return NO_ANNOTATIONS;
  }
  return cls.getDeclaredAnnotations();
}

代码示例来源:origin: springside/springside4

private static <A extends Annotation> void getSuperAnnotations(Class<A> annotationType, Set<Annotation> visited) {
  Annotation[] anns = annotationType.getDeclaredAnnotations();
  for (Annotation ann : anns) {
    if (!ann.annotationType().getName().startsWith("java.lang") && visited.add(ann)) {
      getSuperAnnotations(ann.annotationType(), visited);
    }
  }
}

代码示例来源:origin: PipelineAI/pipeline

public static <T extends Annotation> Optional<T> getAnnotation(Class<?> type, Class<T> annotation) {
  Validate.notNull(annotation, "annotation cannot be null");
  Validate.notNull(type, "type cannot be null");
  for (Annotation ann : type.getDeclaredAnnotations()) {
    if (ann.annotationType().equals(annotation)) return Optional.of((T) ann);
  }
  Class<?> superType = type.getSuperclass();
  if (superType != null && !superType.equals(Object.class)) {
    return getAnnotation(superType, annotation);
  }
  return Optional.absent();
}

代码示例来源:origin: ronmamo/reflections

public List<String> getClassAnnotationNames(Class aClass) {
  return getAnnotationNames(aClass.getDeclaredAnnotations());
}

代码示例来源:origin: apache/drill

/**
 * @since 2.7
 */
public static Annotation[] findClassAnnotations(Class<?> cls) {
  if (isObjectOrPrimitive(cls)) {
    return NO_ANNOTATIONS;
  }
  return cls.getDeclaredAnnotations();
}

代码示例来源:origin: redisson/redisson

/**
 * {@inheritDoc}
 */
@CachedReturnPlugin.Enhance("declaredAnnotations")
public AnnotationList getDeclaredAnnotations() {
  return new AnnotationList.ForLoadedAnnotations(type.getDeclaredAnnotations());
}

代码示例来源:origin: spring-projects/spring-framework

for (Annotation composedAnn : clazz.getDeclaredAnnotations()) {
  Class<? extends Annotation> composedType = composedAnn.annotationType();
  if (!AnnotationUtils.isInJavaLangAnnotationPackage(composedType.getName()) && visited.add(composedAnn)) {

代码示例来源:origin: spring-projects/spring-framework

for (Annotation composedAnnotation : clazz.getDeclaredAnnotations()) {
  if (!AnnotationUtils.isInJavaLangAnnotationPackage(composedAnnotation) && visited.add(composedAnnotation)) {
    UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes(

代码示例来源:origin: spring-projects/spring-framework

@Test
public void getValueFromNonPublicAnnotation() throws Exception {
  Annotation[] declaredAnnotations = NonPublicAnnotatedClass.class.getDeclaredAnnotations();
  assertEquals(1, declaredAnnotations.length);
  Annotation annotation = declaredAnnotations[0];
  assertNotNull(annotation);
  assertEquals("NonPublicAnnotation", annotation.annotationType().getSimpleName());
  assertEquals(42, getValue(annotation, VALUE));
  assertEquals(42, getValue(annotation));
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void getDefaultValueFromNonPublicAnnotation() {
  Annotation[] declaredAnnotations = NonPublicAnnotatedClass.class.getDeclaredAnnotations();
  assertEquals(1, declaredAnnotations.length);
  Annotation annotation = declaredAnnotations[0];
  assertNotNull(annotation);
  assertEquals("NonPublicAnnotation", annotation.annotationType().getSimpleName());
  assertEquals(-1, getDefaultValue(annotation, VALUE));
  assertEquals(-1, getDefaultValue(annotation));
}

代码示例来源:origin: jersey/jersey

@Override
public Result process(final EntityProcessorContext context) {
  switch (context.getType()) {
    case CLASS_READER:
    case CLASS_WRITER:
      addGlobalScopes(EntityFilteringHelper.getFilteringScopes(context.getEntityClass().getDeclaredAnnotations()),
          context.getEntityGraph());
      break;
    default:
      // NOOP.
      break;
  }
  return super.process(context);
}

相关文章

Class类方法