diff options
author | aclement <aclement> | 2005-10-20 10:32:20 +0000 |
---|---|---|
committer | aclement <aclement> | 2005-10-20 10:32:20 +0000 |
commit | 720a6d9d5c1900b79a91d704af8c3973f6165e0d (patch) | |
tree | 3c1d187b35205707b2f61557445cbde4cb206692 /tests/java5 | |
parent | a07fd2951422464096ce02a682e8d02be17353ff (diff) | |
download | aspectj-720a6d9d5c1900b79a91d704af8c3973f6165e0d.tar.gz aspectj-720a6d9d5c1900b79a91d704af8c3973f6165e0d.zip |
Fix for ordering problem when using generic abstract aspects. Fix for crappy code (of mine) in ResolvedType.discover... - see pr112105 comment #10
Diffstat (limited to 'tests/java5')
3 files changed, 150 insertions, 35 deletions
diff --git a/tests/java5/generics/genericaspects/BlobContainment.aj b/tests/java5/generics/genericaspects/BlobContainment.aj index 923e12224..9ae21df0b 100644 --- a/tests/java5/generics/genericaspects/BlobContainment.aj +++ b/tests/java5/generics/genericaspects/BlobContainment.aj @@ -1,6 +1,5 @@ public aspect BlobContainment extends ParentChildRelationship<Blob,Blob> { - public static void main(String []argv) { Blob a = new Blob(); Blob b = new Blob(); @@ -17,12 +16,14 @@ public aspect BlobContainment extends ParentChildRelationship<Blob,Blob> { // 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 index 6d9624d6d..b5fb093fb 100644 --- a/tests/java5/generics/genericaspects/ParentChildRelationship.aj +++ b/tests/java5/generics/genericaspects/ParentChildRelationship.aj @@ -1,57 +1,99 @@ import java.util.*; import org.aspectj.lang.annotation.*; + +abstract aspect ParentChildRelationship<Parent,Child> { + + interface ParentHasChildren<C>{} + interface ChildHasParent<P>{} + + declare parents: Parent implements ParentHasChildren<Child>; + declare parents: Child implements ChildHasParent<Parent>; + + public List<E> ParentHasChildren<E>.children = new ArrayList<E>(); + public P ChildHasParent<P>.parent; + + public List<D> ParentHasChildren<D>.getChildren() { + return Collections.unmodifiableList(children); + } + + public P ChildHasParent<P>.getParent() { + return parent; + } + + public void ChildHasParent<R>.setParent(R parent) { + this.parent = parent; + ParentHasChildren phc = (ParentHasChildren)parent; + if (phc.getChildren().contains(this)) + phc.addChild(this); + } + + public void ParentHasChildren<X>.addChild(X child) { + if (((ChildHasParent)child).parent != null) { + ((ParentHasChildren)((ChildHasParent)child).parent).removeChild(child); + } else { + ((ChildHasParent)child).setParent((ParentHasChildren)this); + } + children.add(child); + } + + public void ParentHasChildren<Y>.removeChild(Y child) { + if (children.remove(child)) { + ((ChildHasParent)child).parent = null; + } + } + +} +/* abstract aspect ParentChildRelationship<Parent,Child> { - /** interface implemented by parents */ + // interface implemented by parents interface ParentHasChildren<C>{ -// List<C> getChildren(); -// void addChild(C child); -// void removeChild(C child); + List<C> getChildren(); + void addChild(C child); + void removeChild(C child); } - /** interface implemented by children */ + // interface implemented by children interface ChildHasParent<P>{ -// P getParent(); -// void setParent(P parent); + P getParent(); + void setParent(P parent); } - /** ensure the parent type implements ParentHasChildren<child type> */ + // ensure the parent type implements ParentHasChildren<child type> declare parents: Parent implements ParentHasChildren<Child>; - /** ensure the child type implements ChildHasParent<parent type> */ + // ensure the child type implements ChildHasParent<parent type> declare parents: Child implements ChildHasParent<Parent>; // Inter-type declarations made on the *generic* interface types to provide // default implementations. - /** list of children maintained by parent */ + // list of children maintained by parent public List<E> ParentHasChildren<E>.children = new ArrayList<E>(); - /** reference to parent maintained by child */ + // reference to parent maintained by child public P ChildHasParent<P>.parent; - /** Default implementation of getChildren for the generic type ParentHasChildren */ + // Default implementation of getChildren for the generic + // type ParentHasChildren public List<D> ParentHasChildren<D>.getChildren() { return Collections.unmodifiableList(children); } - /** Default implementation of getParent for the generic type ChildHasParent */ + // Default implementation of getParent for the generic + // type ChildHasParent public P ChildHasParent<P>.getParent() { return parent; } - /** - * Default implementation of setParent for the generic type ChildHasParent. - * Ensures that this child is added to the children of the parent too. - */ + // Default implementation of setParent for the generic type ChildHasParent. + // Ensures that this child is added to the children of the parent too. public void ChildHasParent<R>.setParent(R parent) { ((ParentHasChildren)parent).addChild(this); } - /** - * Default implementation of addChild, ensures that parent of child is - * also updated. - */ + // Default implementation of addChild, ensures that parent of child is + // also updated. public void ParentHasChildren<X>.addChild(X child) { if (((ChildHasParent)child).parent != null) { ((ParentHasChildren)((ChildHasParent)child).parent).removeChild(child); @@ -60,27 +102,23 @@ abstract aspect ParentChildRelationship<Parent,Child> { ((ChildHasParent)child).parent = (ParentHasChildren)this; } - /** - * Default implementation of removeChild, ensures that parent of - * child is also updated. - */ + // Default implementation of removeChild, ensures that parent of + // child is also updated. public void ParentHasChildren<Y>.removeChild(Y child) { if (children.remove(child)) { ((ChildHasParent)child).parent = null; } } - /** - * Matches at an addChild join point for the parent type P and child type C - */ + + // Matches at an addChild join point for the parent type P and child type C @SuppressAjWarnings public pointcut addingChild(Parent p, Child c) : execution(* Parent.addChild(Child)) && this(p) && args(c); - /** - * Matches at a removeChild join point for the parent type P and child type C - */ - @SuppressAjWarnings - public pointcut removingChild(Parent p, Child c) : - execution(* Parent.removeChild(Child)) && this(p) && args(c); + // Matches at a removeChild join point for the parent type P and child type C + @SuppressAjWarnings + public pointcut removingChild(Parent p, Child c) : + execution(* Parent.removeChild(Child)) && this(p) && args(c); } +*/ diff --git a/tests/java5/generics/genericaspects/TheBigOne.java b/tests/java5/generics/genericaspects/TheBigOne.java new file mode 100644 index 000000000..42be102f1 --- /dev/null +++ b/tests/java5/generics/genericaspects/TheBigOne.java @@ -0,0 +1,76 @@ +import java.util.*; +import org.aspectj.lang.annotation.*; + +class Blob {} + +public aspect TheBigOne 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()); + } + +} + + +abstract aspect ParentChildRelationship<Parent,Child> { + + interface ParentHasChildren<C>{} + interface ChildHasParent<P>{} + + declare parents: Parent implements ParentHasChildren<Child>; + declare parents: Child implements ChildHasParent<Parent>; + + public List<E> ParentHasChildren<E>.children = new ArrayList<E>(); + public P ChildHasParent<P>.parent; + + public List<D> ParentHasChildren<D>.getChildren() { + return Collections.unmodifiableList(children); + } + + public P ChildHasParent<P>.getParent() { + return parent; + } + + public void ChildHasParent<R>.setParent(R parent) { + this.parent = parent; + ParentHasChildren phc = (ParentHasChildren)parent; + if (phc.getChildren().contains(this)) + phc.addChild(this); + } + + public void ParentHasChildren<X>.addChild(X child) { + if (((ChildHasParent)child).parent != null) { + ((ParentHasChildren)((ChildHasParent)child).parent).removeChild(child); + } else { + ((ChildHasParent)child).setParent((ParentHasChildren)this); + } + children.add(child); + } + + public void ParentHasChildren<Y>.removeChild(Y child) { + if (children.remove(child)) { + ((ChildHasParent)child).parent = null; + } + } + +} |