From 4ec35817ae67ddc4afc6ddfe4047eff33451d43f Mon Sep 17 00:00:00 2001 From: Peter Gafert Date: Sat, 25 Jun 2022 12:47:04 +0700 Subject: [PATCH] fixup! extend Onion Architecture to allow defining components by predicate Tried to improve Javadoc of `belongTo...()` Signed-off-by: Peter Gafert --- .../archunit/core/domain/JavaClass.java | 30 +++++++++++++++++-- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/archunit/src/main/java/com/tngtech/archunit/core/domain/JavaClass.java b/archunit/src/main/java/com/tngtech/archunit/core/domain/JavaClass.java index cebb90c89a..4c9f389b68 100644 --- a/archunit/src/main/java/com/tngtech/archunit/core/domain/JavaClass.java +++ b/archunit/src/main/java/com/tngtech/archunit/core/domain/JavaClass.java @@ -2355,7 +2355,27 @@ public static DescribedPredicate equivalentTo(final Class clazz) { /** * A predicate to determine if a {@link JavaClass} "belongs" to one of the passed {@link Class classes}, - * where we define "belong" as being equivalent to the class itself or any inner/anonymous class of this class. + * where "belong" means that this {@link JavaClass} is equivalent to + *
    + *
  • any of the passed {@link Class classes}
  • + *
  • any nested/inner/anonymous class of one of the passed {@link Class classes}
  • + *
+ * + * For example {@code belongToAnyOf(Outer.class)} would apply to the following cases + *

+         * class Outer {
+         *     // Inner would match belongToAnyOf(Outer.class) since it is an inner class of Outer
+         *     class Inner {}
+         *
+         *     void call() {
+         *         // this anonymous class would also match belongToAnyOf(Outer.class) since it is declared within Outer
+         *         new Serializable() {}
+         *     }
+         * }
+         *
+         * // this class would not match, since it is neither Outer itself nor nested within the class body of Outer
+         * class Other {}
+         * 
* * @param classes The {@link Class classes} to check the {@link JavaClass} and its enclosing classes against * @return A {@link DescribedPredicate} returning true, if and only if the tested {@link JavaClass} is equivalent to @@ -2373,8 +2393,12 @@ public static DescribedPredicate belongToAnyOf(Class... classes) { /** * A predicate to determine if a {@link JavaClass} "belongs" to a class matching the given predicate, - * where we define "belong" as being equivalent to the class itself or any inner/anonymous class of this class. - *

+ * where "belong" means that this {@link JavaClass} is + *
    + *
  • directly matching the given predicate
  • + *
  • a nested/inner/anonymous class of another {@link JavaClass} matching the predicate
  • + *
+ * * For example {@code belongTo(annotatedWith(Something.class))} would apply to the following cases *

          *{@literal @}Something