Skip to content

Commit

Permalink
Improve BindingReflectionHintsRegistrar extensibility
Browse files Browse the repository at this point in the history
This commit introduces a shouldSkipType(Class<?> type) method
and changes shouldRegisterMembers(Class<?> type) to
shouldSkipMembers(Class<?> type).

Closes gh-29279
  • Loading branch information
sdeleuze committed Oct 7, 2022
1 parent bbe285d commit a9cd45e
Showing 1 changed file with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,21 @@ public void registerReflectionHints(ReflectionHints hints, Type... types) {
}

/**
* Return whether the members of the type should be registered transitively.
* Return whether the type should be skipped.
* @param type the type to evaluate
* @return {@code true} if the members of the type should be registered transitively
* @return {@code true} if the type should be skipped
*/
protected boolean shouldRegisterMembers(Class<?> type) {
return !type.getCanonicalName().startsWith("java.") && !type.isArray();
protected boolean shouldSkipType(Class<?> type) {
return type.isPrimitive() || type == Object.class;
}

/**
* Return whether the members of the type should be skipped.
* @param type the type to evaluate
* @return {@code true} if the members of the type should be skipped
*/
protected boolean shouldSkipMembers(Class<?> type) {
return type.getCanonicalName().startsWith("java.") || type.isArray();
}

private void registerReflectionHints(ReflectionHints hints, Set<Type> seen, Type type) {
Expand All @@ -78,11 +87,11 @@ private void registerReflectionHints(ReflectionHints hints, Set<Type> seen, Type
}
seen.add(type);
if (type instanceof Class<?> clazz) {
if (clazz.isPrimitive() || clazz == Object.class) {
if (shouldSkipType(clazz)) {
return;
}
hints.registerType(clazz, typeHint -> {
if (shouldRegisterMembers(clazz)) {
if (!shouldSkipMembers(clazz)) {
if (clazz.isRecord()) {
typeHint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);
for (RecordComponent recordComponent : clazz.getRecordComponents()) {
Expand Down

0 comments on commit a9cd45e

Please sign in to comment.