Package io.github.classgraph
Class PackageInfo
- java.lang.Object
-
- io.github.classgraph.PackageInfo
-
- All Implemented Interfaces:
HasName,java.lang.Comparable<PackageInfo>
public class PackageInfo extends java.lang.Object implements java.lang.Comparable<PackageInfo>, HasName
Holds metadata about a package encountered during a scan.
-
-
Field Summary
Fields Modifier and Type Field Description private AnnotationInfoListannotationInfoAnnotationInfofor any annotations on the package-info.class file, if present, else null.private java.util.Set<AnnotationInfo>annotationInfoSetUniqueAnnotationInfoobjects for any annotations on the package-info.class file, if present, else null.private java.util.Set<PackageInfo>childrenThe child packages of this package.private java.util.Map<java.lang.String,ClassInfo>memberClassNameToClassInfoSet of classes in the package.private java.lang.StringnameName of the package.private PackageInfoparentThe parent package of this package.
-
Constructor Summary
Constructors Constructor Description PackageInfo()Deerialization constructor.PackageInfo(java.lang.String packageName)Construct a PackageInfo object.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) voidaddAnnotations(AnnotationInfoList packageAnnotations)Add annotations found in a package descriptor classfile.(package private) voidaddClassInfo(ClassInfo classInfo)Merge aClassInfoobject for a package-info.class file into this PackageInfo.intcompareTo(PackageInfo o)booleanequals(java.lang.Object obj)AnnotationInfoListgetAnnotationInfo()Get any annotations on thepackage-info.classfile.AnnotationInfogetAnnotationInfo(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)Get a the annotation on this package, or null if the package does not have the annotation.AnnotationInfogetAnnotationInfo(java.lang.String annotationName)Get a the named annotation on this package, or null if the package does not have the named annotation.PackageInfoListgetChildren()The child packages of this package, or the empty list if none.ClassInfoListgetClassInfo()Get theClassInfoobjects for all classes that are members of this package.ClassInfogetClassInfo(java.lang.String className)Get theClassInfoobject for the named class in this package, or null if the class was not found in this package.ClassInfoListgetClassInfoRecursive()Get theClassInfoobjects for all classes that are members of this package or a sub-package.java.lang.StringgetName()The package name ("" for the root package).(package private) static PackageInfogetOrCreatePackage(java.lang.String packageName, java.util.Map<java.lang.String,PackageInfo> packageNameToPackageInfo, ScanSpec scanSpec)Get thePackageInfoobject for the named package, creating it if it doesn't exist, and also creatingPackageInfoobjects for any needed parent packages for which aPackageInfohas not yet been created.PackageInfogetParent()The parent package of this package, or null if this is the root package.(package private) static java.lang.StringgetParentPackageName(java.lang.String packageOrClassName)Get the name of the parent package of a parent, or the package of the named class.booleanhasAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)Check if the package has the annotation.booleanhasAnnotation(java.lang.String annotationName)Check if the package has the named annotation.inthashCode()private voidobtainClassInfoRecursive(java.util.Set<ClassInfo> reachableClassInfo)Get theClassInfoobjects within this package recursively.java.lang.StringtoString()
-
-
-
Field Detail
-
name
private java.lang.String name
Name of the package.
-
annotationInfoSet
private java.util.Set<AnnotationInfo> annotationInfoSet
UniqueAnnotationInfoobjects for any annotations on the package-info.class file, if present, else null.
-
annotationInfo
private AnnotationInfoList annotationInfo
AnnotationInfofor any annotations on the package-info.class file, if present, else null.
-
parent
private PackageInfo parent
The parent package of this package.
-
children
private java.util.Set<PackageInfo> children
The child packages of this package.
-
memberClassNameToClassInfo
private java.util.Map<java.lang.String,ClassInfo> memberClassNameToClassInfo
Set of classes in the package.
-
-
Method Detail
-
getName
public java.lang.String getName()
The package name ("" for the root package).
-
addAnnotations
void addAnnotations(AnnotationInfoList packageAnnotations)
Add annotations found in a package descriptor classfile.- Parameters:
packageAnnotations- the package annotations
-
addClassInfo
void addClassInfo(ClassInfo classInfo)
Merge aClassInfoobject 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- theClassInfoobject to add to the package.
-
getAnnotationInfo
public AnnotationInfo getAnnotationInfo(java.lang.Class<? extends java.lang.annotation.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
AnnotationInfoobject representing the annotation on this package, or null if the package does not have the annotation.
-
getAnnotationInfo
public AnnotationInfo getAnnotationInfo(java.lang.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
AnnotationInfoobject 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 thepackage-info.classfile.- Returns:
- the annotations on the
package-info.classfile.
-
hasAnnotation
public boolean hasAnnotation(java.lang.Class<? extends java.lang.annotation.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(java.lang.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(java.lang.String className)
Get theClassInfoobject 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
ClassInfoobject for the named class in this package, or null if the class was not found in this package.
-
getClassInfo
public ClassInfoList getClassInfo()
Get theClassInfoobjects for all classes that are members of this package.- Returns:
- the
ClassInfoobjects for all classes that are members of this package.
-
obtainClassInfoRecursive
private void obtainClassInfoRecursive(java.util.Set<ClassInfo> reachableClassInfo)
Get theClassInfoobjects within this package recursively.- Parameters:
reachableClassInfo- the reachable class info
-
getClassInfoRecursive
public ClassInfoList getClassInfoRecursive()
Get theClassInfoobjects for all classes that are members of this package or a sub-package.- Returns:
- the the
ClassInfoobjects for all classes that are members of this package or a sub-package.
-
getParentPackageName
static java.lang.String getParentPackageName(java.lang.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(java.lang.String packageName, java.util.Map<java.lang.String,PackageInfo> packageNameToPackageInfo, ScanSpec scanSpec)
Get thePackageInfoobject for the named package, creating it if it doesn't exist, and also creatingPackageInfoobjects for any needed parent packages for which aPackageInfohas not yet been created.- Parameters:
packageName- the package namepackageNameToPackageInfo- a map from package name to package infoscanSpec- the ScanSpec.- Returns:
- the
PackageInfofor the named package.
-
compareTo
public int compareTo(PackageInfo o)
- Specified by:
compareToin interfacejava.lang.Comparable<PackageInfo>
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-