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.

WithinInners.java 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import org.aspectj.testing.Tester;
  2. public class WithinInners {
  3. public static void main(String[] args) {
  4. C c = new C();
  5. c.getRunnable().run();
  6. // 1.1 doesn't capture withincode and execution of local types
  7. //(1.0 behavior)Tester.checkEqual(A.notes, "before-within:before-withincode:around-in:run:around-out:");
  8. Tester.checkEqual(A.notes, "before-within:around-in:run:around-out:");
  9. }
  10. }
  11. class C {
  12. public C() {
  13. class Inner {
  14. public void write( String text ) {
  15. System.out.println( "write( String )" );
  16. System.out.println( text );
  17. }
  18. }
  19. Inner i = new Inner();
  20. String s = "TEXT";
  21. i.write( s );
  22. }
  23. public Runnable getRunnable() {
  24. return new Runnable() {
  25. public void run() {
  26. A.notes += "run:";
  27. }
  28. };
  29. }
  30. }
  31. aspect A {
  32. public static String notes = "";
  33. /* These don't work because we can't give local types reasonable top-level names */
  34. before(String s): call(void write(String)) && args(s) { //&& withincode(C.new()) {
  35. System.out.println(s);
  36. }
  37. void around(String s): call(void write(String)) && args(s) && withincode(C.new()) {
  38. proceed(s.toLowerCase());
  39. }
  40. /* These now work and are checked */
  41. //XXX not being able to do this(c) is a pain
  42. before(Runnable runnable): execution(void Runnable.run()) && target(runnable) && within(C) { // && this(c) {
  43. //System.out.println("about to call Runnable.run in " + c + " on " + runnable);
  44. notes += "before-within:";
  45. }
  46. before(): execution(void run()) && withincode(Runnable C.getRunnable()) {
  47. //System.out.println("about to call Runnable.run in C");
  48. notes += "before-withincode:";
  49. }
  50. void around(): execution(void run()) {
  51. //System.out.println("about to call Runnable.run in C");
  52. notes += "around-in:";
  53. proceed();
  54. notes += "around-out:";
  55. }
  56. }