Package io.github.classgraph
Class PackageInfo
java.lang.Object
io.github.classgraph.PackageInfo
- All Implemented Interfaces:
HasName,Comparable<PackageInfo>
Holds metadata about a package encountered during a scan.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate AnnotationInfoListAnnotationInfofor any annotations on the package-info.class file, if present, else null.private Set<AnnotationInfo> UniqueAnnotationInfoobjects for any annotations on the package-info.class file, if present, else null.private Set<PackageInfo> The child packages of this package.Set of classes in the package.private StringName of the package.private PackageInfoThe parent package of this package. -
Constructor Summary
ConstructorsConstructorDescriptionDeerialization constructor.PackageInfo(String packageName) Construct a PackageInfo object. -
Method Summary
Modifier and TypeMethodDescription(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.intbooleanGet any annotations on thepackage-info.classfile.getAnnotationInfo(Class<? extends Annotation> annotation) Get a the annotation on this package, or null if the package does not have the annotation.getAnnotationInfo(String annotationName) Get a the named annotation on this package, or null if the package does not have the named annotation.The child packages of this package, or the empty list if none.Get theClassInfoobjects for all classes that are members of this package.getClassInfo(String className) Get theClassInfoobject for the named class in this package, or null if the class was not found in this package.Get theClassInfoobjects for all classes that are members of this package or a sub-package.getName()The package name ("" for the root package).(package private) static PackageInfogetOrCreatePackage(String packageName, Map<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.The parent package of this package, or null if this is the root package.(package private) static StringgetParentPackageName(String packageOrClassName) Get the name of the parent package of a parent, or the package of the named class.booleanhasAnnotation(Class<? extends Annotation> annotation) Check if the package has the annotation.booleanhasAnnotation(String annotationName) Check if the package has the named annotation.inthashCode()private voidobtainClassInfoRecursive(Set<ClassInfo> reachableClassInfo) Get theClassInfoobjects within this package recursively.toString()
-
Field Details
-
name
Name of the package. -
annotationInfoSet
UniqueAnnotationInfoobjects for any annotations on the package-info.class file, if present, else null. -
annotationInfo
AnnotationInfofor any annotations on the package-info.class file, if present, else null. -
parent
The parent package of this package. -
children
The child packages of this package. -
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
The package name ("" for the root package). -
addAnnotations
Add annotations found in a package descriptor classfile.- Parameters:
packageAnnotations- the package annotations
-
addClassInfo
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
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
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
Get any annotations on thepackage-info.classfile.- Returns:
- the annotations on the
package-info.classfile.
-
hasAnnotation
Check if the package has the annotation.- Parameters:
annotation- The annotation.- Returns:
- true if this package has the annotation.
-
hasAnnotation
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
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
The child packages of this package, or the empty list if none.- Returns:
- the child packages, or the empty list if none.
-
getClassInfo
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
Get theClassInfoobjects for all classes that are members of this package.- Returns:
- the
ClassInfoobjects for all classes that are members of this package.
-
obtainClassInfoRecursive
Get theClassInfoobjects within this package recursively.- Parameters:
reachableClassInfo- the reachable class info
-
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
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 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
- Specified by:
compareToin interfaceComparable<PackageInfo>
-
hashCode
public int hashCode() -
equals
-
toString
-