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.

Aspect.java 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import org.aspectj.testing.Tester;
  2. import org.aspectj.lang.JoinPoint;
  3. import library1.Library1;
  4. import library2.Library2;
  5. /** extend abstract, and implement needed */
  6. aspect AnotherAspect extends Library2 {
  7. public pointcut targetJoinPoints() :
  8. execution(public static void Main.main(..));
  9. protected String renderId(JoinPoint jp) {
  10. String result = super.renderId(jp);
  11. return result + " - ok";
  12. }
  13. }
  14. class Testing {
  15. static aspect Init {
  16. declare precedence : Init, Library1, AnotherAspect;
  17. before() : AnotherAspect.targetJoinPoints() {
  18. Main.i = 1;
  19. Tester.expectEvent("before main");
  20. Tester.expectEvent("after main");
  21. Tester.expectEvent("after 2 main - ok");
  22. Tester.expectEvent("before 2 main - ok");
  23. Tester.expectEvent("before run");
  24. }
  25. after () returning : AnotherAspect.targetJoinPoints() {
  26. Tester.checkAllEvents();
  27. }
  28. before() : call(void run()) {
  29. Tester.event("before run");
  30. }
  31. }
  32. }