summaryrefslogtreecommitdiffstats
path: root/tests/java5/generics
diff options
context:
space:
mode:
authoraclement <aclement>2005-08-09 10:08:07 +0000
committeraclement <aclement>2005-08-09 10:08:07 +0000
commit43f8b24ddb2cb8b092921e614669a429830f795a (patch)
treee41c491062836197ace7f1a292f4cd9de81de509 /tests/java5/generics
parent2682cfbeaede95a9f01ea7b8fe06fd61920602c9 (diff)
downloadaspectj-43f8b24ddb2cb8b092921e614669a429830f795a.tar.gz
aspectj-43f8b24ddb2cb8b092921e614669a429830f795a.zip
GenericAspects: from AJDK
Diffstat (limited to 'tests/java5/generics')
-rw-r--r--tests/java5/generics/genericaspects/Blob.java1
-rw-r--r--tests/java5/generics/genericaspects/BlobContainment.aj28
-rw-r--r--tests/java5/generics/genericaspects/ParentChildRelationship.aj61
3 files changed, 90 insertions, 0 deletions
diff --git a/tests/java5/generics/genericaspects/Blob.java b/tests/java5/generics/genericaspects/Blob.java
new file mode 100644
index 000000000..467247589
--- /dev/null
+++ b/tests/java5/generics/genericaspects/Blob.java
@@ -0,0 +1 @@
+public class Blob {}
diff --git a/tests/java5/generics/genericaspects/BlobContainment.aj b/tests/java5/generics/genericaspects/BlobContainment.aj
new file mode 100644
index 000000000..923e12224
--- /dev/null
+++ b/tests/java5/generics/genericaspects/BlobContainment.aj
@@ -0,0 +1,28 @@
+public aspect BlobContainment extends ParentChildRelationship<Blob,Blob> {
+
+
+ public static void main(String []argv) {
+ Blob a = new Blob();
+ Blob b = new Blob();
+ Blob c = new Blob();
+ Blob d = new Blob();
+ Blob e = new Blob();
+
+ // arrange as follows: A contains B,C,D and B contains E
+
+ a.addChild(b);
+ a.addChild(c);
+ a.addChild(d);
+ b.addChild(e);
+
+ // now query the layout
+
+ if (!e.getParent().equals(b))
+ throw new RuntimeException("why is E not parent of B? "+e.getParent());
+ if (!d.getParent().equals(a))
+ throw new RuntimeException("why is A not parent of D? "+d.getParent());
+ if (a.getChildren().size()!=3)
+ throw new RuntimeException("A should have 3 children, not:"+a.getChildren().size());
+ }
+
+}
diff --git a/tests/java5/generics/genericaspects/ParentChildRelationship.aj b/tests/java5/generics/genericaspects/ParentChildRelationship.aj
new file mode 100644
index 000000000..3e34e3afd
--- /dev/null
+++ b/tests/java5/generics/genericaspects/ParentChildRelationship.aj
@@ -0,0 +1,61 @@
+import java.util.*;
+
+public abstract aspect ParentChildRelationship<P,C> {
+
+ /**
+ * Parents contain a list of children
+ */
+ private List<C> P.children;
+
+ /**
+ * Each child has a parent
+ */
+ private P C.parent;
+
+ /**
+ * Parents provide access to their children
+ */
+ public List<C> P.getChildren() {
+ return Collections.unmodifiableList(children);
+ }
+
+ /**
+ * A child provides access to its parent
+ */
+ public P C.getParent() {
+ return parent;
+ }
+
+ /**
+ * ensure bi-directional navigation on adding a child
+ */
+ public void P.addChild(C child) {
+ if (child.parent != null) {
+ child.parent.removeChild(child);
+ }
+ children.add(child);
+ child.parent = this;
+ }
+
+ /**
+ * ensure bi-directional navigation on removing a child
+ */
+ public void P.removeChild(C child) {
+ if (children.remove(child)) {
+ child.parent = null;
+ }
+ }
+
+ /**
+ * ensure bi-directional navigation on setting parent
+ */
+ public void C.setParent(P parent) {
+ parent.addChild(this);
+ }
+
+ public pointcut addingChild(P p, C c) :
+ execution(* P.addChild(C)) && this(p) && args(c);
+
+ public pointcut removingChild(P p, C c) :
+ execution(* P.removeChild(C)) && this(p) && args(c);
+}