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.

IntroducedFieldsNotBinding.java 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import org.aspectj.testing.Tester;
  2. import org.aspectj.testing.Tester;
  3. public class IntroducedFieldsNotBinding {
  4. public static void main(String[]args) {
  5. TargetClass target = new TargetClass();
  6. // when the compiler passes the test, validate runtime
  7. int result = target.getField();
  8. Tester.checkEqual(result, 1, "1 != result: " + result);
  9. Tester.checkAllEvents();
  10. }
  11. static {
  12. Tester.event("execution of getField");
  13. }
  14. }
  15. class TargetClass { }
  16. class TargetClass2 { }
  17. aspect A {
  18. private String TargetClass2.s = "hi";
  19. private int TargetClass.field = 1;
  20. public int TargetClass.getField() {
  21. int i = field; // compiler error here
  22. String s = new TargetClass2().s;
  23. Tester.checkEqual(s, "hi");
  24. Runnable r = new Runnable() {
  25. public void run() {
  26. System.out.println("running: " + field);
  27. }
  28. };
  29. r.run();
  30. return i ;
  31. }
  32. after ()
  33. : execution(public int TargetClass.getField()) {
  34. Tester.expectEvent("execution of getField");
  35. }
  36. }