]> source.dussan.org Git - aspectj.git/commitdiff
updated section 3
authorehilsdal <ehilsdal>
Thu, 28 Aug 2003 17:34:47 +0000 (17:34 +0000)
committerehilsdal <ehilsdal>
Thu, 28 Aug 2003 17:34:47 +0000 (17:34 +0000)
docs/teaching/exercises/answers/Answer1d.java [deleted file]
docs/teaching/exercises/answers/Answer3a.java
docs/teaching/exercises/answers/Answer3b.java
docs/teaching/exercises/answers/Answer3c.java
docs/teaching/exercises/build.xml
docs/teaching/exercises/index.html

diff --git a/docs/teaching/exercises/answers/Answer1d.java b/docs/teaching/exercises/answers/Answer1d.java
deleted file mode 100644 (file)
index 1aa74e7..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-/* *******************************************************************
- * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
- * All rights reserved.
- * This program and the accompanying materials are made available
- * under the terms of the Common Public License v1.0
- * which accompanies this distribution and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- *     PARC     initial implementation
- * ******************************************************************/
-
-package answers;
-
-aspect Answer1c {
-    declare error
-        : set(private * *)
-          && !(withincode(* set*(..))
-               || withincode(new(..))
-               || withincode(void figures.Point.move(int, int)))
-          && within(figures.*)
-        : "bad field set";
-}
index fc5e1d3f7bbcca99d97a460a52148d44cc3034f6..3bbfb1e980a62544a6316802371dece96a042fd5 100644 (file)
@@ -14,10 +14,8 @@ package answers;
 
 import support.Log;
 
-import figures.Point;
-
 aspect Answer3a {
-    before(): execution(void Point.move(int, int)) {
-        Log.log("moving");
+    before(): execution(public * *(..)) && within(figures.*) {
+        Log.log(thisJoinPoint.toString());
     }
 }
index 0328fe1641c5610e189b05d6d770ef44d5fb34e4..b88e45780673fcb083196230b2e87297c37d27fe 100644 (file)
@@ -19,8 +19,11 @@ import figures.Group;
 import figures.FigureElement;
 
 aspect Answer3b {
-    before():
-        execution(void Group.add(FigureElement)) && args(Point) {
-        Log.log("adding Point");
+    before(Object o):
+            execution(public * *(..))
+            && within(figures.*) && target(o)
+            && !withincode(public String toString(..)) // don't overflow!
+    {
+        Log.log(thisJoinPoint.toString() + " at " + o);
     }
 }
index 576694e68201ad378c4359e6abda31c835b22561..33483bc215a995638e0a15d20feebf910cbceb90 100644 (file)
@@ -14,21 +14,11 @@ package answers;
 
 import support.Log;
 
-import figures.Point;
-import figures.Group;
-import figures.FigureElement;
+import figures.*;
 
 aspect Answer3c {
-    private Group Point.enclosingGroup = null;
-
-    before(Point p, Group g):
-        execution(void add(FigureElement)) && args(p) && target(g) {
-        p.enclosingGroup = g;
-    }
-
-    before(Point p):
-        call(void move(int, int)) && target(p) {
-        Log.log("moving as a part of " + p.enclosingGroup);
+    before():
+       execution(void Group.add(FigureElement)) && args(Point) {
+        Log.log("adding Point");
     }
-
 }
index 4ba785dc115cc0bf4f51823114e4ae8507bd8205..faf5237540244f66b2e76719c5fe5ef339b5bd89 100755 (executable)
     <delete dir="dist" />
   </target>
 
+  <target name="javaclean">
+    <delete dir="dist" />
+  </target>
+
+
 </project>
 
index f44ac7806144dd924012ca187b0ff784405bbbe8..755c15f9da81f15f926002acd599626d4f9e656e 100644 (file)
@@ -265,29 +265,26 @@ aspect,
 </p>
 
 <blockquote><PRE>
-$ ajc -Xlint -argfile base.lst
-
 $ java tests.Test2a
-.F.F.F....
-Time: 0.099
-There were 3 failures:
+.F..F....
+Time: 0.04
+There were 2 failures:
 1) testTooSmall(tests.Test2a)junit.framework.AssertionFailedError: should have thrown IllegalArgumentException
-2) testTooBig(tests.Test2a)junit.framework.AssertionFailedError: should have thrown IllegalArgumentException
-3) testMove(tests.Test2a)junit.framework.AssertionFailedError: should have thrown IllegalArgumentException
+2) testMove(tests.Test2a)junit.framework.AssertionFailedError: should have thrown IllegalArgumentException
 
 FAILURES!!!
-Tests run: 7,  Failures: 3,  Errors: 0
+Tests run: 7,  Failures: 2,  Errors: 0
 </PRE></blockquote>
 
 <p> But after compiling in the aspect...
 </p>
 
 <blockquote><PRE>
-$ ajc -Xlint -argfile base.lst
+$ ajc -Xlint -argfile base.lst answers/Answer.java
 
 $ java tests.Test2a
 .......
-Time: 0.097
+Time: 0.04
 
 OK (7 tests)
 </PRE></blockquote>
@@ -430,6 +427,15 @@ and call <code>Log.log(String)</code></p>
 <p> <strong>Tools:</strong> <code>target</code>
 </p>
 
+<p> AspectJ can expose the target object at a join point for tracing.
+In this exercise, you will print not only the join point information,
+but also the target object, with the form
+</p>
+
+<blockquote><pre>
+<em>thisJoinPointInfo</em> at <em>targetObject</em>
+</pre></blockquote>
+
 
 <h3>c. More specialized logging</h3>