diff options
author | Alexander Kriegisch <Alexander@Kriegisch.name> | 2023-01-07 14:23:26 +0100 |
---|---|---|
committer | Alexander Kriegisch <Alexander@Kriegisch.name> | 2023-01-07 14:23:26 +0100 |
commit | 0e3d9f0dbc853b168cf84118490ddcb487f2aa0f (patch) | |
tree | a87009166d143eb755cb815e3f3c140b8d6ace28 /tests/bugs183/442425/MyAnnotatedController.java | |
parent | 09ada8dd884eb66911d58d1b76d7e1ae4ab145f2 (diff) | |
download | aspectj-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/bugs183/442425/MyAnnotatedController.java')
-rw-r--r-- | tests/bugs183/442425/MyAnnotatedController.java | 63 |
1 files changed, 35 insertions, 28 deletions
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()); + } } - |