summaryrefslogtreecommitdiffstats
path: root/docs/sandbox/common/libraries/PointcutLibraryTest.java
diff options
context:
space:
mode:
authorwisberg <wisberg>2003-08-06 02:08:40 +0000
committerwisberg <wisberg>2003-08-06 02:08:40 +0000
commita63bc04fb1cb6e8d6d0bc2a509ab9658e3d78c43 (patch)
treecd4e827c60136df7bf9850591b0c64baff549d20 /docs/sandbox/common/libraries/PointcutLibraryTest.java
parentb0d37c4b51a344bee94bb7f7cc1ecef1a233e3ab (diff)
downloadaspectj-a63bc04fb1cb6e8d6d0bc2a509ab9658e3d78c43.tar.gz
aspectj-a63bc04fb1cb6e8d6d0bc2a509ab9658e3d78c43.zip
initial checkin of the sandbox.
The basic structure and examples of each type are there, but I have more examples and the ones there are not altogether validated. I'll make a few more changes before emailing dev and users about usage, etc.
Diffstat (limited to 'docs/sandbox/common/libraries/PointcutLibraryTest.java')
-rw-r--r--docs/sandbox/common/libraries/PointcutLibraryTest.java95
1 files changed, 95 insertions, 0 deletions
diff --git a/docs/sandbox/common/libraries/PointcutLibraryTest.java b/docs/sandbox/common/libraries/PointcutLibraryTest.java
new file mode 100644
index 000000000..e110c7ced
--- /dev/null
+++ b/docs/sandbox/common/libraries/PointcutLibraryTest.java
@@ -0,0 +1,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
+