Class ScanningForClassUtils

java.lang.Object
ru.objectsfill.utils.ScanningForClassUtils

public class ScanningForClassUtils extends Object
Utility class for scanning classes and retrieving annotated instances or implementations of interfaces.
  • Method Details

    • scanProjectForAnnotationAndCastToInterface

      public static <T extends Annotation, K> List<K> scanProjectForAnnotationAndCastToInterface(Class<T> annotationClazz, Class<K> castInterface)
      Scans the project for classes annotated with a specific annotation and casts them to a given interface.
      Type Parameters:
      T - the type of the annotation
      K - the type of the interface
      Parameters:
      annotationClazz - the class object representing the annotation to scan for
      castInterface - the class object representing the interface to cast the annotated classes to
      Returns:
      a list of instances of the annotated classes casted to the specified interface
    • scanClassImplInterface

      public static <T> List<T> scanClassImplInterface(Class<T> castInterface, String packagePath)
      Scans the classpath for classes implementing a specific interface.
      Type Parameters:
      T - the type of the interface
      Parameters:
      castInterface - the class object representing the interface to scan for implementations
      packagePath - the package path to scan for classes
      Returns:
      a list of instances of the classes implementing the specified interface
    • deduceMainApplicationClass

      public static Class<?> deduceMainApplicationClass()
      Deduces the main application class by inspecting the stack trace.
      Returns:
      the main application class, or null if it cannot be deduced