|
|
|
@ -109,11 +109,14 @@ public final class ConfigurationPropertiesReflectionHintsProcessor { |
|
|
|
private void handleConstructor(ReflectionHints reflectionHints) { |
|
|
|
private void handleConstructor(ReflectionHints reflectionHints) { |
|
|
|
if (this.bindConstructor != null) { |
|
|
|
if (this.bindConstructor != null) { |
|
|
|
reflectionHints.registerConstructor(this.bindConstructor); |
|
|
|
reflectionHints.registerConstructor(this.bindConstructor); |
|
|
|
|
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
Arrays.stream(this.type.getDeclaredConstructors()).filter(this::hasNoParameters).findFirst() |
|
|
|
Arrays.stream(this.type.getDeclaredConstructors()).filter((candidate) -> candidate.getParameterCount() == 0) |
|
|
|
.ifPresent(reflectionHints::registerConstructor); |
|
|
|
.findFirst().ifPresent(reflectionHints::registerConstructor); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private boolean hasNoParameters(Constructor<?> candidate) { |
|
|
|
|
|
|
|
return candidate.getParameterCount() == 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void handleValueObjectProperties(ReflectionHints reflectionHints) { |
|
|
|
private void handleValueObjectProperties(ReflectionHints reflectionHints) { |
|
|
|
@ -138,6 +141,17 @@ public final class ConfigurationPropertiesReflectionHintsProcessor { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean isSetterMandatory(String propertyName, ResolvableType propertyType) { |
|
|
|
|
|
|
|
Class<?> propertyClass = propertyType.resolve(); |
|
|
|
|
|
|
|
if (propertyClass == null) { |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (isContainer(propertyType)) { |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return !isNestedType(propertyName, propertyClass); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void handleProperty(ReflectionHints reflectionHints, String propertyName, ResolvableType propertyType) { |
|
|
|
private void handleProperty(ReflectionHints reflectionHints, String propertyName, ResolvableType propertyType) { |
|
|
|
Class<?> propertyClass = propertyType.resolve(); |
|
|
|
Class<?> propertyClass = propertyType.resolve(); |
|
|
|
if (propertyClass == null) { |
|
|
|
if (propertyClass == null) { |
|
|
|
@ -146,7 +160,7 @@ public final class ConfigurationPropertiesReflectionHintsProcessor { |
|
|
|
if (propertyClass.equals(this.type)) { |
|
|
|
if (propertyClass.equals(this.type)) { |
|
|
|
return; // Prevent infinite recursion
|
|
|
|
return; // Prevent infinite recursion
|
|
|
|
} |
|
|
|
} |
|
|
|
Class<?> componentType = getComponentType(propertyType); |
|
|
|
Class<?> componentType = getComponentClass(propertyType); |
|
|
|
if (componentType != null) { |
|
|
|
if (componentType != null) { |
|
|
|
// Can be a list of simple types
|
|
|
|
// Can be a list of simple types
|
|
|
|
if (!isJavaType(componentType)) { |
|
|
|
if (!isJavaType(componentType)) { |
|
|
|
@ -158,50 +172,41 @@ public final class ConfigurationPropertiesReflectionHintsProcessor { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private boolean isSetterMandatory(String propertyName, ResolvableType propertyType) { |
|
|
|
private Class<?> getComponentClass(ResolvableType type) { |
|
|
|
Class<?> propertyClass = propertyType.resolve(); |
|
|
|
ResolvableType componentType = getComponentType(type); |
|
|
|
if (propertyClass == null) { |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (isContainer(propertyType)) { |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return !isNestedType(propertyName, propertyClass); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Class<?> getComponentType(ResolvableType propertyType) { |
|
|
|
|
|
|
|
Class<?> propertyClass = propertyType.toClass(); |
|
|
|
|
|
|
|
ResolvableType componentType = null; |
|
|
|
|
|
|
|
if (propertyType.isArray()) { |
|
|
|
|
|
|
|
componentType = propertyType.getComponentType(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if (Collection.class.isAssignableFrom(propertyClass)) { |
|
|
|
|
|
|
|
componentType = propertyType.asCollection().getGeneric(0); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if (Map.class.isAssignableFrom(propertyClass)) { |
|
|
|
|
|
|
|
componentType = propertyType.asMap().getGeneric(1); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (componentType == null) { |
|
|
|
if (componentType == null) { |
|
|
|
return null; |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
if (isContainer(componentType)) { |
|
|
|
if (isContainer(componentType)) { |
|
|
|
// Resolve nested generics like Map<String, List<SomeType>>
|
|
|
|
// Resolve nested generics like Map<String, List<SomeType>>
|
|
|
|
return getComponentType(componentType); |
|
|
|
return getComponentClass(componentType); |
|
|
|
} |
|
|
|
} |
|
|
|
return componentType.toClass(); |
|
|
|
return componentType.toClass(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private boolean isContainer(ResolvableType type) { |
|
|
|
private ResolvableType getComponentType(ResolvableType type) { |
|
|
|
if (type.isArray()) { |
|
|
|
if (type.isArray()) { |
|
|
|
return true; |
|
|
|
return type.getComponentType(); |
|
|
|
} |
|
|
|
} |
|
|
|
if (Collection.class.isAssignableFrom(type.toClass())) { |
|
|
|
if (isCollection(type)) { |
|
|
|
return true; |
|
|
|
return type.asCollection().getGeneric(); |
|
|
|
} |
|
|
|
} |
|
|
|
else if (Map.class.isAssignableFrom(type.toClass())) { |
|
|
|
if (isMap(type)) { |
|
|
|
return true; |
|
|
|
return type.asMap().getGeneric(1); |
|
|
|
} |
|
|
|
} |
|
|
|
return false; |
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean isContainer(ResolvableType type) { |
|
|
|
|
|
|
|
return type.isArray() || isCollection(type) || isMap(type); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean isCollection(ResolvableType type) { |
|
|
|
|
|
|
|
return Collection.class.isAssignableFrom(type.toClass()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean isMap(ResolvableType type) { |
|
|
|
|
|
|
|
return Map.class.isAssignableFrom(type.toClass()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
|