aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAlexander Kriegisch <Alexander@Kriegisch.name>2023-01-07 14:23:26 +0100
committerAlexander Kriegisch <Alexander@Kriegisch.name>2023-01-07 14:23:26 +0100
commit0e3d9f0dbc853b168cf84118490ddcb487f2aa0f (patch)
treea87009166d143eb755cb815e3f3c140b8d6ace28 /tests
parent09ada8dd884eb66911d58d1b76d7e1ae4ab145f2 (diff)
downloadaspectj-0e3d9f0dbc853b168cf84118490ddcb487f2aa0f.tar.gz
aspectj-0e3d9f0dbc853b168cf84118490ddcb487f2aa0f.zip
Refactor, comment and reactivate Ajc183Tests.testAnnoStyleDecp_442425
This test was always inactive and did not add any value other than during development. No it runs, passes and documents the status quo of - what was fixed (regression for AJC 1.8.2 core dump fixed in 1.8.3), - the current limitations of @DeclareParents and @DeclareMixin regarding generic interfaces. Signed-off-by: Alexander Kriegisch <Alexander@Kriegisch.name>
Diffstat (limited to 'tests')
-rw-r--r--tests/bugs183/442425/EntityController.java4
-rw-r--r--tests/bugs183/442425/EntityControllerAspect.java15
-rw-r--r--tests/bugs183/442425/EntityMongoController.java9
-rw-r--r--tests/bugs183/442425/IEntityController.java7
-rw-r--r--tests/bugs183/442425/MyAnnotatedController.java63
-rw-r--r--tests/src/test/java/org/aspectj/systemtest/ajc183/Ajc183Tests.java8
-rw-r--r--tests/src/test/resources/org/aspectj/systemtest/ajc183/ajc183.xml35
7 files changed, 74 insertions, 67 deletions
diff --git a/tests/bugs183/442425/EntityController.java b/tests/bugs183/442425/EntityController.java
index 2423b642d..e5141c97c 100644
--- a/tests/bugs183/442425/EntityController.java
+++ b/tests/bugs183/442425/EntityController.java
@@ -1,5 +1,3 @@
-package de.scrum_master.app;
-
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -7,4 +5,4 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
-public @interface EntityController {}
+public @interface EntityController { }
diff --git a/tests/bugs183/442425/EntityControllerAspect.java b/tests/bugs183/442425/EntityControllerAspect.java
index 7540db933..af3211fcb 100644
--- a/tests/bugs183/442425/EntityControllerAspect.java
+++ b/tests/bugs183/442425/EntityControllerAspect.java
@@ -1,16 +1,15 @@
-package de.scrum_master.app;
-
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.*;
@Aspect
public class EntityControllerAspect {
- @DeclareParents(value = "@EntityController *", defaultImpl = EntityMongoController.class)
- private IEntityController iEntityController;
+ @DeclareParents(value = "@EntityController *", defaultImpl = EntityMongoController.class)
+ private IEntityController iEntityController;
+
/*
- @DeclareMixin("@EntityController *")
- private IEntityController createEntityControllerInstance() {
- return new EntityMongoController();
- }
+ @DeclareMixin("@EntityController *")
+ private IEntityController createEntityControllerInstance() {
+ return new EntityMongoController();
+ }
*/
}
diff --git a/tests/bugs183/442425/EntityMongoController.java b/tests/bugs183/442425/EntityMongoController.java
index 345f32043..194d1777d 100644
--- a/tests/bugs183/442425/EntityMongoController.java
+++ b/tests/bugs183/442425/EntityMongoController.java
@@ -1,8 +1,7 @@
-package de.scrum_master.app;
-
public class EntityMongoController<T> implements IEntityController<T> {
- private T entity;
+ private T entity;
+
+ public void setEntity(T entity) { this.entity = entity; }
- public void setEntity(T entity) { this.entity = entity; }
- public T getEntity() { return entity; }
+ public T getEntity() { return entity; }
}
diff --git a/tests/bugs183/442425/IEntityController.java b/tests/bugs183/442425/IEntityController.java
index 440edcd31..8391db834 100644
--- a/tests/bugs183/442425/IEntityController.java
+++ b/tests/bugs183/442425/IEntityController.java
@@ -1,6 +1,5 @@
-package de.scrum_master.app;
-
public interface IEntityController<T> {
- void setEntity(T entity);
- T getEntity();
+ void setEntity(T entity);
+
+ T getEntity();
}
diff --git a/tests/bugs183/442425/MyAnnotatedController.java b/tests/bugs183/442425/MyAnnotatedController.java
index fab43b835..cafe5bcbc 100644
--- a/tests/bugs183/442425/MyAnnotatedController.java
+++ b/tests/bugs183/442425/MyAnnotatedController.java
@@ -1,37 +1,44 @@
-package de.scrum_master.app;
-
import java.lang.reflect.Method;
@EntityController
public class MyAnnotatedController<T> {
- public void doSomething() {
- System.out.println("Doing something");
- }
+ public void doSomething() {
+ System.out.println("Doing something");
+ }
- public static void main(String[] args) {
- // Use class type directly so as to call its method
- MyAnnotatedController<String> annotatedTextController = new MyAnnotatedController<>();
- annotatedTextController.doSomething();
+ public static void main(String[] args) {
+ // Use class type directly so as to call its method
+ MyAnnotatedController<String> annotatedTextController = new MyAnnotatedController<>();
+ annotatedTextController.doSomething();
- // Print all declared methods (should also show interface methods introduced via ITD)
- for (Method method : annotatedTextController.getClass().getDeclaredMethods()) {
- if (!method.getName().startsWith("ajc$"))
- System.out.println(method);
- }
+ // Print all declared methods (should also show interface methods introduced via ITD)
+ for (Method method : annotatedTextController.getClass().getDeclaredMethods()) {
+ if (!method.getName().startsWith("ajc$"))
+ System.out.println(method);
+ }
- // Prove that class type is compatible with interface type
- //IEntityController<String> entityTextController = annotatedTextController;
- //entityTextController.setEntity("foo");
- // Would not work here because generic interface type is type-safe:
- // entityNumberController.setEntity(123);
- //System.out.println("Entity value = " + entityTextController.getEntity());
+ // Prove that class type is compatible with interface type
+ //
+ // NOTE: As explained in https://bugs.eclipse.org/bugs/show_bug.cgi?id=442425#c2, @DeclareParents will add the
+ // raw form of the parent to the target class, not the generic one. Therefore, the additional cast is necessary.
+ // Otherwise, AJC would throw:
+ // Type mismatch: cannot convert from MyAnnotatedController<String> to IEntityController<String>
+ IEntityController<String> entityTextController = (IEntityController<String>) annotatedTextController;
+ entityTextController.setEntity("foo");
+ // Would not work here because generic interface type is type-safe:
+ // entityNumberController.setEntity(123);
+ System.out.println("Entity value = " + entityTextController.getEntity());
- // Create another object and directly assign it to interface type
- //IEntityController<Integer> entityNumberController = new MyAnnotatedController<>();
- //entityNumberController.setEntity(123);
- // Would not work here because generic interface type is type-safe:
- // entityNumberController.setEntity("foo");
- //System.out.println("Entity value = " + entityNumberController.getEntity());
- }
+ // Create another object and directly assign it to interface type.
+ //
+ // NOTE: As explained in https://bugs.eclipse.org/bugs/show_bug.cgi?id=442425#c2, @DeclareParents will add the
+ // raw form of the parent to the target class, not the generic one. Therefore, the additional cast is necessary.
+ // Otherwise, AJC would throw:
+ // Cannot infer type arguments for MyAnnotatedController<>
+ IEntityController<Integer> entityNumberController = (IEntityController<Integer>) new MyAnnotatedController<>();
+ entityNumberController.setEntity(123);
+ // Would not work here because generic interface type is type-safe:
+ // entityNumberController.setEntity("foo");
+ System.out.println("Entity value = " + entityNumberController.getEntity());
+ }
}
-
diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc183/Ajc183Tests.java b/tests/src/test/java/org/aspectj/systemtest/ajc183/Ajc183Tests.java
index 1afdde23c..0311ab124 100644
--- a/tests/src/test/java/org/aspectj/systemtest/ajc183/Ajc183Tests.java
+++ b/tests/src/test/java/org/aspectj/systemtest/ajc183/Ajc183Tests.java
@@ -78,10 +78,10 @@ public class Ajc183Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
public void testVerifyError_443447() {
runTest("verifyerror");
}
-//
-// public void testAnnoStyleDecp_442425() {
-// runTest("anno style decp");
-// }
+
+ public void testAnnoStyleDecp_442425() {
+ runTest("anno style decp");
+ }
// ---
diff --git a/tests/src/test/resources/org/aspectj/systemtest/ajc183/ajc183.xml b/tests/src/test/resources/org/aspectj/systemtest/ajc183/ajc183.xml
index 0e495139c..373340920 100644
--- a/tests/src/test/resources/org/aspectj/systemtest/ajc183/ajc183.xml
+++ b/tests/src/test/resources/org/aspectj/systemtest/ajc183/ajc183.xml
@@ -156,25 +156,30 @@
<ajc-test dir="bugs183/442425" title="anno style decp">
<compile options="-1.8" files="EntityController.java IEntityController.java MyAnnotatedController.java EntityControllerAspect.java EntityMongoController.java">
- <message kind="error" line="23" text="Type mismatch: cannot convert from MyAnnotatedController&lt;String&gt; to IEntityController&lt;String&gt;"/>
- <message kind="error" line="30" text="Cannot infer type arguments for MyAnnotatedController&lt;&gt;"/>
+ <!--
+ NOTE: As explained in https://bugs.eclipse.org/bugs/show_bug.cgi?id=442425#c2, @DeclareParents will add the
+ raw form of the parent to the target class, not the generic one. Therefore, without additional casts AJC would
+ throw the following two errors:
+ -->
+ <!--<message kind="error" line="26" text="Type mismatch: cannot convert from MyAnnotatedController&lt;String&gt; to IEntityController&lt;String&gt;"/>-->
+ <!--<message kind="error" line="38" text="Cannot infer type arguments for MyAnnotatedController&lt;&gt;"/>-->
</compile>
- <!--
- <run class="de.scrum_master.app.MyAnnotatedController">
- <stdout>
- <line text="Doing something"/>
- <line text="public static void de.scrum_master.app.MyAnnotatedController.main(java.lang.String[])"/>
- <line text="public void de.scrum_master.app.MyAnnotatedController.doSomething()"/>
- <line text="public java.lang.Object de.scrum_master.app.MyAnnotatedController.getEntity()"/>
- <line text="public void de.scrum_master.app.MyAnnotatedController.setEntity(java.lang.Object)"/>
- <line text="Entity value = foo"/>
- <line text="Entity value = 123"/>
- </stdout>
+ <run class="MyAnnotatedController">
+ <stdout ordered="no">
+ <line text="Doing something"/>
+ <line text="public static void MyAnnotatedController.main(java.lang.String[])"/>
+ <line text="public void MyAnnotatedController.doSomething()"/>
+ <!-- Object, not generic type -->
+ <line text="public java.lang.Object MyAnnotatedController.getEntity()"/>
+ <!-- Object, not generic type -->
+ <line text="public void MyAnnotatedController.setEntity(java.lang.Object)"/>
+ <line text="Entity value = foo"/>
+ <line text="Entity value = 123"/>
+ </stdout>
</run>
- -->
</ajc-test>
- <ajc-test dir="bugs183/443477" title="verifyerror">
+ <ajc-test dir="bugs183/443477" title="verifyerror">
<compile options="-1.7" files="Coo.java"/>
<run class="Coo"/>
</ajc-test>