47
47
import org .springframework .core .annotation .AnnotatedElementUtils ;
48
48
import org .springframework .core .annotation .AnnotationUtils ;
49
49
import org .springframework .core .annotation .SynthesizingMethodParameter ;
50
+ import org .springframework .lang .Nullable ;
50
51
import org .springframework .objenesis .ObjenesisException ;
51
52
import org .springframework .objenesis .SpringObjenesis ;
52
53
import org .springframework .util .Assert ;
120
121
* </pre>
121
122
*
122
123
* @author Rossen Stoyanchev
124
+ * @since 5.0
123
125
*/
124
126
public class ResolvableMethod {
125
127
@@ -133,7 +135,7 @@ public class ResolvableMethod {
133
135
134
136
135
137
private ResolvableMethod (Method method ) {
136
- Assert .notNull (method , "method is required" );
138
+ Assert .notNull (method , "Method is required" );
137
139
this .method = method ;
138
140
}
139
141
@@ -202,14 +204,14 @@ public final ArgResolver annotNotPresent(Class<? extends Annotation>... annotati
202
204
return new ArgResolver ().annotNotPresent (annotationTypes );
203
205
}
204
206
205
-
206
207
@ Override
207
208
public String toString () {
208
209
return "ResolvableMethod=" + formatMethod ();
209
210
}
210
211
212
+
211
213
private String formatMethod () {
212
- return (this . method ().getName () +
214
+ return (method ().getName () +
213
215
Arrays .stream (this .method .getParameters ())
214
216
.map (this ::formatParameter )
215
217
.collect (joining (",\n \t " , "(\n \t " , "\n )" )));
@@ -246,7 +248,7 @@ private static ResolvableType toResolvableType(Class<?> type, ResolvableType gen
246
248
247
249
248
250
/**
249
- * Main entry point providing access to a {@code ResolvableMethod} builder.
251
+ * Create a {@code ResolvableMethod} builder for the given handler class .
250
252
*/
251
253
public static <T > Builder <T > on (Class <T > objectClass ) {
252
254
return new Builder <>(objectClass );
@@ -262,13 +264,11 @@ public static class Builder<T> {
262
264
263
265
private final List <Predicate <Method >> filters = new ArrayList <>(4 );
264
266
265
-
266
267
private Builder (Class <?> objectClass ) {
267
268
Assert .notNull (objectClass , "Class must not be null" );
268
269
this .objectClass = objectClass ;
269
270
}
270
271
271
-
272
272
private void addFilter (String message , Predicate <Method > filter ) {
273
273
this .filters .add (new LabeledPredicate <>(message , filter ));
274
274
}
@@ -277,7 +277,7 @@ private void addFilter(String message, Predicate<Method> filter) {
277
277
* Filter on methods with the given name.
278
278
*/
279
279
public Builder <T > named (String methodName ) {
280
- addFilter ("methodName=" + methodName , m -> m .getName ().equals (methodName ));
280
+ addFilter ("methodName=" + methodName , method -> method .getName ().equals (methodName ));
281
281
return this ;
282
282
}
283
283
@@ -384,7 +384,6 @@ public ResolvableMethod mockCall(Consumer<T> invoker) {
384
384
return new ResolvableMethod (method );
385
385
}
386
386
387
-
388
387
// Build & resolve shortcuts...
389
388
390
389
/**
@@ -438,7 +437,6 @@ public MethodParameter resolveReturnType(ResolvableType returnType) {
438
437
return returning (returnType ).build ().returnType ();
439
438
}
440
439
441
-
442
440
@ Override
443
441
public String toString () {
444
442
return "ResolvableMethod.Builder[\n " +
@@ -452,6 +450,7 @@ private String formatFilters() {
452
450
}
453
451
}
454
452
453
+
455
454
/**
456
455
* Predicate with a descriptive label.
457
456
*/
@@ -461,7 +460,6 @@ private static class LabeledPredicate<T> implements Predicate<T> {
461
460
462
461
private final Predicate <T > delegate ;
463
462
464
-
465
463
private LabeledPredicate (String label , Predicate <T > delegate ) {
466
464
this .label = label ;
467
465
this .delegate = delegate ;
@@ -494,14 +492,14 @@ public String toString() {
494
492
}
495
493
}
496
494
495
+
497
496
/**
498
497
* Resolver for method arguments.
499
498
*/
500
499
public class ArgResolver {
501
500
502
501
private final List <Predicate <MethodParameter >> filters = new ArrayList <>(4 );
503
502
504
-
505
503
@ SafeVarargs
506
504
private ArgResolver (Predicate <MethodParameter >... filter ) {
507
505
this .filters .addAll (Arrays .asList (filter ));
@@ -593,17 +591,18 @@ private List<MethodParameter> applyFilters() {
593
591
}
594
592
}
595
593
594
+
596
595
private static class MethodInvocationInterceptor
597
596
implements org .springframework .cglib .proxy .MethodInterceptor , MethodInterceptor {
598
597
599
598
private Method invokedMethod ;
600
599
601
-
602
600
Method getInvokedMethod () {
603
601
return this .invokedMethod ;
604
602
}
605
603
606
604
@ Override
605
+ @ Nullable
607
606
public Object intercept (Object object , Method method , Object [] args , MethodProxy proxy ) {
608
607
if (ReflectionUtils .isObjectMethod (method )) {
609
608
return ReflectionUtils .invokeMethod (method , object , args );
@@ -615,6 +614,7 @@ public Object intercept(Object object, Method method, Object[] args, MethodProxy
615
614
}
616
615
617
616
@ Override
617
+ @ Nullable
618
618
public Object invoke (org .aopalliance .intercept .MethodInvocation inv ) throws Throwable {
619
619
return intercept (inv .getThis (), inv .getMethod (), inv .getArguments (), null );
620
620
}
0 commit comments