You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

IntroductionsOverriding.java 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import org.aspectj.testing.*;
  2. /** @testcase PR#654 Overriding method implementations using introduction on interfaces */
  3. public class IntroductionsOverriding {
  4. public static void main (String [] args) {
  5. (new BaseClass ()).foo("Base");
  6. (new DerivedClass ()).foo("Derived");
  7. Tester.checkAllEvents();
  8. }
  9. static {
  10. Tester.expectEvent("Derived.foo(\"Derived\")");
  11. Tester.expectEvent("Base.foo(\"Base\")");
  12. Tester.expectEvent("around call Base");
  13. Tester.expectEvent("around execution Base");
  14. Tester.expectEvent("around call Base"); // called for both Base+ and Derived+
  15. Tester.expectEvent("around execution Base");
  16. Tester.expectEvent("around call Derived");
  17. Tester.expectEvent("around execution Derived");
  18. }
  19. }
  20. interface Base { public void foo(String s); }
  21. interface Derived extends Base { public void foo(String s); }
  22. class DerivedClass implements Derived { }
  23. class BaseClass implements Base { }
  24. aspect A {
  25. public void Base.foo (String arg) {
  26. Tester.check("Base".equals(arg),
  27. "Base.foo(\"" + arg + "\")");
  28. Tester.event("Base.foo(\"" + arg + "\")");
  29. }
  30. public void Derived.foo (String arg) {
  31. Tester.check("Derived".equals(arg),
  32. "Derived.foo(\"" + arg + "\")");
  33. Tester.event("Derived.foo(\"" + arg + "\")");
  34. }
  35. void around (Base o)
  36. : execution (void Base+.foo(..)) // ok if replacing call with execution
  37. && target (o) {
  38. Tester.event("around execution Base");
  39. proceed(o);
  40. }
  41. void around (Base o)
  42. : call (void Base+.foo(..))
  43. && target (o) {
  44. Tester.event("around call Base");
  45. proceed(o);
  46. }
  47. void around () : call (void Derived+.foo(..)) {
  48. Tester.event("around call Derived");
  49. proceed();
  50. }
  51. void around () : execution (void Derived+.foo(..)) {
  52. Tester.event("around execution Derived");
  53. proceed();
  54. }
  55. }