Class PackageInfo
- All Implemented Interfaces:
Annotatable
Package object providing convenient access to package metadata and annotations.
This class provides a cached wrapper around Java Package objects, extending the standard API with
convenient methods for accessing package annotations and metadata. Instances are cached and reused for efficiency.
Features:
- Cached instances - package info objects are cached and reused
- Annotation support - get annotations declared on the package
- Convenient access - easy access to package name and metadata
- Thread-safe - instances are immutable and safe for concurrent access
Use Cases:
- Accessing package-level annotations
- Working with package metadata
- Building frameworks that need to analyze package information
Usage:
See Also:
ClassInfo- Class introspection- Reflection Package
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturnstrue if the specified object is equal to this package.Returns the type of this annotatable object.Returns all annotations on this package, wrapped inAnnotationInfoobjects.<A extends Annotation>
Stream<AnnotationInfo<A>>getAnnotations(Class<A> type) Returns this package's annotations of the specified type (including repeated annotations), wrapped inAnnotationInfo.Returns the title of this package's implementation.Returns the name of the organization that provided this package's implementation.Returns the version of this package's implementation.getLabel()Returns a human-readable label for this annotatable element.getName()Returns the name of this package.Returns the title of the specification that this package implements.Returns the name of the organization that maintains the specification implemented by this package.Returns the version number of the specification that this package implements.inthashCode()Returns the hash code of this package.inner()Returns the wrappedPackageobject.booleanisCompatibleWith(String desired) Compares this package's specification version with a desired version.booleanisSealed()Returnstrue if this package is sealed.booleanReturnstrue if this package is sealed with respect to the specified code source URL.static PackageInfoReturns a package info wrapper around the package of the specified class.static PackageInfoReturns a package info wrapper around the specified package object.static PackageInfoReturns a package info wrapper around the package of the specified class info.toString()Returns the string representation of this package.
-
Constructor Details
-
PackageInfo
Constructor.- Parameters:
inner- The package object.
-
-
Method Details
-
of
Returns a package info wrapper around the package of the specified class.- Parameters:
childClass- The class whose package to retrieve.- Returns:
- A package info wrapper.
-
of
Returns a package info wrapper around the package of the specified class info.- Parameters:
childClass- The class info whose package to retrieve.- Returns:
- A package info wrapper.
-
of
Returns a package info wrapper around the specified package object.- Parameters:
inner- The package object.- Returns:
- A package info wrapper.
-
equals
Returnstrue if the specified object is equal to this package.Two packages are equal if they have the same name.
-
getAnnotatableType
Description copied from interface:AnnotatableReturns the type of this annotatable object.- Specified by:
getAnnotatableTypein interfaceAnnotatable- Returns:
- The type of annotatable object this represents.
-
getAnnotations
Returns all annotations on this package, wrapped inAnnotationInfoobjects.Cached and unmodifiable. Repeated annotations (from
@Repeatablecontainers) have been automatically unwrapped and are present as individual instances in the list.- Returns:
- All annotations present on this package, or an empty list if there are none.
-
getAnnotations
Returns this package's annotations of the specified type (including repeated annotations), wrapped inAnnotationInfo.Filters the cached annotations list by type.
- Type Parameters:
A- The annotation type.- Parameters:
type- The annotation type.- Returns:
- A stream of annotation infos of the specified type, never
null .
-
getImplementationTitle
Returns the title of this package's implementation.Same as calling
Package.getImplementationTitle().- Returns:
- The implementation title, or
null if it is not known. - See Also:
-
getImplementationVendor
Returns the name of the organization that provided this package's implementation.Same as calling
Package.getImplementationVendor().- Returns:
- The implementation vendor, or
null if it is not known. - See Also:
-
getImplementationVersion
Returns the version of this package's implementation.Same as calling
Package.getImplementationVersion().- Returns:
- The implementation version, or
null if it is not known. - See Also:
-
getLabel
Description copied from interface:AnnotatableReturns a human-readable label for this annotatable element.The label format depends on the type of annotatable:
CLASS_TYPE- Simple class name (e.g.,"MyClass" )METHOD_TYPE- Class and method with parameter types (e.g.,"MyClass.myMethod(String,int)" )FIELD_TYPE- Class and field name (e.g.,"MyClass.myField" )CONSTRUCTOR_TYPE- Class and constructor with parameter types (e.g.,"MyClass.MyClass(String)" )PARAMETER_TYPE- Class, method/constructor, and parameter index (e.g.,"MyClass.myMethod[0]" )PACKAGE_TYPE- Package name (e.g.,"com.example.package" )
- Specified by:
getLabelin interfaceAnnotatable- Returns:
- The human-readable label for this annotatable element.
-
getName
Returns the name of this package.Same as calling
Package.getName().Example:
PackageInfo
pi = PackageInfo.of (String.class ); Stringname =pi .getName();// "java.lang" - Returns:
- The fully-qualified name of this package.
- See Also:
-
getSpecificationTitle
Returns the title of the specification that this package implements.Same as calling
Package.getSpecificationTitle().- Returns:
- The specification title, or
null if it is not known. - See Also:
-
getSpecificationVendor
Returns the name of the organization that maintains the specification implemented by this package.Same as calling
Package.getSpecificationVendor().- Returns:
- The specification vendor, or
null if it is not known. - See Also:
-
getSpecificationVersion
Returns the version number of the specification that this package implements.Same as calling
Package.getSpecificationVersion().This version string must be a sequence of nonnegative decimal integers separated by periods and may have leading zeros.
- Returns:
- The specification version, or
null if it is not known. - See Also:
-
hashCode
Returns the hash code of this package.Same as calling
Package.hashCode(). -
inner
Returns the wrappedPackageobject.- Returns:
- The wrapped
Packageobject.
-
isCompatibleWith
Compares this package's specification version with a desired version.Same as calling
Package.isCompatibleWith(String).The version strings are compared by comparing each decimal integer in the version string.
- Parameters:
desired- The desired version.- Returns:
true if this package's specification version is compatible with the desired version.- Throws:
NumberFormatException- If the desired or current version is not in the correct format.- See Also:
-
isSealed
Returnstrue if this package is sealed.Same as calling
Package.isSealed().- Returns:
true if this package is sealed.- See Also:
-
isSealed
Returnstrue if this package is sealed with respect to the specified code source URL.Same as calling
Package.isSealed(URL).- Parameters:
url- The code source URL.- Returns:
true if this package is sealed with respect to the specified URL.- See Also:
-
toString
Returns the string representation of this package.Same as calling
Package.toString().Example:
PackageInfo
pi = PackageInfo.of (String.class ); Strings =pi .toString();// "package java.lang"
-