aboutsummaryrefslogtreecommitdiffstats
path: root/tests/bugs
diff options
context:
space:
mode:
authoraclement <aclement>2004-05-12 13:02:27 +0000
committeraclement <aclement>2004-05-12 13:02:27 +0000
commit052de1776081d412871faabef068de543e21f360 (patch)
tree778fab7b01aa6d18b4fb7a8b5096051ff943b354 /tests/bugs
parentb127f5214ae81a3620794d8bfac97df7ad9e23f5 (diff)
downloadaspectj-052de1776081d412871faabef068de543e21f360.tar.gz
aspectj-052de1776081d412871faabef068de543e21f360.zip
Test for Bugzilla Bug 61538
nested uses of this() inside constructors not handled properly for initialization and preinitialization pointcuts
Diffstat (limited to 'tests/bugs')
-rw-r--r--tests/bugs/ConstructorMain.java117
1 files changed, 117 insertions, 0 deletions
diff --git a/tests/bugs/ConstructorMain.java b/tests/bugs/ConstructorMain.java
new file mode 100644
index 000000000..3814d9a91
--- /dev/null
+++ b/tests/bugs/ConstructorMain.java
@@ -0,0 +1,117 @@
+public class ConstructorMain { // Bug 61538
+
+ public static void main(String args[]) {
+
+ ConstructorAspects.preinitcalls = 0;
+ B b1 = new B();
+ // preinitcalls should be 2
+ // System.out.println("Preinitcalls="+ConstructorAspects.preinitcalls);
+ int bPreinitcalls = ConstructorAspects.preinitcalls;
+
+ // Only difference between B and C is the order in which the
+ // constructors are declared in the class file
+ ConstructorAspects.preinitcalls = 0;
+ C c1 = new C();
+ // preinitcalls should be 2
+ // System.out.println("Preinitcalls="+ConstructorAspects.preinitcalls);
+ int cPreinitcalls = ConstructorAspects.preinitcalls;
+
+ if (bPreinitcalls!=cPreinitcalls)
+ throw new RuntimeException("Both b("+bPreinitcalls+") and c("+cPreinitcalls+") should report the same number of preinit jps");
+ }
+}
+
+class A {
+ int x = 4;
+ A (int x) { this.x = x; }
+}
+
+class B extends A {
+ int y;
+ static int k = 4;
+ static int j = 5;
+ static int l = 6;
+
+ B (int x, int y) { super(x+y); this.y = x+y; }
+
+ B (int x) { this(x+l, x+l); this.y = x+l; }
+
+ B () { this(k+j); this.y = l; }
+
+
+}
+class C extends A {
+ int y;
+ static int k = 4;
+ static int j = 5;
+ static int l = 6;
+
+ C () { this(k+j); this.y = l; }
+
+ C (int x) { this(x+l, x+l); this.y = x+l; }
+
+ C (int x, int y) { super(x+y); this.y = x+y; }
+
+}
+
+
+aspect ConstructorAspects {
+
+ public static int preinitcalls = 0;
+ public static int initcalls = 0;
+ public static int execs = 0;
+
+ static private int aspectnesting = 0;
+ private final static boolean log = false;
+
+ static void message(String s) {
+ if (log) {
+ for (int i=0; i<aspectnesting; i++) System.out.print("---+");
+ System.out.println(s);
+ }
+ }
+
+
+ // call of all constructors
+ pointcut allconstrcalls() : call(*..new(..)) &&
+ !within(ConstructorAspects) && !call(java.lang..new(..));
+
+ // execution of all constructors
+ pointcut allconstrexecutions() : execution(*..new(..)) &&
+ !within(ConstructorAspects);
+
+ // intialization of all constructors
+ pointcut allconstrinitializations() : initialization(*..new(..)) &&
+ !within(ConstructorAspects);
+
+ // preinitialization of all constructors
+ pointcut allconstrpreinitializations() : preinitialization(*..new(..)) &&
+ !within(ConstructorAspects);
+
+ before(): !within(ConstructorAspects) && allconstrpreinitializations() {
+ preinitcalls++;
+ }
+ // before advice
+ before () : !within(ConstructorAspects) &&
+ (allconstrpreinitializations() ||
+ allconstrinitializations() ||
+ allconstrexecutions() ) {
+ message(
+ "BEFORE: " + thisJoinPointStaticPart.getSourceLocation() +
+ " " +thisJoinPointStaticPart.toLongString());
+ aspectnesting++;
+ }
+
+ // after advice
+ after () returning : !within(ConstructorAspects) &&
+ (allconstrpreinitializations() ||
+ allconstrinitializations() ||
+ allconstrexecutions() )
+ {
+ aspectnesting--;
+ message(
+ "AFTER: " + thisJoinPointStaticPart.getSourceLocation() +
+ " " +thisJoinPointStaticPart.toLongString());
+ }
+
+}