Interface ClassesShould
-
Method Summary
Modifier and TypeMethodDescriptionAsserts that all classes selected by this rule access certain classes (compareonlyAccessClassesThat()
).
NOTE: This usually makes more sense the negated way, e.g.accessClassesThat
(DescribedPredicate<? super JavaClass> predicate) Asserts that all classes selected by this rule access certain classes (compareonlyAccessClassesThat(DescribedPredicate)
.
NOTE: This usually makes more sense the negated way, e.g.accessField
(Class<?> owner, String fieldName) Matches against all accesses (setting or getting) of a specific field.accessField
(String ownerName, String fieldName) Matches against all accesses (setting or getting) of a specific field.accessFieldWhere
(DescribedPredicate<? super JavaFieldAccess> predicate) Matches against accessing fields, where origin (a method or constructor) and target (a field) can be freely restricted by the supplied predicate.accessTargetWhere
(DescribedPredicate<? super JavaAccess<?>> predicate) Matches against access of arbitrary targets (compareAccessTarget
) where origin (a method or constructor) and target (a field, method or constructor) can be freely restricted by the supplied predicate.Asserts that the rule matches exactly the given class.Asserts that the rule matches exactly the class with the given fully qualified class name.beAnnotatedWith
(DescribedPredicate<? super JavaAnnotation<?>> predicate) Asserts that classes are annotated with a certain annotation, where matching annotations are determined by the supplied predicate.beAnnotatedWith
(Class<? extends Annotation> annotationType) Asserts that classes are annotated with a certain type of annotation.beAnnotatedWith
(String annotationTypeName) Asserts that classes are annotated with a certain type of annotation.beAssignableFrom
(DescribedPredicate<? super JavaClass> predicate) Asserts that classes are assignable from a certain type matching the given predicate.beAssignableFrom
(Class<?> type) Asserts that classes are assignable from a certain type (compareClass.isAssignableFrom(Class)
to terminology).beAssignableFrom
(String typeName) Asserts that classes are assignable from a certain type with the given type name.beAssignableTo
(DescribedPredicate<? super JavaClass> predicate) Asserts that classes are assignable to a certain type matching the given predicate.beAssignableTo
(Class<?> type) Asserts that classes are assignable to a certain type (compareClass.isAssignableFrom(Class)
to terminology).beAssignableTo
(String typeName) Asserts that classes are assignable to a certain type with the given type name.beEnums()
Asserts that classes are enums.Asserts that classes are interfaces.beMetaAnnotatedWith
(DescribedPredicate<? super JavaAnnotation<?>> predicate) Asserts that classes are meta-annotated with a certain annotation, where matching meta-annotations are determined by the supplied predicate.beMetaAnnotatedWith
(Class<? extends Annotation> annotationType) Asserts that classes are meta-annotated with a certain type of annotation.beMetaAnnotatedWith
(String annotationTypeName) Asserts that classes are meta-annotated with a certain type of annotation.Asserts that classes are package private.Asserts that classes are private.Asserts that classes are protected.bePublic()
Asserts that classes are public.Asserts that classes are records.callCodeUnitWhere
(DescribedPredicate<? super JavaCall<?>> predicate) Matches against code unit calls (compareJavaCodeUnit
) where origin (a code unit) and target (a code unit) can be freely restricted by the supplied predicate.callConstructor
(Class<?> owner, Class<?>... parameterTypes) Matches against a constructor call to a specific constructor (e.g.callConstructor
(String ownerName, String... parameterTypeNames) Matches against constructor call to a specific constructor (e.g.callConstructorWhere
(DescribedPredicate<? super JavaConstructorCall> predicate) Matches against constructor calls where origin (a method or constructor) and target (a constructor) can be freely restricted by the supplied predicate.callMethod
(Class<?> owner, String methodName, Class<?>... parameterTypes) Matches against a method call to a specific method (e.g.callMethod
(String ownerName, String methodName, String... parameterTypeNames) Matches against method call to a specific method (e.g.callMethodWhere
(DescribedPredicate<? super JavaMethodCall> predicate) Matches against method calls where origin (a method or constructor) and target (a method) can be freely restricted by the supplied predicate.containNumberOfElements
(DescribedPredicate<? super Integer> predicate) Asserts that the number of classes checked by this rule conforms to the supplied predicate.Asserts that all classes selected by this rule depend on certain classes.
NOTE: This usually makes more sense the negated way, e.g.dependOnClassesThat
(DescribedPredicate<? super JavaClass> predicate) Asserts that all classes selected by this rule depend on certain classes.
NOTE: This usually makes more sense the negated way, e.g.Matches against getting of a specific field (e.g.Matches against getting a specific field (e.g.getFieldWhere
(DescribedPredicate<? super JavaFieldAccess> predicate) Matches against getting of fields, where origin (a method or constructor) and target (a field) can be freely restricted by the supplied predicate.haveFullyQualifiedName
(String name) Asserts that classes have a certain fully qualified class name.haveModifier
(JavaModifier modifier) Asserts that classes have a certainJavaModifier
(e.g.haveNameMatching
(String regex) Asserts that classes have a fully qualified class name matching a given regular expression.haveNameNotMatching
(String regex) Asserts that classes have a fully qualified class name not matching a given regular expression.Asserts that classes have only final fields.Asserts that classes have only private constructors.haveSimpleName
(String name) Asserts that classes have a certain simple class name.haveSimpleNameContaining
(String infix) Asserts that classes' simple class names contain the specified infix.haveSimpleNameEndingWith
(String suffix) Asserts that classes' simple class names end with a given suffix.Asserts that classes' simple class names do not contain the specified infix.haveSimpleNameNotEndingWith
(String suffix) Asserts that classes' simple class names do not end with a given suffix.haveSimpleNameNotStartingWith
(String prefix) Asserts that classes' simple class names do not start with a given prefix.haveSimpleNameStartingWith
(String prefix) Asserts that classes' simple class names start with a given prefix.implement
(DescribedPredicate<? super JavaClass> predicate) Asserts that classes implement a certain interface matching the given predicate.Asserts that classes implement a certain interface.Asserts that classes implement a certain interface with the given type name.Asserts that the rule does not match the given class.Asserts that the rule does not match the class with the given fully qualified class name.notBeAnnotatedWith
(DescribedPredicate<? super JavaAnnotation<?>> predicate) Asserts that classes are not annotated with a certain annotation, where matching annotations are determined by the supplied predicate.notBeAnnotatedWith
(Class<? extends Annotation> annotationType) Asserts that classes are not annotated with a certain type of annotation.notBeAnnotatedWith
(String annotationTypeName) Asserts that classes are not annotated with a certain type of annotation.notBeAssignableFrom
(DescribedPredicate<? super JavaClass> predicate) Asserts that classes are not assignable from a certain type matching the given predicate.notBeAssignableFrom
(Class<?> type) Asserts that classes are not assignable from a certain type.notBeAssignableFrom
(String typeName) Asserts that classes are not assignable from a certain type with the given type name.notBeAssignableTo
(DescribedPredicate<? super JavaClass> predicate) Asserts that classes are not assignable to a certain type matching the given predicate.notBeAssignableTo
(Class<?> type) Asserts that classes are not assignable to a certain type.notBeAssignableTo
(String typeName) Asserts that classes are not assignable to a certain type with the given type name.Asserts that classes are not enums.Asserts that classes are not interfaces.notBeMetaAnnotatedWith
(DescribedPredicate<? super JavaAnnotation<?>> predicate) Asserts that classes are not meta-annotated with a certain annotation, where matching meta-annotations are determined by the supplied predicate.notBeMetaAnnotatedWith
(Class<? extends Annotation> annotationType) Asserts that classes are not meta-annotated with a certain type of annotation.notBeMetaAnnotatedWith
(String annotationTypeName) Asserts that classes are not meta-annotated with a certain type of annotation.Asserts that classes are non-package private.Asserts that classes are non-private.Asserts that classes are non-protected.Asserts that classes are non-public.Asserts that classes are not records.Asserts that classes do not have a certain fully qualified class name.notHaveModifier
(JavaModifier modifier) Asserts that classes do not have a certainJavaModifier
(e.g.notHaveSimpleName
(String name) Asserts that classes do not have a certain simple class name.notImplement
(DescribedPredicate<? super JavaClass> predicate) Asserts that classes do not implement a certain interface matching the given predicate.notImplement
(Class<?> type) Asserts that classes do not implement a certain interface.notImplement
(String typeName) Asserts that classes do not implement a certain interface with the given type name.Asserts that all classes selected by this rule ONLY access certain classes (compareaccessClassesThat()
).
E.g.onlyAccessClassesThat
(DescribedPredicate<? super JavaClass> predicate) Asserts that all classes selected by this rule ONLY access certain classes (compareaccessClassesThat(DescribedPredicate)
).
E.g.onlyAccessFieldsThat
(DescribedPredicate<? super JavaField> predicate) Matches all field accesses against the supplied predicate.onlyAccessMembersThat
(DescribedPredicate<? super JavaMember> predicate) Matches all members calls against the supplied predicate.Asserts that only certain classes access the classes selected by this rule.
E.g.onlyCallCodeUnitsThat
(DescribedPredicate<? super JavaCodeUnit> predicate) Matches all code unit calls against the supplied predicate.onlyCallConstructorsThat
(DescribedPredicate<? super JavaConstructor> predicate) Matches all constructor calls against the supplied predicate.onlyCallMethodsThat
(DescribedPredicate<? super JavaMethod> predicate) Matches all method calls against the supplied predicate.Asserts that all classes selected by this rule ONLY depend on certain classes (comparedependOnClassesThat()
).
E.g.onlyDependOnClassesThat
(DescribedPredicate<? super JavaClass> predicate) Asserts that all classes selected by this rule ONLY depend on certain classes (comparedependOnClassesThat(DescribedPredicate)
).
E.g.Asserts that only certain classes depend on the classes selected by this rule.
E.g.onlyHaveDependentClassesThat
(DescribedPredicate<? super JavaClass> predicate) Asserts that only certain classes depend on the classes selected by this rule.
E.g.resideInAnyPackage
(String... packageIdentifiers) Asserts that classes reside in a package matching any of the supplied package identifiers.resideInAPackage
(String packageIdentifier) Asserts that classes reside in a package matching the supplied package identifier.resideOutsideOfPackage
(String packageIdentifier) Asserts that classes do not reside in a package matching the supplied package identifier.resideOutsideOfPackages
(String... packageIdentifiers) Asserts that classes do not reside in a package matching any of the supplied package identifiers.Matches against setting a specific field (e.g.Matches against setting a specific field (e.g.setFieldWhere
(DescribedPredicate<? super JavaFieldAccess> predicate) Matches against setting of fields, where origin (a method or constructor) and target (a field) can be freely restricted by the supplied predicate.Asserts that all classes selected by this rule transitively depend on any matching classes.
It focuses on detecting all direct dependencies of the selected classes that are themselves matched or have any transitive dependencies on matched classes.transitivelyDependOnClassesThat
(DescribedPredicate<? super JavaClass> predicate) Asserts that all classes selected by this rule transitively depend on any matching classes.
It focuses on detecting all direct dependencies of the selected classes that are themselves matched or have any transitive dependencies on matched classes.
-
Method Details
-
haveFullyQualifiedName
Asserts that classes have a certain fully qualified class name.- Parameters:
name
- The fully qualified class name- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
notHaveFullyQualifiedName
Asserts that classes do not have a certain fully qualified class name.- Parameters:
name
- The fully qualified class name- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
haveSimpleName
Asserts that classes have a certain simple class name.- Parameters:
name
- The simple class name- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
notHaveSimpleName
Asserts that classes do not have a certain simple class name.- Parameters:
name
- The simple class name- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
haveSimpleNameStartingWith
Asserts that classes' simple class names start with a given prefix.- Parameters:
prefix
- A prefix the simple class name should start with- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
haveSimpleNameNotStartingWith
Asserts that classes' simple class names do not start with a given prefix.- Parameters:
prefix
- A prefix the simple class name should not start with- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
haveSimpleNameContaining
Asserts that classes' simple class names contain the specified infix.- Parameters:
infix
- An infix the simple class name should contain- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
haveSimpleNameNotContaining
Asserts that classes' simple class names do not contain the specified infix.- Parameters:
infix
- An infix the simple class name should not contain- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
haveSimpleNameEndingWith
Asserts that classes' simple class names end with a given suffix.- Parameters:
suffix
- A suffix the simple class name should end with- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
haveSimpleNameNotEndingWith
Asserts that classes' simple class names do not end with a given suffix.- Parameters:
suffix
- A suffix the simple class name should not end with- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
haveNameMatching
Asserts that classes have a fully qualified class name matching a given regular expression.- Parameters:
regex
- A regular expression- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
haveNameNotMatching
Asserts that classes have a fully qualified class name not matching a given regular expression.- Parameters:
regex
- A regular expression- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
resideInAPackage
Asserts that classes reside in a package matching the supplied package identifier.- Parameters:
packageIdentifier
- A string identifying packages, for details seePackageMatcher
- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
resideInAnyPackage
Asserts that classes reside in a package matching any of the supplied package identifiers.- Parameters:
packageIdentifiers
- Strings identifying packages, for details seePackageMatcher
- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
resideOutsideOfPackage
Asserts that classes do not reside in a package matching the supplied package identifier.- Parameters:
packageIdentifier
- A string identifying packages, for details seePackageMatcher
- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
resideOutsideOfPackages
@PublicAPI(usage=ACCESS) ClassesShouldConjunction resideOutsideOfPackages(String... packageIdentifiers) Asserts that classes do not reside in a package matching any of the supplied package identifiers.- Parameters:
packageIdentifiers
- Strings identifying packages, for details seePackageMatcher
- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
bePublic
Asserts that classes are public.- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
notBePublic
Asserts that classes are non-public.- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
beProtected
Asserts that classes are protected.- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
notBeProtected
Asserts that classes are non-protected.- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
bePackagePrivate
Asserts that classes are package private.- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
notBePackagePrivate
Asserts that classes are non-package private.- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
bePrivate
Asserts that classes are private.- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
notBePrivate
Asserts that classes are non-private.- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
haveOnlyFinalFields
Asserts that classes have only final fields.- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
haveOnlyPrivateConstructors
Asserts that classes have only private constructors.- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
haveModifier
Asserts that classes have a certainJavaModifier
(e.g.JavaModifier.ABSTRACT
).- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
notHaveModifier
Asserts that classes do not have a certainJavaModifier
(e.g.JavaModifier.ABSTRACT
).- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
beAnnotatedWith
@PublicAPI(usage=ACCESS) ClassesShouldConjunction beAnnotatedWith(Class<? extends Annotation> annotationType) Asserts that classes are annotated with a certain type of annotation.- Parameters:
annotationType
- Specific type ofAnnotation
- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
notBeAnnotatedWith
@PublicAPI(usage=ACCESS) ClassesShouldConjunction notBeAnnotatedWith(Class<? extends Annotation> annotationType) Asserts that classes are not annotated with a certain type of annotation.- Parameters:
annotationType
- Specific type ofAnnotation
- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
beAnnotatedWith
Asserts that classes are annotated with a certain type of annotation.- Parameters:
annotationTypeName
- Fully qualified class name of a specific type ofAnnotation
- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
notBeAnnotatedWith
Asserts that classes are not annotated with a certain type of annotation.- Parameters:
annotationTypeName
- Fully qualified class name of a specific type ofAnnotation
- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
beAnnotatedWith
@PublicAPI(usage=ACCESS) ClassesShouldConjunction beAnnotatedWith(DescribedPredicate<? super JavaAnnotation<?>> predicate) Asserts that classes are annotated with a certain annotation, where matching annotations are determined by the supplied predicate.
Note that many predefinedpredicates
can be found within a subclassPredicates
of the respective domain object or a common ancestor. For example,predicates
targetingJavaAnnotation
can be found within one of the respective ancestors likeHasType.Predicates
.- Parameters:
predicate
- A predicate defining matchingJavaAnnotations
- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
notBeAnnotatedWith
@PublicAPI(usage=ACCESS) ClassesShouldConjunction notBeAnnotatedWith(DescribedPredicate<? super JavaAnnotation<?>> predicate) Asserts that classes are not annotated with a certain annotation, where matching annotations are determined by the supplied predicate.
Note that many predefinedpredicates
can be found within a subclassPredicates
of the respective domain object or a common ancestor. For example,predicates
targetingJavaAnnotation
can be found within one of the respective ancestors likeHasType.Predicates
.- Parameters:
predicate
- A predicate defining matchingJavaAnnotations
- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
beMetaAnnotatedWith
@PublicAPI(usage=ACCESS) ClassesShouldConjunction beMetaAnnotatedWith(Class<? extends Annotation> annotationType) Asserts that classes are meta-annotated with a certain type of annotation. A meta-annotation is an annotation that is declared on another annotation.The assertion is also successful if classes are directly annotated with the supplied annotation type.
- Parameters:
annotationType
- Specific type ofAnnotation
- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
notBeMetaAnnotatedWith
@PublicAPI(usage=ACCESS) ClassesShouldConjunction notBeMetaAnnotatedWith(Class<? extends Annotation> annotationType) Asserts that classes are not meta-annotated with a certain type of annotation. A meta-annotation is an annotation that is declared on another annotation.The assertion also fails if classes are directly annotated with the supplied annotation type.
- Parameters:
annotationType
- Specific type ofAnnotation
- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
beMetaAnnotatedWith
Asserts that classes are meta-annotated with a certain type of annotation. A meta-annotation is an annotation that is declared on another annotation.The assertion is also successful if classes are directly annotated with the supplied annotation type.
- Parameters:
annotationTypeName
- Fully qualified class name of a specific type ofAnnotation
- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
notBeMetaAnnotatedWith
Asserts that classes are not meta-annotated with a certain type of annotation. A meta-annotation is an annotation that is declared on another annotation.The assertion also fails if classes are directly annotated with the supplied annotation type.
- Parameters:
annotationTypeName
- Fully qualified class name of a specific type ofAnnotation
- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
beMetaAnnotatedWith
@PublicAPI(usage=ACCESS) ClassesShouldConjunction beMetaAnnotatedWith(DescribedPredicate<? super JavaAnnotation<?>> predicate) Asserts that classes are meta-annotated with a certain annotation, where matching meta-annotations are determined by the supplied predicate. A meta-annotation is an annotation that is declared on another annotation.The assertion is also successful if classes are directly annotated with an annotation matching the supplied predicate.
Note that many predefinedpredicates
can be found within a subclassPredicates
of the respective domain object or a common ancestor. For example,predicates
targetingJavaAnnotation
can be found within one of the respective ancestors likeHasType.Predicates
.- Parameters:
predicate
- A predicate defining matchingJavaAnnotations
- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
notBeMetaAnnotatedWith
@PublicAPI(usage=ACCESS) ClassesShouldConjunction notBeMetaAnnotatedWith(DescribedPredicate<? super JavaAnnotation<?>> predicate) Asserts that classes are not meta-annotated with a certain annotation, where matching meta-annotations are determined by the supplied predicate. A meta-annotation is an annotation that is declared on another annotation.The assertion also fails if classes are directly annotated with an annotation matching the supplied predicate.
Note that many predefinedpredicates
can be found within a subclassPredicates
of the respective domain object or a common ancestor. For example,predicates
targetingJavaAnnotation
can be found within one of the respective ancestors likeHasType.Predicates
.- Parameters:
predicate
- A predicate defining matchingJavaAnnotations
- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
implement
Asserts that classes implement a certain interface. Note that this only matches non-interfaceclasses
that implement the supplied interfacetype
(compareJavaClass.Predicates.implement(Class)
. For general assignability seebeAssignableTo(Class)
- Parameters:
type
- An interface imported classes should implement- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
- See Also:
-
notImplement
Asserts that classes do not implement a certain interface. This is the negation ofimplement(Class)
.- Parameters:
type
- An interface imported classes should NOT implement- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
- See Also:
-
implement
Asserts that classes implement a certain interface with the given type name. This is equivalent toimplement(Class)
, but does not depend on having a certain type on the classpath. Note that this only matches non-interfaceclasses
that implement the supplied interfacetypeName
(compareJavaClass.Predicates.implement(Class)
. For general assignability seebeAssignableTo(String)
- Parameters:
typeName
- Name of an interface imported classes should implement- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
- See Also:
-
notImplement
Asserts that classes do not implement a certain interface with the given type name. This is equivalent tonotImplement(Class)
, but does not depend on having a certain type on the classpath.- Parameters:
typeName
- Name of an interface imported classes should NOT implement- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
- See Also:
-
implement
@PublicAPI(usage=ACCESS) ClassesShouldConjunction implement(DescribedPredicate<? super JavaClass> predicate) Asserts that classes implement a certain interface matching the given predicate. For example, a call withHasName.Predicates.name(String)
would be equivalent toimplement(String)
, but the approach is a lot more generic. Note that this only matches non-interfaceclasses
that implement an interface matching thepredicate
(compareJavaClass.Predicates.implement(Class)
. For general assignability seebeAssignableTo(DescribedPredicate)
Note that many predefinedpredicates
can be found within a subclassPredicates
of the respective domain object or a common ancestor. For example,predicates
targetingJavaClass
can be found withinJavaClass.Predicates
or one of the respective ancestors likeHasName.Predicates
.- Parameters:
predicate
- A predicate identifying an interface imported classes should implement- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
- See Also:
-
notImplement
@PublicAPI(usage=ACCESS) ClassesShouldConjunction notImplement(DescribedPredicate<? super JavaClass> predicate) Asserts that classes do not implement a certain interface matching the given predicate. This is the negation ofimplement(DescribedPredicate)
.
Note that many predefinedpredicates
can be found within a subclassPredicates
of the respective domain object or a common ancestor. For example,predicates
targetingJavaClass
can be found withinJavaClass.Predicates
or one of the respective ancestors likeHasName.Predicates
.- Parameters:
predicate
- A predicate identifying an interface imported classes should NOT implement- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
- See Also:
-
beAssignableTo
Asserts that classes are assignable to a certain type (compareClass.isAssignableFrom(Class)
to terminology). A simple example for this predicate would beassignableTo(Object.class).test(importedStringClass); // --> returns true assignableTo(String.class).test(importedStringClass); // --> returns true assignableTo(List.class).test(importedStringClass); // --> returns false
- Parameters:
type
- An upper type bound to match imported classes against (imported subtypes will match)- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
- See Also:
-
notBeAssignableTo
Asserts that classes are not assignable to a certain type. This is the negation ofbeAssignableTo(Class)
.- Parameters:
type
- An upper type bound imported classes should NOT have- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
- See Also:
-
beAssignableTo
Asserts that classes are assignable to a certain type with the given type name. This is equivalent tobeAssignableTo(Class)
, but does not depend on having a certain type on the classpath.- Parameters:
typeName
- Name of an upper type bound to match imported classes against (imported subtypes will match)- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
- See Also:
-
notBeAssignableTo
Asserts that classes are not assignable to a certain type with the given type name. This is equivalent tonotBeAssignableTo(Class)
, but does not depend on having a certain type on the classpath.- Parameters:
typeName
- Name of an upper type bound imported classes should NOT have- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
- See Also:
-
beAssignableTo
@PublicAPI(usage=ACCESS) ClassesShouldConjunction beAssignableTo(DescribedPredicate<? super JavaClass> predicate) Asserts that classes are assignable to a certain type matching the given predicate. For example, a call withHasName.Predicates.name(String)
would be equivalent tobeAssignableTo(String)
, but the approach is a lot more generic.
Note that many predefinedpredicates
can be found within a subclassPredicates
of the respective domain object or a common ancestor. For example,predicates
targetingJavaClass
can be found withinJavaClass.Predicates
or one of the respective ancestors likeHasName.Predicates
.- Parameters:
predicate
- A predicate identifying an upper type bound to match imported classes against (imported subtypes will match)- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
- See Also:
-
notBeAssignableTo
@PublicAPI(usage=ACCESS) ClassesShouldConjunction notBeAssignableTo(DescribedPredicate<? super JavaClass> predicate) Asserts that classes are not assignable to a certain type matching the given predicate. This is the negation ofbeAssignableTo(DescribedPredicate)
.
Note that many predefinedpredicates
can be found within a subclassPredicates
of the respective domain object or a common ancestor. For example,predicates
targetingJavaClass
can be found withinJavaClass.Predicates
or one of the respective ancestors likeHasName.Predicates
.- Parameters:
predicate
- A predicate identifying an upper type bound imported classes should NOT have- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
- See Also:
-
beAssignableFrom
Asserts that classes are assignable from a certain type (compareClass.isAssignableFrom(Class)
to terminology). This is roughly equivalent to the use of reflection:
A simple example for this predicate would besomeClass.class.isAssignableFrom(type);
assignableFrom(ArrayList.class).test(importedArrayListClass); // --> returns true assignableFrom(ArrayList.class).test(importedListClass); // --> returns true assignableFrom(ArrayList.class).test(importedStringClass); // --> returns false
- Parameters:
type
- A lower type bound to match imported classes against (imported supertypes will match)- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
- See Also:
-
notBeAssignableFrom
Asserts that classes are not assignable from a certain type. This is the negation ofbeAssignableFrom(Class)
.- Parameters:
type
- A lower type bound imported classes should NOT have- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
- See Also:
-
beAssignableFrom
Asserts that classes are assignable from a certain type with the given type name. This is equivalent tobeAssignableFrom(Class)
, but does not depend on having a certain type on the classpath.- Parameters:
typeName
- Name of a lower type bound to match imported classes against (imported supertypes will match)- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
- See Also:
-
notBeAssignableFrom
Asserts that classes are not assignable from a certain type with the given type name. This is equivalent tonotBeAssignableFrom(Class)
, but does not depend on having a certain type on the classpath.- Parameters:
typeName
- Name of a lower type bound imported classes should NOT have- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
- See Also:
-
beAssignableFrom
@PublicAPI(usage=ACCESS) ClassesShouldConjunction beAssignableFrom(DescribedPredicate<? super JavaClass> predicate) Asserts that classes are assignable from a certain type matching the given predicate. For example, a call withHasName.Predicates.name(String)
would be equivalent tobeAssignableFrom(String)
, but the approach is a lot more generic.
Note that many predefinedpredicates
can be found within a subclassPredicates
of the respective domain object or a common ancestor. For example,predicates
targetingJavaClass
can be found withinJavaClass.Predicates
or one of the respective ancestors likeHasName.Predicates
.- Parameters:
predicate
- A predicate identifying a lower type bound to match imported classes against (imported supertypes will match)- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
- See Also:
-
notBeAssignableFrom
@PublicAPI(usage=ACCESS) ClassesShouldConjunction notBeAssignableFrom(DescribedPredicate<? super JavaClass> predicate) Asserts that classes are not assignable from a certain type matching the given predicate. This is the negation ofbeAssignableFrom(DescribedPredicate)
.
Note that many predefinedpredicates
can be found within a subclassPredicates
of the respective domain object or a common ancestor. For example,predicates
targetingJavaClass
can be found withinJavaClass.Predicates
or one of the respective ancestors likeHasName.Predicates
.- Parameters:
predicate
- A predicate identifying a lower type bound imported classes should NOT have- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
- See Also:
-
accessField
Matches against all accesses (setting or getting) of a specific field.- Parameters:
owner
- The class declaring the fieldfieldName
- The name of the field to match- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
accessField
Matches against all accesses (setting or getting) of a specific field.- Parameters:
ownerName
- The fully qualified class name of the class declaring the fieldfieldName
- The name of the field to match- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
accessFieldWhere
@PublicAPI(usage=ACCESS) ClassesShouldConjunction accessFieldWhere(DescribedPredicate<? super JavaFieldAccess> predicate) Matches against accessing fields, where origin (a method or constructor) and target (a field) can be freely restricted by the supplied predicate.
Note that many predefinedpredicates
can be found within a subclassPredicates
of the respective domain object or a common ancestor. For example,predicates
targetingJavaFieldAccess
can be found withinJavaFieldAccess.Predicates
or one of the respective ancestors likeJavaAccess.Predicates
.- Parameters:
predicate
- Determines whichJavaFieldAccesses
match the rule- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
onlyAccessFieldsThat
@PublicAPI(usage=ACCESS) ClassesShouldConjunction onlyAccessFieldsThat(DescribedPredicate<? super JavaField> predicate) Matches all field accesses against the supplied predicate.
Note that many predefinedpredicates
can be found within a subclassPredicates
of the respective domain object or a common ancestor. For example,predicates
targetingJavaField
can be found withinJavaMember.Predicates
or one of the respective ancestors likeHasName.Predicates
.- Parameters:
predicate
- Determines whichJavaFields
match the rule- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
getField
Matches against getting of a specific field (e.g.return someClass.someField;
).- Parameters:
owner
- The class declaring the fieldfieldName
- The name of the field to match- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
getField
Matches against getting a specific field (e.g.return someClass.someField;
).- Parameters:
ownerName
- The fully qualified class name of the class declaring the fieldfieldName
- The name of the field to match- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
getFieldWhere
@PublicAPI(usage=ACCESS) ClassesShouldConjunction getFieldWhere(DescribedPredicate<? super JavaFieldAccess> predicate) Matches against getting of fields, where origin (a method or constructor) and target (a field) can be freely restricted by the supplied predicate.
Note that many predefinedpredicates
can be found within a subclassPredicates
of the respective domain object or a common ancestor. For example,predicates
targetingJavaFieldAccess
can be found withinJavaFieldAccess.Predicates
or one of the respective ancestors likeJavaAccess.Predicates
.- Parameters:
predicate
- Determines whichJavaFieldAccesses
match the rule- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
setField
Matches against setting a specific field (e.g.someClass.someField = newValue;
).- Parameters:
owner
- The class declaring the fieldfieldName
- The name of the field to match- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
setField
Matches against setting a specific field (e.g.someClass.someField = newValue;
).- Parameters:
ownerName
- The fully qualified class name of the class declaring the fieldfieldName
- The name of the field to match- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
setFieldWhere
@PublicAPI(usage=ACCESS) ClassesShouldConjunction setFieldWhere(DescribedPredicate<? super JavaFieldAccess> predicate) Matches against setting of fields, where origin (a method or constructor) and target (a field) can be freely restricted by the supplied predicate.
Note that many predefinedpredicates
can be found within a subclassPredicates
of the respective domain object or a common ancestor. For example,predicates
targetingJavaFieldAccess
can be found withinJavaFieldAccess.Predicates
or one of the respective ancestors likeJavaAccess.Predicates
.- Parameters:
predicate
- Determines whichJavaFieldAccesses
match the rule- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
callMethod
@PublicAPI(usage=ACCESS) ClassesShouldConjunction callMethod(Class<?> owner, String methodName, Class<?>... parameterTypes) Matches against a method call to a specific method (e.g.someClass.call();
).- Parameters:
owner
- Class declaring the methodmethodName
- The method name to match againstparameterTypes
- The parameter types of the respective method- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
callMethod
@PublicAPI(usage=ACCESS) ClassesShouldConjunction callMethod(String ownerName, String methodName, String... parameterTypeNames) Matches against method call to a specific method (e.g.someClass.call();
).- Parameters:
ownerName
- The fully qualified class name declaring the methodmethodName
- The method name to match againstparameterTypeNames
- The fully qualified parameter type names- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
callMethodWhere
@PublicAPI(usage=ACCESS) ClassesShouldConjunction callMethodWhere(DescribedPredicate<? super JavaMethodCall> predicate) Matches against method calls where origin (a method or constructor) and target (a method) can be freely restricted by the supplied predicate.
Note that many predefinedpredicates
can be found within a subclassPredicates
of the respective domain object or a common ancestor. For example,predicates
targetingJavaMethodCall
can be found withinJavaCall.Predicates
or one of the respective ancestors likeJavaAccess.Predicates
.- Parameters:
predicate
- Determines whichJavaMethodCalls
match the rule- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
onlyCallMethodsThat
@PublicAPI(usage=ACCESS) ClassesShouldConjunction onlyCallMethodsThat(DescribedPredicate<? super JavaMethod> predicate) Matches all method calls against the supplied predicate.
Note that many predefinedpredicates
can be found within a subclassPredicates
of the respective domain object or a common ancestor. For example,predicates
targetingJavaMethod
can be found withinJavaCodeUnit.Predicates
or one of the respective ancestors likeJavaMember.Predicates
.- Parameters:
predicate
- Determines whichJavaMethods
match the rule- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
callConstructor
@PublicAPI(usage=ACCESS) ClassesShouldConjunction callConstructor(Class<?> owner, Class<?>... parameterTypes) Matches against a constructor call to a specific constructor (e.g.new SomeClass();
).- Parameters:
owner
- Class declaring the constructorparameterTypes
- The parameter types of the respective constructor- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
callConstructor
@PublicAPI(usage=ACCESS) ClassesShouldConjunction callConstructor(String ownerName, String... parameterTypeNames) Matches against constructor call to a specific constructor (e.g.new SomeClass();
).- Parameters:
ownerName
- The fully qualified class name declaring the constructorparameterTypeNames
- The fully qualified parameter type names- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
callConstructorWhere
@PublicAPI(usage=ACCESS) ClassesShouldConjunction callConstructorWhere(DescribedPredicate<? super JavaConstructorCall> predicate) Matches against constructor calls where origin (a method or constructor) and target (a constructor) can be freely restricted by the supplied predicate.
Note that many predefinedpredicates
can be found within a subclassPredicates
of the respective domain object or a common ancestor. For example,predicates
targetingJavaConstructorCall
can be found withinJavaCall.Predicates
or one of the respective ancestors likeJavaAccess.Predicates
.- Parameters:
predicate
- Determines whichJavaConstructorCalls
match the rule- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
onlyCallConstructorsThat
@PublicAPI(usage=ACCESS) ClassesShouldConjunction onlyCallConstructorsThat(DescribedPredicate<? super JavaConstructor> predicate) Matches all constructor calls against the supplied predicate.
Note that many predefinedpredicates
can be found within a subclassPredicates
of the respective domain object or a common ancestor. For example,predicates
targetingJavaConstructor
can be found withinJavaCodeUnit.Predicates
or one of the respective ancestors likeJavaMember.Predicates
.- Parameters:
predicate
- Determines whichJavaConstructors
match the rule- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
accessTargetWhere
@PublicAPI(usage=ACCESS) ClassesShouldConjunction accessTargetWhere(DescribedPredicate<? super JavaAccess<?>> predicate) Matches against access of arbitrary targets (compareAccessTarget
) where origin (a method or constructor) and target (a field, method or constructor) can be freely restricted by the supplied predicate.
Note that many predefinedpredicates
can be found within a subclassPredicates
of the respective domain object or a common ancestor. For example,predicates
targetingJavaAccess
can be found withinJavaAccess.Predicates
or one of the respective ancestors likeHasName.Predicates
.- Parameters:
predicate
- Determines whichJavaAccesses
match the rule- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
onlyAccessMembersThat
@PublicAPI(usage=ACCESS) ClassesShouldConjunction onlyAccessMembersThat(DescribedPredicate<? super JavaMember> predicate) Matches all members calls against the supplied predicate.
Note that many predefinedpredicates
can be found within a subclassPredicates
of the respective domain object or a common ancestor. For example,predicates
targetingJavaMember
can be found withinJavaMember.Predicates
or one of the respective ancestors likeHasName.Predicates
.- Parameters:
predicate
- Determines whichJavaMembers
match the rule- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
callCodeUnitWhere
@PublicAPI(usage=ACCESS) ClassesShouldConjunction callCodeUnitWhere(DescribedPredicate<? super JavaCall<?>> predicate) Matches against code unit calls (compareJavaCodeUnit
) where origin (a code unit) and target (a code unit) can be freely restricted by the supplied predicate.
Note that many predefinedpredicates
can be found within a subclassPredicates
of the respective domain object or a common ancestor. For example,predicates
targetingJavaCall
can be found withinJavaCall.Predicates
or one of the respective ancestors likeJavaAccess.Predicates
.- Parameters:
predicate
- Determines whichJavaCalls
match the rule- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
onlyCallCodeUnitsThat
@PublicAPI(usage=ACCESS) ClassesShouldConjunction onlyCallCodeUnitsThat(DescribedPredicate<? super JavaCodeUnit> predicate) Matches all code unit calls against the supplied predicate.
Note that many predefinedpredicates
can be found within a subclassPredicates
of the respective domain object or a common ancestor. For example,predicates
targetingJavaCodeUnit
can be found withinJavaCodeUnit.Predicates
or one of the respective ancestors likeJavaMember.Predicates
.- Parameters:
predicate
- Determines whichJavaCodeUnits
match the rule- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
accessClassesThat
Asserts that all classes selected by this rule access certain classes (compareonlyAccessClassesThat()
).
NOTE: This usually makes more sense the negated way, e.g.
NOTE: 'access' refers only to violations by real accesses, i.e. accessing a field, and calling a method. Compare withnoClasses()
.should()
.accessClassesThat()
.haveFullyQualifiedName(String)
dependOnClassesThat()
that catches a wider variety of violations.- Returns:
- A syntax element that allows choosing which classes should be accessed
-
accessClassesThat
@PublicAPI(usage=ACCESS) ClassesShouldConjunction accessClassesThat(DescribedPredicate<? super JavaClass> predicate) Asserts that all classes selected by this rule access certain classes (compareonlyAccessClassesThat(DescribedPredicate)
.
NOTE: This usually makes more sense the negated way, e.g.
NOTE: 'access' refers only to violations by real accesses, i.e. accessing a field, and calling a method. Compare withnoClasses()
.should()
.accessClassesThat(myPredicate)
dependOnClassesThat(DescribedPredicate)
that catches a wider variety of violations.
Note that many predefinedpredicates
can be found within a subclassPredicates
of the respective domain object or a common ancestor. For example,predicates
targetingJavaClass
can be found withinJavaClass.Predicates
or one of the respective ancestors likeHasName.Predicates
.- Parameters:
predicate
- Determines whichJavaClasses
match the access target- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
onlyAccessClassesThat
Asserts that all classes selected by this rule ONLY access certain classes (compareaccessClassesThat()
).
E.g.
NOTE: 'access' refers only to violations by real accesses, i.e. accessing a field, and calling a method. Compare withclasses()
.should()
.onlyAccessClassesThat()
.haveFullyQualifiedName(String)
onlyDependOnClassesThat()
) that catches a wider variety of violations.- Returns:
- A syntax element that allows choosing which classes should only be accessed
-
onlyAccessClassesThat
@PublicAPI(usage=ACCESS) ClassesShouldConjunction onlyAccessClassesThat(DescribedPredicate<? super JavaClass> predicate) Asserts that all classes selected by this rule ONLY access certain classes (compareaccessClassesThat(DescribedPredicate)
).
E.g.
NOTE: 'access' refers only to violations by real accesses, i.e. accessing a field, and calling a method. Compare withclasses()
.should()
.onlyAccessClassesThat(myPredicate)
onlyDependOnClassesThat(DescribedPredicate)
that catches a wider variety of violations.
Note that many predefinedpredicates
can be found within a subclassPredicates
of the respective domain object or a common ancestor. For example,predicates
targetingJavaClass
can be found withinJavaClass.Predicates
or one of the respective ancestors likeHasName.Predicates
.- Parameters:
predicate
- Determines whichJavaClasses
match the access target- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
dependOnClassesThat
Asserts that all classes selected by this rule depend on certain classes.
NOTE: This usually makes more sense the negated way, e.g.
NOTE: 'dependOn' catches wide variety of violations, e.g. having fields of type, having method parameters of type, extending type etc... Compare withnoClasses()
.should()
.dependOnClassesThat()
.haveFullyQualifiedName(String)
accessClassesThat()
that catches violations only by real accesses.- Returns:
- A syntax element that allows choosing to which classes a dependency should exist
-
dependOnClassesThat
@PublicAPI(usage=ACCESS) ClassesShouldConjunction dependOnClassesThat(DescribedPredicate<? super JavaClass> predicate) Asserts that all classes selected by this rule depend on certain classes.
NOTE: This usually makes more sense the negated way, e.g.
NOTE: 'dependOn' catches wide variety of violations, e.g. having fields of type, having method parameters of type, extending type etc... Compare withnoClasses()
.should()
.dependOnClassesThat(myPredicate)
accessClassesThat(DescribedPredicate)
that catches violations only by real accesses.
Note that many predefinedpredicates
can be found within a subclassPredicates
of the respective domain object or a common ancestor. For example,predicates
targetingJavaClass
can be found withinJavaClass.Predicates
or one of the respective ancestors likeHasName.Predicates
.- Parameters:
predicate
- Determines whichJavaClasses
match the dependency target- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
onlyDependOnClassesThat
Asserts that all classes selected by this rule ONLY depend on certain classes (comparedependOnClassesThat()
).
E.g.
NOTE: 'dependOn' catches wide variety of violations, e.g. having fields of type, having method parameters of type, extending type etc... Compare withclasses()
.should()
.onlyDependOnClassesThat()
.haveFullyQualifiedName(String)
onlyAccessClassesThat()
that catches violations only by real accesses.- Returns:
- A syntax element that allows choosing to which classes a dependency should only exist
-
onlyDependOnClassesThat
@PublicAPI(usage=ACCESS) ClassesShouldConjunction onlyDependOnClassesThat(DescribedPredicate<? super JavaClass> predicate) Asserts that all classes selected by this rule ONLY depend on certain classes (comparedependOnClassesThat(DescribedPredicate)
).
E.g.
NOTE: 'dependOn' catches wide variety of violations, e.g. having fields of type, having method parameters of type, extending type etc... Compare withclasses()
.should()
.onlyDependOnClassesThat(myPredicate)
onlyAccessClassesThat(DescribedPredicate)
that catches violations only by real accesses.
Note that many predefinedpredicates
can be found within a subclassPredicates
of the respective domain object or a common ancestor. For example,predicates
targetingJavaClass
can be found withinJavaClass.Predicates
or one of the respective ancestors likeHasName.Predicates
.- Parameters:
predicate
- Determines whichJavaClasses
match the dependency target- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
transitivelyDependOnClassesThat
Asserts that all classes selected by this rule transitively depend on any matching classes.
It focuses on detecting all direct dependencies of the selected classes that are themselves matched or have any transitive dependencies on matched classes. Thus, it doesn't discover all possible dependency paths but stops at the first match to be fast and resource-friendly.
NOTE: This usually makes more sense the negated way, e.g.
NOTE: 'dependOn' catches wide variety of violations, e.g. having fields of type, having method parameters of type, extending type etc...noClasses()
.should()
.transitivelyDependOnClassesThat()
.haveFullyQualifiedName(String)
- Returns:
- A syntax element that allows choosing to which classes a transitive dependency should exist
-
transitivelyDependOnClassesThat
@PublicAPI(usage=ACCESS) ClassesShouldConjunction transitivelyDependOnClassesThat(DescribedPredicate<? super JavaClass> predicate) Asserts that all classes selected by this rule transitively depend on any matching classes.
It focuses on detecting all direct dependencies of the selected classes that are themselves matched or have any transitive dependencies on matched classes. Thus, it doesn't discover all possible dependency paths but stops at the first match to be fast and resource-friendly.
NOTE: This usually makes more sense the negated way, e.g.
NOTE: 'dependOn' catches wide variety of violations, e.g. having fields of type, having method parameters of type, extending type etc...noClasses()
.should()
.transitivelyDependOnClassesThat(myPredicate)
Note that many predefinedpredicates
can be found within a subclassPredicates
of the respective domain object or a common ancestor. For example,predicates
targetingJavaClass
can be found withinJavaClass.Predicates
or one of the respective ancestors likeHasName.Predicates
.- Parameters:
predicate
- Determines whichJavaClasses
match the dependency target- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
onlyBeAccessed
Asserts that only certain classes access the classes selected by this rule.
E.g.
NOTE: 'access' refers only to violations by real accesses, i.e. accessing a field, and calling a method. Compare withonlyBeAccessed()
.byAnyPackage(String...)
onlyHaveDependentClassesThat()
that catches a wider variety of violations.- Returns:
- A syntax element that allows restricting how classes should be accessed
-
onlyHaveDependentClassesThat
Asserts that only certain classes depend on the classes selected by this rule.
E.g.
NOTE: 'depends' catches wide variety of violations, e.g. having fields of type, having method parameters of type, extending type etc... Compare withclasses()
.should()
.onlyHaveDependentClassesThat()
.haveFullyQualifiedName(String)
onlyBeAccessed()
that catches violations only by real accesses.- Returns:
- A syntax element that allows choosing from which classes a dependency to these classes may exist
-
onlyHaveDependentClassesThat
@PublicAPI(usage=ACCESS) ClassesShouldConjunction onlyHaveDependentClassesThat(DescribedPredicate<? super JavaClass> predicate) Asserts that only certain classes depend on the classes selected by this rule.
E.g.
NOTE: 'depends' catches wide variety of violations, e.g. having fields of type, having method parameters of type, extending type etc... Compare withclasses()
.should()
.onlyHaveDependentClassesThat(myPredicate)
onlyBeAccessed()
.byClassesThat(DescribedPredicate)
that catches violations only by real accesses.
Note that many predefinedpredicates
can be found within a subclassPredicates
of the respective domain object or a common ancestor. For example,predicates
targetingJavaClass
can be found withinJavaClass.Predicates
or one of the respective ancestors likeHasName.Predicates
.- Parameters:
predicate
- Determines whichJavaClasses
match the dependency origin- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
beInterfaces
Asserts that classes are interfaces.- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
notBeInterfaces
Asserts that classes are not interfaces.- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
beEnums
Asserts that classes are enums.- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
notBeEnums
Asserts that classes are not enums.- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
beRecords
Asserts that classes are records.- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
- See Also:
-
notBeRecords
Asserts that classes are not records.- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
- See Also:
-
beTopLevelClasses
-
notBeTopLevelClasses
-
beNestedClasses
-
notBeNestedClasses
-
beMemberClasses
-
notBeMemberClasses
-
beInnerClasses
-
notBeInnerClasses
-
beAnonymousClasses
-
notBeAnonymousClasses
-
beLocalClasses
-
notBeLocalClasses
-
be
Asserts that the rule matches exactly the given class.- Parameters:
clazz
- the only class the should be matched- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
notBe
Asserts that the rule does not match the given class.- Parameters:
clazz
- the class that should not be matched- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
be
Asserts that the rule matches exactly the class with the given fully qualified class name.- Parameters:
className
- the name of the only class that should be matched.- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
notBe
Asserts that the rule does not match the class with the given fully qualified class name.- Parameters:
className
- the name of the class that should not be matched.- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-
containNumberOfElements
@PublicAPI(usage=ACCESS) ClassesShouldConjunction containNumberOfElements(DescribedPredicate<? super Integer> predicate) Asserts that the number of classes checked by this rule conforms to the supplied predicate.- Returns:
- A syntax element that can either be used as working rule, or to continue specifying a more complex rule
-