From f1a7345a62bd1f227dd64fcd7c2d519c8911ae5c Mon Sep 17 00:00:00 2001 From: jhugunin Date: Wed, 27 Aug 2003 20:49:20 +0000 Subject: [PATCH] rough edit of text for section 3 --- docs/teaching/exercises/index.html | 98 +++++++++++------------------- 1 file changed, 37 insertions(+), 61 deletions(-) diff --git a/docs/teaching/exercises/index.html b/docs/teaching/exercises/index.html index 20671cdcf..59c95f4ff 100644 --- a/docs/teaching/exercises/index.html +++ b/docs/teaching/exercises/index.html @@ -468,85 +468,43 @@ they're stuck somewhere, see if you can help them.


-

3. Tracing

+

3. Logging

The crosscutting feature you will be adding in part (4) will be support for caching the bound objects of Group figure elements, which may be costly to compute. On the way to that, though, it's useful to explore the system with some tracing aspects.

-

a. Simple tracing

+

a. Simple logging

-

Write an aspect to trace whenever a Point is moved. -To do this, use the utility class Log (with an import -from support.Log) and call

+

Problem: Pass tests.Test3a.

-
-Log.log("moving")
-
- -

This will write the string "moving", followed by a semicolon -terminator, to the Log. For example, with your aspect enabled, -

- -
-Point p1 = new Point(10, 100);
-p1.move(37, 8);
-System.out.println(Log.getString());
-
- -

should print out "moving;". +

Tools: Log.log(String), + thisJoinPoint.toString(), execution, + within

-

Test this with the JUnit test case tests.Test3a. -Without adding any aspects, this test should fail:

- -
-$ ajc -Xlint -argfile base.lst 
-$ java tests.Test3a
-..F.......
-Time: 0.07
-There was 1 failure:
-1) testMovePointLog(tests.Test3a)junit.framework.AssertionFailedError: expected:<set;> but was:<>
-        at tests.Test3a.testMovePointLog(Test1a.java:30)
-        at tests.Test3a.main(Test1a.java:16)
+

Write an aspect to log the execution of all public methods +in the figures package. To do this, use the utility class +Log (with an import from support.Log) +and call Log.log(String)

-FAILURES!!! -Tests run: 9, Failures: 1, Errors: 0 -
+

b. Simple logging

-

But with the proper aspect added to the compilation, (in this -case, answers/Answer3a.java, but you should feel free to -use more evocative names), the test should pass

- -
-$ ajc -Xlint -argfile base.lst answers/Answer3a.java
-$ java tests.Test3a
-.........
-Time: 0.089
-
-OK (9 tests)
-
+

Problem: Pass tests.Test3b.

-

Answer: +

Tools: target

-
-package answers;
 
-import support.Log;
-import figures.*;
+

c. More specialized logging

-aspect Answer3a { - before(): execution(void Point.move(int, int)) { - Log.log("moving"); - } -} -
+

Problem: Pass tests.Test3c.

-

b. More complex tracing

+

Tools: +

-

Write an aspect to trace whenever a Point is added to +

Write an aspect to log whenever a Point is added to a group (including initially). To do this, use the utility class Log (with an import from support.Log) and call

@@ -572,8 +530,26 @@ System.out.println(Log.getString());

Hint: The args pointcut allows you to select join points based on the type of a parameter to a method call.

-

Test this with the JUnit test case tests.Test3b. +

d. Logging extended to checking an invariant

+ +

Problem: Pass tests.Test3d.

+ +

Tools: inter-type field declaration +

+ +

Make sure that a Point is never added to more than one Group.

+ + +

e. Better error messages for 3d

+ +

Problem: Pass tests.Test3e.

+ +

Tools: +

+

Make sure that a Point is never added to more than one Group. +Include the Group that the Point was previously a part of in the +thrown exception.

c. Keeping track of state

-- 2.39.5