Aspect-Oriented Software Development (Advanced Object-Oriented Systems) COM 3362 Fall 2002 Homework 1 ========== Due date: Jan. 15. AspectJ can be used in two phases: first for development aspects, then for production aspects. In hw 1 we focus on development aspects. SETUP: Follow: http://www.ccs.neu.edu/home/lieber/com3362/w02/CCS_AspectJ_Usage.html Put the file rt.jar into your class path as described at the beginning of: http://www.ccs.neu.edu/research/demeter/software/docs/install.html PART 1: ======= The starting point is the Java program in: /proj/adaptive2/course/com3360/f01/hw/1/graph/gen We want to do some simple statistics for the execution of this program. Write a Trace aspect that counts the number of method calls the number of constructor calls the number of field accesses the number of field modifications Hint: the number of method calls: call(* *(..)) && !within(Trace) Your program should print the output in a form similar to: the number of method calls: : 10000 the number of constructor calls: 5000 the number of field accesses: 2000000 the number of field modifications: 700 Run your program with the input in /proj/adaptive2/course/com3360/f01/hw/1/graph/class-graph.input by using: java Main <../class-graph.input > out & Turn in your program and the output it produced. PART 2: ======= Add a second aspect PTrace that executes for each constructor call: System.out.println("Created a new object " + thisJoinPoint); Use both Trace and PTrace simultaneously. How can you control which aspect to apply first? Explain. Does it matter in this case? Run your program with the same input as in Part 1. Turn in your aspect and an explanation of how you can order aspects. PART 3: ======= Consider the following aspect: aspect Diff { pointcut thisPC(Vertex c) : this(c); pointcut targetPC(Vertex c) : target(c); before(Vertex c): thisPC(c){ System.out.println("ThisPC give ==> "+ thisJoinPoint+c ); } before(Vertex c): targetPC(c){ System.out.println("TargetPC gives ---------> " +thisJoinPoint + c ); } } Explain how the two pointcuts differ. Turn in your explanation. PART 4: ======= Above we were counting the number of method calls in the execution of a Java program. How would you write a Java program tha counts the number of methods contained in a given Java program? static question: count number of methods in program dynamic question: count number of method calls during execution of program The dynamic question was answered above. Describe the design of an aspect-oriented program that answers the static question. Keep it brief. Turn in your design. Acknowledgements: PART 1 - PART 3 tested by Therapon Skotiniotis.