summaryrefslogtreecommitdiffstats
path: root/tests/java5/generics/genericaspects/GenericAspectO.aj
blob: 297d2a656f9a5087f27d030e6d6a47736908f1c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import java.util.*;
import java.lang.reflect.*;
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<C> ParentHasChildren<C>.children;
  public P ChildHasParent<P>.parent;

}

aspect GenericAspectO extends ParentChildRelationship<Top,Bottom> { 


  public static void main(String []argv) {

    Top t = new Top();
    Bottom.parent = t; // error - its not a static field
    List<Bottom> kids = new ArrayList<Bottom>();
    kids.add(t);
    Top.children = kids; // error - its not a static field


  }

  public static void check(boolean b,String msg) {
    if (!b) throw new RuntimeException(msg);
  }
}

class Top {}
class Bottom {}

//////////////////////////////////////////////////////////////////

/* End game for test Z, as bits work they are promoted up into the 
   testcase above :)

   TestN promoted the declare parents statements up
   TestO promoted the fields up - a parent knows its children, a 
         child knows its parents - but then uses them incorrectly

public abstract aspect ParentChildRelationship<Parent,Child> {

  public List<C> ParentHasChildren<C>.getChildren() {
        return Collections.unmodifiableList(children);  
  }

  public P ChildHasParent<P>.getParent() {
       return parent;
  }

  public void ParentHasChildren<C>.addChild(C child) {
       if (child.parent != null) {
         child.parent.removeChild(child);
       }
       children.add(child);
       child.parent = this;
    }

   public void ParentHasChildren<C>.removeChild(C child) {
       if (children.remove(child)) {
         child.parent = null;
       }
    }

    public void ChildHasParent<P>.setParent(P parent) {
       parent.addChild(this);
    }

    @SuppressAjWarnings
    public pointcut addingChild(Parent p, Child c) :
      execution(* Parent.addChild(Child)) && this(p) && args(c);
      
    @SuppressAjWarnings
    public pointcut removingChild(Parent p, Child c) :
      execution(* Parent.removeChild(Child)) && this(p) && args(c);
}
*/