diff options
author | wisberg <wisberg> | 2002-12-16 18:51:06 +0000 |
---|---|---|
committer | wisberg <wisberg> | 2002-12-16 18:51:06 +0000 |
commit | 144143c2970a1e874d74cdbd0f8c622d4282a3c3 (patch) | |
tree | b12383d3d9e76c7e1f25f7fbec83051ef17f81fb /tests/design/intro | |
parent | fafae443719b26159ab2d7dac1c9b46b5e00b671 (diff) | |
download | aspectj-144143c2970a1e874d74cdbd0f8c622d4282a3c3.tar.gz aspectj-144143c2970a1e874d74cdbd0f8c622d4282a3c3.zip |
initial version
Diffstat (limited to 'tests/design/intro')
-rw-r--r-- | tests/design/intro/Interfaces.java | 98 | ||||
-rw-r--r-- | tests/design/intro/MultiInheritCF.java | 47 | ||||
-rw-r--r-- | tests/design/intro/MultiInheritCP.java | 46 | ||||
-rw-r--r-- | tests/design/intro/Overriding.java | 82 | ||||
-rw-r--r-- | tests/design/intro/Simple.java | 80 | ||||
-rw-r--r-- | tests/design/intro/Statics.java | 56 | ||||
-rw-r--r-- | tests/design/intro/Within.java | 64 | ||||
-rw-r--r-- | tests/design/intro/p1/C1.java | 11 | ||||
-rw-r--r-- | tests/design/intro/p1/ScopeIssues.java | 16 |
9 files changed, 500 insertions, 0 deletions
diff --git a/tests/design/intro/Interfaces.java b/tests/design/intro/Interfaces.java new file mode 100644 index 000000000..67ca0f684 --- /dev/null +++ b/tests/design/intro/Interfaces.java @@ -0,0 +1,98 @@ +import org.aspectj.testing.Tester; + +import java.util.*; + +import org.aspectj.lang.reflect.*; + +public class Interfaces { + public static void main(String[] args) { + String v = I.staticField; + Tester.checkEqual(notes, "I.staticField", "static init of I"); + Tester.checkEqual(v, "I.staticField"); + clearNotes(); + + I i = (I)new C(); + Tester.checkEqual(notes, + "initialize-I instanceField-A* I.instanceField privateField-A* I.privateField-from-A privateField-A* I.privateField-from-B", + "inst init of I"); + Tester.checkEqual(i.instanceField, "I.instanceField"); + clearNotes(); + + v = SubI.staticField; + Tester.checkEqual(notes, "SubI.staticField", "static init of SubI"); + Tester.checkEqual(v, "SubI.staticField"); + clearNotes(); + + SubI si = (SubI)new SubC(); + Tester.checkEqual(notes, + "initialize-I instanceField-A* I.instanceField privateField-A* I.privateField-from-A privateField-A* I.privateField-from-B SubI.instanceField", + "inst init of SubI"); + Tester.checkEqual(si.instanceField, "SubI.instanceField"); + clearNotes(); + + + i.instanceField += "-XXX"; + Tester.checkEqual(notes, "I.instanceField-!I||A*", "I.instanceField set"); + Tester.checkEqual(i.instanceField, "I.instanceField-XXX"); + } + + private static List notes = new LinkedList(); + + public static void clearNotes() { + notes = new LinkedList(); + //System.out.println("***********************************************"); + } + + public static String note(String note) { + notes.add(note); + //System.out.println(note); + return note; + } +} + +class C implements I { + String instanceField = "C.instanceField"; +} + +class SubC extends C implements SubI { + String instanceField = "SubC.instanceField"; +} + +interface I { + // must follow standard Java rules + String staticField = Interfaces.note("I.staticField"); +} + +interface SubI extends I { + String staticField = Interfaces.note("SubI.staticField"); +} + + + +aspect A1 { + public String SubI.instanceField = Interfaces.note("SubI.instanceField"); + + public String I.instanceField = Interfaces.note("I.instanceField"); + private String I.privateField = Interfaces.note("I.privateField-from-A"); +} + +aspect A2 { + private String I.privateField = Interfaces.note("I.privateField-from-B"); +} + +aspect A3 { + before(I i): !within(I||A*) && set(String I.*) && target(i) { + Interfaces.note(thisJoinPoint.getSignature().toShortString()+"-!I||A*"); // +"::" + thisJoinPoint.getSourceLocation().getWithinType()); + } + + before(I i): within(I) && set(String I.*) && target(i) { + Interfaces.note(thisJoinPoint.getSignature().getName()+"-I"); //toShortString()); + } + before(I i): within(A*) && set(String I.*) && target(i) { + Interfaces.note(thisJoinPoint.getSignature().getName()+"-A*"); //toShortString()); + } + + before(I i): initialization(I.new(..)) && target(i) { + Interfaces.note("initialize-I"); + } +} diff --git a/tests/design/intro/MultiInheritCF.java b/tests/design/intro/MultiInheritCF.java new file mode 100644 index 000000000..cd9be4b91 --- /dev/null +++ b/tests/design/intro/MultiInheritCF.java @@ -0,0 +1,47 @@ +import org.aspectj.testing.Tester; + +public class MultiInheritCF { + public static void main(String[] args) { + C c = new C(); + Tester.checkEqual(c.fromRoot(), "Root"); + Tester.checkEqual(c.toString(), "I1"); + Tester.checkEqual(c.fromI2(), "I2"); + Tester.checkEqual(c.fromIRoot0(), "IRoot"); + Tester.checkEqual(c.fromIRoot1(), "I1"); + Tester.checkEqual(c.fromIRoot2(), "I2"); + } +} + +abstract class Root { + public String fromRoot() { return "Root"; } + public abstract String fromI2(); + public String toString() { return "Root"; } +} + +class C extends Root implements I1, I2 { +} + +interface IRoot { +} + +interface I1 extends IRoot { + public String fromRoot(); +} + +interface I2 extends IRoot { +} + + +aspect A { + public String IRoot.fromIRoot0() { return "IRoot"; } + public String IRoot.fromIRoot1() { return "IRoot"; } + public String IRoot.fromIRoot2() { return "IRoot"; } + + + public String I1.toString() { return "I1"; } //ERR: conflicts with Root + public abstract int I2.toString(); //ERR: conflicts with Root and I1 + String I2.fromI2() { return "I2"; } //ERR: weaker than Root + + public String I1.fromIRoot1() { return "I1"; } + public String I2.fromIRoot1() { return "I1"; } //ERR: conflicts with I1 +} diff --git a/tests/design/intro/MultiInheritCP.java b/tests/design/intro/MultiInheritCP.java new file mode 100644 index 000000000..704041086 --- /dev/null +++ b/tests/design/intro/MultiInheritCP.java @@ -0,0 +1,46 @@ +import org.aspectj.testing.Tester; + +public class MultiInheritCP { + public static void main(String[] args) { + C c = new C(); + Tester.checkEqual(c.fromRoot(), "Root"); + Tester.checkEqual(c.toString(), "I1"); + Tester.checkEqual(c.fromI2(), "I2"); + Tester.checkEqual(c.fromIRoot0(), "IRoot"); + Tester.checkEqual(c.fromIRoot1(), "I1"); + Tester.checkEqual(c.fromIRoot2(), "I2"); + } +} + +abstract class Root { + public String fromRoot() { return "Root"; } + public abstract String fromI2(); +} + +class C extends Root implements I1, I2 { +} + +interface IRoot { +} + +interface I1 extends IRoot { + public String fromRoot(); +} + +interface I2 extends IRoot { +} + + +aspect A { + public String IRoot.fromIRoot0() { return "IRoot"; } + public String IRoot.fromIRoot1() { return "IRoot"; } + public String IRoot.fromIRoot2() { return "IRoot"; } + + + public String I1.toString() { return "I1"; } + public abstract String I2.toString(); + public String I2.fromI2() { return "I2"; } + + public String I1.fromIRoot1() { return "I1"; } + public String I2.fromIRoot2() { return "I2"; } +} diff --git a/tests/design/intro/Overriding.java b/tests/design/intro/Overriding.java new file mode 100644 index 000000000..7e8412eac --- /dev/null +++ b/tests/design/intro/Overriding.java @@ -0,0 +1,82 @@ +import org.aspectj.testing.Tester; + +public class Overriding { + public static void main(String[] args) { + SuperC sc = new C(); + + Tester.checkEqual(sc.m(), "A2"); + Tester.checkEqual(A3.getMi(sc), "A3.I2"); + Tester.checkEqual(A4.getMi(sc), "A4.I2"); + Tester.checkEqual(A3.getM2(sc), "A3.Inner"); + Tester.checkEqual(A4.getM2(sc), "A4.Inner"); + } +} + +abstract class SuperC { } +class C extends SuperC {} +class SubC extends C {} + +aspect A1 { + abstract String SuperC.m(); +} + + +aspect A2 { + String C.m() { + return "A2"; + } +} + +class A3 { + static aspect I1 { + private abstract String SuperC.mi(); + } + + static aspect I2 { + private String C.mi() { + return "A3.I2"; + } + } + + public static String getMi(SuperC sc) { + return sc.mi(); + } + + + static aspect Inner { + private abstract String SuperC.m2(); + private String C.m2() { + return "A3.Inner"; + } + } + public static String getM2(SuperC sc) { + return sc.m2(); + } +} + +class A4 { + static aspect I1 { + private abstract String SuperC.mi(); + } + + static aspect I2 { + private String C.mi() { + return "A4.I2"; + } + } + + public static String getMi(SuperC sc) { + return sc.mi(); + } + + static aspect Inner { + private abstract String SuperC.m2(); + private String C.m2() { + return "A4.Inner"; + } + } + public static String getM2(SuperC sc) { + return sc.m2(); + } + +} diff --git a/tests/design/intro/Simple.java b/tests/design/intro/Simple.java new file mode 100644 index 000000000..cd995d993 --- /dev/null +++ b/tests/design/intro/Simple.java @@ -0,0 +1,80 @@ +import org.aspectj.testing.Tester; + +public class Simple { + public static void main(String[] args) { + C c = new C(); + I i = (I)new C("hi"); + Tester.checkEqual(c.foo(), "foo:bar"); + Tester.checkEqual(i.mumble(), "mumble:foo:bar"); + + Tester.checkEqual(A.Cm(), "from A"); + Tester.checkEqual(B.Cm(), "from B"); + + c.idata = "c-mumble"; + Tester.checkEqual(c.idata, "c-mumble"); + Tester.checkEqual(i.idata, "mumble"); + + Tester.check("new A.C"); + Tester.check("new B.C"); + } +} + +class C { + public C() { super(); } + public String bar() {return "bar"; } +} + +interface I { + String foo(); + String bar(); +} + + +aspect A { + private String C.data = "foo"; + private String C.data1 = this.data; + + public String I.idata = "mumble"; + + public String C.foo() { + String s = this.data; + Tester.checkEqual(s, data1); + return data + ":" + bar(); + } + + declare parents: C implements I; + + public String I.mumble() { + return idata + ":" + foo(); + } + + private String C.m() { + return "from A"; + } + + public static String Cm() { + return new C(2).m(); + } + + public C.new(String s) { } + + private C.new(int i) { + Tester.note("new A.C"); + } +} + +aspect B { + private String C.data = "B"; + + private String C.m() { + return "from " + data; + } + + public static String Cm() { + return new C(2).m(); + } + + private C.new(int i) { + Tester.note("new B.C"); + } +} diff --git a/tests/design/intro/Statics.java b/tests/design/intro/Statics.java new file mode 100644 index 000000000..183e96be9 --- /dev/null +++ b/tests/design/intro/Statics.java @@ -0,0 +1,56 @@ +import org.aspectj.testing.Tester; + +public class Statics { + public static void main(String[] args) { + new C(); + Tester.checkEqual(C.getCount(), 1, "C.getCount()"); + Tester.checkEqual(SubC.getCount(), 0, "SubC.getCount()"); + new SubC(); + Tester.checkEqual(C.getCount(), 1, "C.getCount()"); + Tester.checkEqual(SubC.getCount(), 1, "SubC.getCount()"); + new SubC(); + Tester.checkEqual(C.getCount(), 1, "C.getCount()"); + Tester.checkEqual(SubC.getCount(), 2, "SubC.getCount()"); + + I.count += 1; + Tester.checkEqual(I.getCount(), 1, "I.getCount()"); + + Tester.checkEqual(I1.count, 10, "I1.count"); + Tester.checkEqual(SubI.count, 20, "SubI.count"); + Tester.checkEqual(SubI.getCount(), 1, "SubI.getCount()"); + } +} + + +class C { } + +class SubC extends C {} + +interface I {} + +interface I1 { + int N = -1; + Object o = new Integer(2); +} + +interface SubI extends I, I1 { } + +aspect Counter { + private static int C.instanceCount = 0; + private void C.incCount() { instanceCount++; } + static int C.getCount() { return instanceCount; } + private static int SubC.instanceCount = 0; + private void SubC.incCount() { instanceCount++; } + static int SubC.getCount() { return instanceCount; } + + static int I.count = 0; + static int I.getCount() { return count; } + + static int I1.count = 10; + + static int SubI.count = 20; + + after() returning (C c) : call(C+.new(..)) { + c.incCount(); + } +} diff --git a/tests/design/intro/Within.java b/tests/design/intro/Within.java new file mode 100644 index 000000000..49021c1f0 --- /dev/null +++ b/tests/design/intro/Within.java @@ -0,0 +1,64 @@ +import org.aspectj.testing.Tester; + +public class Within { + public static void main(String[] args) { + C c = new C(); + c.mi(); + + Tester.check("I.mi within A1"); + Tester.check("I.mi instanceof C"); + Tester.check("I.mi instanceof I"); + + c.mc(); + } +} + + +class C { + void mc() {} +} + +interface I {} + +aspect A1 { + void I.mi() {} +} + +aspect A2 { + declare parents: C implements I; +} + + + +aspect Test { + before (): execution(* I.*(..)) && within(C) { + Tester.checkFailed(thisJoinPoint + " I.* within C"); + } + before (): execution(* I.*(..)) && within(I) { + Tester.checkFailed(thisJoinPoint + " I.* within I"); + } + before (): execution(* I.*(..)) && within(A1) { + Tester.checkEqual(thisJoinPoint.getSignature().getName(), "mi", + thisJoinPoint + " I.* within A1"); + Tester.note("I.mi within A1"); + } + before (): execution(* I.*(..)) && within(A2) { + } + + before (): execution(* I.*(..)) && this(C) { + Tester.checkEqual(thisJoinPoint.getSignature().getName(), "mi", + thisJoinPoint + " I.* instanceof C"); + Tester.note("I.mi instanceof C"); + } + before (): execution(* I.*(..)) && this(I) { + Tester.checkEqual(thisJoinPoint.getSignature().getName(), "mi", + thisJoinPoint + " I.* instanceof I"); + Tester.note("I.mi instanceof I"); + } + before (): execution(* I.*(..)) && this(A1) { + Tester.checkFailed(thisJoinPoint + " I.* instanceof A1"); + } + before (): execution(* I.*(..)) && this(A2) { + Tester.checkFailed(thisJoinPoint + " I.* instanceof A2"); + } +} diff --git a/tests/design/intro/p1/C1.java b/tests/design/intro/p1/C1.java new file mode 100644 index 000000000..f7d7bd081 --- /dev/null +++ b/tests/design/intro/p1/C1.java @@ -0,0 +1,11 @@ +package p1; + +import java.util.*; + +public class C1 { + Map map = new HashMap(); +} + +class Helper { + List l = new LinkedList(); +} diff --git a/tests/design/intro/p1/ScopeIssues.java b/tests/design/intro/p1/ScopeIssues.java new file mode 100644 index 000000000..2aa2add92 --- /dev/null +++ b/tests/design/intro/p1/ScopeIssues.java @@ -0,0 +1,16 @@ +package p1; + +import org.aspectj.testing.Tester; + +import java.math.*; + +public aspect ScopeIssues { + public static void main(String[] args) { + Tester.checkEqual(C1.bi, BigInteger.ONE); + + Tester.checkEqual(Helper.bi, BigInteger.ONE); + } + + private static BigInteger C1.bi = BigInteger.ONE; + private static BigInteger Helper.bi = BigInteger.ONE; +} |