36
36
* match the expected behavior for reflection.
37
37
*
38
38
* @author Brian Clozel
39
+ * @author Stephane Nicoll
39
40
* @since 6.0
40
41
*/
41
42
public class ReflectionHintsPredicates {
@@ -248,15 +249,17 @@ public boolean test(RuntimeHints runtimeHints) {
248
249
abstract Predicate <RuntimeHints > exactMatch ();
249
250
250
251
/**
251
- * Indicate whether the first {@code ExecutableHint} covers the reflection needs for the other one.
252
- * For that, both hints must apply to the same member (same type, name and parameters)
253
- * and the configured {@code ExecutableMode} of the first must cover the second.
252
+ * Indicate whether the specified {@code ExecutableHint} covers the
253
+ * reflection needs of the specified executable definition.
254
+ * @return {@code true} if the member matches (same type, name and parameters),
255
+ * and the configured {@code ExecutableMode} is compatibe
254
256
*/
255
- static boolean includes (ExecutableHint hint , ExecutableHint other ) {
256
- return hint .getName ().equals (other .getName ())
257
- && hint .getParameterTypes ().equals (other .getParameterTypes ())
257
+ static boolean includes (ExecutableHint hint , String name ,
258
+ List <TypeReference > parameterTypes , List <ExecutableMode > executableModes ) {
259
+ return hint .getName ().equals (name )
260
+ && hint .getParameterTypes ().equals (parameterTypes )
258
261
&& (hint .getModes ().contains (ExecutableMode .INVOKE )
259
- || !other . getModes () .contains (ExecutableMode .INVOKE ));
262
+ || !executableModes .contains (ExecutableMode .INVOKE ));
260
263
}
261
264
}
262
265
@@ -269,31 +272,32 @@ public static class ConstructorHintPredicate extends ExecutableHintPredicate<Con
269
272
@ Override
270
273
MemberCategory [] getPublicMemberCategories () {
271
274
if (this .executableMode == ExecutableMode .INTROSPECT ) {
272
- return new MemberCategory [] {MemberCategory .INTROSPECT_PUBLIC_CONSTRUCTORS ,
273
- MemberCategory .INVOKE_PUBLIC_CONSTRUCTORS };
275
+ return new MemberCategory [] { MemberCategory .INTROSPECT_PUBLIC_CONSTRUCTORS ,
276
+ MemberCategory .INVOKE_PUBLIC_CONSTRUCTORS };
274
277
}
275
- return new MemberCategory [] {MemberCategory .INVOKE_PUBLIC_CONSTRUCTORS };
278
+ return new MemberCategory [] { MemberCategory .INVOKE_PUBLIC_CONSTRUCTORS };
276
279
}
277
280
278
281
@ Override
279
282
MemberCategory [] getDeclaredMemberCategories () {
280
283
if (this .executableMode == ExecutableMode .INTROSPECT ) {
281
- return new MemberCategory [] {MemberCategory .INTROSPECT_DECLARED_CONSTRUCTORS ,
282
- MemberCategory .INVOKE_DECLARED_CONSTRUCTORS };
284
+ return new MemberCategory [] { MemberCategory .INTROSPECT_DECLARED_CONSTRUCTORS ,
285
+ MemberCategory .INVOKE_DECLARED_CONSTRUCTORS };
283
286
}
284
- return new MemberCategory [] {MemberCategory .INVOKE_DECLARED_CONSTRUCTORS };
287
+ return new MemberCategory [] { MemberCategory .INVOKE_DECLARED_CONSTRUCTORS };
285
288
}
286
289
287
290
@ Override
288
291
Predicate <RuntimeHints > exactMatch () {
289
292
return hints -> (hints .reflection ().getTypeHint (this .executable .getDeclaringClass ()) != null ) &&
290
293
hints .reflection ().getTypeHint (this .executable .getDeclaringClass ()).constructors ().anyMatch (executableHint -> {
291
- List <TypeReference > parameters = Arrays .stream (this .executable .getParameterTypes ()). map ( TypeReference :: of ). toList ();
292
- ExecutableHint syntheticHint = ExecutableHint . ofConstructor ( parameters )
293
- . setModes ( this . executableMode ). build ();
294
- return includes ( executableHint , syntheticHint );
295
- });
294
+ List <TypeReference > parameters = Arrays .stream (this .executable .getParameterTypes ())
295
+ . map ( TypeReference :: of ). toList ();
296
+ return includes ( executableHint , "<init>" ,
297
+ parameters , List . of ( this . executableMode ) );
298
+ });
296
299
}
300
+
297
301
}
298
302
299
303
public static class MethodHintPredicate extends ExecutableHintPredicate <Method > {
@@ -306,32 +310,33 @@ public static class MethodHintPredicate extends ExecutableHintPredicate<Method>
306
310
@ Override
307
311
MemberCategory [] getPublicMemberCategories () {
308
312
if (this .executableMode == ExecutableMode .INTROSPECT ) {
309
- return new MemberCategory [] {MemberCategory .INTROSPECT_PUBLIC_METHODS ,
310
- MemberCategory .INVOKE_PUBLIC_METHODS };
313
+ return new MemberCategory [] { MemberCategory .INTROSPECT_PUBLIC_METHODS ,
314
+ MemberCategory .INVOKE_PUBLIC_METHODS };
311
315
}
312
- return new MemberCategory [] {MemberCategory .INVOKE_PUBLIC_METHODS };
316
+ return new MemberCategory [] { MemberCategory .INVOKE_PUBLIC_METHODS };
313
317
}
314
318
315
319
@ Override
316
320
MemberCategory [] getDeclaredMemberCategories () {
317
321
318
322
if (this .executableMode == ExecutableMode .INTROSPECT ) {
319
- return new MemberCategory [] {MemberCategory .INTROSPECT_DECLARED_METHODS ,
320
- MemberCategory .INVOKE_DECLARED_METHODS };
323
+ return new MemberCategory [] { MemberCategory .INTROSPECT_DECLARED_METHODS ,
324
+ MemberCategory .INVOKE_DECLARED_METHODS };
321
325
}
322
- return new MemberCategory [] {MemberCategory .INVOKE_DECLARED_METHODS };
326
+ return new MemberCategory [] { MemberCategory .INVOKE_DECLARED_METHODS };
323
327
}
324
328
325
329
@ Override
326
330
Predicate <RuntimeHints > exactMatch () {
327
331
return hints -> (hints .reflection ().getTypeHint (this .executable .getDeclaringClass ()) != null ) &&
328
332
hints .reflection ().getTypeHint (this .executable .getDeclaringClass ()).methods ().anyMatch (executableHint -> {
329
- List <TypeReference > parameters = Arrays .stream (this .executable .getParameterTypes ()). map ( TypeReference :: of ). toList ();
330
- ExecutableHint syntheticHint = ExecutableHint . ofMethod ( this . executable . getName (), parameters )
331
- . setModes ( this .executableMode ). build ();
332
- return includes ( executableHint , syntheticHint );
333
+ List <TypeReference > parameters = Arrays .stream (this .executable .getParameterTypes ())
334
+ . map ( TypeReference :: of ). toList ();
335
+ return includes ( executableHint , this .executable . getName (),
336
+ parameters , List . of ( this . executableMode ) );
333
337
});
334
338
}
339
+
335
340
}
336
341
337
342
public static class FieldHintPredicate implements Predicate <RuntimeHints > {
0 commit comments