Class ScanResultObject

java.lang.Object
io.github.classgraph.ScanResultObject
Direct Known Subclasses:
AnnotationClassRef, AnnotationEnumValue, AnnotationInfo, AnnotationParameterValue, ClassInfo, ClassMemberInfo, HierarchicalTypeSignature, ObjectTypedValueWrapper

abstract class ScanResultObject extends Object
A superclass of objects accessible from a ScanResult that are associated with a ClassInfo object.
  • Field Details

    • scanResult

      protected transient ScanResult scanResult
      The scan result.
    • classInfo

      private transient ClassInfo classInfo
      The associated ClassInfo object.
    • classRef

      protected transient Class<?> classRef
      The class ref, once the class is loaded.
  • Constructor Details

    • ScanResultObject

      ScanResultObject()
  • Method Details

    • setScanResult

      void setScanResult(ScanResult scanResult)
      Set ScanResult backreferences in info objects after scan has completed.
      Parameters:
      scanResult - the scan result
    • findReferencedClassInfo

      final Set<ClassInfo> findReferencedClassInfo(LogNode log)
      Get ClassInfo objects for any classes referenced by this object.
      Parameters:
      log - the log
      Returns:
      the referenced class info.
    • findReferencedClassInfo

      protected void findReferencedClassInfo(Map<String,ClassInfo> classNameToClassInfo, Set<ClassInfo> refdClassInfo, LogNode log)
      Get ClassInfo objects for any classes referenced by this object.
      Parameters:
      classNameToClassInfo - the map from class name to ClassInfo.
      refdClassInfo - the referenced class info
      log - the log
    • getClassName

      protected abstract String getClassName()
      The name of the class (used by getClassInfo() to fetch the ClassInfo object for the class).
      Returns:
      The class name.
    • getClassInfo

      ClassInfo getClassInfo()
      Get the ClassInfo object for the referenced class, or null if the referenced class was not encountered during scanning (i.e. no ClassInfo object was created for the class during scanning). N.B. even if this method returns null, loadClass() may be able to load the referenced class by name.
      Returns:
      The ClassInfo object for the referenced class.
    • getClassInfoNameOrClassName

      private String getClassInfoNameOrClassName()
      Get the class name by calling getClassInfo().getName(), or as a fallback, by calling getClassName().
      Returns:
      the class name
    • loadClass

      <T> Class<T> loadClass(Class<T> superclassOrInterfaceType, boolean ignoreExceptions)
      Load the class named returned by getClassInfo(), or if that returns null, the class named by getClassName(). Returns a Class<?> reference for the class, cast to the requested superclass or interface type.
      Type Parameters:
      T - the superclass or interface type
      Parameters:
      superclassOrInterfaceType - The type to cast the resulting class reference to.
      ignoreExceptions - If true, ignore classloading exceptions and return null on failure.
      Returns:
      The Class<?> reference for the referenced class, or null if the class could not be loaded (or casting failed) and ignoreExceptions is true.
      Throws:
      IllegalArgumentException - if the class could not be loaded or cast, and ignoreExceptions was false.
    • loadClass

      <T> Class<T> loadClass(Class<T> superclassOrInterfaceType)
      Load the class named returned by getClassInfo(), or if that returns null, the class named by getClassName(). Returns a Class<?> reference for the class, cast to the requested superclass or interface type.
      Type Parameters:
      T - the superclass or interface type
      Parameters:
      superclassOrInterfaceType - The type to cast the resulting class reference to.
      Returns:
      The Class<?> reference for the referenced class, or null if the class could not be loaded (or casting failed) and ignoreExceptions is true.
      Throws:
      IllegalArgumentException - if the class could not be loaded or cast, and ignoreExceptions was false.
    • loadClass

      Class<?> loadClass(boolean ignoreExceptions)
      Load the class named returned by getClassInfo(), or if that returns null, the class named by getClassName(). Returns a Class<?> reference for the class.
      Parameters:
      ignoreExceptions - If true, ignore classloading exceptions and return null on failure.
      Returns:
      The Class<?> reference for the referenced class, or null if the class could not be loaded and ignoreExceptions is true.
      Throws:
      IllegalArgumentException - if the class could not be loaded and ignoreExceptions was false.
    • loadClass

      Class<?> loadClass()
      Load the class named returned by getClassInfo(), or if that returns null, the class named by getClassName(). Returns a Class<?> reference for the class.
      Returns:
      The Class<?> reference for the referenced class.
      Throws:
      IllegalArgumentException - if the class could not be loaded.
    • toString

      protected abstract void toString(boolean useSimpleNames, StringBuilder buf)
      Render to string.
      Parameters:
      useSimpleNames - if true, use just the simple name of each class.
      buf - the buf
    • toString

      String toString(boolean useSimpleNames)
      Render to string, with simple names for classes if useSimpleNames is true.
      Parameters:
      useSimpleNames - if true, use just the simple name of each class.
      Returns:
      the string representation.
    • toStringWithSimpleNames

      public String toStringWithSimpleNames()
      Render to string, using only simple names for classes.
      Returns:
      the string representation, using simple names for classes.
    • toString

      public String toString()
      Render to string.
      Overrides:
      toString in class Object
      Returns:
      the string representation.