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, Iterable<com.tngtech.archunit.core.domain.JavaClass>

public class JavaPackage extends Object implements com.tngtech.archunit.base.DescribedIterable<com.tngtech.archunit.core.domain.JavaClass>
An abstraction of a Java package.
Author:
Oliver Drotbohm
  • Method Details

    • of

      public static JavaPackage of(Classes classes, String name)
      Creates a new JavaPackage 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 the package-info.java one.
      Parameters:
      type - must not be null.
    • getName

      public String getName()
      Returns the name of the package.
      Returns:
      will never be null.
    • toSingle

      public JavaPackage toSingle()
      Reduces the JavaPackage to only its base package.
      Returns:
      will never be null.
    • getLocalName

      public String getLocalName()
      Returns the local name of the package, i.e. the last segment of the qualified package name.
      Returns:
      will never be null.
    • getDirectSubPackages

      public Collection<JavaPackage> getDirectSubPackages()
      Returns all direct sub-packages of the current one.
      Returns:
      will never be null.
    • getClasses

      public Classes 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

      public Classes getExposedClasses()
      Returns the classes exposed by this package, i.e. only public ones. Also filters the package-info type.
      Returns:
      will never be null.
    • getSubPackagesAnnotatedWith

      public Stream<JavaPackage> getSubPackagesAnnotatedWith(Class<? extends Annotation> annotation)
      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 all Classes that match the given DescribedPredicate.
      Parameters:
      predicate - must not be null.
      Returns:
    • contains

      public boolean contains(com.tngtech.archunit.core.domain.JavaClass type)
      Return whether the JavaPackage contains the given type.
      Parameters:
      type - must not be null.
    • contains

      public boolean contains(String typeName)
      Returns whether the JavaPackage contains the type with the given name.
      Parameters:
      typeName - must not be null or empty.
    • stream

      public Stream<com.tngtech.archunit.core.domain.JavaClass> stream()
      Returns a Stream of all JavaClasses contained in the JavaPackage.
      Returns:
      will never be null.
    • getAnnotation

      public <A extends Annotation> Optional<A> getAnnotation(Class<A> annotationType)
      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.
    • findAnnotation

      public <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 .
      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

      public String getDescription()
      Specified by:
      getDescription in interface com.tngtech.archunit.base.HasDescription
    • iterator

      public Iterator<com.tngtech.archunit.core.domain.JavaClass> iterator()
      Specified by:
      iterator in interface Iterable<com.tngtech.archunit.core.domain.JavaClass>
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object