Package com.tngtech.archunit.core.domain
Class JavaClass.Predicates
java.lang.Object
com.tngtech.archunit.core.domain.JavaClass.Predicates
- Enclosing class:
- JavaClass
Predefined
predicates
targeting JavaClass
.
Note that due to inheritance further predicates for JavaClass
can be found in the following locations:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final DescribedPredicate<JavaClass>
static final DescribedPredicate<JavaClass>
static final DescribedPredicate<JavaClass>
static final DescribedPredicate<JavaClass>
static final DescribedPredicate<JavaClass>
static final DescribedPredicate<JavaClass>
static final DescribedPredicate<JavaClass>
static final DescribedPredicate<JavaClass>
static final DescribedPredicate<JavaClass>
static final DescribedPredicate<JavaClass>
-
Method Summary
Modifier and TypeMethodDescriptionstatic DescribedPredicate<JavaClass>
assignableFrom
(DescribedPredicate<? super JavaClass> predicate) Same asassignableFrom(Class)
, but returnstrue
whenever the testedJavaClass
is assignable from a class that matches the supplied predicate.
This is the opposite ofassignableTo(DescribedPredicate)
: some classB
is assignable from a classA
if and only ifA
is assignable toA
.static DescribedPredicate<JavaClass>
assignableFrom
(Class<?> type) static DescribedPredicate<JavaClass>
assignableFrom
(String typeName) Same asassignableFrom(Class)
but takes a fully qualified class name as an argument instead of a class object.static DescribedPredicate<JavaClass>
assignableTo
(DescribedPredicate<? super JavaClass> predicate) Same asassignableTo(Class)
, but returnstrue
whenever the testedJavaClass
is assignable to a class that matches the supplied predicate.
This is the opposite ofassignableFrom(DescribedPredicate)
: some classA
is assignable to a classB
if and only ifB
is assignable fromA
.static DescribedPredicate<JavaClass>
assignableTo
(Class<?> type) static DescribedPredicate<JavaClass>
assignableTo
(String typeName) Same asassignableTo(Class)
but takes a fully qualified class name as an argument instead of a class object.static DescribedPredicate<JavaClass>
belongTo
(DescribedPredicate<? super JavaClass> predicate) A predicate to determine if aJavaClass
"belongs" to a class matching the given predicate, where "belong" means that thisJavaClass
is directly matching the given predicate a nested/inner/anonymous class of anotherJavaClass
matching the predicate For examplebelongTo(annotatedWith(Something.class))
would apply to the following casesstatic DescribedPredicate<JavaClass>
belongToAnyOf
(Class<?>... classes) static DescribedPredicate<JavaClass>
containAnyCodeUnitsThat
(DescribedPredicate<? super JavaCodeUnit> predicate) A predicate to determine if aJavaClass
contains one or morecode units
matching the supplied predicate.static DescribedPredicate<JavaClass>
containAnyConstructorsThat
(DescribedPredicate<? super JavaConstructor> predicate) A predicate to determine if aJavaClass
contains one or moreconstructors
matching the supplied predicate.static DescribedPredicate<JavaClass>
containAnyFieldsThat
(DescribedPredicate<? super JavaField> predicate) static DescribedPredicate<JavaClass>
containAnyMembersThat
(DescribedPredicate<? super JavaMember> predicate) static DescribedPredicate<JavaClass>
containAnyMethodsThat
(DescribedPredicate<? super JavaMethod> predicate) static DescribedPredicate<JavaClass>
containAnyStaticInitializersThat
(DescribedPredicate<? super JavaStaticInitializer> predicate) A predicate to determine if aJavaClass
contains one or morestatic initializers
matching the supplied predicate.static DescribedPredicate<JavaClass>
equivalentTo
(Class<?> clazz) static DescribedPredicate<JavaClass>
implement
(DescribedPredicate<? super JavaClass> predicate) Same asimplement(Class)
but returnstrue
whenever the testedJavaClass
implements an interface that matches the supplied predicate.static DescribedPredicate<JavaClass>
static DescribedPredicate<JavaClass>
Same asimplement(Class)
but takes a fully qualified class name as an argument instead of a class object.static DescribedPredicate<JavaClass>
resideInAnyPackage
(String... packageIdentifiers) static DescribedPredicate<JavaClass>
resideInAPackage
(String packageIdentifier) Offers a syntax to identify packages similar to AspectJ.static DescribedPredicate<JavaClass>
resideOutsideOfPackage
(String packageIdentifier) static DescribedPredicate<JavaClass>
resideOutsideOfPackages
(String... packageIdentifiers) static DescribedPredicate<JavaClass>
simpleName
(String name) static DescribedPredicate<JavaClass>
simpleNameContaining
(String infix) static DescribedPredicate<JavaClass>
simpleNameEndingWith
(String suffix) static DescribedPredicate<JavaClass>
simpleNameStartingWith
(String prefix) static DescribedPredicate<JavaClass>
-
Field Details
-
INTERFACES
-
ENUMS
-
ANNOTATIONS
-
RECORDS
-
TOP_LEVEL_CLASSES
-
NESTED_CLASSES
-
MEMBER_CLASSES
-
INNER_CLASSES
-
LOCAL_CLASSES
-
ANONYMOUS_CLASSES
-
-
Method Details
-
type
-
simpleName
-
simpleNameStartingWith
@PublicAPI(usage=ACCESS) public static DescribedPredicate<JavaClass> simpleNameStartingWith(String prefix) -
simpleNameContaining
@PublicAPI(usage=ACCESS) public static DescribedPredicate<JavaClass> simpleNameContaining(String infix) -
simpleNameEndingWith
@PublicAPI(usage=ACCESS) public static DescribedPredicate<JavaClass> simpleNameEndingWith(String suffix) -
assignableTo
- Parameters:
type
- the type to check for assignability- Returns:
- a
DescribedPredicate
that returnstrue
, if the respectiveJavaClass
is assignable to the suppliedtype
. I.e. the type represented by the testedJavaClass
could be casted to the suppliedtype
.
This is the opposite ofassignableFrom(Class)
: some classA
is assignable to a classB
if and only ifB
is assignable fromA
. - See Also:
-
assignableFrom
- Parameters:
type
- the type to check for assignability- Returns:
- a
DescribedPredicate
that returnstrue
, if the respectiveJavaClass
is assignable from the suppliedtype
. I.e. the suppliedtype
could be casted to the type represented by the testedJavaClass
.
This is the opposite ofassignableTo(Class)
: some classB
is assignable from a classA
if and only ifA
is assignable toB
. - See Also:
-
assignableTo
Same asassignableTo(Class)
but takes a fully qualified class name as an argument instead of a class object. -
assignableFrom
@PublicAPI(usage=ACCESS) public static DescribedPredicate<JavaClass> assignableFrom(String typeName) Same asassignableFrom(Class)
but takes a fully qualified class name as an argument instead of a class object. -
assignableTo
@PublicAPI(usage=ACCESS) public static DescribedPredicate<JavaClass> assignableTo(DescribedPredicate<? super JavaClass> predicate) Same asassignableTo(Class)
, but returnstrue
whenever the testedJavaClass
is assignable to a class that matches the supplied predicate.
This is the opposite ofassignableFrom(DescribedPredicate)
: some classA
is assignable to a classB
if and only ifB
is assignable fromA
. -
assignableFrom
@PublicAPI(usage=ACCESS) public static DescribedPredicate<JavaClass> assignableFrom(DescribedPredicate<? super JavaClass> predicate) Same asassignableFrom(Class)
, but returnstrue
whenever the testedJavaClass
is assignable from a class that matches the supplied predicate.
This is the opposite ofassignableTo(DescribedPredicate)
: some classB
is assignable from a classA
if and only ifA
is assignable toA
. -
implement
- Parameters:
type
- the interface type to check for- Returns:
- a
DescribedPredicate
that returnstrue
if the testedJavaClass
implements the supplied interfacetype
. I.e. the suppliedtype
must be an interface and the testedJavaClass
must be a class (it resembles delarations likeclass A implements B
, which only works for a classA
and an interfaceB
). - Throws:
ArchUnitException.InvalidSyntaxUsageException
- iftype
is not an interface- See Also:
-
implement
Same asimplement(Class)
but takes a fully qualified class name as an argument instead of a class object. -
implement
@PublicAPI(usage=ACCESS) public static DescribedPredicate<JavaClass> implement(DescribedPredicate<? super JavaClass> predicate) Same asimplement(Class)
but returnstrue
whenever the testedJavaClass
implements an interface that matches the supplied predicate. -
resideInAPackage
@PublicAPI(usage=ACCESS) public static DescribedPredicate<JavaClass> resideInAPackage(String packageIdentifier) Offers a syntax to identify packages similar to AspectJ. In particular '*' stands for any sequence of characters, '..' stands for any sequence of packages. For further details seePackageMatcher
.- Parameters:
packageIdentifier
- A string representing the identifier to match packages against- Returns:
- A
DescribedPredicate
returningtrue
if and only if the package of the testedJavaClass
matches the identifier
-
resideInAnyPackage
@PublicAPI(usage=ACCESS) public static DescribedPredicate<JavaClass> resideInAnyPackage(String... packageIdentifiers) - See Also:
-
resideOutsideOfPackage
@PublicAPI(usage=ACCESS) public static DescribedPredicate<JavaClass> resideOutsideOfPackage(String packageIdentifier) -
resideOutsideOfPackages
@PublicAPI(usage=ACCESS) public static DescribedPredicate<JavaClass> resideOutsideOfPackages(String... packageIdentifiers) -
equivalentTo
- See Also:
-
belongToAnyOf
@PublicAPI(usage=ACCESS) public static DescribedPredicate<JavaClass> belongToAnyOf(Class<?>... classes) A predicate to determine if aJavaClass
"belongs" to one of the passedclasses
, where "belong" means that thisJavaClass
is equivalent to For examplebelongToAnyOf(Outer.class)
would apply to the following casesclass Outer { // Inner would match belongToAnyOf(Outer.class) since it is an inner class of Outer class Inner {} void call() { // this anonymous class would also match belongToAnyOf(Outer.class) since it is declared within Outer new Serializable() {} } } // this class would not match, since it is neither Outer itself nor nested within the class body of Outer class Other {}
- Parameters:
classes
- Theclasses
to check theJavaClass
and its enclosing classes against- Returns:
- A
DescribedPredicate
returning true, if and only if the testedJavaClass
is equivalent to one of the suppliedclasses
or is a nested/inner/anonymous class of one of those classes. - See Also:
-
belongTo
@PublicAPI(usage=ACCESS) public static DescribedPredicate<JavaClass> belongTo(DescribedPredicate<? super JavaClass> predicate) A predicate to determine if aJavaClass
"belongs" to a class matching the given predicate, where "belong" means that thisJavaClass
is- directly matching the given predicate
- a nested/inner/anonymous class of another
JavaClass
matching the predicate
belongTo(annotatedWith(Something.class))
would apply to the following cases@Something class Outer { // Inner would match belongTo(annotatedWith(Something.class)) class Inner {} void call() { // this anonymous class would also match belongTo(annotatedWith(Something.class)) new Serializable() {} } } // this class would not match, since it does not belong to a class annotated with @Something class Other {}
- Parameters:
predicate
- Thepredicate
to check theJavaClass
and enclosing classes against- Returns:
- A
DescribedPredicate
returning true, if and only if the testedJavaClass
or one of its enclosing classes matches the given predicate.
-
containAnyMembersThat
@PublicAPI(usage=ACCESS) public static DescribedPredicate<JavaClass> containAnyMembersThat(DescribedPredicate<? super JavaMember> predicate) A predicate to determine if aJavaClass
contains one or moremembers
matching the supplied predicate.- Parameters:
predicate
- The predicate to check against theclasses'
members.- Returns:
- A
DescribedPredicate
returning true, if and only if the testedJavaClass
contains at least one member matching the given predicate.
-
containAnyFieldsThat
@PublicAPI(usage=ACCESS) public static DescribedPredicate<JavaClass> containAnyFieldsThat(DescribedPredicate<? super JavaField> predicate) A predicate to determine if aJavaClass
contains one or morefields
matching the supplied predicate.- Parameters:
predicate
- The predicate to check against theclasses'
fields.- Returns:
- A
DescribedPredicate
returning true, if and only if the testedJavaClass
contains at least one field matching the given predicate.
-
containAnyCodeUnitsThat
@PublicAPI(usage=ACCESS) public static DescribedPredicate<JavaClass> containAnyCodeUnitsThat(DescribedPredicate<? super JavaCodeUnit> predicate) A predicate to determine if aJavaClass
contains one or morecode units
matching the supplied predicate.- Parameters:
predicate
- The predicate to check against theclasses'
code units.- Returns:
- A
DescribedPredicate
returning true, if and only if the testedJavaClass
contains at least one code unit matching the given predicate.
-
containAnyMethodsThat
@PublicAPI(usage=ACCESS) public static DescribedPredicate<JavaClass> containAnyMethodsThat(DescribedPredicate<? super JavaMethod> predicate) A predicate to determine if aJavaClass
contains one or moremethods
matching the supplied predicate.- Parameters:
predicate
- The predicate to check against theclasses'
methods.- Returns:
- A
DescribedPredicate
returning true, if and only if the testedJavaClass
contains at least one method matching the given predicate.
-
containAnyConstructorsThat
@PublicAPI(usage=ACCESS) public static DescribedPredicate<JavaClass> containAnyConstructorsThat(DescribedPredicate<? super JavaConstructor> predicate) A predicate to determine if aJavaClass
contains one or moreconstructors
matching the supplied predicate.- Parameters:
predicate
- The predicate to check against theclasses'
constructors.- Returns:
- A
DescribedPredicate
returning true, if and only if the testedJavaClass
contains at least one constructor matching the given predicate.
-
containAnyStaticInitializersThat
@PublicAPI(usage=ACCESS) public static DescribedPredicate<JavaClass> containAnyStaticInitializersThat(DescribedPredicate<? super JavaStaticInitializer> predicate) A predicate to determine if aJavaClass
contains one or morestatic initializers
matching the supplied predicate.- Parameters:
predicate
- The predicate to check against theclasses'
static initializers.- Returns:
- A
DescribedPredicate
returning true, if and only if the testedJavaClass
contains at least one static initializer matching the given predicate.
-