Fix since in javadoc

This commit is contained in:
Gary Russell
2021-03-09 17:06:53 -05:00
parent fdfd541ddf
commit 65377ea778

View File

@@ -106,8 +106,8 @@ public class RecoverAnnotationRecoveryHandler<T> implements MethodInvocationReco
result = method;
}
else if (distance == min) {
boolean parametersMatch = compareParameters(args, meta.getArgCount(),
method.getParameterTypes());
boolean parametersMatch = compareParameters(args,
meta.getArgCount(), method.getParameterTypes());
if (parametersMatch) {
result = method;
}
@@ -120,8 +120,8 @@ public class RecoverAnnotationRecoveryHandler<T> implements MethodInvocationReco
Method method = entry.getKey();
if (method.getName().equals(this.recoverMethodName)) {
SimpleMetadata meta = entry.getValue();
if (meta.type.isAssignableFrom(cause)
&& compareParameters(args, meta.getArgCount(), method.getParameterTypes())) {
if (meta.type.isAssignableFrom(cause) && compareParameters(args,
meta.getArgCount(), method.getParameterTypes())) {
result = method;
break;
}
@@ -131,7 +131,8 @@ public class RecoverAnnotationRecoveryHandler<T> implements MethodInvocationReco
return result;
}
private int calculateDistance(Class<? extends Throwable> cause, Class<? extends Throwable> type) {
private int calculateDistance(Class<? extends Throwable> cause,
Class<? extends Throwable> type) {
int result = 0;
Class<?> current = cause;
while (current != type && current != Throwable.class) {
@@ -141,14 +142,17 @@ public class RecoverAnnotationRecoveryHandler<T> implements MethodInvocationReco
return result;
}
private boolean compareParameters(Object[] args, int argCount, Class<?>[] parameterTypes) {
private boolean compareParameters(Object[] args, int argCount,
Class<?>[] parameterTypes) {
if (argCount == (args.length + 1)) {
int startingIndex = 0;
if (parameterTypes.length > 0 && Throwable.class.isAssignableFrom(parameterTypes[0])) {
if (parameterTypes.length > 0
&& Throwable.class.isAssignableFrom(parameterTypes[0])) {
startingIndex = 1;
}
for (int i = startingIndex; i < parameterTypes.length; i++) {
final Object argument = i - startingIndex < args.length ? args[i - startingIndex] : null;
final Object argument = i - startingIndex < args.length
? args[i - startingIndex] : null;
if (argument == null) {
continue;
}
@@ -170,19 +174,24 @@ public class RecoverAnnotationRecoveryHandler<T> implements MethodInvocationReco
}
ReflectionUtils.doWithMethods(target.getClass(), new MethodCallback() {
@Override
public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException {
public void doWith(Method method)
throws IllegalArgumentException, IllegalAccessException {
Recover recover = AnnotationUtils.findAnnotation(method, Recover.class);
if (recover == null) {
recover = findAnnotationOnTarget(target, method);
}
if (recover != null && failingMethod.getGenericReturnType() instanceof ParameterizedType
if (recover != null
&& failingMethod
.getGenericReturnType() instanceof ParameterizedType
&& method.getGenericReturnType() instanceof ParameterizedType) {
if (isParameterizedTypeAssignable((ParameterizedType) method.getGenericReturnType(),
if (isParameterizedTypeAssignable(
(ParameterizedType) method.getGenericReturnType(),
(ParameterizedType) failingMethod.getGenericReturnType())) {
putToMethodsMap(method, types);
}
}
else if (recover != null && method.getReturnType().isAssignableFrom(failingMethod.getReturnType())) {
else if (recover != null && method.getReturnType()
.isAssignableFrom(failingMethod.getReturnType())) {
putToMethodsMap(method, types);
}
}
@@ -198,7 +207,7 @@ public class RecoverAnnotationRecoveryHandler<T> implements MethodInvocationReco
* @param methodReturnType
* @param failingMethodReturnType
* @return true if the parameterized return types match.
* @since 1.3.1
* @since 1.3.2
*/
private boolean isParameterizedTypeAssignable(ParameterizedType methodReturnType,
ParameterizedType failingMethodReturnType) {
@@ -212,7 +221,8 @@ public class RecoverAnnotationRecoveryHandler<T> implements MethodInvocationReco
for (int i = startingIndex; i < methodActualArgs.length; i++) {
Type methodArgType = methodActualArgs[i];
Type failingMethodArgType = failingMethodActualArgs[i];
if (methodArgType instanceof ParameterizedType && failingMethodArgType instanceof ParameterizedType) {
if (methodArgType instanceof ParameterizedType
&& failingMethodArgType instanceof ParameterizedType) {
return isParameterizedTypeAssignable((ParameterizedType) methodArgType,
(ParameterizedType) failingMethodArgType);
}
@@ -224,23 +234,28 @@ public class RecoverAnnotationRecoveryHandler<T> implements MethodInvocationReco
return true;
}
private void putToMethodsMap(Method method, Map<Class<? extends Throwable>, Method> types) {
private void putToMethodsMap(Method method,
Map<Class<? extends Throwable>, Method> types) {
Class<?>[] parameterTypes = method.getParameterTypes();
if (parameterTypes.length > 0 && Throwable.class.isAssignableFrom(parameterTypes[0])) {
if (parameterTypes.length > 0
&& Throwable.class.isAssignableFrom(parameterTypes[0])) {
@SuppressWarnings("unchecked")
Class<? extends Throwable> type = (Class<? extends Throwable>) parameterTypes[0];
types.put(type, method);
RecoverAnnotationRecoveryHandler.this.methods.put(method, new SimpleMetadata(parameterTypes.length, type));
RecoverAnnotationRecoveryHandler.this.methods.put(method,
new SimpleMetadata(parameterTypes.length, type));
}
else {
RecoverAnnotationRecoveryHandler.this.classifier.setDefaultValue(method);
RecoverAnnotationRecoveryHandler.this.methods.put(method, new SimpleMetadata(parameterTypes.length, null));
RecoverAnnotationRecoveryHandler.this.methods.put(method,
new SimpleMetadata(parameterTypes.length, null));
}
}
private Recover findAnnotationOnTarget(Object target, Method method) {
try {
Method targetMethod = target.getClass().getMethod(method.getName(), method.getParameterTypes());
Method targetMethod = target.getClass().getMethod(method.getName(),
method.getParameterTypes());
return AnnotationUtils.findAnnotation(targetMethod, Recover.class);
}
catch (Exception e) {
@@ -287,7 +302,8 @@ public class RecoverAnnotationRecoveryHandler<T> implements MethodInvocationReco
result[0] = t;
startArgs = 1;
}
int length = result.length - startArgs > args.length ? args.length : result.length - startArgs;
int length = result.length - startArgs > args.length ? args.length
: result.length - startArgs;
if (length == 0) {
return result;
}