Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4b53612

Browse files
authored
Improve documentation of slices rules (#1454)
[The user guide's slices documentation](https://www.archunit.org/userguide/html/000_Index.html#_slices) had a comment that didn't perfectly match the code: ```java // checks all subpackages of 'myapp' for cycles SlicesRuleDefinition.slices().matching("..myapp.(**)").should().notDependOnEachOther() ``` In addition, the involved methods could use some more JavaDoc: * [`matching(String)`](https://javadoc.io/static/com.tngtech.archunit/archunit/1.4.0/com/tngtech/archunit/library/dependencies/SlicesRuleDefinition.Creator.html#matching(java.lang.String)) * [`notDependOnEachOther()`](https://javadoc.io/static/com.tngtech.archunit/archunit/1.4.0/com/tngtech/archunit/library/dependencies/syntax/SlicesShould.html#notDependOnEachOther())
2 parents c8631c2 + 1358b82 commit 4b53612

File tree

4 files changed

+31
-12
lines changed

4 files changed

+31
-12
lines changed

archunit/src/main/java/com/tngtech/archunit/library/dependencies/SlicesRuleDefinition.java

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package com.tngtech.archunit.library.dependencies;
1717

1818
import com.tngtech.archunit.PublicAPI;
19+
import com.tngtech.archunit.core.domain.PackageMatcher;
1920
import com.tngtech.archunit.lang.ArchRule;
2021
import com.tngtech.archunit.lang.Priority;
2122
import com.tngtech.archunit.library.dependencies.syntax.GivenSlices;
@@ -24,22 +25,20 @@
2425
import static com.tngtech.archunit.PublicAPI.Usage.ACCESS;
2526

2627
/**
27-
* Allows to specify {@link ArchRule ArchRules} for "slices" of a code base. A slice is conceptually
28-
* a cut through a code base according to business logic. Take for example
28+
* Allows to specify {@link ArchRule ArchRules} for "slices" of a code base.
29+
* A slice is conceptually a cut through a code base according to business logic.
30+
* <h6>Example</h6>
2931
* <pre><code>
3032
* com.mycompany.myapp.order
3133
* com.mycompany.myapp.customer
3234
* com.mycompany.myapp.user
3335
* com.mycompany.myapp.authorization
3436
* </code></pre>
35-
* The top level packages under 'myapp' are composed according to different domain aspects. It is
36-
* good practice, to keep such packages free of cycles, which is one capability that this class
37-
* provides.<br>
38-
* Consider
39-
* <pre><code>
40-
* {@link #slices() slices()}.{@link Slices#matching(String) matching("..myapp.(*)..")}.{@link GivenSlices#should() should()}.{@link SlicesShould#beFreeOfCycles() beFreeOfCycles()}
41-
* </code></pre>
42-
* Then this rule will assert, that the four slices of 'myapp' are free of cycles.
37+
* The top level packages under {@code myapp} are composed according to different domain aspects.
38+
* It is good practice to keep such packages free of cycles,
39+
* which can be tested with the following rule:
40+
* <pre><code>{@link #slices() slices()}.{@link Creator#matching(String) matching("..myapp.(*)..")}.{@link GivenSlices#should() should()}.{@link SlicesShould#beFreeOfCycles() beFreeOfCycles()}</code></pre>
41+
* This rule asserts that the four slices of {@code myapp} are free of cycles.
4342
*/
4443
@PublicAPI(usage = ACCESS)
4544
public final class SlicesRuleDefinition {
@@ -60,6 +59,8 @@ private Creator() {
6059
}
6160

6261
/**
62+
* defines a {@link SlicesRuleDefinition "slices" rule}
63+
* based on a {@link PackageMatcher package identifier} with capturing groups
6364
* @see Slices#matching(String)
6465
*/
6566
@PublicAPI(usage = ACCESS)
@@ -68,6 +69,8 @@ public GivenSlices matching(String packageIdentifier) {
6869
}
6970

7071
/**
72+
* defines a {@link SlicesRuleDefinition "slices" rule}
73+
* based on a {@link PackageMatcher package identifier} with capturing groups
7174
* @see Slices#matching(String)
7275
*/
7376
@PublicAPI(usage = ACCESS)
@@ -76,6 +79,8 @@ public GivenSlices matching(String packageIdentifier, Priority priority) {
7679
}
7780

7881
/**
82+
* defines a {@link SlicesRuleDefinition "slices" rule}
83+
* based on an explicit {@link SliceAssignment}
7984
* @see Slices#assignedFrom(SliceAssignment)
8085
*/
8186
@PublicAPI(usage = ACCESS)
@@ -84,6 +89,8 @@ public GivenSlices assignedFrom(SliceAssignment assignment) {
8489
}
8590

8691
/**
92+
* defines a {@link SlicesRuleDefinition "slices" rule}
93+
* based on an explicit {@link SliceAssignment}
8794
* @see Slices#assignedFrom(SliceAssignment)
8895
*/
8996
@PublicAPI(usage = ACCESS)

archunit/src/main/java/com/tngtech/archunit/library/dependencies/syntax/SlicesShould.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,21 @@
2222

2323
@PublicAPI(usage = ACCESS)
2424
public interface SlicesShould {
25+
/**
26+
* @return a {@link SliceRule} asserting that
27+
* there are no cycles via dependencies between the evaluated slices
28+
* (which is weaker than requiring
29+
* that the slices do {@link #notDependOnEachOther()} at all)
30+
*/
2531
@PublicAPI(usage = ACCESS)
2632
SliceRule beFreeOfCycles();
2733

34+
/**
35+
* @return a {@link SliceRule} asserting that
36+
* there are no dependencies at all between the evaluated slices
37+
* (which is stronger than requiring
38+
* that {@link #beFreeOfCycles() there are no dependency cycles} between the slices)
39+
*/
2840
@PublicAPI(usage = ACCESS)
2941
SliceRule notDependOnEachOther();
3042
}

docs/userguide/008_The_Library_API.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ infixes, and then write assertions against those slices. At the moment this is f
139139
SlicesRuleDefinition.slices().matching("..myapp.(*)..").should().beFreeOfCycles()
140140
141141
// checks all subpackages of 'myapp' for cycles
142-
SlicesRuleDefinition.slices().matching("..myapp.(**)").should().notDependOnEachOther()
142+
SlicesRuleDefinition.slices().matching("..myapp.(**)").should().beFreeOfCycles()
143143
144144
// sort classes by packages between 'myapp' and 'service'
145145
// then check those slices for not having any dependencies on each other

docs/userguide/html/000_Index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1813,7 +1813,7 @@ <h3 id="_slices"><a class="anchor" href="#_slices"></a>8.2. Slices</h3>
18131813
SlicesRuleDefinition.slices().matching("..myapp.(*)..").should().beFreeOfCycles()
18141814

18151815
// checks all subpackages of 'myapp' for cycles
1816-
SlicesRuleDefinition.slices().matching("..myapp.(**)").should().notDependOnEachOther()
1816+
SlicesRuleDefinition.slices().matching("..myapp.(**)").should().beFreeOfCycles()
18171817

18181818
// sort classes by packages between 'myapp' and 'service'
18191819
// then check those slices for not having any dependencies on each other

0 commit comments

Comments
 (0)