49
49
public class ReflectionHintsPredicates {
50
50
51
51
ReflectionHintsPredicates () {
52
-
53
52
}
54
53
55
54
/**
@@ -138,10 +137,10 @@ private Method getMethod(Class<?> type, String methodName) {
138
137
return methods .iterator ().next ();
139
138
}
140
139
else if (methods .size () > 1 ) {
141
- throw new IllegalArgumentException (String . format ( "Found multiple methods named '%s' on class %s" , methodName , type .getName ()));
140
+ throw new IllegalArgumentException ("Found multiple methods named '%s' on class %s" . formatted ( methodName , type .getName ()));
142
141
}
143
142
else {
144
- throw new IllegalArgumentException ("No method named '" + methodName + " ' on class " + type .getName ());
143
+ throw new IllegalArgumentException ("No method named '%s ' on class %s" . formatted ( methodName , type .getName () ));
145
144
}
146
145
}
147
146
@@ -160,7 +159,7 @@ public FieldHintPredicate onField(Class<?> type, String fieldName) {
160
159
Assert .hasText (fieldName , "'fieldName' should not be empty" );
161
160
Field field = ReflectionUtils .findField (type , fieldName );
162
161
if (field == null ) {
163
- throw new IllegalArgumentException ("No field named '" + fieldName + " ' on class " + type .getName ());
162
+ throw new IllegalArgumentException ("No field named '%s ' on class %s" . formatted ( fieldName , type .getName () ));
164
163
}
165
164
return new FieldHintPredicate (field );
166
165
}
@@ -315,15 +314,13 @@ public boolean test(RuntimeHints runtimeHints) {
315
314
/**
316
315
* Indicate whether the specified {@code ExecutableHint} covers the
317
316
* reflection needs of the specified executable definition.
318
- * @return {@code true} if the member matches (same type, name and parameters),
319
- * and the configured {@code ExecutableMode} is compatibe
317
+ * @return {@code true} if the member matches (same type, name, and parameters),
318
+ * and the configured {@code ExecutableMode} is compatible
320
319
*/
321
320
static boolean includes (ExecutableHint hint , String name ,
322
321
List <TypeReference > parameterTypes , ExecutableMode executableModes ) {
323
- return hint .getName ().equals (name )
324
- && hint .getParameterTypes ().equals (parameterTypes )
325
- && (hint .getMode ().equals (ExecutableMode .INVOKE )
326
- || !executableModes .equals (ExecutableMode .INVOKE ));
322
+ return hint .getName ().equals (name ) && hint .getParameterTypes ().equals (parameterTypes ) &&
323
+ (hint .getMode ().equals (ExecutableMode .INVOKE ) || !executableModes .equals (ExecutableMode .INVOKE ));
327
324
}
328
325
}
329
326
@@ -355,18 +352,15 @@ MemberCategory[] getDeclaredMemberCategories() {
355
352
Predicate <RuntimeHints > exactMatch () {
356
353
return hints -> (hints .reflection ().getTypeHint (this .executable .getDeclaringClass ()) != null ) &&
357
354
hints .reflection ().getTypeHint (this .executable .getDeclaringClass ()).constructors ().anyMatch (executableHint -> {
358
- List <TypeReference > parameters = Arrays .stream (this .executable .getParameterTypes ())
359
- .map (TypeReference ::of ).toList ();
360
- return includes (executableHint , "<init>" ,
361
- parameters , this .executableMode );
355
+ List <TypeReference > parameters = TypeReference .listOf (this .executable .getParameterTypes ());
356
+ return includes (executableHint , "<init>" , parameters , this .executableMode );
362
357
});
363
358
}
364
359
365
360
}
366
361
367
362
public static class MethodHintPredicate extends ExecutableHintPredicate <Method > {
368
363
369
-
370
364
MethodHintPredicate (Method method ) {
371
365
super (method );
372
366
}
@@ -394,10 +388,8 @@ MemberCategory[] getDeclaredMemberCategories() {
394
388
Predicate <RuntimeHints > exactMatch () {
395
389
return hints -> (hints .reflection ().getTypeHint (this .executable .getDeclaringClass ()) != null ) &&
396
390
hints .reflection ().getTypeHint (this .executable .getDeclaringClass ()).methods ().anyMatch (executableHint -> {
397
- List <TypeReference > parameters = Arrays .stream (this .executable .getParameterTypes ())
398
- .map (TypeReference ::of ).toList ();
399
- return includes (executableHint , this .executable .getName (),
400
- parameters , this .executableMode );
391
+ List <TypeReference > parameters = TypeReference .listOf (this .executable .getParameterTypes ());
392
+ return includes (executableHint , this .executable .getName (), parameters , this .executableMode );
401
393
});
402
394
}
403
395
@@ -422,8 +414,8 @@ public boolean test(RuntimeHints runtimeHints) {
422
414
423
415
private boolean memberCategoryMatch (TypeHint typeHint ) {
424
416
if (Modifier .isPublic (this .field .getModifiers ())) {
425
- return typeHint .getMemberCategories ().contains (MemberCategory .PUBLIC_FIELDS )
426
- || typeHint .getMemberCategories ().contains (MemberCategory .DECLARED_FIELDS );
417
+ return typeHint .getMemberCategories ().contains (MemberCategory .PUBLIC_FIELDS ) ||
418
+ typeHint .getMemberCategories ().contains (MemberCategory .DECLARED_FIELDS );
427
419
}
428
420
else {
429
421
return typeHint .getMemberCategories ().contains (MemberCategory .DECLARED_FIELDS );
@@ -434,6 +426,7 @@ private boolean exactMatch(TypeHint typeHint) {
434
426
return typeHint .fields ().anyMatch (fieldHint ->
435
427
this .field .getName ().equals (fieldHint .getName ()));
436
428
}
429
+
437
430
}
438
431
439
432
}
0 commit comments