]> source.dussan.org Git - aspectj.git/commitdiff
Add failing test reproducing #246
authorAlexander Kriegisch <Alexander@Kriegisch.name>
Sat, 24 Jun 2023 06:15:24 +0000 (08:15 +0200)
committerAlexander Kriegisch <Alexander@Kriegisch.name>
Mon, 26 Jun 2023 06:48:27 +0000 (13:48 +0700)
Signed-off-by: Alexander Kriegisch <Alexander@Kriegisch.name>
tests/bugs1920/github_246/App.java [new file with mode: 0644]
tests/bugs1920/github_246/First.java [new file with mode: 0644]
tests/bugs1920/github_246/ITDAspect.aj [new file with mode: 0644]
tests/bugs1920/github_246/Second.java [new file with mode: 0644]
tests/src/test/java/org/aspectj/systemtest/ajc1920/Bugs1920Tests.java
tests/src/test/resources/org/aspectj/systemtest/ajc1920/ajc1920.xml

diff --git a/tests/bugs1920/github_246/App.java b/tests/bugs1920/github_246/App.java
new file mode 100644 (file)
index 0000000..8e0bbe8
--- /dev/null
@@ -0,0 +1,11 @@
+import java.lang.reflect.Method;
+import java.util.Arrays;
+
+public class App {
+  public static void main(String[] args) {
+    for (Method method : App.class.getDeclaredMethods()) {
+      if (method.getName().equals("foo"))
+        System.out.println(Arrays.toString(method.getDeclaredAnnotations()) + " " + method);
+    }
+  }
+}
diff --git a/tests/bugs1920/github_246/First.java b/tests/bugs1920/github_246/First.java
new file mode 100644 (file)
index 0000000..aa482ca
--- /dev/null
@@ -0,0 +1,5 @@
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+@Retention(RetentionPolicy.RUNTIME)
+public @interface First { }
diff --git a/tests/bugs1920/github_246/ITDAspect.aj b/tests/bugs1920/github_246/ITDAspect.aj
new file mode 100644 (file)
index 0000000..fffef16
--- /dev/null
@@ -0,0 +1,13 @@
+public aspect ITDAspect {
+  @First
+  @Second
+  public void App.foo(Object parameter) { }
+
+  @First
+  public void App.foo(String parameter) { }
+
+  @Second
+  public int App.foo(int parameter) {
+    return parameter + 3;
+  }
+}
diff --git a/tests/bugs1920/github_246/Second.java b/tests/bugs1920/github_246/Second.java
new file mode 100644 (file)
index 0000000..d599f7b
--- /dev/null
@@ -0,0 +1,5 @@
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+@Retention(RetentionPolicy.RUNTIME)
+public @interface Second { }
index fca9fee20c6f0648fc431d5a6ed662fa231774f0..409a2e6751bb9d7495f8d3c4b9eb67f71d145ef6 100644 (file)
@@ -15,8 +15,15 @@ import org.aspectj.testing.XMLBasedAjcTestCase;
  */
 public class Bugs1920Tests extends XMLBasedAjcTestCase {
 
-  public void testDummyJava20() {
-    //runTest("dummy Java 20");
+  /**
+   * Add correct annotations to multiple ITD methods with the same name and same number of arguments, i.e. copy the
+   * annotations correctly from the aspect into the target class instead of falsely always copying the annotations (if
+   * any) from the first ITD method found.
+   * <p>
+   * See <a href="https://github.com/eclipse-aspectj/aspectj/issues/246">GitHub issue 246</a>.
+   */
+  public void test_GitHub_246() {
+    runTest("add correct annotations to multiple ITD methods with the same name and same number of arguments");
   }
 
   public static Test suite() {
index 8f566b6437a8fcacc5a74d91e6d27e809dbd2a58..2026df491bc22d6f9264434f3191d2718171e5e5 100644 (file)
                </run>
        </ajc-test>
 
+       <!-- https://github.com/eclipse-aspectj/aspectj/issues/246 -->
+       <ajc-test dir="bugs1920/github_246" vm="8" title="add correct annotations to multiple ITD methods with the same name and same number of arguments">
+               <compile files="First.java Second.java App.java ITDAspect.aj" options="-8"/>
+               <run class="App">
+                       <stdout>
+                               <line text="[@First(), @Second()] public void App.foo(java.lang.Object)"/>
+                               <line text="[@First()] public void App.foo(java.lang.String)"/>
+                               <line text="[@Second()] public int App.foo(int)"/>
+                       </stdout>
+               </run>
+       </ajc-test>
+
 </suite>