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.

IntroOrder.java 1.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import org.aspectj.testing.Tester;
  2. public class IntroOrder {
  3. public static void main(String[] args) {
  4. Persist.HasPersistor hp1 = new Class1();
  5. Persist.HasPersistor hp2 = new Class2();
  6. Persistor p = new Persistor();
  7. hp1.setPersistor(p);
  8. Tester.checkEqual(p, hp1.getPersistor(), "basic intro");
  9. }
  10. }
  11. class Class1 {}
  12. class Class2 {}
  13. aspect A1 {
  14. declare parents: Class1 implements Persist.HasPersistor;
  15. }
  16. abstract aspect Persist {
  17. interface HasPersistor {
  18. // introduction below specifies this interface
  19. }
  20. private Persistor HasPersistor.persistor;
  21. public void HasPersistor.setPersistor(Persistor p) { persistor = p; }
  22. public Persistor HasPersistor.getPersistor() { return persistor; }
  23. abstract pointcut readMethods();
  24. abstract pointcut writeMethods();
  25. //advices
  26. }
  27. aspect A2 extends Persist {
  28. declare parents: Class2 implements HasPersistor;
  29. // concretize pointcuts
  30. pointcut readMethods();
  31. pointcut writeMethods();
  32. }
  33. class Persistor {}