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

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

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

Method.getParameterAnnotations介绍

[英]Returns an array of arrays that represent the annotations on the formal parameters, in declaration order, of the method represented by this Method object. (Returns an array of length zero if the underlying method is parameterless. If the method has one or more parameters, a nested array of length zero is returned for each parameter with no annotations.) The annotation objects contained in the returned arrays are serializable. The caller of this method is free to modify the returned arrays; it will have no effect on the arrays returned to other callers.
[中]返回一个数组数组,这些数组按声明顺序表示此方法对象表示的方法的形式参数上的注释。(如果基础方法是无参数的,则返回长度为零的数组。如果该方法有一个或多个参数,则为每个不带注释的参数返回长度为零的嵌套数组。)返回数组中包含的注释对象是可序列化的。此方法的调用方可以自由修改返回的数组;它对返回给其他调用者的数组没有影响。

代码示例

代码示例来源:origin: google/guava

@Override
final Annotation[][] getParameterAnnotations() {
 return method.getParameterAnnotations();
}

代码示例来源:origin: jenkinsci/jenkins

public Annotation[][] annotations() {
  if (annotations==null)
    annotations = method.getParameterAnnotations();
  return annotations;
}

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

/**
   * {@inheritDoc}
   */
  public Annotation[][] getParameterAnnotations() {
    return method.getParameterAnnotations();
  }
}

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

@Override
final Annotation[][] getParameterAnnotations() {
 return method.getParameterAnnotations();
}

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

@Override
public boolean hasTestInstance(Method method, int i) {
 final Annotation[][] annotations = method.getParameterAnnotations();
 if (annotations.length > 0 && annotations[i].length > 0) {
  final Annotation[] pa = annotations[i];
  for (Annotation a : pa) {
   if (a instanceof TestInstance) {
    return true;
   }
  }
 }
 return false;
}

代码示例来源:origin: square/retrofit

Builder(Retrofit retrofit, Method method) {
 this.retrofit = retrofit;
 this.method = method;
 this.methodAnnotations = method.getAnnotations();
 this.parameterTypes = method.getGenericParameterTypes();
 this.parameterAnnotationsArray = method.getParameterAnnotations();
}

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

private static boolean hasConstraintParameter(Method method) {
  Annotation[][] parameterAnnotations = method.getParameterAnnotations();
  if (parameterAnnotations != null && parameterAnnotations.length > 0) {
    for (Annotation[] annotations : parameterAnnotations) {
      for (Annotation annotation : annotations) {
        if (annotation.annotationType().isAnnotationPresent(Constraint.class)) {
          return true;
        }
      }
    }
  }
  return false;
}

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

private static boolean hasConstraintParameter(Method method) {
  Annotation[][] parameterAnnotations = method.getParameterAnnotations();
  if (parameterAnnotations != null && parameterAnnotations.length > 0) {
    for (Annotation[] annotations : parameterAnnotations) {
      for (Annotation annotation : annotations) {
        if (annotation.annotationType().isAnnotationPresent(Constraint.class)) {
          return true;
        }
      }
    }
  }
  return false;
}

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

public CacheParameterDetail(Method method, int parameterPosition) {
  this.rawType = method.getParameterTypes()[parameterPosition];
  this.annotations = new LinkedHashSet<>();
  boolean foundKeyAnnotation = false;
  boolean foundValueAnnotation = false;
  for (Annotation annotation : method.getParameterAnnotations()[parameterPosition]) {
    this.annotations.add(annotation);
    if (CacheKey.class.isAssignableFrom(annotation.annotationType())) {
      foundKeyAnnotation = true;
    }
    if (CacheValue.class.isAssignableFrom(annotation.annotationType())) {
      foundValueAnnotation = true;
    }
  }
  this.parameterPosition = parameterPosition;
  this.isKey = foundKeyAnnotation;
  this.isValue = foundValueAnnotation;
}

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

private List<Annotation[][]> getInterfaceParameterAnnotations() {
  List<Annotation[][]> parameterAnnotations = this.interfaceParameterAnnotations;
  if (parameterAnnotations == null) {
    parameterAnnotations = new ArrayList<>();
    for (Class<?> ifc : this.method.getDeclaringClass().getInterfaces()) {
      for (Method candidate : ifc.getMethods()) {
        if (isOverrideFor(candidate)) {
          parameterAnnotations.add(candidate.getParameterAnnotations());
        }
      }
    }
    this.interfaceParameterAnnotations = parameterAnnotations;
  }
  return parameterAnnotations;
}

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

/**
   * {@inheritDoc}
   */
  @CachedReturnPlugin.Enhance("parameterAnnotations")
  public Annotation[][] getParameterAnnotations() {
    return method.getParameterAnnotations();
  }
}

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

@Override
public List<String> getParameterNames(Method method) {
  Parameter[] parameters = method.getParameters();
  Annotation[][] parameterAnnotations = method.getParameterAnnotations();
  List<String> names = new ArrayList<>(parameterAnnotations.length);
  for (int i = 0; i < parameterAnnotations.length; i++) {
    Annotation[] annotations = parameterAnnotations[i];
    String name = getParameterNameFromAnnotations(annotations).orElse(parameters[i].getName());
    names.add(name);
  }
  return names;
}

代码示例来源:origin: junit-team/junit4

public static ArrayList<ParameterSignature> signatures(Method method) {
  return signatures(method.getParameterTypes(), method
      .getParameterAnnotations());
}

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

/**
 * Extracts method parameters.
 *
 * @param method any valid method.
 * @return extracted method parameters.
 */
public static Parameter[] getMethodParameters(final Method method) {
 if (method == null) {
  return new Parameter[]{};
 }
 return getParameters(method.getParameterTypes(), method.getParameterAnnotations());
}

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

@Override
public String[] findOptionalValues(Method method) {
 return optionalValues(method.getParameterAnnotations());
}

代码示例来源:origin: google/j2objc

public static ArrayList<ParameterSignature> signatures(Method method) {
  return signatures(method.getParameterTypes(), method
      .getParameterAnnotations());
}

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

public List<TypeSignature> getInputTypesSignatures(Method inputFunction)
{
  ImmutableList.Builder<TypeSignature> builder = ImmutableList.builder();
  Annotation[][] parameterAnnotations = inputFunction.getParameterAnnotations();
  for (Annotation[] annotations : parameterAnnotations) {
    for (Annotation annotation : annotations) {
      if (annotation instanceof SqlType) {
        String typeName = ((SqlType) annotation).value();
        builder.add(parseTypeSignature(typeName, literalParameters));
      }
    }
  }
  return builder.build();
}

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

protected AnnotatedMethod constructFactoryCreator(Method m, Method mixin)
{
  final int paramCount = m.getParameterTypes().length;
  if (_intr == null) { // when annotation processing is disabled
    return new AnnotatedMethod(_typeContext, m, _emptyAnnotationMap(),
        _emptyAnnotationMaps(paramCount));
  }
  if (paramCount == 0) { // common enough we can slightly optimize
    return new AnnotatedMethod(_typeContext, m, collectAnnotations(m, mixin),
        NO_ANNOTATION_MAPS);
  }
  return new AnnotatedMethod(_typeContext, m, collectAnnotations(m, mixin),
      collectAnnotations(m.getParameterAnnotations(),
          (mixin == null) ? null : mixin.getParameterAnnotations()));
}

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

protected AnnotatedMethod constructFactoryCreator(Method m, Method mixin)
{
  final int paramCount = m.getParameterTypes().length;
  if (_intr == null) { // when annotation processing is disabled
    return new AnnotatedMethod(_typeContext, m, _emptyAnnotationMap(),
        _emptyAnnotationMaps(paramCount));
  }
  if (paramCount == 0) { // common enough we can slightly optimize
    return new AnnotatedMethod(_typeContext, m, collectAnnotations(m, mixin),
        NO_ANNOTATION_MAPS);
  }
  return new AnnotatedMethod(_typeContext, m, collectAnnotations(m, mixin),
      collectAnnotations(m.getParameterAnnotations(),
          (mixin == null) ? null : mixin.getParameterAnnotations()));
}

代码示例来源:origin: square/dagger

@Override public void attach(Linker linker) {
 Type[] types = method.getGenericParameterTypes();
 Annotation[][] annotations = method.getParameterAnnotations();
 parameters = new Binding[types.length];
 for (int i = 0; i < parameters.length; i++) {
  String key = Keys.get(types[i], annotations[i], method + " parameter " + i);
  parameters[i] = linker.requestBinding(key, method, instance.getClass().getClassLoader());
 }
}

相关文章

微信公众号

最新文章

更多