Class PackageInfo

java.lang.Object
io.github.classgraph.PackageInfo
All Implemented Interfaces:
HasName, Comparable<PackageInfo>

public class PackageInfo extends Object implements Comparable<PackageInfo>, HasName
Holds metadata about a package encountered during a scan.
  • Field Details

    • name

      private String name
      Name of the package.
    • annotationInfoSet

      private Set<AnnotationInfo> annotationInfoSet
      Unique AnnotationInfo objects for any annotations on the package-info.class file, if present, else null.
    • annotationInfo

      private AnnotationInfoList annotationInfo
      AnnotationInfo for any annotations on the package-info.class file, if present, else null.
    • parent

      private PackageInfo parent
      The parent package of this package.
    • children

      private Set<PackageInfo> children
      The child packages of this package.
    • memberClassNameToClassInfo

      private Map<String,ClassInfo> memberClassNameToClassInfo
      Set of classes in the package.
  • Constructor Details

    • PackageInfo

      PackageInfo()
      Deerialization constructor.
    • PackageInfo

      PackageInfo(String packageName)
      Construct a PackageInfo object.
      Parameters:
      packageName - the package name
  • Method Details

    • getName

      public String getName()
      The package name ("" for the root package).
      Specified by:
      getName in interface HasName
      Returns:
      the name
    • addAnnotations

      void addAnnotations(AnnotationInfoList packageAnnotations)
      Add annotations found in a package descriptor classfile.
      Parameters:
      packageAnnotations - the package annotations
    • addClassInfo

      void addClassInfo(ClassInfo classInfo)
      Merge a ClassInfo object for a package-info.class file into this PackageInfo. (The same package-info.class file may be present in multiple definitions of the package in different modules.)
      Parameters:
      classInfo - the ClassInfo object to add to the package.
    • getAnnotationInfo

      public AnnotationInfo getAnnotationInfo(Class<? extends Annotation> annotation)
      Get a the annotation on this package, or null if the package does not have the annotation.
      Parameters:
      annotation - The annotation.
      Returns:
      An AnnotationInfo object representing the annotation on this package, or null if the package does not have the annotation.
    • getAnnotationInfo

      public AnnotationInfo getAnnotationInfo(String annotationName)
      Get a the named annotation on this package, or null if the package does not have the named annotation.
      Parameters:
      annotationName - The annotation name.
      Returns:
      An AnnotationInfo object representing the named annotation on this package, or null if the package does not have the named annotation.
    • getAnnotationInfo

      public AnnotationInfoList getAnnotationInfo()
      Get any annotations on the package-info.class file.
      Returns:
      the annotations on the package-info.class file.
    • hasAnnotation

      public boolean hasAnnotation(Class<? extends Annotation> annotation)
      Check if the package has the annotation.
      Parameters:
      annotation - The annotation.
      Returns:
      true if this package has the annotation.
    • hasAnnotation

      public boolean hasAnnotation(String annotationName)
      Check if the package has the named annotation.
      Parameters:
      annotationName - The name of an annotation.
      Returns:
      true if this package has the named annotation.
    • getParent

      public PackageInfo getParent()
      The parent package of this package, or null if this is the root package.
      Returns:
      the parent package, or null if this is the root package.
    • getChildren

      public PackageInfoList getChildren()
      The child packages of this package, or the empty list if none.
      Returns:
      the child packages, or the empty list if none.
    • getClassInfo

      public ClassInfo getClassInfo(String className)
      Get the ClassInfo object for the named class in this package, or null if the class was not found in this package.
      Parameters:
      className - the class name
      Returns:
      the ClassInfo object for the named class in this package, or null if the class was not found in this package.
    • getClassInfo

      public ClassInfoList getClassInfo()
      Get the ClassInfo objects for all classes that are members of this package.
      Returns:
      the ClassInfo objects for all classes that are members of this package.
    • obtainClassInfoRecursive

      private void obtainClassInfoRecursive(Set<ClassInfo> reachableClassInfo)
      Get the ClassInfo objects within this package recursively.
      Parameters:
      reachableClassInfo - the reachable class info
    • getClassInfoRecursive

      public ClassInfoList getClassInfoRecursive()
      Get the ClassInfo objects for all classes that are members of this package or a sub-package.
      Returns:
      the the ClassInfo objects for all classes that are members of this package or a sub-package.
    • getParentPackageName

      static String getParentPackageName(String packageOrClassName)
      Get the name of the parent package of a parent, or the package of the named class.
      Parameters:
      packageOrClassName - The package or class name.
      Returns:
      the parent package, or the package of the named class, or null if packageOrClassName is the root package ("").
    • getOrCreatePackage

      static PackageInfo getOrCreatePackage(String packageName, Map<String,PackageInfo> packageNameToPackageInfo, ScanSpec scanSpec)
      Get the PackageInfo object for the named package, creating it if it doesn't exist, and also creating PackageInfo objects for any needed parent packages for which a PackageInfo has not yet been created.
      Parameters:
      packageName - the package name
      packageNameToPackageInfo - a map from package name to package info
      scanSpec - the ScanSpec.
      Returns:
      the PackageInfo for the named package.
    • compareTo

      public int compareTo(PackageInfo o)
      Specified by:
      compareTo in interface Comparable<PackageInfo>
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object