Class JavaPackage
java.lang.Object
org.springframework.modulith.core.JavaPackage
- All Implemented Interfaces:
com.tngtech.archunit.base.DescribedIterable<com.tngtech.archunit.core.domain.JavaClass>
,com.tngtech.archunit.base.HasDescription
,Comparable<JavaPackage>
,Iterable<com.tngtech.archunit.core.domain.JavaClass>
public class JavaPackage
extends Object
implements com.tngtech.archunit.base.DescribedIterable<com.tngtech.archunit.core.domain.JavaClass>, Comparable<JavaPackage>
An abstraction of a Java package.
- Author:
- Oliver Drotbohm
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.tngtech.archunit.base.DescribedIterable
com.tngtech.archunit.base.DescribedIterable.From
-
Method Summary
Modifier and TypeMethodDescription(package private) Stream<JavaPackage>
andSubPackagesAnnotatedWith
(Class<? extends Annotation> type) Returns a newStream
of the current package and all its sub-packages annotated with the given annotation type.(package private) String
asFilter()
Returns a filter expression including all types within that package and any nested package.int
boolean
contains
(com.tngtech.archunit.core.domain.JavaClass type) Return whether theJavaPackage
contains the given type.boolean
Returns whether theJavaPackage
contains the type with the given name.boolean
<A extends Annotation>
Optional<A>findAnnotation
(Class<A> annotationType) Finds the annotation of the given type declared on the package itself or any type located the direct package's types .<A extends Annotation>
Optional<A>getAnnotation
(Class<A> annotationType) Return the annotation of the given type declared on the package.Returns all classes residing in the current package and potentially in sub-packages if the current package was created to include them.(package private) Classes
getClasses
(Iterable<JavaPackage> exclusions) Returns all Classes residing in the current package but not in any of the given sub-packages.Returns all direct sub-packages of the current one.Returns the classes exposed by this package, i.e. only public ones.Returns the local name of the package, i.e. the last segment of the qualified package name.getName()
Returns the name of the package.(package private) PackageName
Returns the name of the package.(package private) Optional<JavaPackage>
getSubPackage
(String localName) Returns the sub-package with the given local name.(package private) JavaPackages
Returns aJavaPackages
instance representing all sub-packages.getSubPackagesAnnotatedWith
(Class<? extends Annotation> annotation) Returns all sub-packages that carry the given annotation type.Returns the name of the givenJavaPackage
with regards to the current one.int
hashCode()
static boolean
isPackageInfoType
(com.tngtech.archunit.core.domain.JavaClass type) Returns whether the given type is thepackage-info.java
one.(package private) boolean
isSubPackageOf
(JavaPackage reference) Returns whether the given reference package is a sub-package of the current one.Iterator<com.tngtech.archunit.core.domain.JavaClass>
iterator()
static JavaPackage
Creates a newJavaPackage
for the given classes and name.(package private) static Comparator<JavaPackage>
reverse()
Stream<com.tngtech.archunit.core.domain.JavaClass>
stream()
that
(com.tngtech.archunit.base.DescribedPredicate<? super com.tngtech.archunit.core.domain.JavaClass> predicate) Returns allClasses
that match the givenDescribedPredicate
.toSingle()
Reduces theJavaPackage
to only its base package.toString()
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Method Details
-
of
Creates a newJavaPackage
for the given classes and name.- Parameters:
classes
- must not be null.name
- must not be null or empty.- Returns:
-
isPackageInfoType
public static boolean isPackageInfoType(com.tngtech.archunit.core.domain.JavaClass type) Returns whether the given type is thepackage-info.java
one.- Parameters:
type
- must not be null.
-
getName
Returns the name of the package.- Returns:
- will never be null.
-
getTrailingName
Returns the name of the givenJavaPackage
with regards to the current one.- Parameters:
pkg
- must not be null.- Returns:
- will never be null.
- Since:
- 1.3
-
toSingle
Reduces theJavaPackage
to only its base package.- Returns:
- will never be null.
-
getLocalName
Returns the local name of the package, i.e. the last segment of the qualified package name.- Returns:
- will never be null.
-
getDirectSubPackages
Returns all direct sub-packages of the current one.- Returns:
- will never be null.
-
getClasses
Returns all classes residing in the current package and potentially in sub-packages if the current package was created to include them.- Returns:
- will never be null.
-
getExposedClasses
Returns the classes exposed by this package, i.e. only public ones. Also filters thepackage-info
type.- Returns:
- will never be null.
-
getSubPackagesAnnotatedWith
Returns all sub-packages that carry the given annotation type.- Parameters:
annotation
- must not be null.- Returns:
- will never be null.
-
that
public Classes that(com.tngtech.archunit.base.DescribedPredicate<? super com.tngtech.archunit.core.domain.JavaClass> predicate) Returns allClasses
that match the givenDescribedPredicate
.- Parameters:
predicate
- must not be null.- Returns:
- will never be null.
-
contains
public boolean contains(com.tngtech.archunit.core.domain.JavaClass type) Return whether theJavaPackage
contains the given type.- Parameters:
type
- must not be null.
-
contains
Returns whether theJavaPackage
contains the type with the given name.- Parameters:
typeName
- must not be null or empty.
-
stream
- Returns:
- will never be null.
-
getAnnotation
Return the annotation of the given type declared on the package.- Type Parameters:
A
- the annotation type.- Parameters:
annotationType
- the annotation type to be found.- Returns:
- will never be null.
-
getPackageName
PackageName getPackageName()Returns the name of the package.- Returns:
- will never be null.
- Since:
- 1.3
-
asFilter
String asFilter()Returns a filter expression including all types within that package and any nested package.- Returns:
- will never be null.
- Since:
- 1.3
-
andSubPackagesAnnotatedWith
Returns a newStream
of the current package and all its sub-packages annotated with the given annotation type.- Parameters:
type
- must not be null.- Returns:
- will never be null.
- Since:
- 1.3
-
isSubPackageOf
Returns whether the given reference package is a sub-package of the current one.- Parameters:
reference
- must not be null.- Returns:
- will never be null.
- Since:
- 1.3
-
getClasses
Returns all Classes residing in the current package but not in any of the given sub-packages.- Parameters:
exclusions
- must not be null.- Returns:
- will never be null.
- Since:
- 1.3
-
getSubPackages
JavaPackages getSubPackages()Returns aJavaPackages
instance representing all sub-packages.- Returns:
- will never be null.
- Since:
- 1.3
-
getSubPackage
Returns the sub-package with the given local name.- Parameters:
localName
- must not be null or empty.- Returns:
- will never be null.
- Since:
- 1.3
-
findAnnotation
Finds the annotation of the given type declared on the package itself or any type located the direct package's types .- Type Parameters:
A
- the type of the annotation.- Parameters:
annotationType
- must not be null.- Returns:
- will never be null.
- Throws:
IllegalStateException
- in case multiple types in the current package are annotated with the given annotation.- Since:
- 1.2
-
getDescription
- Specified by:
getDescription
in interfacecom.tngtech.archunit.base.HasDescription
-
iterator
-
compareTo
- Specified by:
compareTo
in interfaceComparable<JavaPackage>
-
toString
-
equals
-
hashCode
public int hashCode() -
reverse
-