Browse Source

Improve BindingReflectionHintsRegistrar extensibility

This commit introduces a shouldSkipType(Class<?> type) method
and changes shouldRegisterMembers(Class<?> type) to
shouldSkipMembers(Class<?> type).

Closes gh-29279
pull/29282/head
Sébastien Deleuze 3 years ago
parent
commit
a9cd45e7f2
  1. 21
      spring-core/src/main/java/org/springframework/aot/hint/BindingReflectionHintsRegistrar.java

21
spring-core/src/main/java/org/springframework/aot/hint/BindingReflectionHintsRegistrar.java

@ -64,12 +64,21 @@ public class BindingReflectionHintsRegistrar { @@ -64,12 +64,21 @@ public class BindingReflectionHintsRegistrar {
}
/**
* 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) {
@ -78,11 +87,11 @@ public class BindingReflectionHintsRegistrar { @@ -78,11 +87,11 @@ public class BindingReflectionHintsRegistrar {
}
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()) {

Loading…
Cancel
Save