Browse Source

Polishing

pull/30915/head
Juergen Hoeller 2 years ago
parent
commit
c1a8b9a14d
  1. 19
      spring-messaging/src/main/java/org/springframework/messaging/handler/HandlerMethod.java
  2. 14
      spring-web/src/main/java/org/springframework/web/method/HandlerMethod.java

19
spring-messaging/src/main/java/org/springframework/messaging/handler/HandlerMethod.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2022 the original author or authors. * Copyright 2002-2023 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -212,7 +212,7 @@ public class HandlerMethod {
/** /**
* If the bean method is a bridge method, this method returns the bridged * If the bean method is a bridge method, this method returns the bridged
* (user-defined) method. Otherwise it returns the same method as {@link #getMethod()}. * (user-defined) method. Otherwise, it returns the same method as {@link #getMethod()}.
*/ */
protected Method getBridgedMethod() { protected Method getBridgedMethod() {
return this.bridgedMethod; return this.bridgedMethod;
@ -297,20 +297,15 @@ public class HandlerMethod {
* Return a short representation of this handler method for log message purposes. * Return a short representation of this handler method for log message purposes.
*/ */
public String getShortLogMessage() { public String getShortLogMessage() {
int args = this.method.getParameterCount(); return getBeanType().getSimpleName() + "#" + this.method.getName() +
return getBeanType().getSimpleName() + "#" + this.method.getName() + "[" + args + " args]"; "[" + this.method.getParameterCount() + " args]";
} }
@Override @Override
public boolean equals(@Nullable Object other) { public boolean equals(@Nullable Object other) {
if (this == other) { return (this == other || (other instanceof HandlerMethod otherMethod &&
return true; this.bean.equals(otherMethod.bean) && this.method.equals(otherMethod.method)));
}
if (!(other instanceof HandlerMethod otherMethod)) {
return false;
}
return (this.bean.equals(otherMethod.bean) && this.method.equals(otherMethod.method));
} }
@Override @Override
@ -363,13 +358,11 @@ public class HandlerMethod {
} }
protected String formatInvokeError(String text, Object[] args) { protected String formatInvokeError(String text, Object[] args) {
String formattedArgs = IntStream.range(0, args.length) String formattedArgs = IntStream.range(0, args.length)
.mapToObj(i -> (args[i] != null ? .mapToObj(i -> (args[i] != null ?
"[" + i + "] [type=" + args[i].getClass().getName() + "] [value=" + args[i] + "]" : "[" + i + "] [type=" + args[i].getClass().getName() + "] [value=" + args[i] + "]" :
"[" + i + "] [null]")) "[" + i + "] [null]"))
.collect(Collectors.joining(",\n", " ", " ")); .collect(Collectors.joining(",\n", " ", " "));
return text + "\n" + return text + "\n" +
"Endpoint [" + getBeanType().getName() + "]\n" + "Endpoint [" + getBeanType().getName() + "]\n" +
"Method [" + getBridgedMethod().toGenericString() + "] " + "Method [" + getBridgedMethod().toGenericString() + "] " +

14
spring-web/src/main/java/org/springframework/web/method/HandlerMethod.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2022 the original author or authors. * Copyright 2002-2023 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -218,6 +218,7 @@ public class HandlerMethod {
this.description = handlerMethod.description; this.description = handlerMethod.description;
} }
private MethodParameter[] initMethodParameters() { private MethodParameter[] initMethodParameters() {
int count = this.bridgedMethod.getParameterCount(); int count = this.bridgedMethod.getParameterCount();
MethodParameter[] result = new MethodParameter[count]; MethodParameter[] result = new MethodParameter[count];
@ -248,7 +249,7 @@ public class HandlerMethod {
for (Class<?> paramType : method.getParameterTypes()) { for (Class<?> paramType : method.getParameterTypes()) {
joiner.add(paramType.getSimpleName()); joiner.add(paramType.getSimpleName());
} }
return beanType.getName() + "#" + method.getName() + joiner.toString(); return beanType.getName() + "#" + method.getName() + joiner;
} }
@ -424,13 +425,8 @@ public class HandlerMethod {
@Override @Override
public boolean equals(@Nullable Object other) { public boolean equals(@Nullable Object other) {
if (this == other) { return (this == other || (other instanceof HandlerMethod otherMethod &&
return true; this.bean.equals(otherMethod.bean) && this.method.equals(otherMethod.method)));
}
if (!(other instanceof HandlerMethod otherMethod)) {
return false;
}
return (this.bean.equals(otherMethod.bean) && this.method.equals(otherMethod.method));
} }
@Override @Override

Loading…
Cancel
Save