Class BeanUtils
java.lang.Object
tech.guilhermekaua.spigotboot.core.utils.BeanUtils
Utility class providing helper methods for bean management in the Spigot Boot dependency injection system.
This class handles qualifier extraction, primary bean detection, and circular dependency detection during bean registration. It supports constructor, field, and setter injection analysis.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voiddetectCircularDependencies(@NotNull Class<?> newDependencyClass, @NotNull Map<Class<?>, List<BeanDefinition>> dependencyMap) Detects circular dependencies in the dependency graph during bean registration.static booleangetIsPrimary(@NotNull AnnotatedElement element) Determines if the given annotated element is marked as the primary bean using thePrimaryannotation.static StringgetQualifier(@NotNull AnnotatedElement element) Retrieves the qualifier value from theQualifierannotation on the given annotated element, if present.
-
Constructor Details
-
BeanUtils
public BeanUtils()
-
-
Method Details
-
getQualifier
Retrieves the qualifier value from theQualifierannotation on the given annotated element, if present.The qualifier is used to disambiguate beans of the same type during dependency resolution.
- Parameters:
element- the annotated element (e.g., field, parameter, or method) to inspect, not null- Returns:
- the qualifier string value, or
nullif noQualifierannotation is present
-
getIsPrimary
Determines if the given annotated element is marked as the primary bean using thePrimaryannotation.Primary beans are preferred during autowiring when multiple candidates exist for the same type.
- Parameters:
element- the annotated element (e.g., class or bean definition) to check, not null- Returns:
trueif the element has thePrimaryannotation,falseotherwise
-
detectCircularDependencies
public static void detectCircularDependencies(@NotNull @NotNull Class<?> newDependencyClass, @NotNull @NotNull Map<Class<?>, List<BeanDefinition>> dependencyMap) Detects circular dependencies in the dependency graph during bean registration.This method performs a depth-first search to analyze dependencies from constructors, fields, and setter methods annotated with
Inject. It checks both the new class being registered and existing dependencies in the map. If a cycle is found, aCircularDependencyExceptionis thrown with the cycle path for debugging.- Parameters:
newDependencyClass- the class being registered as a new dependency, not nulldependencyMap- the current map of registered dependencies mapping types to their instances, not null- Throws:
CircularDependencyException- if a circular dependency path is detected in the graph
-