2020import com .tngtech .archunit .PublicAPI ;
2121import com .tngtech .archunit .base .DescribedPredicate ;
2222import com .tngtech .archunit .core .domain .AccessTarget .MethodCallTarget ;
23+ import com .tngtech .archunit .core .domain .JavaAccess .Functions .Get ;
2324import com .tngtech .archunit .core .domain .JavaClass ;
24- import com .tngtech .archunit .core .domain .JavaMethodCall ;
2525import com .tngtech .archunit .lang .ArchCondition ;
2626import com .tngtech .archunit .lang .ArchRule ;
2727import com .tngtech .archunit .lang .ConditionEvents ;
2828import com .tngtech .archunit .lang .SimpleConditionEvent ;
2929
3030import 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 ;
3133import static com .tngtech .archunit .core .domain .properties .CanBeAnnotated .Predicates .annotatedWith ;
34+ import static com .tngtech .archunit .core .domain .properties .HasModifiers .Predicates .modifier ;
3235import static com .tngtech .archunit .lang .conditions .ArchPredicates .are ;
3336import static com .tngtech .archunit .lang .syntax .ArchRuleDefinition .noClasses ;
3437
@@ -44,7 +47,7 @@ private ProxyRules() {
4447 /**
4548 * Returns a rule that checks that none of the given classes directly calls
4649 * other methods declared in the same class that are annotated with the
47- * given annotation.
50+ * given annotation (ignoring calls from synthetic bridge methods) .
4851 *
4952 * <p>
5053 * 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
9295
9396 /**
9497 * 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).
96100 *
97101 * <p>
98102 * 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
106110
107111 /**
108112 * 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).
111115 * <p>
112116 * As an example, the Spring Framework handles transactions by creating a proxy.
113117 * 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
155159
156160 /**
157161 * 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).
160164 * <p>
161165 * For an example, see {@link #directly_call_other_methods_declared_in_the_same_class_that_are_annotated_with(Class)}
162166 * </p>
@@ -166,10 +170,12 @@ public static ArchCondition<JavaClass> directly_call_other_methods_declared_in_t
166170 return new ArchCondition <JavaClass >("directly call other methods declared in the same class that " + predicate .getDescription ()) {
167171 @ Override
168172 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+ });
173179 }
174180 };
175181 }
0 commit comments