Polish RuntimeHintsPredicates
This commit adds a method variant checking that all `MemberCategory` are supported by the `RuntimeHints` for a given type hint. See gh-28555
This commit is contained in:
parent
dc3ec5b665
commit
15b69a3ede
|
|
@ -180,6 +180,16 @@ public class ReflectionHintsPredicates {
|
||||||
return this.and(hints -> getTypeHint(hints).getMemberCategories().contains(memberCategory));
|
return this.and(hints -> getTypeHint(hints).getMemberCategories().contains(memberCategory));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Refine the current predicate to only match if the given {@link MemberCategory categories} are present.
|
||||||
|
* @param memberCategories the member categories
|
||||||
|
* @return the refined {@link RuntimeHints} predicate
|
||||||
|
*/
|
||||||
|
public Predicate<RuntimeHints> withMemberCategories(MemberCategory... memberCategories) {
|
||||||
|
Assert.notEmpty(memberCategories, "'memberCategories' should not be empty");
|
||||||
|
return this.and(hints -> getTypeHint(hints).getMemberCategories().containsAll(Arrays.asList(memberCategories)));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Refine the current predicate to match if any of the given {@link MemberCategory categories} is present.
|
* Refine the current predicate to match if any of the given {@link MemberCategory categories} is present.
|
||||||
* @param memberCategories the member categories
|
* @param memberCategories the member categories
|
||||||
|
|
|
||||||
|
|
@ -98,6 +98,21 @@ class ReflectionHintsPredicatesTests {
|
||||||
assertPredicateDoesNotMatch(reflection.onType(SampleClass.class).withMemberCategory(MemberCategory.INVOKE_PUBLIC_METHODS));
|
assertPredicateDoesNotMatch(reflection.onType(SampleClass.class).withMemberCategory(MemberCategory.INVOKE_PUBLIC_METHODS));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void typeWithMemberCategoriesMatchesCategories() {
|
||||||
|
runtimeHints.reflection().registerType(SampleClass.class, builder ->
|
||||||
|
builder.withMembers(MemberCategory.INTROSPECT_PUBLIC_CONSTRUCTORS, MemberCategory.INTROSPECT_PUBLIC_METHODS));
|
||||||
|
assertPredicateMatches(reflection.onType(SampleClass.class)
|
||||||
|
.withMemberCategories(MemberCategory.INTROSPECT_PUBLIC_CONSTRUCTORS, MemberCategory.INTROSPECT_PUBLIC_METHODS));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void typeWithMemberCategoriesDoesNotMatchMissingCategory() {
|
||||||
|
runtimeHints.reflection().registerType(SampleClass.class, builder -> builder.withMembers(MemberCategory.INTROSPECT_PUBLIC_METHODS));
|
||||||
|
assertPredicateDoesNotMatch(reflection.onType(SampleClass.class)
|
||||||
|
.withMemberCategories(MemberCategory.INTROSPECT_PUBLIC_CONSTRUCTORS, MemberCategory.INTROSPECT_PUBLIC_METHODS));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void typeWithAnyMemberCategoryFailsWithNullCategories() {
|
void typeWithAnyMemberCategoryFailsWithNullCategories() {
|
||||||
runtimeHints.reflection().registerType(SampleClass.class, builder -> builder.withMembers(MemberCategory.INTROSPECT_PUBLIC_METHODS));
|
runtimeHints.reflection().registerType(SampleClass.class, builder -> builder.withMembers(MemberCategory.INTROSPECT_PUBLIC_METHODS));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue