diff options
author | aclement <aclement> | 2005-11-07 12:56:07 +0000 |
---|---|---|
committer | aclement <aclement> | 2005-11-07 12:56:07 +0000 |
commit | e0289593b9be768233801ba10226534af617c19b (patch) | |
tree | d7b66466231626459def69c64c1008c1f568bea1 | |
parent | 0b6d41c5a5a35c567f6ef391d4579c701d65d7be (diff) | |
download | aspectj-e0289593b9be768233801ba10226534af617c19b.tar.gz aspectj-e0289593b9be768233801ba10226534af617c19b.zip |
test X - matches the spec in the AJDK (work for 112105)
-rw-r--r-- | docs/adk15ProgGuideDB/generics.xml | 4 | ||||
-rw-r--r-- | tests/java5/generics/genericaspects/GenericAspectX.aj | 177 | ||||
-rw-r--r-- | tests/src/org/aspectj/systemtest/ajc150/GenericsTests.java | 1 | ||||
-rw-r--r-- | tests/src/org/aspectj/systemtest/ajc150/ajc150.xml | 4 |
4 files changed, 184 insertions, 2 deletions
diff --git a/docs/adk15ProgGuideDB/generics.xml b/docs/adk15ProgGuideDB/generics.xml index 429f110ec..4b75584b4 100644 --- a/docs/adk15ProgGuideDB/generics.xml +++ b/docs/adk15ProgGuideDB/generics.xml @@ -1122,7 +1122,7 @@ // default implementations. /** list of children maintained by parent */ - private List<C> ParentHasChildren<C>.children; + private List<C> ParentHasChildren<C>.children = new ArrayList<C>(); /** reference to parent maintained by child */ private P ChildHasParent<P>.parent; @@ -1177,7 +1177,7 @@ * Matches at a removeChild join point for the parent type P and child type C */ public pointcut removingChild(Parent p, Child c) : - execution(* Parent.removeChild(C)) && this(p) && args(c); + execution(* Parent.removeChild(Child)) && this(p) && args(c); } diff --git a/tests/java5/generics/genericaspects/GenericAspectX.aj b/tests/java5/generics/genericaspects/GenericAspectX.aj new file mode 100644 index 000000000..837333bb9 --- /dev/null +++ b/tests/java5/generics/genericaspects/GenericAspectX.aj @@ -0,0 +1,177 @@ +import java.util.*; +import java.lang.reflect.*; +import org.aspectj.lang.annotation.*; + +// This one is 99% the same as the one in the AJDK - the only difference it visibility of some +// components for testing. Here the type is not public so it can be embedded in this file, and +// the parent/child fields are not private so they can be easily manipulated. + +// The aim of the test is to verify the ITDs and the type structure of the programming produced +// during compilation, I am not testing the pointcuts work... + + /** + * a generic aspect, we've used descriptive role names for the type variables + * (Parent and Child) but you could use anything of course + */ + /*public */ abstract aspect ParentChildRelationship<Parent,Child> { + + /** generic interface implemented by parents */ + interface ParentHasChildren<C extends ChildHasParent>{ + List<C> getChildren(); + void addChild(C child); + void removeChild(C child); + } + + /** generic interface implemented by children */ + interface ChildHasParent<P extends ParentHasChildren>{ + 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<C> ParentHasChildren<C>.children = new ArrayList<C>(); + + /** reference to parent maintained by child */ + public P ChildHasParent<P>.parent; + + /** Default implementation of getChildren for the generic type ParentHasChildren */ + public List<C> ParentHasChildren<C>.getChildren() { + return Collections.unmodifiableList(children); + } + + /** Default implementation of getParent for the generic type ChildHasParent */ + public P ChildHasParent<P>.getParent() { + return parent; + } + + /** + * Default implementation of addChild, ensures that parent of child is + * also updated. + */ + public void ParentHasChildren<C>.addChild(C child) { + if (child.parent != null) { + child.parent.removeChild(child); + } + children.add(child); + child.parent = this; + } + + /** + * Default implementation of removeChild, ensures that parent of + * child is also updated. + */ + public void ParentHasChildren<C>.removeChild(C child) { + if (children.remove(child)) { + child.parent = null; + } + } + + /** + * 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<P>.setParent(P parent) { + parent.addChild(this); + } + + /** + * Matches at an addChild join point for the parent type P and child type C + */ + 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 + */ + public pointcut removingChild(Parent p, Child c) : + execution(* Parent.removeChild(Child)) && this(p) && args(c); + + } + +aspect GenericAspectX extends ParentChildRelationship<Top,Bottom> { + + public static void main(String []argv) { + + // Check the state of top + Top t = new Top(); + check(t instanceof ParentHasChildren,"Top should implement ParentHasChildren"); + Type[] intfs = Top.class.getGenericInterfaces(); + check(intfs[0] instanceof ParameterizedType, + "Expected Top to have parameterized interface but found "+intfs[0]); + ParameterizedType pt = (ParameterizedType) intfs[0]; + Type[] tArgs = pt.getActualTypeArguments(); + check(tArgs[0]==Bottom.class, + "Expecting Bottom parameter but found " + tArgs[0]); + + + // Check the state of top + Bottom b = new Bottom(); + check(b instanceof ChildHasParent,"Bottom should implement ChildHasParent"); + intfs = Bottom.class.getGenericInterfaces(); + check(intfs[0] instanceof ParameterizedType, + "Expected Bottom to have parameterized interface but found "+intfs[0]); + pt = (ParameterizedType) intfs[0]; + tArgs = pt.getActualTypeArguments(); + check(tArgs[0]==Top.class, + "Expecting Top parameter but found " + tArgs[0]); + + + + + // Field fiddling + b.parent = t; + List<Bottom> kids = new ArrayList<Bottom>(); + kids.add(b); + t.children = kids; + + + // start using the methods + List<Bottom> kids2 = t.getChildren(); + check(kids2.size()==1, + "Expected one child of the Top but found "+kids2.size()); + check(kids2.get(0).equals(b), + "Expected one child of the Top which was what we put in there!"+kids2.get(0)); + + // and the parent methods + Top retrievedParent = b.getParent(); + check(retrievedParent==t, + "parent check 1 failed "+ + "retrieved="+retrievedParent+" expected="+t); + + + Top top2 = new Top(); + b.setParent(top2); + Top retrievedParent2 = b.getParent(); + check(retrievedParent2==top2, + "parent check 2 failed "+ + "retrieved="+retrievedParent2+" expected="+top2); + + Top top3 = new Top(); + Bottom bot2 = new Bottom(); + top3.addChild(bot2); + Bottom aBottom = top3.getChildren().get(0); + check(aBottom==bot2,"Incorrect child? expected="+bot2+" found="+aBottom); + top3.removeChild(bot2); + int size=top3.getChildren().size(); + check(size==0,"Should be no children but there were "+size); + + + } + + public static void check(boolean b,String msg) { + if (!b) throw new RuntimeException(msg); + } +} + +class Top {} +class Bottom {} + diff --git a/tests/src/org/aspectj/systemtest/ajc150/GenericsTests.java b/tests/src/org/aspectj/systemtest/ajc150/GenericsTests.java index 53635a958..6aa9ad518 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/GenericsTests.java +++ b/tests/src/org/aspectj/systemtest/ajc150/GenericsTests.java @@ -376,6 +376,7 @@ public class GenericsTests extends XMLBasedAjcTestCase { public void testSophisticatedAspectsU() {runTest("uberaspects - U");} // includes nasty casts public void testSophisticatedAspectsV() {runTest("uberaspects - V");} // casts are gone public void testSophisticatedAspectsW() {runTest("uberaspects - W");} + public void testSophisticatedAspectsX() {runTest("uberaspects - X");} // from the AJDK // FIXME asc these two tests have peculiar error messages - generic aspect related // public void testItdUsingTypeParameter() {runTest("itd using type parameter");} diff --git a/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml b/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml index b502511ee..6b6a1ac78 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml +++ b/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml @@ -3925,6 +3925,10 @@ <compile files="GenericAspectW.aj" options="-1.5"/> <run class="GenericAspectW"/> </ajc-test> + <ajc-test dir="java5/generics/genericaspects/" title="uberaspects - X"> + <compile files="GenericAspectX.aj" options="-1.5"/> + <run class="GenericAspectX"/> + </ajc-test> |