Allow ReflectionHints to register hints on interface hierarchies
This commit promotes a previously private method in `BeanRegistrationsAotContribution` to a top-level method in `ReflectionHints`. This helps to register hints on all interfaces implemented in the class hierarchy of the given type. Closes gh-32824
This commit is contained in:
@@ -175,6 +175,28 @@ public class ReflectionHints {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register or customize reflection hints for all the interfaces implemented by
|
||||
* the given type and its parent classes, ignoring the common Java language interfaces.
|
||||
* The specified {@code typeHint} consumer is invoked for each type.
|
||||
* @param type the type to consider
|
||||
* @param typeHint a builder to further customize hints for each type
|
||||
* @return {@code this}, to facilitate method chaining
|
||||
*/
|
||||
public ReflectionHints registerForInterfaces(Class<?> type, Consumer<TypeHint.Builder> typeHint) {
|
||||
Class<?> currentClass = type;
|
||||
while (currentClass != null && currentClass != Object.class) {
|
||||
for (Class<?> interfaceType : currentClass.getInterfaces()) {
|
||||
if (!ClassUtils.isJavaLanguageInterface(interfaceType)) {
|
||||
this.registerType(interfaceType, typeHint);
|
||||
registerForInterfaces(interfaceType, typeHint);
|
||||
}
|
||||
}
|
||||
currentClass = currentClass.getSuperclass();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the need for reflection on the specified {@link Field}.
|
||||
* @param field the field that requires reflection
|
||||
|
||||
Reference in New Issue
Block a user