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.

IntroduceInnerInterfaceCP.java 2.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import org.aspectj.testing.Tester;
  2. import org.aspectj.testing.Tester;
  3. public class IntroduceInnerInterfaceCP {
  4. public static void main(String[] args) {
  5. new TargetClass().walk();
  6. new TargetClassWithoutImplementation().run();
  7. AnotherClass.invoke();
  8. Tester.checkAllEvents();
  9. }
  10. private static final String[] EXPECTED;
  11. static {
  12. EXPECTED = new String[]
  13. { "walk", "Implementation.walk",
  14. "execution(void TargetClass.walk())",
  15. "AnotherClass.invoke()",
  16. "Protected execution(void AnotherClass.invoke())"
  17. };
  18. Tester.expectEventsInString(EXPECTED);
  19. }
  20. }
  21. class Signal {
  22. public static final void signal(String s) {
  23. //System.err.println(s);
  24. Tester.event(s);
  25. }
  26. }
  27. class TargetClass {
  28. public void walk() {
  29. Signal.signal("walk");
  30. }
  31. }
  32. class TargetClassWithoutImplementation {
  33. void run() { }
  34. }
  35. aspect Aspect {
  36. /** @testcase PR#494 adding private interface inside aspect */
  37. private interface Inner {
  38. // automagically interpreted as public
  39. void walk();
  40. }
  41. /** @testcase PR#494 using private interface inside aspect for introductions */
  42. declare parents
  43. : TargetClass implements Inner;
  44. declare parents
  45. : TargetClassWithoutImplementation implements Inner;
  46. declare parents
  47. : TargetClassWithoutImplementation extends Implementation;
  48. static class Implementation {
  49. public void walk() {
  50. Signal.signal("Implementation.walk");
  51. }
  52. }
  53. /** @testcase PR#494 using private interface inside aspect in advice */
  54. before(TargetClassWithoutImplementation t) : target(t)
  55. && execution(void TargetClassWithoutImplementation.run()) {
  56. ((Inner) t).walk();
  57. }
  58. /** @testcase PR#494 using private interface inside aspect in execution pcd */
  59. before() : execution(public void Inner.*()) {
  60. // validate that interface implemented - addressable in pcd
  61. Signal.signal(thisJoinPointStaticPart.toString());
  62. }
  63. }
  64. class AnotherClass {
  65. static void invoke() {
  66. Signal.signal("AnotherClass.invoke()");
  67. }
  68. }
  69. abstract aspect AbstractAspect {
  70. /** Protected has no join points - validate with ShowToChild before advice */
  71. protected interface Protected {}
  72. }
  73. aspect ShowToChild extends AbstractAspect {
  74. /** @testcase PR#494 compile should bind protected interface name in aspect subclass for introduction */
  75. declare parents : AnotherClass implements Protected;
  76. /** @testcase PR#494 compile should bind protected interface name in aspect subclass for advice (even when binding static, non-interface methods with tag interfaces) */
  77. after () : within(Protected+) && execution(* *(..)) {
  78. Signal.signal("Protected " + thisJoinPointStaticPart.toString());
  79. }
  80. /** Protected has no join points */
  81. before () : within(Protected) {
  82. Tester.checkFailed("within Protected");
  83. }
  84. }