diff options
author | aclement <aclement> | 2005-08-22 17:00:01 +0000 |
---|---|---|
committer | aclement <aclement> | 2005-08-22 17:00:01 +0000 |
commit | 1abe388fddf09811e19dbb1405ed8d81c0cec694 (patch) | |
tree | 370ef5cb166a1e22a2755020e104b4d6d95c3984 /tests/java5 | |
parent | ffec34a47eb415e55b132be4f73d73c9ae4aadd5 (diff) | |
download | aspectj-1abe388fddf09811e19dbb1405ed8d81c0cec694.tar.gz aspectj-1abe388fddf09811e19dbb1405ed8d81c0cec694.zip |
genericitds: tests moved around and activated in GenericsTests
Diffstat (limited to 'tests/java5')
20 files changed, 133 insertions, 179 deletions
diff --git a/tests/java5/generics/binaryweaving/A1.aj b/tests/java5/generics/binaryweaving/A1.aj new file mode 100644 index 000000000..45f7fe779 --- /dev/null +++ b/tests/java5/generics/binaryweaving/A1.aj @@ -0,0 +1,5 @@ +aspect A1 { + declare parents: C* implements I<String>; +} + +interface I<T> {} diff --git a/tests/java5/generics/binaryweaving/C1.aj b/tests/java5/generics/binaryweaving/C1.aj new file mode 100644 index 000000000..b76d06a3c --- /dev/null +++ b/tests/java5/generics/binaryweaving/C1.aj @@ -0,0 +1 @@ +class C1 {} diff --git a/tests/java5/generics/genericaspects/GenericAspectT.aj b/tests/java5/generics/genericaspects/GenericAspectT.aj index a34e4c0b4..8efc804b7 100644 --- a/tests/java5/generics/genericaspects/GenericAspectT.aj +++ b/tests/java5/generics/genericaspects/GenericAspectT.aj @@ -4,11 +4,11 @@ import org.aspectj.lang.annotation.*; aspect ParentChildRelationship { - interface I<P>{} + interface I<P extends I>{} public String I.parent; - public void I<T>.do(T a) { + public void I<T>.abc(T a) { a.parent=null; } diff --git a/tests/java5/generics/genericaspects/GenericAspectU.aj b/tests/java5/generics/genericaspects/GenericAspectU.aj index 8ed1f100e..7197a51f0 100644 --- a/tests/java5/generics/genericaspects/GenericAspectU.aj +++ b/tests/java5/generics/genericaspects/GenericAspectU.aj @@ -2,6 +2,7 @@ import java.util.*; import java.lang.reflect.*; import org.aspectj.lang.annotation.*; + abstract aspect ParentChildRelationship<Parent,Child> { interface ParentHasChildren<C>{} @@ -22,27 +23,25 @@ abstract aspect ParentChildRelationship<Parent,Child> { } public void ChildHasParent<R>.setParent(R parent) { -// parent.addChild(this); + ((ParentHasChildren)parent).addChild(this); } public void ParentHasChildren<X>.addChild(X child) { - //if (child.parent != null) { - //child.parent.removeChild(child); - // } + if (((ChildHasParent)child).parent != null) { + ((ParentHasChildren)((ChildHasParent)child).parent).removeChild(child); + } children.add(child); } -/* public void ParentHasChildren<Y>.removeChild(Y child) { if (children.remove(child)) { - child.parent = null; + ((ChildHasParent)child).parent = null; } } -*/ } -aspect GenericAspectT extends ParentChildRelationship<Top,Bottom> { +aspect GenericAspectU extends ParentChildRelationship<Top,Bottom> { public static void main(String []argv) { @@ -92,7 +91,7 @@ aspect GenericAspectT extends ParentChildRelationship<Top,Bottom> { "parent check 1 failed "+ "retrieved="+retrievedParent+" expected="+t); -/* + Top top2 = new Top(); b.setParent(top2); Top retrievedParent2 = b.getParent(); @@ -102,12 +101,12 @@ aspect GenericAspectT extends ParentChildRelationship<Top,Bottom> { Bottom bot2 = new Bottom(); top2.addChild(bot2); - //Bottom aBottom = top2.getChildren().get(0); - //check(aBottom==bot2,"Incorrect child? expected="+bot2+" found="+aBottom); - //top2.removeChild(bot2); - //int size=top2.getChildren().size(); - //check(size==0,"Should be no children but there were "+size); -*/ + Bottom aBottom = top2.getChildren().get(0); + check(aBottom==bot2,"Incorrect child? expected="+bot2+" found="+aBottom); + top2.removeChild(bot2); + int size=top2.getChildren().size(); + check(size==0,"Should be no children but there were "+size); + } diff --git a/tests/java5/generics/genericaspects/ParentChildRelationship.aj b/tests/java5/generics/genericaspects/ParentChildRelationship.aj index 3e34e3afd..6d9624d6d 100644 --- a/tests/java5/generics/genericaspects/ParentChildRelationship.aj +++ b/tests/java5/generics/genericaspects/ParentChildRelationship.aj @@ -1,61 +1,86 @@ import java.util.*; +import org.aspectj.lang.annotation.*; +abstract aspect ParentChildRelationship<Parent,Child> { -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; + /** interface implemented by parents */ + interface ParentHasChildren<C>{ +// List<C> getChildren(); +// void addChild(C child); +// void removeChild(C child); + } + + /** interface implemented by children */ + interface ChildHasParent<P>{ +// P getParent(); +// void setParent(P parent); + } + + /** ensure the parent type implements ParentHasChildren<child type> */ + declare parents: Parent implements ParentHasChildren<Child>; + + /** 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 */ + public List<E> ParentHasChildren<E>.children = new ArrayList<E>(); + + /** reference to parent maintained by child */ + public P ChildHasParent<P>.parent; + + /** 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 */ + public P ChildHasParent<P>.getParent() { + return parent; + } /** - * Parents provide access to their children + * Default implementation of setParent for the generic type ChildHasParent. + * Ensures that this child is added to the children of the parent too. */ - 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; - } + public void ChildHasParent<R>.setParent(R parent) { + ((ParentHasChildren)parent).addChild(this); + } - /** - * ensure bi-directional navigation on removing a child - */ - public void P.removeChild(C child) { - if (children.remove(child)) { - child.parent = null; - } + /** + * 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); } + children.add(child); + ((ChildHasParent)child).parent = (ParentHasChildren)this; + } /** - * ensure bi-directional navigation on setting parent + * Default implementation of removeChild, ensures that parent of + * child is also updated. */ - public void C.setParent(P parent) { - parent.addChild(this); + public void ParentHasChildren<Y>.removeChild(Y child) { + if (children.remove(child)) { + ((ChildHasParent)child).parent = null; } - - public pointcut addingChild(P p, C c) : - execution(* P.addChild(C)) && this(p) && args(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); - public pointcut removingChild(P p, C c) : - execution(* P.removeChild(C)) && 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/itds/Parse5.java b/tests/java5/generics/itds/Parse5.java index c322f006d..30514a5d9 100644 --- a/tests/java5/generics/itds/Parse5.java +++ b/tests/java5/generics/itds/Parse5.java @@ -2,15 +2,15 @@ public class Parse5<T,S extends Number> {} aspect X { - String Parse5.m1() {} + void Parse5.m1() {} - String Parse5<Q,R extends Number>.m2() {} + void Parse5<Q,R>.m2() {} - String Parse5<T,V>.m3() {} // error + void Parse5<T,V>.m3() {} - String Parse5<A,B extends Number,C>.m4() {} // error + void Parse5<A,B,C>.m4() {} // error - String Parse5<A>.m5() {} // error + void Parse5<A>.m5() {} // error - String Parse5<String,Integer>.m6() {} // error + void Parse5<String,Integer>.m6() {} // error } diff --git a/tests/java5/generics/itds/binaryweaving/A1.aj b/tests/java5/generics/itds/binaryweaving/A1.aj index 005d9dc2d..c1a25632a 100644 --- a/tests/java5/generics/itds/binaryweaving/A1.aj +++ b/tests/java5/generics/itds/binaryweaving/A1.aj @@ -7,7 +7,7 @@ aspect A1 { after(BaseClass c): execution(* run1(..)) && this(c) { List<String> myLs = new ArrayList<String>(); c.list1 = myLs; - System.err.println("Advice from A1 ran successfully"); + c.count++; } } diff --git a/tests/java5/generics/itds/binaryweaving/A2.aj b/tests/java5/generics/itds/binaryweaving/A2.aj index 20fb8baf5..1837d3e0a 100644 --- a/tests/java5/generics/itds/binaryweaving/A2.aj +++ b/tests/java5/generics/itds/binaryweaving/A2.aj @@ -1,13 +1,14 @@ import java.util.*; aspect A2 { +// declare precedence: A2,A1; public List<Z> BaseClass<Z>.list2; after(): execution(* run2(..)) { BaseClass<Integer> bInt = new BaseClass<Integer>(); bInt.list2 = new ArrayList<Integer>(); - System.err.println("Advice from A2 ran successfully"); + bInt.count++; } } diff --git a/tests/java5/generics/itds/binaryweaving/A3.aj b/tests/java5/generics/itds/binaryweaving/A3.aj index cacd30e0d..66f80ba0a 100644 --- a/tests/java5/generics/itds/binaryweaving/A3.aj +++ b/tests/java5/generics/itds/binaryweaving/A3.aj @@ -2,6 +2,8 @@ import java.util.*; aspect A3 { +// declare precedence: A3,A2; + public List<Z> BaseClass<Z>.m(List<Z> lz) { return lz; } @@ -10,7 +12,7 @@ aspect A3 { List<String> myLs = new ArrayList<String>(); BaseClass<String> bStr = new BaseClass<String>(); List<String> ls2 = bStr.m(myLs); - System.err.println("Advice from A3 ran successfully"); + bStr.count++; } } diff --git a/tests/java5/generics/itds/binaryweaving/BaseClass.java b/tests/java5/generics/itds/binaryweaving/BaseClass.java index edd3e4c93..225dddd46 100644 --- a/tests/java5/generics/itds/binaryweaving/BaseClass.java +++ b/tests/java5/generics/itds/binaryweaving/BaseClass.java @@ -1,9 +1,12 @@ public class BaseClass<N> { + static int count = 0; + public static void main(String[]argv) { BaseClass b = new BaseClass(); b.run1(); b.run2(); b.run3(); + System.err.println("Advice count="+count); } public void run1() {} diff --git a/tests/java5/generics/itds/binaryweaving/TestA_aspect.aj b/tests/java5/generics/itds/binaryweaving/TestA_aspect.aj new file mode 100644 index 000000000..d2c423942 --- /dev/null +++ b/tests/java5/generics/itds/binaryweaving/TestA_aspect.aj @@ -0,0 +1,6 @@ +import java.util.*; + +aspect TestA_aspect { + // scary, multiple tvars, one from member, one from target + public <L extends Number> void TestA_generictype<Z>.m(List<L> ll1, List<Z> lz,List<L> ll2) {} +} diff --git a/tests/java5/generics/itds/binaryweaving/TestA_class.java b/tests/java5/generics/itds/binaryweaving/TestA_class.java new file mode 100644 index 000000000..b5c6c01cd --- /dev/null +++ b/tests/java5/generics/itds/binaryweaving/TestA_class.java @@ -0,0 +1,10 @@ +import java.util.*; + +public class TestA_class { + public static void main(String []argv) { + TestA_generictype<Float> sc = new TestA_generictype<Float>(); + List<Integer> li = new ArrayList<Integer>(); + List<Float> lf = new ArrayList<Float>(); + sc.m(li,lf,li); + } +} diff --git a/tests/java5/generics/itds/binaryweaving/TestA_generictype.java b/tests/java5/generics/itds/binaryweaving/TestA_generictype.java new file mode 100644 index 000000000..005d936a0 --- /dev/null +++ b/tests/java5/generics/itds/binaryweaving/TestA_generictype.java @@ -0,0 +1,4 @@ +import java.util.*; + +class TestA_generictype<N> {// extends Number> { +} diff --git a/tests/java5/generics/itds/sharing/GenericAspectA.aj b/tests/java5/generics/itds/sharing/GenericAspectA.aj deleted file mode 100644 index fcb3090ea..000000000 --- a/tests/java5/generics/itds/sharing/GenericAspectA.aj +++ /dev/null @@ -1,19 +0,0 @@ -// Simple - adding an interface to a type via a generic aspect and decp -abstract aspect GenericAspect<A> { - - declare parents: A implements SimpleI; - - interface SimpleI {} - -} - -aspect GenericAspectA extends GenericAspect<Base> { - public static void main(String []argv) { - Base b = new Base(); - if (!(b instanceof SimpleI)) - throw new RuntimeException("Base should implement SimpleI!"); - } -} - -class Base {} - diff --git a/tests/java5/generics/itds/sharing/GenericAspectB.aj b/tests/java5/generics/itds/sharing/GenericAspectB.aj deleted file mode 100644 index 39d262223..000000000 --- a/tests/java5/generics/itds/sharing/GenericAspectB.aj +++ /dev/null @@ -1,19 +0,0 @@ -// Decp a generic interface -abstract aspect GenericAspect<A> { - - declare parents: A implements SimpleI; - - interface SimpleI<X> {} - -} - -aspect GenericAspectB extends GenericAspect<Base> { - public static void main(String []argv) { - Base b = new Base(); - if (!(b instanceof SimpleI)) - throw new RuntimeException("Base should implement SimpleI!"); - } -} - -class Base {} - diff --git a/tests/java5/generics/itds/sharing/GenericAspectC.aj b/tests/java5/generics/itds/sharing/GenericAspectC.aj deleted file mode 100644 index 3e1d6c6ee..000000000 --- a/tests/java5/generics/itds/sharing/GenericAspectC.aj +++ /dev/null @@ -1,24 +0,0 @@ -// Decp an interface with an ITD method on it -abstract aspect GenericAspect<A> { - - interface SimpleI {} - - declare parents: A implements SimpleI; - - public int SimpleI.m() { return 4;} - -} - -aspect GenericAspectC extends GenericAspect<Base> { - public static void main(String []argv) { - Base b = new Base(); - - if (!(b instanceof SimpleI)) - throw new RuntimeException("Base should implement SimpleI!"); - - int i = b.m(); - } -} - -class Base {} - diff --git a/tests/java5/generics/itds/sharing/GenericAspectD.aj b/tests/java5/generics/itds/sharing/GenericAspectD.aj deleted file mode 100644 index 30775a593..000000000 --- a/tests/java5/generics/itds/sharing/GenericAspectD.aj +++ /dev/null @@ -1,24 +0,0 @@ -// Decp an interface with an ITD field -abstract aspect GenericAspect<A> { - - interface SimpleI {} - - declare parents: A implements SimpleI; - - public int SimpleI.n; - -} - -aspect GenericAspectD extends GenericAspect<Base> { - public static void main(String []argv) { - Base b = new Base(); - - if (!(b instanceof SimpleI)) - throw new RuntimeException("Base should implement SimpleI!"); - - b.n=42; - } -} - -class Base {} - diff --git a/tests/java5/generics/itds/sharing/GenericAspectE.aj b/tests/java5/generics/itds/sharing/GenericAspectE.aj deleted file mode 100644 index 60bf8cd53..000000000 --- a/tests/java5/generics/itds/sharing/GenericAspectE.aj +++ /dev/null @@ -1,18 +0,0 @@ -abstract aspect GenericAspect<A> { - - declare parents: A implements IUtil; - - //public void IUtil<Z>.print(Z n) { System.err.println(n); } -} - -interface IUtil<N extends Number> { } - -aspect GenericAspectE extends GenericAspect<Base> { - public static void main(String []argv) { - Base b = new Base(); - // b.print("hello"); - } -} - -class Base {} - diff --git a/tests/java5/generics/itds/sharing/MethodA4.aj b/tests/java5/generics/itds/sharing/MethodA4.aj index 64c2aced0..192a7dc98 100644 --- a/tests/java5/generics/itds/sharing/MethodA4.aj +++ b/tests/java5/generics/itds/sharing/MethodA4.aj @@ -12,6 +12,8 @@ class Base<N extends Number> { } aspect X { public List<Z> Base<Z>.m() { // OK, Z becomes N in return type List<Z> lz = new ArrayList<Z>(); + List<String> ls; + return lz; }; } diff --git a/tests/java5/generics/itds/sharing/MethodQ.aj b/tests/java5/generics/itds/sharing/MethodQ.aj index bfe415a28..979c3b39a 100644 --- a/tests/java5/generics/itds/sharing/MethodQ.aj +++ b/tests/java5/generics/itds/sharing/MethodQ.aj @@ -9,7 +9,7 @@ public class MethodQ { } } -class SimpleClass<N extends Number> { +class SimpleClass<N> {// extends Number> { // This is what we are trying to mimic with our ITD //public <L extends Number> void m(List<L> ll1, List<N> lz,List<L> ll2) {} } |