From bb357e7c74ec5be0052bbc51761ade7c6ad4c5dc Mon Sep 17 00:00:00 2001 From: ehilsdal Date: Thu, 28 Aug 2003 16:23:04 +0000 Subject: [PATCH] fixes --- docs/teaching/exercises/index.html | 177 ++++++++++------------------- 1 file changed, 61 insertions(+), 116 deletions(-) diff --git a/docs/teaching/exercises/index.html b/docs/teaching/exercises/index.html index 500915e99..f44ac7806 100644 --- a/docs/teaching/exercises/index.html +++ b/docs/teaching/exercises/index.html @@ -13,14 +13,14 @@ cases. They progress, as most users do in their adoption of AspectJ, from non-functional, development-only aspects to aspects which augment a deployed program with crosscutting features.

-

We have made available a package that includes the tests, the base -code, JUnit, and a distribution of AspectJ. All it needs is -information about where Java lives (so set your JAVA_HOME environment -variable). It assumes that you unzip it in c:\ (on Windows) or in -your home directory (on Linux): If you put it somewhere else, edit -setpaths or setpaths.bat, as appropriate. Once all this is done, run -setpaths.bat or source setpaths to export -some other needed environment variables.

+

Before the tutorial we will make available a package that includes +the tests, the base code, JUnit, and a distribution of AspectJ. All +it needs is information about where Java lives (so set your JAVA_HOME +environment variable). It assumes that you unzip it in c:\ (on +Windows) or in your home directory (on Linux): If you put it somewhere +else, edit setpaths or setpaths.bat, as appropriate. Once all this is +done, run setpaths.bat or source setpaths to +export some other needed environment variables.

All the files in the program are listed in base.lst, including test cases and an empty answer aspect, @@ -72,16 +72,39 @@ you go from one exercise to the next, make sure to save your work in a file and go on to work in a different file, even if you plan to duplicate some code.

+

Environment

+ +

You may use whatever editor or environment you choose to work +through these exercises. We provide a simple code-browser that can +work well as an editor for these short exercises, in addition to +providing better visualization of how aspects affect the system:

+ +
+$ ajbrowser base.lst
+
+ +

With the browser you can edit code (including the +answers/Answer.java file), and after saving hit the build +button to start an ajc compile. We recommend you start up another +shell, though, to run the JUnit tests (and don't forget to run the +setpaths script when you open the new shell): You could +set up the run button to run a test through the Options menu, but +we've found this is fairly cumbersome.

+ +
- + + +

1. Static Invariants

a. Catch old tracing

Sample Exercise: The main point of this exercise -is to make sure your configuration works. We have provided the -answer to this exercise below, so XXX. You need not go through the -thought process of fixing this

+is to make sure your configuration works. Type in the answer below +into your answer file, make sure you get the desired compile-time +error, remove the offending line, and make sure you pass the JUnit +test.

Task: Signal a warning for calls to System.out.println. @@ -100,10 +123,9 @@ trace in SlothfulPoint.

 $ ajc -argfile base.lst
-./figures/SlothfulPoint.java:29:9: illegal access to System.out
-        System.out.println("Slothful moving");
-               ^
-1 errors
+./figures/SlothfulPoint.java:38 illegal access to System.out
+
+1 error
 

Remove the illegal tracing call. @@ -116,7 +138,7 @@ all exercises) before continuing.

 $ java tests.Test
 ....
-Time: 0.076
+Time: 0.03
 
 OK (4 tests)
 
@@ -215,20 +237,17 @@ the convention. Make sure your program still passes the JUnit test your left and right. If they're stuck somewhere, see if you can help them.

- -
-

2. Dynamic invariants

+ +
+

2. Dynamic invariants

a. Check a simple precondition

-

Sample Exercise: The main point of this exercise -is to make sure your configuration works. We have provided the -answer to this exercise below, so XXX. You need not go through the -thought process of fixing this

- +

Sample Exercise: We've provided the answer to +this exercise below to get you started.

Task: Pass tests.Test2a.

@@ -283,7 +302,7 @@ import figures.*; aspect Answer2a { before(int newValue): set(int Point.*) && args(newValue) { - if (newValue < 0) { + if (newValue < 0) { throw new IllegalArgumentException("too small"); } } @@ -322,8 +341,6 @@ an attempt is made to call Group.add() on a call.

-XXX RENUMBER LATER -

d. Assure input

Task: Pass tests.Test2g. @@ -380,83 +397,12 @@ throw an IllegalStateException if it is violated.

At this point, check the people to your left and right. If they're stuck somewhere, see if you can help them.

- -
- - -

3. Logging

- -

d. Check a simple postcondition

- -

One of the simplest postconditions to check is that a setter -actually sets its value. Write an aspect that throws a -java.lang.RuntimeException if, after calling -setX() on SlothfulPoint objects, -getX() doesn't return the new value.

-

You'll want to use an args pointcut to expose the -argument to setX() and a target pointcut to -expose the SlothfulPoint object itself (so you can later -call getX() on it). -

- -

An interesting question to think about for discussion is whether -this postcondition should apply when getX() throws an exception, or -when it returns normally, or both?

- -

With this aspect in place, your code should pass -tests.Test2d. -

- - -

e. Check invariant

- -

There is a method on the Box class, void -checkBoxness(), that checks whether the four points making up a -box are correctly positioned relative to each other (i.e., they form a -rectangle). Write an aspect that will make sure that after every time -the void move(int, int) method on Box is -called, that you also call Box.checkBoxness() to ensure -that the move didn't break this invariant.

- -

With this aspect in place, your code should pass -tests.Test2e. -

- -

f. Refine your invariant

- -

move is not the only interesting method on -Box. It may be that a box gets malformed between calls -to move. So instead of checking boxness only -after the move method of Box, check -after the call to every one of Box's public methods. -

- -

When testing this aspect, you may find yourself facing a -StackOverflowException. If so, carefully look at your -pointcuts. Needless to say, there should not be an infinite loop in -your program. You might want to look at using a within -pointcut for a filter.

- -

(You might even find that this test case aborts with no message, -i.e., -

- -
-$ java tests.test2f
-.
-$
-
- -

this is a bug in Sun's JVM where a particular stack overflow -causes the VM to abort.) -

- -

Make sure to pass the JUnit test tests.Test2f -before continuing.

+ -================================================== +
+

3. Tracing

The crosscutting feature you will be adding in part (4) will be support for caching the bound objects of Group figure @@ -465,7 +411,7 @@ it's useful to explore the system with some tracing aspects.

a. Simple logging

-

Problem: Pass tests.Test3a.

+

Task: Pass tests.Test3a.

Tools: Log.log(String), thisJoinPoint.toString(), execution, @@ -479,7 +425,7 @@ and call Log.log(String)

b. Simple logging

-

Problem: Pass tests.Test3b.

+

Task: Pass tests.Test3b.

Tools: target

@@ -487,7 +433,7 @@ and call Log.log(String)

c. More specialized logging

-

Problem: Pass tests.Test3c.

+

Task: Pass tests.Test3c.

Tools:

@@ -520,7 +466,7 @@ based on the type of a parameter to a method call.

d. Logging extended to checking an invariant

-

Problem: Pass tests.Test3d.

+

Task: Pass tests.Test3d.

Tools: inter-type field declaration

@@ -530,7 +476,7 @@ based on the type of a parameter to a method call.

e. Better error messages for 3d

-

Problem: Pass tests.Test3e.

+

Task: Pass tests.Test3e.

Tools:

@@ -581,13 +527,12 @@ previous exercises, you'll be most of the way there.

At this point, check the people to your left and right. If they're stuck somewhere, see if you can help them.

+
-
- - -

4. Caching

+
+

4. Caching

Computation of the bounding box of Group objects needs to deal with all aggregate parts of the group, and this @@ -602,7 +547,7 @@ handle those points contained in Lines and Boxes only if time permits.

a. Make a constant override

-

Problem: Pass tests.Test4a.

+

Task: Pass tests.Test4a.

Tools: around, FigureElement.MAX_BOUNDS @@ -623,7 +568,7 @@ around advice intercepting the method.

b. Make a constant cache

-

Problem: Pass tests.Test4b. +

Task: Pass tests.Test4b.

Tools: private Rectangle Group.mumble; @@ -642,7 +587,7 @@ state for every Group object.

c. Invalidate, part 1

-

Problem: Pass tests.Test4c. +

Task: Pass tests.Test4c.

Tools: before @@ -656,7 +601,7 @@ Change your aspect so that it invalidates the cache whenever the

d. Invalidate, part 2

-

Problem: Pass tests.Test4d.

+

Task: Pass tests.Test4d.

Tools: your solution to 3c

@@ -670,7 +615,7 @@ where there you cared about method calls.

e. Invalidate, part 3

-

Problem: Pass tests.Test4e.

+

Task: Pass tests.Test4e.

Tools: You're on you're own

-- 2.39.5