You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@causeway.apache.org by da...@apache.org on 2023/03/26 15:46:00 UTC

[causeway] branch CAUSEWAY-3397 created (now 19a04055ee)

This is an automated email from the ASF dual-hosted git repository.

danhaywood pushed a change to branch CAUSEWAY-3397
in repository https://gitbox.apache.org/repos/asf/causeway.git


      at 19a04055ee CAUSEWAY-3397: updates InteractAs, and call within _Helper to new use _Annotations API

This branch includes the following new commits:

     new 3ca0b8a0f1 CAUSEWAY-3397: adds new method in _Annotations
     new 19a04055ee CAUSEWAY-3397: updates InteractAs, and call within _Helper to new use _Annotations API

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[causeway] 01/02: CAUSEWAY-3397: adds new method in _Annotations

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

danhaywood pushed a commit to branch CAUSEWAY-3397
in repository https://gitbox.apache.org/repos/asf/causeway.git

commit 3ca0b8a0f1e856057dfcebae09d45d4f2e24ff51
Author: danhaywood <da...@haywood-associates.co.uk>
AuthorDate: Sun Mar 26 12:54:08 2023 +0100

    CAUSEWAY-3397: adds new method in _Annotations
---
 .../commons/internal/reflection/_Annotations.java  | 23 ++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/commons/src/main/java/org/apache/causeway/commons/internal/reflection/_Annotations.java b/commons/src/main/java/org/apache/causeway/commons/internal/reflection/_Annotations.java
index 7d525032d4..dcb916545d 100644
--- a/commons/src/main/java/org/apache/causeway/commons/internal/reflection/_Annotations.java
+++ b/commons/src/main/java/org/apache/causeway/commons/internal/reflection/_Annotations.java
@@ -100,6 +100,29 @@ public final class _Annotations {
         return synthesize(annotatedElement, annotationType, SearchStrategy.TYPE_HIERARCHY);
     }
 
+    /**
+     * Optionally create a type-safe synthesized version of this annotation based on presence.
+     * <p>
+     * Also includes annotated fields, getter methods might be associated with.
+     * If annotations from a getter method are competing with annotations from its corresponding field,
+     * let the one win, that is 'nearer' to the <i>Class</i> that is subject to introspection.
+     * <p>
+     * Perform a full search of the entire type hierarchy,
+     * including super-classes and implemented interfaces.p
+     * Super-class annotations do not need to be meta-annotated with {@link Inherited}.
+     *
+     * @param <A>
+     * @param annotatedElement
+     * @param annotationType
+     * @return non-null
+     */
+    public static <A extends Annotation> Optional<A> synthesizeWrtEnclosingClass(
+            final AnnotatedElement annotatedElement,
+            final Class<A> annotationType) {
+
+        return synthesize(annotatedElement, annotationType, SearchStrategy.TYPE_HIERARCHY_AND_ENCLOSING_CLASSES);
+    }
+
     /**
      * Optionally create a type-safe synthesized version of this annotation based on presence.
      * <p>


[causeway] 02/02: CAUSEWAY-3397: updates InteractAs, and call within _Helper to new use _Annotations API

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

danhaywood pushed a commit to branch CAUSEWAY-3397
in repository https://gitbox.apache.org/repos/asf/causeway.git

commit 19a04055ee6614818dcfe30a6e3e0ce8f4a85b7c
Author: danhaywood <da...@haywood-associates.co.uk>
AuthorDate: Sun Mar 26 16:35:26 2023 +0100

    CAUSEWAY-3397: updates InteractAs, and call within _Helper to new use _Annotations API
---
 .../apache/causeway/testing/integtestsupport/applib/_Helper.java    | 2 +-
 .../testing/integtestsupport/applib/annotation/InteractAs.java      | 6 +++++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/testing/integtestsupport/applib/src/main/java/org/apache/causeway/testing/integtestsupport/applib/_Helper.java b/testing/integtestsupport/applib/src/main/java/org/apache/causeway/testing/integtestsupport/applib/_Helper.java
index e70013c62a..9c32e6d385 100644
--- a/testing/integtestsupport/applib/src/main/java/org/apache/causeway/testing/integtestsupport/applib/_Helper.java
+++ b/testing/integtestsupport/applib/src/main/java/org/apache/causeway/testing/integtestsupport/applib/_Helper.java
@@ -44,7 +44,7 @@ class _Helper {
      */
     static Optional<InteractionContext> getCustomInteractionContext(final ExtensionContext extensionContext) {
         return extensionContext.getTestMethod()
-        .flatMap(testMethod->_Annotations.synthesize(testMethod, InteractAs.class))
+        .flatMap(testMethod->_Annotations.synthesizeWrtEnclosingClass(testMethod, InteractAs.class))
         .map(InteractAsUtils::toInteractionContext);
     }
 
diff --git a/testing/integtestsupport/applib/src/main/java/org/apache/causeway/testing/integtestsupport/applib/annotation/InteractAs.java b/testing/integtestsupport/applib/src/main/java/org/apache/causeway/testing/integtestsupport/applib/annotation/InteractAs.java
index 6661c9659d..47c137da66 100644
--- a/testing/integtestsupport/applib/src/main/java/org/apache/causeway/testing/integtestsupport/applib/annotation/InteractAs.java
+++ b/testing/integtestsupport/applib/src/main/java/org/apache/causeway/testing/integtestsupport/applib/annotation/InteractAs.java
@@ -44,10 +44,14 @@ import org.apache.causeway.applib.services.iactnlayer.InteractionService;
  * }
  * </pre>
  *
+ * <p>
+ * It can also be applied to a class, meaning it will apply to all tests within that class.
+ * </p>
+ *
  * @since 2.0 {@index}
  */
 @Inherited
-@Target({ ElementType.METHOD, ElementType.ANNOTATION_TYPE })
+@Target({ ElementType.METHOD, ElementType.ANNOTATION_TYPE, ElementType.TYPE })
 @Retention(RetentionPolicy.RUNTIME)
 public @interface InteractAs {