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

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

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

Executable.getParameterCount介绍

暂无

代码示例

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

private static int validateIndex(Executable executable, int parameterIndex) {
  int count = executable.getParameterCount();
  Assert.isTrue(parameterIndex >= -1 && parameterIndex < count,
      () -> "Parameter index needs to be between -1 and " + (count - 1));
  return parameterIndex;
}

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

int getParameterCount() {
  return executable.getParameterCount();
}

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

private static int validateIndex(Executable executable, int parameterIndex) {
  int count = executable.getParameterCount();
  Assert.isTrue(parameterIndex >= -1 && parameterIndex < count,
      () -> "Parameter index needs to be between -1 and " + (count - 1));
  return parameterIndex;
}

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

/**
 * Return the generic type of the method/constructor parameter.
 * @return the parameter type (never {@code null})
 * @since 3.0
 */
public Type getGenericParameterType() {
  Type paramType = this.genericParameterType;
  if (paramType == null) {
    if (this.parameterIndex < 0) {
      Method method = getMethod();
      paramType = (method != null ? method.getGenericReturnType() : void.class);
    }
    else {
      Type[] genericParameterTypes = this.executable.getGenericParameterTypes();
      int index = this.parameterIndex;
      if (this.executable instanceof Constructor &&
          ClassUtils.isInnerClass(this.executable.getDeclaringClass()) &&
          genericParameterTypes.length == this.executable.getParameterCount() - 1) {
        // Bug in javac: type array excludes enclosing instance parameter
        // for inner classes with at least one generic constructor parameter,
        // so access it with the actual parameter index lowered by 1
        index = this.parameterIndex - 1;
      }
      paramType = (index >= 0 && index < genericParameterTypes.length ?
          genericParameterTypes[index] : getParameterType());
    }
    this.genericParameterType = paramType;
  }
  return paramType;
}

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

private static boolean isNotPrivateAndAcceptsSingleStringArgument(Executable executable) {
  return isNotPrivate(executable) //
      && (executable.getParameterCount() == 1) //
      && (executable.getParameterTypes()[0] == String.class);
}

代码示例来源: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: org.springframework/spring-core

/**
 * Return the generic type of the method/constructor parameter.
 * @return the parameter type (never {@code null})
 * @since 3.0
 */
public Type getGenericParameterType() {
  Type paramType = this.genericParameterType;
  if (paramType == null) {
    if (this.parameterIndex < 0) {
      Method method = getMethod();
      paramType = (method != null ? method.getGenericReturnType() : void.class);
    }
    else {
      Type[] genericParameterTypes = this.executable.getGenericParameterTypes();
      int index = this.parameterIndex;
      if (this.executable instanceof Constructor &&
          ClassUtils.isInnerClass(this.executable.getDeclaringClass()) &&
          genericParameterTypes.length == this.executable.getParameterCount() - 1) {
        // Bug in javac: type array excludes enclosing instance parameter
        // for inner classes with at least one generic constructor parameter,
        // so access it with the actual parameter index lowered by 1
        index = this.parameterIndex - 1;
      }
      paramType = (index >= 0 && index < genericParameterTypes.length ?
          genericParameterTypes[index] : getParameterType());
    }
    this.genericParameterType = paramType;
  }
  return paramType;
}

代码示例来源: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: AxonFramework/AxonFramework

ReflectionUtils.ensureAccessible(this.executable);
Parameter[] parameters = executable.getParameters();
this.parameterCount = executable.getParameterCount();
parameterResolvers = new ParameterResolver[parameterCount];
Class<?> supportedPayloadType = explicitPayloadType;

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

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

代码示例来源:origin: apache/servicecomb-java-chassis

private List<String> getParameterNamesEx(Executable methodOrConstructor) {
  int parameterCount = methodOrConstructor.getParameterCount();
  List<String> parameterNames = new ArrayList<>(parameterCount);

  for (int i = 0; i < parameterCount; i++) {
   parameterNames.add(ParamUtils.getParameterName(methodOrConstructor, i));
  }
  return Collections.unmodifiableList(parameterNames);
 }
}

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

private static int validateIndex(Executable executable, int parameterIndex) {
  int count = executable.getParameterCount();
  Assert.isTrue(parameterIndex >= -1 && parameterIndex < count,
      () -> "Parameter index needs to be between -1 and " + (count - 1));
  return parameterIndex;
}

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

private static int validateIndex(Executable executable, int parameterIndex) {
 int count = executable.getParameterCount();
 Assert.isTrue(parameterIndex < count, () -> "Parameter index needs to be between -1 and " + (count - 1));
 return parameterIndex;
}

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

/**
 * Return MethodParameters for each parameter of the given method/constructor.
 */
public static Stream<MethodParameter> createMethodParameters(Executable executable) {
  return IntStream.range(0, executable.getParameterCount())
    .mapToObj(i -> createMethodParameter(executable, i));
}

代码示例来源:origin: org.apache.servicecomb/swagger-invocation-validator

private List<String> getParameterNamesEx(Executable methodOrConstructor) {
  int parameterCount = methodOrConstructor.getParameterCount();
  List<String> parameterNames = new ArrayList<>(parameterCount);

  for (int i = 0; i < parameterCount; i++) {
   parameterNames.add(ParamUtils.getParameterName(methodOrConstructor, i));
  }
  return Collections.unmodifiableList(parameterNames);
 }
}

代码示例来源:origin: org.apache.bval/bval-jsr

private ConstraintTarget impliedConstraintTarget() {
    if (meta.getHost().getParameterCount() == 0) {
      return ConstraintTarget.RETURN_VALUE;
    }
    if (Void.TYPE.equals(meta.getType())) {
      return ConstraintTarget.PARAMETERS;
    }
    return null;
  }
}

代码示例来源:origin: org.hibernate.validator/hibernate-validator

public List<String> getParameterNames(Executable executable) {
  //skip parameterless methods
  if ( executable.getParameterCount() == 0 ) {
    return Collections.emptyList();
  }
  if ( executable instanceof Method ) {
    return delegate.getParameterNames( (Method) executable );
  }
  else {
    return delegate.getParameterNames( (Constructor<?>) executable );
  }
}

代码示例来源:origin: org.apache.bval/bval-jsr

ParameterD(Meta.ForParameter meta, int index, MetadataReader.ForContainer<Parameter> reader, P parent) {
  super(reader, parent);
  Validate.isTrue(index >= 0 && index < meta.getHost().getDeclaringExecutable().getParameterCount(),
    "Invalid parameter index %d", index);
  this.index = index;
  name = reader.meta.getName();
  type = resolveType();
}

代码示例来源:origin: org.apache.tomee.patch/bval-jsr

ParameterD(Meta.ForParameter meta, int index, MetadataReader.ForContainer<Parameter> reader, P parent) {
  super(reader, parent);
  Validate.isTrue(index >= 0 && index < meta.getHost().getDeclaringExecutable().getParameterCount(),
    "Invalid parameter index %d", index);
  this.index = index;
  name = reader.meta.getName();
  type = resolveType();
}

相关文章