Class JavaPackage

java.lang.Object
com.tngtech.archunit.core.domain.JavaPackage
All Implemented Interfaces:
HasDescription, CanBeAnnotated, HasAnnotations<JavaPackage>, HasName

@PublicAPI(usage=ACCESS) public final class JavaPackage extends Object implements HasName, HasAnnotations<JavaPackage>
Represents a package of Java classes as defined by the Java Language Specification. I.e. a namespace/group for related classes, where each package can also contain further subpackages. Thus, packages define a hierarchical tree-like structure.
An example would be the package java.lang which contains java.lang.Object.
ArchUnit will consider the "classes of a package" to be the classes residing directly within the package. Furthermore, "subpackages" of a package are considered packages that are residing directly within this package. On the contrary, ArchUnit will call the hierarchical tree-like structure consisting of all packages that can be reached by traversing subpackages, subpackages of subpackages, etc., as "package tree".

Take for example the classes

 com.example.TopLevel
 com.example.first.First
 com.example.first.nested.FirstNested
 com.example.first.nested.deeper_nested.FirstDeeperNested
 com.example.second.Second
 com.example.second.nested.SecondNested
 
Then the package com.example would contain only the class com.example.TopLevel. It would also contain two subpackages com.example.first and com.example.second (but not com.example.first.nested as that is not directly contained within com.example).
The package tree of com.example would contain all packages (and classes within)

 com.example
 com.example.first
 com.example.first.nested
 com.example.first.nested.deeper_nested
 com.example.second
 com.example.second.nested