20
20
import com .tngtech .archunit .PublicAPI ;
21
21
import com .tngtech .archunit .base .DescribedPredicate ;
22
22
import com .tngtech .archunit .core .domain .AccessTarget .MethodCallTarget ;
23
+ import com .tngtech .archunit .core .domain .JavaAccess .Functions .Get ;
23
24
import com .tngtech .archunit .core .domain .JavaClass ;
24
- import com .tngtech .archunit .core .domain .JavaMethodCall ;
25
25
import com .tngtech .archunit .lang .ArchCondition ;
26
26
import com .tngtech .archunit .lang .ArchRule ;
27
27
import com .tngtech .archunit .lang .ConditionEvents ;
28
28
import com .tngtech .archunit .lang .SimpleConditionEvent ;
29
29
30
30
import static com .tngtech .archunit .PublicAPI .Usage .ACCESS ;
31
+ import static com .tngtech .archunit .base .DescribedPredicate .not ;
32
+ import static com .tngtech .archunit .core .domain .JavaModifier .BRIDGE ;
31
33
import static com .tngtech .archunit .core .domain .properties .CanBeAnnotated .Predicates .annotatedWith ;
34
+ import static com .tngtech .archunit .core .domain .properties .HasModifiers .Predicates .modifier ;
32
35
import static com .tngtech .archunit .lang .conditions .ArchPredicates .are ;
33
36
import static com .tngtech .archunit .lang .syntax .ArchRuleDefinition .noClasses ;
34
37
@@ -44,7 +47,7 @@ private ProxyRules() {
44
47
/**
45
48
* Returns a rule that checks that none of the given classes directly calls
46
49
* other methods declared in the same class that are annotated with the
47
- * given annotation.
50
+ * given annotation (ignoring calls from synthetic bridge methods) .
48
51
*
49
52
* <p>
50
53
* As an example, the Spring Framework handles transactions by creating a proxy.
@@ -92,7 +95,8 @@ public static ArchRule no_classes_should_directly_call_other_methods_declared_in
92
95
93
96
/**
94
97
* Returns a rule that checks that none of the given classes directly calls
95
- * other methods declared in the same class that matches the given predicate.
98
+ * other methods declared in the same class that matches the given predicate
99
+ * (ignoring calls from synthetic bridge methods).
96
100
*
97
101
* <p>
98
102
* For an example, see {@link #no_classes_should_directly_call_other_methods_declared_in_the_same_class_that_are_annotated_with(Class)}
@@ -106,8 +110,8 @@ public static ArchRule no_classes_should_directly_call_other_methods_declared_in
106
110
107
111
/**
108
112
* Returns a condition that matches classes that directly calls other methods
109
- * declared in the same class that are annotated with the given annotation.
110
- *
113
+ * declared in the same class that are annotated with the given annotation
114
+ * (ignoring calls from synthetic bridge methods).
111
115
* <p>
112
116
* As an example, the Spring Framework handles transactions by creating a proxy.
113
117
* This proxy does the actual transaction management every time a method
@@ -155,8 +159,8 @@ public static ArchCondition<JavaClass> directly_call_other_methods_declared_in_t
155
159
156
160
/**
157
161
* Returns a condition that matches classes that directly calls other methods
158
- * declared in the same class that matches the given predicate.
159
- *
162
+ * declared in the same class that matches the given predicate
163
+ * (ignoring calls from synthetic bridge methods).
160
164
* <p>
161
165
* For an example, see {@link #directly_call_other_methods_declared_in_the_same_class_that_are_annotated_with(Class)}
162
166
* </p>
@@ -166,10 +170,12 @@ public static ArchCondition<JavaClass> directly_call_other_methods_declared_in_t
166
170
return new ArchCondition <JavaClass >("directly call other methods declared in the same class that " + predicate .getDescription ()) {
167
171
@ Override
168
172
public void check (JavaClass javaClass , ConditionEvents events ) {
169
- for (JavaMethodCall call : javaClass .getMethodCallsFromSelf ()) {
170
- boolean satisfied = call .getOriginOwner ().equals (call .getTargetOwner ()) && predicate .test (call .getTarget ());
171
- events .add (new SimpleConditionEvent (call , satisfied , call .getDescription ()));
172
- }
173
+ javaClass .getMethodCallsFromSelf ().stream ()
174
+ .filter (Get .origin ().is (not (modifier (BRIDGE ))))
175
+ .forEach (call -> {
176
+ boolean satisfied = call .getOriginOwner ().equals (call .getTargetOwner ()) && predicate .test (call .getTarget ());
177
+ events .add (new SimpleConditionEvent (call , satisfied , call .getDescription ()));
178
+ });
173
179
}
174
180
};
175
181
}
0 commit comments