Home / Class/ Bindable Class — spring-boot Architecture

Bindable Class — spring-boot Architecture

Architecture documentation for the Bindable class in PropertyDescriptorResolver.java from the spring-boot codebase.

Entity Profile

Source Code

configuration-metadata/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/PropertyDescriptorResolver.java lines 164–239

	private static class Bindable {

		private final TypeElement type;

		private final List<ExecutableElement> constructors;

		private final List<ExecutableElement> boundConstructors;

		Bindable(TypeElement type, List<ExecutableElement> constructors, List<ExecutableElement> boundConstructors) {
			this.type = type;
			this.constructors = constructors;
			this.boundConstructors = boundConstructors;
		}

		TypeElement getType() {
			return this.type;
		}

		boolean isConstructorBindingEnabled() {
			return !this.boundConstructors.isEmpty();
		}

		ExecutableElement getBindConstructor() {
			if (this.boundConstructors.isEmpty()) {
				return findBoundConstructor();
			}
			if (this.boundConstructors.size() == 1) {
				return this.boundConstructors.get(0);
			}
			return null;
		}

		private ExecutableElement findBoundConstructor() {
			ExecutableElement boundConstructor = null;
			for (ExecutableElement candidate : this.constructors) {
				if (!candidate.getParameters().isEmpty()) {
					if (boundConstructor != null) {
						return null;
					}
					boundConstructor = candidate;
				}
			}
			return boundConstructor;
		}

		static Bindable of(TypeElement type, MetadataGenerationEnvironment env) {
			List<ExecutableElement> constructors = ElementFilter.constructorsIn(type.getEnclosedElements());
			List<ExecutableElement> boundConstructors = getBoundConstructors(type, env, constructors);
			return new Bindable(type, constructors, boundConstructors);
		}

		private static List<ExecutableElement> getBoundConstructors(TypeElement type, MetadataGenerationEnvironment env,
				List<ExecutableElement> constructors) {
			ExecutableElement bindConstructor = deduceBindConstructor(type, constructors, env);
			if (bindConstructor != null) {
				return Collections.singletonList(bindConstructor);
			}
			return constructors.stream().filter(env::hasConstructorBindingAnnotation).toList();
		}

		private static ExecutableElement deduceBindConstructor(TypeElement type, List<ExecutableElement> constructors,
				MetadataGenerationEnvironment env) {
			if (constructors.size() == 1) {
				ExecutableElement candidate = constructors.get(0);
				if (!candidate.getParameters().isEmpty() && !env.hasAutowiredAnnotation(candidate)) {
					if (type.getNestingKind() == NestingKind.MEMBER
							&& candidate.getModifiers().contains(Modifier.PRIVATE)) {
						return null;
					}
					return candidate;
				}
			}
			return null;
		}

	}

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free