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 newStreamof the current package and all its sub-packages annotated with the given annotation type.(package private) StringasFilter()Returns a filter expression including all types within that package and any nested package.intbooleancontains(com.tngtech.archunit.core.domain.JavaClass type) Return whether theJavaPackagecontains the given type.booleanReturns whether theJavaPackagecontains 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) ClassesgetClassesExcept(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.Returns the name of the package.(package private) Optional<JavaPackage>getSubPackage(String localName) Returns the sub-package with the given local name.(package private) JavaPackagesReturns aJavaPackagesinstance representing all sub-packages.getSubPackagesAnnotatedWith(Class<? extends Annotation> annotation) Returns all sub-packages that carry the given annotation type.Returns all sub-packages that match the givenBiPredicatefor the candidate package and its trailing name relative to the current one.Returns the name of the givenJavaPackagewith regards to the current one.inthashCode()(package private) booleanisDirectParentOf(JavaPackage reference) Returns whether the currentJavaPackageis the direct parent of the given one.static booleanisPackageInfoType(com.tngtech.archunit.core.domain.JavaClass type) Returns whether the given type is thepackage-info.javaone.(package private) booleanisParentPackageOf(JavaPackage reference) Returns whether the currentJavaPackageis a parent package of the given reference one.(package private) booleanisSubPackageOf(JavaPackage reference) Returns whether the currentJavaPackageis a sub-package of the given reference one.Iterator<com.tngtech.archunit.core.domain.JavaClass>iterator()static JavaPackageCreates a newJavaPackagefor the given classes and name.(package private) JavaPackagesonlySubPackagesExcept(Collection<JavaPackage> packages) Returns all sub-packages of the current one, except the given ones.(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 allClassesthat match the givenDescribedPredicate.toSingle()Reduces theJavaPackageto only its base package.toString()(package private) JavaPackagewithout(JavaPackages exclusions) Returns a new JavaPacMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Method Details
-
of
Creates a newJavaPackagefor 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.javaone.- Parameters:
type- must not be null.
-
getName
Returns the name of the package.- Returns:
- will never be null.
-
getTrailingName
Returns the name of the givenJavaPackagewith regards to the current one.- Parameters:
pkg- must not be null.- Returns:
- will never be null.
- Since:
- 1.3
-
toSingle
Reduces theJavaPackageto 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-infotype.- 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.
-
getSubPackagesMatching
Returns all sub-packages that match the givenBiPredicatefor the candidate package and its trailing name relative to the current one.- Parameters:
filter- must not be null.- Returns:
- will never be null.
- Since:
- 1.4
- See Also:
-
that
public Classes that(com.tngtech.archunit.base.DescribedPredicate<? super com.tngtech.archunit.core.domain.JavaClass> predicate) Returns allClassesthat 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 theJavaPackagecontains the given type.- Parameters:
type- must not be null.
-
contains
Returns whether theJavaPackagecontains 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
Returns the name of the package.- Returns:
- will never be null.
- Since:
- 1.4, package protected 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 newStreamof 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 currentJavaPackageis a sub-package of the given reference one.- Parameters:
reference- must not be null.- Since:
- 1.3
-
isParentPackageOf
Returns whether the currentJavaPackageis a parent package of the given reference one.- Parameters:
reference- must not be null.- Since:
- 1.4.2
-
getClassesExcept
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 aJavaPackagesinstance 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
-
isDirectParentOf
Returns whether the currentJavaPackageis the direct parent of the given one.- Parameters:
reference- must not be null.- Since:
- 1.4
-
getDescription
- Specified by:
getDescriptionin interfacecom.tngtech.archunit.base.HasDescription
-
iterator
-
compareTo
- Specified by:
compareToin interfaceComparable<JavaPackage>
-
toString
-
equals
-
hashCode
public int hashCode() -
reverse
-
onlySubPackagesExcept
Returns all sub-packages of the current one, except the given ones.- Parameters:
packages- will never be null.- Returns:
- will never be null.
-
without
Returns a new JavaPac- Parameters:
exclusions- allJavaPackagesto exclude.- Returns:
- will never be null.
-