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.

IntroductionOfInitializer.java 787B

123456789101112131415161718192021222324252627282930313233343536
  1. import org.aspectj.testing.Tester;
  2. import java.io.*;
  3. /**
  4. * Test for: PR #98
  5. */
  6. public class IntroductionOfInitializer {
  7. public static void main(String[] args) { test(); }
  8. public static void test() {
  9. Tester.checkEqual(Foo.a, "class", "zero instances");
  10. Foo foo = new Foo();
  11. Tester.checkEqual(Foo.a, "class-instance", "one instances");
  12. foo = new Foo();
  13. Tester.checkEqual(Foo.a, "class-instance-instance", "two instances");
  14. }
  15. }
  16. aspect A {
  17. private static String classValue = "class";
  18. private static String instanceValue = "-instance";
  19. after(): staticinitialization(Foo) {
  20. Foo.a += classValue;
  21. }
  22. after(): initialization(Foo.new(..)) {
  23. Foo.a += instanceValue;
  24. }
  25. }
  26. class Foo {
  27. static String a = "";
  28. }