|
|
@ -47,6 +47,7 @@ import org.springframework.core.ResolvableType; |
|
|
|
import org.springframework.core.annotation.AnnotatedElementUtils; |
|
|
|
import org.springframework.core.annotation.AnnotatedElementUtils; |
|
|
|
import org.springframework.core.annotation.AnnotationUtils; |
|
|
|
import org.springframework.core.annotation.AnnotationUtils; |
|
|
|
import org.springframework.core.annotation.SynthesizingMethodParameter; |
|
|
|
import org.springframework.core.annotation.SynthesizingMethodParameter; |
|
|
|
|
|
|
|
import org.springframework.lang.Nullable; |
|
|
|
import org.springframework.objenesis.ObjenesisException; |
|
|
|
import org.springframework.objenesis.ObjenesisException; |
|
|
|
import org.springframework.objenesis.SpringObjenesis; |
|
|
|
import org.springframework.objenesis.SpringObjenesis; |
|
|
|
import org.springframework.util.Assert; |
|
|
|
import org.springframework.util.Assert; |
|
|
@ -120,6 +121,7 @@ import static java.util.stream.Collectors.*; |
|
|
|
* </pre> |
|
|
|
* </pre> |
|
|
|
* |
|
|
|
* |
|
|
|
* @author Rossen Stoyanchev |
|
|
|
* @author Rossen Stoyanchev |
|
|
|
|
|
|
|
* @since 5.0 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class ResolvableMethod { |
|
|
|
public class ResolvableMethod { |
|
|
|
|
|
|
|
|
|
|
@ -133,7 +135,7 @@ public class ResolvableMethod { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private ResolvableMethod(Method method) { |
|
|
|
private ResolvableMethod(Method method) { |
|
|
|
Assert.notNull(method, "method is required"); |
|
|
|
Assert.notNull(method, "Method is required"); |
|
|
|
this.method = method; |
|
|
|
this.method = method; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -202,14 +204,14 @@ public class ResolvableMethod { |
|
|
|
return new ArgResolver().annotNotPresent(annotationTypes); |
|
|
|
return new ArgResolver().annotNotPresent(annotationTypes); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public String toString() { |
|
|
|
public String toString() { |
|
|
|
return "ResolvableMethod=" + formatMethod(); |
|
|
|
return "ResolvableMethod=" + formatMethod(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String formatMethod() { |
|
|
|
private String formatMethod() { |
|
|
|
return (this.method().getName() + |
|
|
|
return (method().getName() + |
|
|
|
Arrays.stream(this.method.getParameters()) |
|
|
|
Arrays.stream(this.method.getParameters()) |
|
|
|
.map(this::formatParameter) |
|
|
|
.map(this::formatParameter) |
|
|
|
.collect(joining(",\n\t", "(\n\t", "\n)"))); |
|
|
|
.collect(joining(",\n\t", "(\n\t", "\n)"))); |
|
|
@ -262,13 +264,11 @@ public class ResolvableMethod { |
|
|
|
|
|
|
|
|
|
|
|
private final List<Predicate<Method>> filters = new ArrayList<>(4); |
|
|
|
private final List<Predicate<Method>> filters = new ArrayList<>(4); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Builder(Class<?> objectClass) { |
|
|
|
private Builder(Class<?> objectClass) { |
|
|
|
Assert.notNull(objectClass, "Class must not be null"); |
|
|
|
Assert.notNull(objectClass, "Class must not be null"); |
|
|
|
this.objectClass = objectClass; |
|
|
|
this.objectClass = objectClass; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void addFilter(String message, Predicate<Method> filter) { |
|
|
|
private void addFilter(String message, Predicate<Method> filter) { |
|
|
|
this.filters.add(new LabeledPredicate<>(message, filter)); |
|
|
|
this.filters.add(new LabeledPredicate<>(message, filter)); |
|
|
|
} |
|
|
|
} |
|
|
@ -394,7 +394,6 @@ public class ResolvableMethod { |
|
|
|
return new ResolvableMethod(method); |
|
|
|
return new ResolvableMethod(method); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Build & resolve shortcuts...
|
|
|
|
// Build & resolve shortcuts...
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -448,7 +447,6 @@ public class ResolvableMethod { |
|
|
|
return returning(returnType).build().returnType(); |
|
|
|
return returning(returnType).build().returnType(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public String toString() { |
|
|
|
public String toString() { |
|
|
|
return "ResolvableMethod.Builder[\n" + |
|
|
|
return "ResolvableMethod.Builder[\n" + |
|
|
@ -462,6 +460,7 @@ public class ResolvableMethod { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Predicate with a descriptive label. |
|
|
|
* Predicate with a descriptive label. |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -471,7 +470,6 @@ public class ResolvableMethod { |
|
|
|
|
|
|
|
|
|
|
|
private final Predicate<T> delegate; |
|
|
|
private final Predicate<T> delegate; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private LabeledPredicate(String label, Predicate<T> delegate) { |
|
|
|
private LabeledPredicate(String label, Predicate<T> delegate) { |
|
|
|
this.label = label; |
|
|
|
this.label = label; |
|
|
|
this.delegate = delegate; |
|
|
|
this.delegate = delegate; |
|
|
@ -504,6 +502,7 @@ public class ResolvableMethod { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Resolver for method arguments. |
|
|
|
* Resolver for method arguments. |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -511,7 +510,6 @@ public class ResolvableMethod { |
|
|
|
|
|
|
|
|
|
|
|
private final List<Predicate<MethodParameter>> filters = new ArrayList<>(4); |
|
|
|
private final List<Predicate<MethodParameter>> filters = new ArrayList<>(4); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@SafeVarargs |
|
|
|
@SafeVarargs |
|
|
|
private ArgResolver(Predicate<MethodParameter>... filter) { |
|
|
|
private ArgResolver(Predicate<MethodParameter>... filter) { |
|
|
|
this.filters.addAll(Arrays.asList(filter)); |
|
|
|
this.filters.addAll(Arrays.asList(filter)); |
|
|
@ -603,17 +601,18 @@ public class ResolvableMethod { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static class MethodInvocationInterceptor |
|
|
|
private static class MethodInvocationInterceptor |
|
|
|
implements org.springframework.cglib.proxy.MethodInterceptor, MethodInterceptor { |
|
|
|
implements org.springframework.cglib.proxy.MethodInterceptor, MethodInterceptor { |
|
|
|
|
|
|
|
|
|
|
|
private Method invokedMethod; |
|
|
|
private Method invokedMethod; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Method getInvokedMethod() { |
|
|
|
Method getInvokedMethod() { |
|
|
|
return this.invokedMethod; |
|
|
|
return this.invokedMethod; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
|
|
|
|
@Nullable |
|
|
|
public Object intercept(Object object, Method method, Object[] args, MethodProxy proxy) { |
|
|
|
public Object intercept(Object object, Method method, Object[] args, MethodProxy proxy) { |
|
|
|
if (ReflectionUtils.isObjectMethod(method)) { |
|
|
|
if (ReflectionUtils.isObjectMethod(method)) { |
|
|
|
return ReflectionUtils.invokeMethod(method, object, args); |
|
|
|
return ReflectionUtils.invokeMethod(method, object, args); |
|
|
@ -625,6 +624,7 @@ public class ResolvableMethod { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
|
|
|
|
@Nullable |
|
|
|
public Object invoke(org.aopalliance.intercept.MethodInvocation inv) throws Throwable { |
|
|
|
public Object invoke(org.aopalliance.intercept.MethodInvocation inv) throws Throwable { |
|
|
|
return intercept(inv.getThis(), inv.getMethod(), inv.getArguments(), null); |
|
|
|
return intercept(inv.getThis(), inv.getMethod(), inv.getArguments(), null); |
|
|
|
} |
|
|
|
} |
|
|
|