summaryrefslogtreecommitdiffstats
path: root/docs/sandbox/common/libraries/PointcutLibraryTest.java
blob: e110c7cedaa217449858e33b5b5f66a13a3827f4 (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
87
88
89
90
91
92
93
94
95
package libraries;

/** @author Wes Isberg */
public class PointcutLibraryTest {
    public static void main(String[] a) {
        new Test().run();
    }
}

class Test {
    public Test() {}
    public void run(){ prun(); }
    private void prun() {
        System.out.println("Test.prun()");
    }
}

// START-SAMPLE library-classPointcutLibrary Defining library pointcuts in a class
/** private default implementation of library */
class PrivatePointcutLibrary {
    pointcut adviceCflow() : cflow(adviceexecution());
    pointcut publicCalls() : call(public * *(..))
        && !adviceCflow()
        ;
}

/** public interface for library */
class PointcutLibrary extends PrivatePointcutLibrary {
}

// ---- different clients of the library

/** client by external reference to library */
aspect ExternalClientOfLibrary {
  before() : PointcutLibrary.publicCalls() {
      System.out.println("XCL: " 
          + thisJoinPointStaticPart);
  }
}

/** use library by inheriting scope in aspect */
aspect AEL extends PointcutLibrary {
    before() : publicCalls() {
        System.out.println("AEL: " 
            + thisJoinPointStaticPart);
    }
}

/** use library by inheriting scope in class */
class CEL extends PointcutLibrary {
    static aspect A {
        before() : publicCalls() {
            System.out.println("CEL: " 
                + thisJoinPointStaticPart);
        }
    }
}

/** more clients by inheritance */
aspect CELSubAspect extends CEL {
    before() : publicCalls() {
        System.out.println("CSA: " 
            + thisJoinPointStaticPart);
    }
}


// ---- redefining library pointcuts

//-- affect all clients of PointcutLibrary
// test: XCL advises Test()
class VendorPointcutLibrary extends PrivatePointcutLibrary {
    /** add calls to public constructors */
    pointcut publicCalls() : PrivatePointcutLibrary.publicCalls()
        || (call(public new(..)) && !adviceCflow());
    static aspect A {
        declare parents: 
            PointcutLibrary extends VendorPointcutLibrary;
    }
}

//-- only affect CEL, subtypes, & references thereto
// test: CSA does not advise call(* println(String))
// test: CSA advises call(* prun())
class CPlus extends PointcutLibrary {
    /** add calls to private methods, remove calls to java..* */
    pointcut publicCalls() : (PointcutLibrary.publicCalls()
        || (call(private * *(..)) && !adviceCflow()))
        && (!(call(* java..*.*(..)) || call(java..*.new(..))));
    static aspect A {
        declare parents: CEL extends CPlus;
    }
}
// END-SAMPLE library-classPointcutLibrary