java.lang.reflect.Executable类的使用及代码示例

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

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

Executable介绍

[英]A shared superclass for the common functionality of Methodand Constructor.
[中]Methodand构造函数的公共功能的共享超类。

代码示例

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

public Parameter[] getParameters(Executable executable) {
    return executable.getParameters();
  }
}

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

if (executable instanceof Constructor && ClassUtils.isInnerClass(executable.getDeclaringClass()) &&
    executable.getParameterAnnotations().length == executable.getParameterCount() - 1) {
  return (index == 0 ? EMPTY_ANNOTATED_ELEMENT : executable.getParameters()[index - 1]);

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

/**
 * Return the type of the method/constructor parameter.
 * @return the parameter type (never {@code null})
 */
public Class<?> getParameterType() {
  Class<?> paramType = this.parameterType;
  if (paramType == null) {
    if (this.parameterIndex < 0) {
      Method method = getMethod();
      paramType = (method != null ? method.getReturnType() : void.class);
    }
    else {
      paramType = this.executable.getParameterTypes()[this.parameterIndex];
    }
    this.parameterType = paramType;
  }
  return paramType;
}

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

/**
 * 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: pholser/junit-quickcheck

private static String declarerName(Parameter p) {
    Executable exec = p.getDeclaringExecutable();
    return exec.getDeclaringClass().getName() + '.' + exec.getName();
  }
}

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

BeanDefinitionValueResolver valueResolver =
    new BeanDefinitionValueResolver(this.beanFactory, beanName, mbd, converter);
Class<?>[] paramTypes = executable.getParameterTypes();
  Object argValue = argsToResolve[argIndex];
  MethodParameter methodParam = MethodParameter.forExecutable(executable, argIndex);
  GenericTypeResolver.resolveParameterType(methodParam, executable.getDeclaringClass());
  if (argValue instanceof AutowiredArgumentMarker) {
    argValue = resolveAutowiredArgument(methodParam, beanName, null, converter, fallback);

代码示例来源:origin: oblac/jodd

/**
 * Takes given parameters references and returns reference set for given method or constructor.
 */
public BeanReferences[] resolveReferenceFromValues(final Executable methodOrCtor, final String... parameterReferences) {
  BeanReferences[] references = convertRefToReferences(parameterReferences);
  if (references == null || references.length == 0) {
    references = buildDefaultReferences(methodOrCtor);
  }
  if (methodOrCtor.getParameterTypes().length != references.length) {
    throw new PetiteException("Different number of method parameters and references for: " +
      methodOrCtor.getDeclaringClass().getName() + '#' + methodOrCtor.getName());
  }
  removeAllDuplicateNames(references);
  return references;
}

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

this.messageType = messageType;
ReflectionUtils.ensureAccessible(this.executable);
Parameter[] parameters = executable.getParameters();
this.parameterCount = executable.getParameterCount();
parameterResolvers = new ParameterResolver[parameterCount];
Class<?> supportedPayloadType = explicitPayloadType;
    throw new UnsupportedHandlerException(
        "Unable to resolve parameter " + i + " (" + parameters[i].getType().getSimpleName() +
            ") in handler " + executable.toGenericString() + ".", executable);
    throw new UnsupportedHandlerException(String.format(
        "The method %s seems to have parameters that put conflicting requirements on the payload type" +
            " applicable on that method: %s vs %s", executable.toGenericString(),
        supportedPayloadType, parameterResolvers[i].supportedPayloadType()), executable);

代码示例来源:origin: leangen/graphql-spqr

PropertyDescriptor fromConstructorParameter(AnnotatedParameter ctorParam) {
  Executable constructor = (Executable) ctorParam.getOwner().getMember();
  Parameter parameter = constructor.getParameters()[ctorParam.getIndex()];
  AnnotatedType fieldType = transform(ClassUtils.getParameterTypes(constructor, type)[ctorParam.getIndex()], parameter);
  return new PropertyDescriptor(type, constructor.getDeclaringClass(), parameter, fieldType, ctorParam);
}

代码示例来源:origin: jooby-project/jooby

boolean hasBody = Arrays.asList(p.getDeclaringExecutable().getParameters()).stream()
  .filter(it -> Stream.of(it.getAnnotations())
    .filter(e -> e.annotationType() == Body.class)
 return RouteParameter.Kind.PATH;
boolean formLike = !hasBody && p.getDeclaringExecutable().getAnnotation(POST.class) != null;
if (formLike) {
 return RouteParameter.Kind.FORM;

代码示例来源:origin: line/armeria

boolean implicitRequestObjectAnnotation,
                      boolean isServiceMethod) {
final Parameter[] parameters = constructorOrMethod.getParameters();
if (parameters.length == 0) {
  throw new NoParameterException(constructorOrMethod.toGenericString());
                      constructorOrMethod.toGenericString());
                      constructorOrMethod.toGenericString());
         implicitRequestObjectAnnotation);
} else if (!isServiceMethod &&
      constructorOrMethod.getAnnotationsByType(RequestConverter.class).length > 0 &&
      parameters.length == 1) {
                      constructorOrMethod.toGenericString());
  if (constructorOrMethod.isAnnotationPresent(Default.class)) {
    throw new IllegalArgumentException(
        '@' + Default.class.getSimpleName() + " is not supported for: " +
        constructorOrMethod.toGenericString());
              .collect(Collectors.toList()));
if (list.isEmpty()) {
  throw new NoAnnotatedParameterException(constructorOrMethod.toGenericString());
                      constructorOrMethod.toGenericString());
  } else {

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

/**
 * Return the class that declares the underlying Method or Constructor.
 */
public Class<?> getDeclaringClass() {
  return this.executable.getDeclaringClass();
}

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

private BeanReferences[] updateReferencesWithDefaultsIfNeeded(final Executable methodOrCtor, BeanReferences[] references) {
  BeanReferences[] defaultReferences = buildDefaultReferences(methodOrCtor);
  if (references == null || references.length == 0) {
    references = defaultReferences;
  }
  if (methodOrCtor.getParameterTypes().length != references.length) {
    throw new PetiteException(
      "Different number of parameters and references for: " + methodOrCtor.getName());
  }
  // apply default parameters
  for (int i = 0; i < references.length; i++) {
    BeanReferences parameterReferences = references[i];
    if (parameterReferenceIsNotSet(parameterReferences)) {
      references[i] = defaultReferences[i];
    }
  }
  return references;
}

代码示例来源:origin: org.graalvm.truffle/truffle-api

protected SingleMethod(Executable executable) {
  this.varArgs = executable.isVarArgs();
  this.parameterTypes = executable.getParameterTypes();
  this.genericParameterTypes = executable.getGenericParameterTypes();
}

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

@Override
  public String toString() {
    return getClass().getSimpleName() + " " + executable.toGenericString();
  }
}

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

executable.getGenericParameterTypes();
executable.getGenericExceptionTypes();
executable.getParameters();

代码示例来源:origin: com.gitee.ainilili/noaoc

hitEntity.getParameters(),
      paramSource,
      hitEntity.getMethod().getParameterTypes());
  target = (T) ((Constructor<T>)hitEntity.getMethod()).newInstance(objects);
}else{
if(hitEntity.getMethod().getParameterCount() > 0){
  for(Type type: hitEntity.getMethod().getGenericParameterTypes()){
    types.add(type.getTypeName());

代码示例来源:origin: io.airlift/parameternames

ParameterNameClassVisitor(Executable executable)
{
  super(Opcodes.ASM5);
  methodName = executable instanceof Constructor ? "<init>" : executable.getName();
  parameterTypes = Arrays.stream(executable.getParameterTypes())
      .map(Type::getType)
      .collect(toList());
  this.methodVisitor = new ParameterNameMethodVisitor(isStatic(executable.getModifiers()), parameterTypes);
}

相关文章