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.

SimpleGets.java 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import org.aspectj.testing.Tester;
  2. import java.util.*;
  3. import java.io.*;
  4. public class SimpleGets {
  5. public static void main(String[] args) {
  6. Test t = new Test();
  7. t.go();
  8. System.out.println("s: " + t.s);
  9. Test.ss += "hi";
  10. //Tester.checkEqual(Test.calls, ", Test.go->Test, Test.foo->java.io.PrintStream");
  11. }
  12. }
  13. class Test {
  14. int x = 10;
  15. String s = "string";
  16. String s1 = "";
  17. static String ss = "";
  18. Test getT() {
  19. return new Test();
  20. }
  21. void go() {
  22. System.out.println(x);
  23. s = getT().s + ":went";
  24. Test.ss += "static";
  25. getT().s += ":more";
  26. Test t = this;
  27. t.s1 += "xxx";
  28. x += 10;
  29. x++;
  30. System.out.println(x + " == " + x--);
  31. System.out.println(x + " == " + x++);
  32. System.out.println(x-1 + " == " + --x);
  33. }
  34. }
  35. aspect NoteGets {
  36. static after(Test t) returning (Object v): gets(* t.*) {
  37. System.out.println("got it: " + v + " from " + t + " at " + thisJoinPoint);
  38. }
  39. static after(String v): sets(String Test.*)[v][] {
  40. new Test().s += "gi";
  41. System.out.println("set: " + v + " at " + thisJoinPoint);
  42. }
  43. static around(Object old, String v) returns String: sets(String Test.*)[old][v] {
  44. new Test().s += "gi";
  45. System.out.println("around set: " + old + " --> " + v + " at " + thisJoinPoint);
  46. return proceed(old, v+"-advised");
  47. }
  48. static after(): sets(int Test.x) {
  49. int v = 0;
  50. System.out.println("iset: " + v + " at " + thisJoinPoint);
  51. }
  52. static after(Object v, Object old): sets(* Test.*)[old][v] {
  53. System.out.println("oset: " + old + " -> " + v + " at " + thisJoinPoint);
  54. }
  55. static after(): gets(PrintStream java.lang.*.*) {
  56. System.out.println("got System.out");
  57. }
  58. }