Package com.tngtech.archunit.lang
Interface ArchRule
- All Superinterfaces:
CanBeEvaluated
,CanOverrideDescription<ArchRule>
,HasDescription
- All Known Subinterfaces:
ClassesShouldConjunction
,CodeUnitsShouldConjunction<CODE_UNIT>
,FieldsShouldConjunction
,MembersShouldConjunction<MEMBER>
,MethodsShouldConjunction
- All Known Implementing Classes:
Architectures.LayeredArchitecture
,Architectures.OnionArchitecture
,CompositeArchRule
,FreezingArchRule
,SliceRule
@PublicAPI(usage=ACCESS)
public interface ArchRule
extends CanBeEvaluated, CanOverrideDescription<ArchRule>
Represents a rule about a specified set of objects of interest (e.g.
To write rules on custom objects, you can use
JavaClass
).
To define a rule, use one of the factory methods within ArchRuleDefinition
, for example
ArchRule rule = ArchRuleDefinition.noClasses()
.that()
.resideInAPackage("..svc..")
.should()
.accessClassesThat()
.resideInAPackage("..ui..")
;
rule.check(importedJavaClasses);
To write rules on custom objects, you can use
ArchRuleDefinition.all(ClassesTransformer)
, where
ClassesTransformer
defines how the type of objects can be created from imported JavaClasses
.
E.g. if you want to define a rule on all imported methods you could specify a transformer to retrieve methods
from classes, or if you're interested in slices of packages, the input transformer would specify how to transform
the imported classes to those slices to run an ArchCondition
against.- See Also:
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic final class
static class
static interface
-
Method Summary
Modifier and TypeMethodDescriptionallowEmptyShould
(boolean allowEmptyShould) If set totrue
allows the should-clause of this rule to be checked against an empty set of elements.void
check
(JavaClasses classes) Methods inherited from interface com.tngtech.archunit.lang.CanBeEvaluated
evaluate
Methods inherited from interface com.tngtech.archunit.core.domain.properties.CanOverrideDescription
as
Methods inherited from interface com.tngtech.archunit.base.HasDescription
getDescription
-
Method Details
-
check
-
because
-
allowEmptyShould
If set totrue
allows the should-clause of this rule to be checked against an empty set of elements. Otherwise, the rule will fail with a respective message. This is to prevent possible implementation errors, like filtering for a non-existing package in the that-clause causing an always-passing rule.
Note that this method will override the configuration propertyarchRule.failOnEmptyShould
.- Parameters:
allowEmptyShould
- Whether the rule fails if the should-clause is evaluated with an empty set of elements- Returns:
- A (new)
ArchRule
with adjustedallowEmptyShould
behavior
-