Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

SourceLocationWithinExprHard.java 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import org.aspectj.testing.Tester;
  2. import org.aspectj.lang.*;
  3. import org.aspectj.lang.reflect.*;
  4. /** @testcase PR#885 call source locations within expression */
  5. public class SourceLocationWithinExprHard {
  6. public static void main (String[] args) {
  7. new // 9*
  8. C() // 10
  9. . // 11
  10. getD() // 12*
  11. . // 13
  12. getE() // 14*
  13. . // 15
  14. getF() // 16*
  15. ;
  16. Tester.expectEvent("setup");
  17. Tester.checkAllEvents();
  18. }
  19. }
  20. class C { D getD() { return new D(); } }
  21. class D { E getE() { return new E(); } }
  22. class E { F getF() { return new F(); } }
  23. class F { }
  24. aspect A {
  25. private static final String SEP = " - ";
  26. static {
  27. // using qualifying expr?
  28. Tester.expectEvent("C()" + SEP + "9");
  29. Tester.expectEvent("getD()" + SEP + "12");
  30. Tester.expectEvent("getE()" + SEP + "14");
  31. Tester.expectEvent("getF()" + SEP + "16");
  32. Tester.event("setup");
  33. }
  34. pointcut filter() : withincode(static void SourceLocationWithinExpr.main(String[]));
  35. before() : filter() && call(C.new()) { signal("C()", thisJoinPoint); }
  36. before() : filter() && call(D C.getD()) { signal("getD()", thisJoinPoint); }
  37. before() : filter() && call(E D.getE()) { signal("getE()", thisJoinPoint); }
  38. before() : filter() && call(F E.getF()) { signal("getF()", thisJoinPoint); }
  39. void signal(String prefix, JoinPoint jp) {
  40. SourceLocation sl = jp.getSourceLocation();
  41. System.out.println(prefix + SEP + sl.getLine());
  42. Tester.event(prefix + SEP + sl.getLine());
  43. }
  44. }