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

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

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

Method.toGenericString介绍

[英]Returns a string describing this Method, including type parameters. The string is formatted as the method access modifiers, if any, followed by an angle-bracketed comma-separated list of the method's type parameters, if any, followed by the method's generic return type, followed by a space, followed by the class declaring the method, followed by a period, followed by the method name, followed by a parenthesized, comma-separated list of the method's generic formal parameter types. If this method was declared to take a variable number of arguments, instead of denoting the last parameter as "Type[]", it is denoted as "Type...". A space is used to separate access modifiers from one another and from the type parameters or return type. If there are no type parameters, the type parameter list is elided; if the type parameter list is present, a space separates the list from the class name. If the method is declared to throw exceptions, the parameter list is followed by a space, followed by the word throws followed by a comma-separated list of the generic thrown exception types. If there are no type parameters, the type parameter list is elided.

The access modifiers are placed in canonical order as specified by "The Java Language Specification". This is public, protected or private first, and then other modifiers in the following order: abstract, static, final, synchronized, native, strictfp.
[中]

代码示例

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

@Override
public String toString() {
  return this.method.toGenericString();
}

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

@Override
public String toString() {
  return this.method.toGenericString();
}

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

@Override
public String toString() {
  return this.method.toGenericString();
}

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

@Override
public String toString() {
  return this.method.toGenericString();
}

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

@Override
public String toString() {
  return this.method.toGenericString();
}

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

/**
 * Add additional details such as the bean type and method signature to
 * the given error message.
 * @param message error message to append the HandlerMethod details to
 */
protected String getDetailedErrorMessage(Object bean, String message) {
  StringBuilder sb = new StringBuilder(message).append("\n");
  sb.append("HandlerMethod details: \n");
  sb.append("Bean [").append(bean.getClass().getName()).append("]\n");
  sb.append("Method [").append(this.method.toGenericString()).append("]\n");
  return sb.toString();
}

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

@Override
  public String toString() {
    return this.handlerMethod.getMethod().toGenericString();
  }
}

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

/**
 * Register the given mapping.
 * <p>This method may be invoked at runtime after initialization has completed.
 * @param mapping the mapping for the handler method
 * @param handler the handler
 * @param method the method
 */
public void registerMapping(T mapping, Object handler, Method method) {
  if (logger.isTraceEnabled()) {
    logger.trace("Register \"" + mapping + "\" to " + method.toGenericString());
  }
  this.mappingRegistry.register(mapping, handler, method);
}

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

/**
 * Register the given mapping.
 * <p>This method may be invoked at runtime after initialization has completed.
 * @param mapping the mapping for the handler method
 * @param handler the handler
 * @param method the method
 */
public void registerMapping(T mapping, Object handler, Method method) {
  if (logger.isTraceEnabled()) {
    logger.trace("Register \"" + mapping + "\" to " + method.toGenericString());
  }
  this.mappingRegistry.register(mapping, handler, method);
}

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

protected String formatInvokeError(String text, Object[] args) {
  String formattedArgs = IntStream.range(0, args.length)
      .mapToObj(i -> (args[i] != null ?
          "[" + i + "] [type=" + args[i].getClass().getName() + "] [value=" + args[i] + "]" :
          "[" + i + "] [null]"))
      .collect(Collectors.joining(",\n", " ", " "));
  return text + "\n" +
      "Endpoint [" + getBeanType().getName() + "]\n" +
      "Method [" + getBridgedMethod().toGenericString() + "] " +
      "with argument values:\n" + formattedArgs;
}

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

private static String getMethodMapping(Method method) {
  Assert.notNull(method, "'method' must not be null");
  RequestMapping requestMapping = AnnotatedElementUtils.findMergedAnnotation(method, RequestMapping.class);
  if (requestMapping == null) {
    throw new IllegalArgumentException("No @RequestMapping on: " + method.toGenericString());
  }
  String[] paths = requestMapping.path();
  if (ObjectUtils.isEmpty(paths) || StringUtils.isEmpty(paths[0])) {
    return "/";
  }
  if (paths.length > 1 && logger.isTraceEnabled()) {
    logger.trace("Using first of multiple paths on " + method.toGenericString());
  }
  return paths[0];
}

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

protected String formatInvokeError(String text, Object[] args) {
  String formattedArgs = IntStream.range(0, args.length)
      .mapToObj(i -> (args[i] != null ?
          "[" + i + "] [type=" + args[i].getClass().getName() + "] [value=" + args[i] + "]" :
          "[" + i + "] [null]"))
      .collect(Collectors.joining(",\n", " ", " "));
  return text + "\n" +
      "Controller [" + getBeanType().getName() + "]\n" +
      "Method [" + getBridgedMethod().toGenericString() + "] " +
      "with argument values:\n" + formattedArgs;
}

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

/**
 * Add additional details such as the bean type and method signature to
 * the given error message.
 * @param message error message to append the HandlerMethod details to
 */
protected String getDetailedErrorMessage(Object bean, String message) {
  StringBuilder sb = new StringBuilder(message).append("\n");
  sb.append("HandlerMethod details: \n");
  sb.append("Bean [").append(bean.getClass().getName()).append("]\n");
  sb.append("Method [").append(this.method.toGenericString()).append("]\n");
  return sb.toString();
}

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

@Override
  public String toString() {
    return this.handlerMethod.getMethod().toGenericString();
  }
}

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

protected String formatInvokeError(String text, Object[] args) {
  String formattedArgs = IntStream.range(0, args.length)
      .mapToObj(i -> (args[i] != null ?
          "[" + i + "] [type=" + args[i].getClass().getName() + "] [value=" + args[i] + "]" :
          "[" + i + "] [null]"))
      .collect(Collectors.joining(",\n", " ", " "));
  return text + "\n" +
      "Controller [" + getBeanType().getName() + "]\n" +
      "Method [" + getBridgedMethod().toGenericString() + "] " +
      "with argument values:\n" + formattedArgs;
}

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

/**
 * Handles a fatal error thrown while asynchronously invoking the specified
 * {@link Method}.
 * <p>If the return type of the method is a {@link Future} object, the original
 * exception can be propagated by just throwing it at the higher level. However,
 * for all other cases, the exception will not be transmitted back to the client.
 * In that later case, the current {@link AsyncUncaughtExceptionHandler} will be
 * used to manage such exception.
 * @param ex the exception to handle
 * @param method the method that was invoked
 * @param params the parameters used to invoke the method
 */
protected void handleError(Throwable ex, Method method, Object... params) throws Exception {
  if (Future.class.isAssignableFrom(method.getReturnType())) {
    ReflectionUtils.rethrowException(ex);
  }
  else {
    // Could not transmit the exception to the caller with default executor
    try {
      this.exceptionHandler.obtain().handleUncaughtException(ex, method, params);
    }
    catch (Throwable ex2) {
      logger.warn("Exception handler for async method '" + method.toGenericString() +
          "' threw unexpected exception itself", ex2);
    }
  }
}

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

private GenericMetadataSupport resolveGenericType(Type type, Method method) {
  if (type instanceof Class) {
    return new NotGenericReturnTypeSupport(this, type);
  }
  if (type instanceof ParameterizedType) {
    return new ParameterizedReturnType(this, method.getTypeParameters(), (ParameterizedType) type);
  }
  if (type instanceof TypeVariable) {
    return new TypeVariableReturnType(this, method.getTypeParameters(), (TypeVariable<?>) type);
  }
  throw new MockitoException("Ouch, it shouldn't happen, type '" + type.getClass().getCanonicalName() + "' on method : '" + method.toGenericString() + "' is not supported : " + type);
}

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

/**
 * Invoke the handler, wrapping any exception to a {@link ListenerExecutionFailedException}
 * with a dedicated error message.
 */
@Nullable
private Object invokeHandler(javax.jms.Message jmsMessage, @Nullable Session session, Message<?> message) {
  InvocableHandlerMethod handlerMethod = getHandlerMethod();
  try {
    return handlerMethod.invoke(message, jmsMessage, session);
  }
  catch (MessagingException ex) {
    throw new ListenerExecutionFailedException(
        createMessagingErrorMessage("Listener method could not be invoked with incoming message"), ex);
  }
  catch (Exception ex) {
    throw new ListenerExecutionFailedException("Listener method '" +
        handlerMethod.getMethod().toGenericString() + "' threw exception", ex);
  }
}

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

@Test
public void cannotResolveArg() {
  Method method = ResolvableMethod.on(TestController.class).mockCall(o -> o.singleArg(null)).method();
  Mono<HandlerResult> mono = invoke(new TestController(), method);
  try {
    mono.block();
    fail("Expected IllegalStateException");
  }
  catch (IllegalStateException ex) {
    assertThat(ex.getMessage(), is("Could not resolve parameter [0] in " +
        method.toGenericString() + ": No suitable resolver"));
  }
}

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

@Test
public void invalidPayloadType() throws JMSException {
  MessagingMessageListenerAdapter listener = createDefaultInstance(Integer.class);
  Session session = mock(Session.class);
  this.thrown.expect(ListenerExecutionFailedException.class);
  this.thrown.expectCause(Matchers.isA(MessageConversionException.class));
  this.thrown.expectMessage(getDefaultListenerMethod(Integer.class).toGenericString()); // ref to method
  listener.onMessage(createSimpleJmsTextMessage("test"), session); // test is not a valid integer
}

相关文章

微信公众号

最新文章

更多