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
FieldsModifier 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 returnstruewhenever the testedJavaClassis assignable from a class that matches the supplied predicate.
This is the opposite ofassignableTo(DescribedPredicate): some classBis assignable from a classAif and only ifAis assignable toB.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 returnstruewhenever the testedJavaClassis assignable to a class that matches the supplied predicate.
This is the opposite ofassignableFrom(DescribedPredicate): some classAis assignable to a classBif and only ifBis 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 thisJavaClassis directly matching the given predicate a nested/inner/anonymous class of anotherJavaClassmatching 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 aJavaClasscontains one or morecode unitsmatching the supplied predicate.static DescribedPredicate<JavaClass>containAnyConstructorsThat(DescribedPredicate<? super JavaConstructor> predicate) A predicate to determine if aJavaClasscontains one or moreconstructorsmatching 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 aJavaClasscontains one or morestatic initializersmatching the supplied predicate.static DescribedPredicate<JavaClass>equivalentTo(Class<?> clazz) static DescribedPredicate<JavaClass>implement(DescribedPredicate<? super JavaClass> predicate) Same asimplement(Class)but returnstruewhenever the testedJavaClassimplements 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
DescribedPredicatethat returnstrue, if the respectiveJavaClassis assignable to the suppliedtype. I.e. the type represented by the testedJavaClasscould be casted to the suppliedtype.
This is the opposite ofassignableFrom(Class): some classAis assignable to a classBif and only ifBis assignable fromA. - See Also:
-
assignableFrom
- Parameters:
type- the type to check for assignability- Returns:
- a
DescribedPredicatethat returnstrue, if the respectiveJavaClassis assignable from the suppliedtype. I.e. the suppliedtypecould be casted to the type represented by the testedJavaClass.
This is the opposite ofassignableTo(Class): some classBis assignable from a classAif and only ifAis 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 returnstruewhenever the testedJavaClassis assignable to a class that matches the supplied predicate.
This is the opposite ofassignableFrom(DescribedPredicate): some classAis assignable to a classBif and only ifBis assignable fromA. -
assignableFrom
@PublicAPI(usage=ACCESS) public static DescribedPredicate<JavaClass> assignableFrom(DescribedPredicate<? super JavaClass> predicate) Same asassignableFrom(Class), but returnstruewhenever the testedJavaClassis assignable from a class that matches the supplied predicate.
This is the opposite ofassignableTo(DescribedPredicate): some classBis assignable from a classAif and only ifAis assignable toB. -
implement
- Parameters:
type- the interface type to check for- Returns:
- a
DescribedPredicatethat returnstrueif the testedJavaClassimplements the supplied interfacetype. I.e. the suppliedtypemust be an interface and the testedJavaClassmust be a class (it resembles delarations likeclass A implements B, which only works for a classAand an interfaceB). - Throws:
ArchUnitException.InvalidSyntaxUsageException- iftypeis 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 returnstruewhenever the testedJavaClassimplements 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
DescribedPredicatereturningtrueif and only if the package of the testedJavaClassmatches 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 thisJavaClassis 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- Theclassesto check theJavaClassand its enclosing classes against- Returns:
- A
DescribedPredicatereturning true, if and only if the testedJavaClassis equivalent to one of the suppliedclassesor 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 thisJavaClassis- directly matching the given predicate
- a nested/inner/anonymous class of another
JavaClassmatching 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- Thepredicateto check theJavaClassand enclosing classes against- Returns:
- A
DescribedPredicatereturning true, if and only if the testedJavaClassor 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 aJavaClasscontains one or moremembersmatching the supplied predicate.- Parameters:
predicate- The predicate to check against theclasses'members.- Returns:
- A
DescribedPredicatereturning true, if and only if the testedJavaClasscontains 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 aJavaClasscontains one or morefieldsmatching the supplied predicate.- Parameters:
predicate- The predicate to check against theclasses'fields.- Returns:
- A
DescribedPredicatereturning true, if and only if the testedJavaClasscontains 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 aJavaClasscontains one or morecode unitsmatching the supplied predicate.- Parameters:
predicate- The predicate to check against theclasses'code units.- Returns:
- A
DescribedPredicatereturning true, if and only if the testedJavaClasscontains 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 aJavaClasscontains one or moremethodsmatching the supplied predicate.- Parameters:
predicate- The predicate to check against theclasses'methods.- Returns:
- A
DescribedPredicatereturning true, if and only if the testedJavaClasscontains 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 aJavaClasscontains one or moreconstructorsmatching the supplied predicate.- Parameters:
predicate- The predicate to check against theclasses'constructors.- Returns:
- A
DescribedPredicatereturning true, if and only if the testedJavaClasscontains 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 aJavaClasscontains one or morestatic initializersmatching the supplied predicate.- Parameters:
predicate- The predicate to check against theclasses'static initializers.- Returns:
- A
DescribedPredicatereturning true, if and only if the testedJavaClasscontains at least one static initializer matching the given predicate.
-