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 )" )));
@@ -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
}
@@ -394,7 +394,6 @@ public ResolvableMethod mockCall(Consumer<T> invoker) {
394
394
return new ResolvableMethod (method );
395
395
}
396
396
397
-
398
397
// Build & resolve shortcuts...
399
398
400
399
/**
@@ -448,7 +447,6 @@ public MethodParameter resolveReturnType(ResolvableType returnType) {
448
447
return returning (returnType ).build ().returnType ();
449
448
}
450
449
451
-
452
450
@ Override
453
451
public String toString () {
454
452
return "ResolvableMethod.Builder[\n " +
@@ -462,6 +460,7 @@ private String formatFilters() {
462
460
}
463
461
}
464
462
463
+
465
464
/**
466
465
* Predicate with a descriptive label.
467
466
*/
@@ -471,7 +470,6 @@ private static class LabeledPredicate<T> implements Predicate<T> {
471
470
472
471
private final Predicate <T > delegate ;
473
472
474
-
475
473
private LabeledPredicate (String label , Predicate <T > delegate ) {
476
474
this .label = label ;
477
475
this .delegate = delegate ;
@@ -504,14 +502,14 @@ public String toString() {
504
502
}
505
503
}
506
504
505
+
507
506
/**
508
507
* Resolver for method arguments.
509
508
*/
510
509
public class ArgResolver {
511
510
512
511
private final List <Predicate <MethodParameter >> filters = new ArrayList <>(4 );
513
512
514
-
515
513
@ SafeVarargs
516
514
private ArgResolver (Predicate <MethodParameter >... filter ) {
517
515
this .filters .addAll (Arrays .asList (filter ));
@@ -603,17 +601,18 @@ private List<MethodParameter> applyFilters() {
603
601
}
604
602
}
605
603
604
+
606
605
private static class MethodInvocationInterceptor
607
606
implements org .springframework .cglib .proxy .MethodInterceptor , MethodInterceptor {
608
607
609
608
private Method invokedMethod ;
610
609
611
-
612
610
Method getInvokedMethod () {
613
611
return this .invokedMethod ;
614
612
}
615
613
616
614
@ Override
615
+ @ Nullable
617
616
public Object intercept (Object object , Method method , Object [] args , MethodProxy proxy ) {
618
617
if (ReflectionUtils .isObjectMethod (method )) {
619
618
return ReflectionUtils .invokeMethod (method , object , args );
@@ -625,6 +624,7 @@ public Object intercept(Object object, Method method, Object[] args, MethodProxy
625
624
}
626
625
627
626
@ Override
627
+ @ Nullable
628
628
public Object invoke (org .aopalliance .intercept .MethodInvocation inv ) throws Throwable {
629
629
return intercept (inv .getThis (), inv .getMethod (), inv .getArguments (), null );
630
630
}
0 commit comments