Class BeanUtils

java.lang.Object
tech.guilhermekaua.spigotboot.core.utils.BeanUtils

public final class BeanUtils extends Object
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 Details

    • BeanUtils

      public BeanUtils()
  • Method Details

    • getQualifier

      public static String getQualifier(@NotNull @NotNull AnnotatedElement element)
      Retrieves the qualifier value from the Qualifier annotation 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 null if no Qualifier annotation is present
    • getIsPrimary

      public static boolean getIsPrimary(@NotNull @NotNull AnnotatedElement element)
      Determines if the given annotated element is marked as the primary bean using the Primary annotation.

      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:
      true if the element has the Primary annotation, false otherwise
    • 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, a CircularDependencyException is thrown with the cycle path for debugging.

      Parameters:
      newDependencyClass - the class being registered as a new dependency, not null
      dependencyMap - 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