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.

SimpleBefore.java 628B

1234567891011121314151617181920212223242526272829
  1. import org.aspectj.lang.annotation.*;
  2. public class SimpleBefore {
  3. public static void main(String []argv) {
  4. SimpleBefore instance = new SimpleBefore();
  5. X.s.append("1");
  6. instance.m();
  7. if (!X.s.toString().equals("1b2"))
  8. throw new RuntimeException("Either advice not run or ordering wrong, expected 1b2: "+X.s);
  9. }
  10. public void m() {
  11. X.s.append("2");
  12. }
  13. @Aspect("issingleton")
  14. public static class X {
  15. public static StringBuffer s = new StringBuffer("");
  16. @Before("execution(* SimpleBefore.m())")
  17. public void before() {
  18. s.append("b");
  19. }
  20. }
  21. }