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

x33g5p2x  于2022-01-17 转载在 其他  
字(8.0k)|赞(0)|评价(0)|浏览(172)

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

Field.getDeclaredAnnotations介绍

暂无

代码示例

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

public Annotation[] getDeclaredAnnotations() {
  return (Annotation[]) f_annotated.getDeclaredAnnotations();
}

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

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

代码示例来源:origin: org.springframework.boot/spring-boot

public Annotation[] getAnnotations() {
  try {
    return (this.field != null) ? this.field.getDeclaredAnnotations() : null;
  }
  catch (Exception ex) {
    return null;
  }
}

代码示例来源:origin: kiegroup/optaplanner

@Override
public Annotation[] getDeclaredAnnotations() {
  return field.getDeclaredAnnotations();
}

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

/** Returns an array of {@link Annotation} objects reflecting all annotations declared by this field,
 * or an empty array if there are none. Does not include inherited annotations. */
public Annotation[] getDeclaredAnnotations () {
  java.lang.annotation.Annotation[] annotations = field.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 array of {@link Annotation} objects reflecting all annotations declared by this field,
 * or an empty array if there are none. Does not include inherited annotations. */
public Annotation[] getDeclaredAnnotations () {
  java.lang.annotation.Annotation[] annotations = field.getDeclaredAnnotations();
  Annotation[] result = new Annotation[annotations.length];
  for (int i = 0; i < annotations.length; i++) {
    result[i] = new Annotation(annotations[i]);
  }
  return result;
}

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

public List<Annotation> callFieldGetDeclaredAnnotations(Field m) {
  return Arrays.asList(m.getDeclaredAnnotations());
}
public boolean callFieldIsAnnotationPresent(Field m, Class<? extends Annotation> annotClass) {

代码示例来源:origin: stackoverflow.com

for(Field field : cls.getDeclaredFields()){
 Class type = field.getType();
 String name = field.getName();
 Annotation[] annotations = field.getDeclaredAnnotations();
}

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

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

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

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

代码示例来源:origin: spockframework/spock

private static Set<Annotation> getQualifierAnnotations(Field field) {
 // Assume that any annotations other than @MockBean/@SpyBean are qualifiers
 Annotation[] candidates = field.getDeclaredAnnotations();
 Set<Annotation> annotations = new HashSet<>(candidates.length);
 for (Annotation candidate : candidates) {
  if (!isMockOrSpyAnnotation(candidate)) {
   annotations.add(candidate);
  }
 }
 return annotations;
}

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

public List<String> getFieldAnnotationNames(Field field) {
  return getAnnotationNames(field.getDeclaredAnnotations());
}

代码示例来源:origin: org.reflections/reflections

public List<String> getFieldAnnotationNames(Field field) {
  return getAnnotationNames(field.getDeclaredAnnotations());
}

代码示例来源:origin: Alluxio/alluxio

/**
  * @param name the name of a property key
  * @return if this property key is deprecated
  */
 public static boolean isDeprecated(String name) {
  try {
   PropertyKey key = new PropertyKey(name);
   Class c = key.getClass();
   Field field = c.getDeclaredField(name);
   Annotation[] annotations = field.getDeclaredAnnotations();
   for (Annotation anno : annotations) {
    if (anno instanceof Deprecated) {
     return true;
    }
   }
   return false;
  } catch (NoSuchFieldException e) {
   return false;
  }
 }
}

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

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

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

/**
 * Method called to add field mix-ins from given mix-in class (and its fields)
 * into already collected actual fields (from introspected classes and their
 * super-classes)
 */
private void _addFieldMixIns(Class<?> mixInCls, Class<?> targetClass,
    Map<String,FieldBuilder> fields)
{
  List<Class<?>> parents = ClassUtil.findSuperClasses(mixInCls, targetClass, true);
  for (Class<?> mixin : parents) {
    for (Field mixinField : ClassUtil.getDeclaredFields(mixin)) {
      // there are some dummy things (static, synthetic); better ignore
      if (!_isIncludableField(mixinField)) {
        continue;
      }
      String name = mixinField.getName();
      // anything to mask? (if not, quietly ignore)
      FieldBuilder b = fields.get(name);
      if (b != null) {
        b.annotations = collectAnnotations(b.annotations, mixinField.getDeclaredAnnotations());
      }
    }
  }
}

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

/**
 * Method called to add field mix-ins from given mix-in class (and its fields)
 * into already collected actual fields (from introspected classes and their
 * super-classes)
 */
private void _addFieldMixIns(Class<?> mixInCls, Class<?> targetClass,
    Map<String,FieldBuilder> fields)
{
  List<Class<?>> parents = ClassUtil.findSuperClasses(mixInCls, targetClass, true);
  for (Class<?> mixin : parents) {
    for (Field mixinField : ClassUtil.getDeclaredFields(mixin)) {
      // there are some dummy things (static, synthetic); better ignore
      if (!_isIncludableField(mixinField)) {
        continue;
      }
      String name = mixinField.getName();
      // anything to mask? (if not, quietly ignore)
      FieldBuilder b = fields.get(name);
      if (b != null) {
        b.annotations = collectAnnotations(b.annotations, mixinField.getDeclaredAnnotations());
      }
    }
  }
}

代码示例来源:origin: h2oai/h2o-2

static FFilter Request2FFilter = new FFilter() { @Override boolean involve(Field f) { return contains(API.class, f.getDeclaredAnnotations()); } };
static boolean contains(Class<? extends Annotation> annoType, Annotation[] annotations) {

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

/**
 * Gets a method parameter (or a parameter field) name, if the violation raised in it.
 */
private static Optional<String> getMemberName(ConstraintViolation<?> violation, Invocable invocable) {
  final List<Path.Node> propertyPath = Lists.of(violation.getPropertyPath());
  final int size = propertyPath.size();
  if (size < 2) {
    return Optional.empty();
  }
  final Path.Node parent = propertyPath.get(size - 2);
  final Path.Node member = propertyPath.get(size - 1);
  switch (parent.getKind()) {
    case PARAMETER:
      // Constraint violation most likely failed with a BeanParam
      final List<Parameter> parameters = invocable.getParameters();
      final Parameter param = parameters.get(parent.as(Path.ParameterNode.class).getParameterIndex());
      // Extract the failing *Param annotation inside the Bean Param
      if (param.getSource().equals(Parameter.Source.BEAN_PARAM)) {
        final Field field = FieldUtils.getField(param.getRawType(), member.getName(), true);
        return JerseyParameterNameProvider.getParameterNameFromAnnotations(field.getDeclaredAnnotations());
      }
      break;
    case METHOD:
      return Optional.of(member.getName());
    default:
      break;
  }
  return Optional.empty();
}

代码示例来源:origin: org.codehaus.jackson/jackson-mapper-asl

protected AnnotatedField _constructField(Field f)
{
  if (_annotationIntrospector == null) { // when annotation processing is disabled
    return new AnnotatedField(f, _emptyAnnotationMap());
  }
  return new AnnotatedField(f, _collectRelevantAnnotations(f.getDeclaredAnnotations()));
}

相关文章

微信公众号

最新文章

更多