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.

AdviceOnEmptyConstructor.java 845B

123456789101112131415161718192021222324252627282930313233
  1. import org.aspectj.testing.Tester;
  2. public aspect AdviceOnEmptyConstructor {
  3. public static void main(String[] args) { test(); }
  4. public static void test() {
  5. // C has an implied empty constructor so should be advised
  6. Tester.checkEqual(new C().value, "afterInit:foo", "new C");
  7. // C1 has no implied empty constructor (make sure we aren't cheating)
  8. Tester.checkEqual(new C1(0).value, "foo", "new C1");
  9. }
  10. /*static*/ after() returning (C c):
  11. //this(c) &&
  12. call(C.new()) {
  13. c.value = "afterInit:" + c.value;
  14. }
  15. /*static*/ after() returning(C1 c1):
  16. //this(c1) &&
  17. call(C1.new()) {
  18. c1.value = "afterInit:" + c1.value;
  19. }
  20. }
  21. class C {
  22. public String value = "foo";
  23. }
  24. class C1 {
  25. public String value = "foo";
  26. public C1(int dummy) {}
  27. }