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

x33g5p2x  于2022-01-19 转载在 其他  
字(8.1k)|赞(0)|评价(0)|浏览(171)

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

Executable.getParameterAnnotations介绍

暂无

代码示例

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

/**
 * Return the annotations associated with the specific method/constructor parameter.
 */
public Annotation[] getParameterAnnotations() {
  Annotation[] paramAnns = this.parameterAnnotations;
  if (paramAnns == null) {
    Annotation[][] annotationArray = this.executable.getParameterAnnotations();
    int index = this.parameterIndex;
    if (this.executable instanceof Constructor &&
        ClassUtils.isInnerClass(this.executable.getDeclaringClass()) &&
        annotationArray.length == this.executable.getParameterCount() - 1) {
      // Bug in javac in JDK <9: annotation array excludes enclosing instance parameter
      // for inner classes, so access it with the actual parameter index lowered by 1
      index = this.parameterIndex - 1;
    }
    paramAnns = (index >= 0 && index < annotationArray.length ?
        adaptAnnotationArray(annotationArray[index]) : EMPTY_ANNOTATION_ARRAY);
    this.parameterAnnotations = paramAnns;
  }
  return paramAnns;
}

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

Executable executable = parameter.getDeclaringExecutable();
if (executable instanceof Constructor && ClassUtils.isInnerClass(executable.getDeclaringClass()) &&
    executable.getParameterAnnotations().length == executable.getParameterCount() - 1) {

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

/**
 * Return the annotations associated with the specific method/constructor parameter.
 */
public Annotation[] getParameterAnnotations() {
  Annotation[] paramAnns = this.parameterAnnotations;
  if (paramAnns == null) {
    Annotation[][] annotationArray = this.executable.getParameterAnnotations();
    int index = this.parameterIndex;
    if (this.executable instanceof Constructor &&
        ClassUtils.isInnerClass(this.executable.getDeclaringClass()) &&
        annotationArray.length == this.executable.getParameterCount() - 1) {
      // Bug in javac in JDK <9: annotation array excludes enclosing instance parameter
      // for inner classes, so access it with the actual parameter index lowered by 1
      index = this.parameterIndex - 1;
    }
    paramAnns = (index >= 0 && index < annotationArray.length ?
        adaptAnnotationArray(annotationArray[index]) : EMPTY_ANNOTATION_ARRAY);
    this.parameterAnnotations = paramAnns;
  }
  return paramAnns;
}

代码示例来源:origin: org.junit.jupiter/junit-jupiter-engine

&& executable.getParameterAnnotations().length == executable.getParameterCount() - 1) {

代码示例来源:origin: com.oracle.substratevm/library-support

@Override
  public Object compute(MetaAccessProvider metaAccess, ResolvedJavaField original, ResolvedJavaField annotated, Object receiver) {
    Executable executable = (Executable) receiver;
    return executable.getParameterAnnotations();
  }
}

代码示例来源:origin: org.eclipse.persistence/org.eclipse.persistence.moxy

private boolean detectParameterConstraints(Executable c) {
    for (Annotation[] aa : c.getParameterAnnotations())
      for (Annotation a : aa) {
        final Class<? extends Annotation> annType = a.annotationType();
        if (knownConstraints.contains(annType)) {
          return true;
        }
        // detect custom annotations
        for (Annotation annOnAnnType : annType.getAnnotations()) {
          final Class<? extends Annotation> annTypeOnAnnType = annOnAnnType.annotationType();
          if (Constraint.class == annTypeOnAnnType) {
            knownConstraints.add(annType);
            return true;
          }
        }
      }
    return false;
  }
}

代码示例来源:origin: com.github.XDean/spring-annotation

/**
 * Return the annotations associated with the specific method/constructor parameter.
 */
public Annotation[] getParameterAnnotations() {
 Annotation[] paramAnns = this.parameterAnnotations;
 if (paramAnns == null) {
  Annotation[][] annotationArray = this.executable.getParameterAnnotations();
  if (this.parameterIndex >= 0 && this.parameterIndex < annotationArray.length) {
   paramAnns = adaptAnnotationArray(annotationArray[this.parameterIndex]);
  } else {
   paramAnns = new Annotation[0];
  }
  this.parameterAnnotations = paramAnns;
 }
 return paramAnns;
}

代码示例来源:origin: com.fitbur.core/core-hk2

public <T extends Annotation> Optional<T> findParameter(Injectee injectee, Class<T> type) {
  AnnotatedElement parent = injectee.getParent();
  Optional<T> annotation;
  if (parent instanceof Field) {
    Field field = (Field) parent;
    annotation = Optional.ofNullable(field.getAnnotation(type));
  } else {
    Executable executable = (Executable) parent;
    Annotation[][] annotations = executable.getParameterAnnotations();
    Annotation[] params = annotations[injectee.getPosition()];
    annotation = Stream.of(params)
        .parallel()
        .filter(p -> type.equals(p.annotationType()))
        .map(p -> (T) p)
        .findFirst();
  }
  return annotation;
}

代码示例来源:origin: weld/weld-junit

private static List<Class<?>> getExecutableParameterTypes(Executable executable, Weld weld, boolean explicitInjection) {
  List<Class<?>> types = new ArrayList<>();
  if (explicitInjection) {
    Annotation[][] paramAnns = executable.getParameterAnnotations();
    Class<?>[] paramTypes = executable.getParameterTypes();
    for (int c = 0; c < paramAnns.length; ++c) {
      if (stream(paramAnns[c]).anyMatch(ann -> isAnnotated(ann.annotationType(), Qualifier.class) || isAnnotated(ann.annotationType(), NormalScope.class))) {
        weld.addBeanClass(paramTypes[c]);
        types.add(paramTypes[c]);
      }
    }
  } else {
    for (Class<?> paramType : executable.getParameterTypes()) {
      weld.addBeanClass(paramType);
      types.add(paramType);
    }
  }
  return types;
}

代码示例来源:origin: org.jboss.weld/weld-junit5

private static List<Class<?>> getExecutableParameterTypes(Executable executable, Weld weld, boolean explicitInjection) {
  List<Class<?>> types = new ArrayList<>();
  if (explicitInjection) {
    Annotation[][] paramAnns = executable.getParameterAnnotations();
    Class<?>[] paramTypes = executable.getParameterTypes();
    for (int c = 0; c < paramAnns.length; ++c) {
      if (stream(paramAnns[c]).anyMatch(ann -> isAnnotated(ann.annotationType(), Qualifier.class) || isAnnotated(ann.annotationType(), NormalScope.class))) {
        weld.addBeanClass(paramTypes[c]);
        types.add(paramTypes[c]);
      }
    }
  } else {
    for (Class<?> paramType : executable.getParameterTypes()) {
      weld.addBeanClass(paramType);
      types.add(paramType);
    }
  }
  return types;
}

代码示例来源:origin: org.minijax/minijax-core

private Provider<?>[] getParamProviders(final Key<?> key, final Executable executable, final Set<Key<?>> chain) {
  final Class<?>[] paramClasses = executable.getParameterTypes();
  final Type[] paramTypes = executable.getGenericParameterTypes();
  final Annotation[][] annotations = executable.getParameterAnnotations();
  final Provider<?>[] result = new Provider<?>[paramTypes.length];
  for (int i = 0; i < paramTypes.length; ++i) {
    result[i] = getParamProvider(key, paramClasses[i], paramTypes[i], annotations[i], chain);
  }
  return result;
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.spring-core

/**
 * Return the annotations associated with the specific method/constructor parameter.
 */
public Annotation[] getParameterAnnotations() {
  Annotation[] paramAnns = this.parameterAnnotations;
  if (paramAnns == null) {
    Annotation[][] annotationArray = this.executable.getParameterAnnotations();
    int index = this.parameterIndex;
    if (this.executable instanceof Constructor &&
        ClassUtils.isInnerClass(this.executable.getDeclaringClass()) &&
        annotationArray.length == this.executable.getParameterCount() - 1) {
      // Bug in javac in JDK <9: annotation array excludes enclosing instance parameter
      // for inner classes, so access it with the actual parameter index lowered by 1
      index = this.parameterIndex - 1;
    }
    paramAnns = (index >= 0 && index < annotationArray.length ?
        adaptAnnotationArray(annotationArray[index]) : EMPTY_ANNOTATION_ARRAY);
    this.parameterAnnotations = paramAnns;
  }
  return paramAnns;
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.spring-test

Executable executable = parameter.getDeclaringExecutable();
if (executable instanceof Constructor && ClassUtils.isInnerClass(executable.getDeclaringClass()) &&
    executable.getParameterAnnotations().length == executable.getParameterCount() - 1) {

代码示例来源:origin: apache/servicemix-bundles

Executable executable = parameter.getDeclaringExecutable();
if (executable instanceof Constructor && ClassUtils.isInnerClass(executable.getDeclaringClass()) &&
    executable.getParameterAnnotations().length == executable.getParameterCount() - 1) {

相关文章