-------------------------------------------------------------------------- Software Engineering Fall 2002 COM 3205 --------------------------------------------------------------------------- Assignment 3 Due date: Oct. 17, 2002 -------------------------------------------------------------------------- This assignment is stored in file $SE/hw/3 in file hw3-SE.txt -------------------------------------------------------------------------- Topics: Implementing a Crosscutting Style Rule Spiral software development: a little analysis, design, implementation Composing aspects and spiral development in the presence of aspects Tip 23: Always Use Source Code Control Start using a source control system like CVS for the LoD checker. Read section 17 of TPP. PART 1 ====================================== An important concept in Computer Science is the concept of simulation between languages: can one language L1 express another language L2 within a certain resource bound? For example, in hw 1 you probably encountered the simulation that any program that violates the LoD can be simulated by an equivalent program that is not much larger and that satisfies the LoD. Here we investigate the simulation: Can any Java program be simulated by an equivalent AspectJ program where all Java method bodies are empty. The idea of the simulation is: The normal method: in class Supplier: void add(Object target,String i) { targets.put(target,i); is equivalent to the aspectual method: in aspect Supplier: void add(Object target,String i) {} void around (Object target,String i): call(void Supplier.add(Object,String)) && args(target, i){ targets.put(target,i); } In this example we notice that the size increases by less than a factor of 4: the signature is duplicated less than 4 times. The body of the method is copied to the body of the advice. Translate the program http://www.ccs.neu.edu/home/lieber/com3205/f02/hw/3/Trip.java into an AspectJ program where there are no non-empty method calls. All code has to be in advice. Can this be accomplished? Please note the comment at he beginning of Trip.java. Write a paragraph or two that argues for or against the following statement: Any Java or AspectJ program can be simulated by an equivalent AspectJ program where all Java method bodies are empty. The AspectJ program is less than 4 times the length of the Java program. PART 2: ================================= In homework 2 we implemented the direct part rule of LoD. In this homework part we deal with an other rule independent of the direct part rule: we want to flag all calls where we send a message to an argument. In the program below I have deleted a few lines and labeled them UNKNOWN1, UNKNOWN2 and UNKNOWN3. Turn in the three UNKNOWNs. The lines I deleted I left blank. This shows you how long my solution is. But it is ok if your solution is longer. We reuse the design from homework 2. For each call where the target is an argument, your program will print something like: target found OK--Argument at Foo3.java:44:4 this Foo@6930e2 target Foo@6930e2 object id Foo@14df86 // sol/part2-args-only-david package lawOfDemeter; import java.util.*; /** * An implementation of a part of the LoD checker. Only allows calls to * argument objects. * Will create many violations for this simplified form. * * @author David H. Lorenz (author of correct version) */ abstract class Any { // we encapsulate all pointcuts we need in a class and // refer to them later as Any.* // to avoid capturing join points in the advice // of the LoD checker itself. within(someClass) // picks out all join points where the executing code is defined in someClass. // ! is complement. private pointcut scope(): !within(lawOfDemeter..*) ; // not in this package // AspectJ doc: http://aspectj.org/doc/dist/progguide/apas02.html // .. in an identifier any sequence of characters starting and ending with "." // * is the wildcard symbol. l..* matches e.g. l.p1.p2.C and also l.C // capturing method calls. // thisJoinPoint.getThis() and thisJoinPoint.getTarget() denote usually two // distinct objects: the currently executing object and the target object. pointcut MethodCall(): scope() && call(* *(..)); // identical: pointcut MethodExecution(): scope() && execution(* *.*(..)); // The defining type name, if not present, defaults to * // AspectJ doc: http://aspectj.org/doc/dist/progguide/apbs02.html // capturing method executions. // thisJoinPoint.getThis() and thisJoinPoint.getTarget() denote identical // objects: the target object. // pointcut call(Signature) // Picks out a method or constructor call join point // based on the static signature at the caller side. // pointcut execution(Signature) // Picks out a method or constructor execution join point // based on the static signature at the callee side. pointcut MethodExecution(): scope() && execution(* *(..)); // execution(*.new (..)) is NOT a subset of execution(* *(..)) pointcut ConstructorExecution(): scope() && execution(*.new (..)); pointcut Execution(): ConstructorExecution() || MethodExecution(); } // a super class for the aspects. Keeps track of a HashMap targets // that keeps track of the preferred supplier objects. abstract class Supplier { boolean contains(Object target) { if (targets.containsKey(target)) { System.out.println(" target found " + targets.get(target) +" object id " + target.toString()); return true; } return false; } void add(Object target,String i) { targets.put(target,i); } void addAll(Object[] targetlist,String i) { for (int k=0; k Violation if (!contains(target)) System.out.println(" !! LoD Violation !! "); } // needed for arguments! boolean contains(Object target) { // UNKNOWN 2: // INSERT YOUR CODE for // check whether target is contained in the allowed target objects (arguments). // Call method contains. // END INSERT YOUR CODE } } // ==== arguments // UNKNOWN 3: // INSERT YOUR CODE for // making the program work correctly // END INSERT YOUR CODE Part 3: ================================ We take a spiral development approach to devloping our project. In part 2 we did analysis, design and implementation for the arguments case. Now in this part we do analysis, design and implementation for composing what we did in the previous homework and in part 2: In other words, we want to write a program that flags all calls where the target object is either an immediate part or an argument. Write a document that describes your aspect composition approach. Turn in the complete composed program. Turn in your AspectJ program and your test program and the output produced.