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