BeanProperties Class — spring-boot Architecture
Architecture documentation for the BeanProperties class in JavaBeanBinder.java from the spring-boot codebase.
Entity Profile
Relationship Graph
Source Code
core/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/JavaBeanBinder.java lines 153–256
static class BeanProperties {
private final Map<String, BeanProperty> properties = new LinkedHashMap<>();
private final ResolvableType type;
private final Class<?> resolvedType;
BeanProperties(ResolvableType type, Class<?> resolvedType) {
this.type = type;
this.resolvedType = resolvedType;
addProperties(resolvedType);
}
private void addProperties(Class<?> type) {
while (type != null && !Object.class.equals(type)) {
Method[] declaredMethods = getSorted(type, this::getDeclaredMethods, Method::getName);
Field[] declaredFields = getSorted(type, Class::getDeclaredFields, Field::getName);
addProperties(declaredMethods, declaredFields);
type = type.getSuperclass();
}
}
private Method[] getDeclaredMethods(Class<?> type) {
Method[] methods = type.getDeclaredMethods();
Set<Method> result = new LinkedHashSet<>(methods.length);
for (Method method : methods) {
result.add(BridgeMethodResolver.findBridgedMethod(method));
}
return result.toArray(new Method[0]);
}
private <S, E> E[] getSorted(S source, Function<S, E[]> elements, Function<E, String> name) {
E[] result = elements.apply(source);
Arrays.sort(result, Comparator.comparing(name));
return result;
}
protected void addProperties(Method[] declaredMethods, Field[] declaredFields) {
@Nullable Method[] methods = new Method[declaredMethods.length];
for (int i = 0; i < declaredMethods.length; i++) {
methods[i] = isCandidate(declaredMethods[i]) ? declaredMethods[i] : null;
}
for (Method method : methods) {
addMethodIfPossible(method, "is", 0, BeanProperty::addGetter);
}
for (Method method : methods) {
addMethodIfPossible(method, "get", 0, BeanProperty::addGetter);
}
for (Method method : methods) {
addMethodIfPossible(method, "set", 1, BeanProperty::addSetter);
}
for (Field field : declaredFields) {
addField(field);
}
}
private boolean isCandidate(Method method) {
int modifiers = method.getModifiers();
return !Modifier.isPrivate(modifiers) && !Modifier.isProtected(modifiers) && !Modifier.isAbstract(modifiers)
&& !Modifier.isStatic(modifiers) && !method.isBridge()
&& !Object.class.equals(method.getDeclaringClass())
&& !Class.class.equals(method.getDeclaringClass()) && method.getName().indexOf('$') == -1;
}
private void addMethodIfPossible(@Nullable Method method, String prefix, int parameterCount,
BiConsumer<BeanProperty, Method> consumer) {
if (method != null && method.getParameterCount() == parameterCount && method.getName().startsWith(prefix)
&& method.getName().length() > prefix.length()) {
String propertyName = Introspector.decapitalize(method.getName().substring(prefix.length()));
consumer.accept(this.properties.computeIfAbsent(propertyName, this::getBeanProperty), method);
}
}
private BeanProperty getBeanProperty(String name) {
return new BeanProperty(name, this.type);
}
private void addField(Field field) {
BeanProperty property = this.properties.get(field.getName());
if (property != null) {
property.addField(field);
}
}
protected final ResolvableType getType() {
return this.type;
}
protected final Class<?> getResolvedType() {
return this.resolvedType;
}
final Map<String, BeanProperty> getProperties() {
return this.properties;
}
static BeanProperties of(Bindable<?> bindable) {
ResolvableType type = bindable.getType();
Class<?> resolvedType = type.resolve(Object.class);
return new BeanProperties(type, resolvedType);
}
}
Domain
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free