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.

AspectOnInterface.java 669B

123456789101112131415161718192021222324252627
  1. import org.aspectj.testing.Tester;
  2. public aspect AspectOnInterface /*of eachobject(instanceof(I1))*/ {
  3. before (I1 i1): target(i1) && call(String process()) {
  4. i1.addToS("-advised");
  5. }
  6. public static void main(String[] args) { test(); }
  7. public static void test() {
  8. ConcreteC1 c1 = new ConcreteC1();
  9. Tester.checkEqual(c1.process(), "foo-advised-processed", "");
  10. }
  11. }
  12. interface I1 {
  13. public void addToS(String newS);
  14. public String process();
  15. }
  16. class ConcreteC1 implements I1 {
  17. String s = "foo";
  18. public void addToS(String newS) { s += newS; }
  19. public String process() {
  20. return s + "-processed";
  21. }
  22. }