Course Progress • Lecture 1 – Java data binding: Basket example: UML class diagram -> class dictionary without tokens-> language design -> class dictionary with token -> adaptive programming with DJ library – lec1-3360-w03.ppt – Introduction to AspectJ • Intertype declarations • Around advice
29
Embed
Course Progress Lecture 1 –Java data binding: Basket example: UML class diagram -> class dictionary without tokens-> language design -> class dictionary.
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Course Progress
• Lecture 1– Java data binding: Basket example: UML class
diagram -> class dictionary without tokens-> language design -> class dictionary with token -> adaptive programming with DJ library
– lec1-3360-w03.ppt– Introduction to AspectJ
• Intertype declarations• Around advice
Course Progress
• Lecture 2– AspectJ introduction (continued)– Using AspectJ to introduce DJ– lec1a-3360-w03.ppt
Definition 1: The LoD_JPF requires that for each join point J, target(J) is a potential preferred supplier of J.
Definition 2: The set of potential preferred suppliers to a join point J, child to the enclosing join point E, is the union of the objects in the following sets:
• Argument rule: the args of the enclosing join point E, including the target
• Associated rule: the associated values of E: the ret values of the children of E before J whose target is the target of E or whose target is null.
• LoD is a ``pseudo'' aspect because it cannot run in the current implementation of AspectJ, which doesn't allow declare warning to be defined on any pointcut with an if expression.
Join Point Form
• The pointcuts ArgumentRule and AssociatedRule select the ``good'' join points.
• ArgumentRule selects those join points whose target is one of the arguments of the enclosing join point;
Join Point Form
• AssociatedRule selects those join points whose target is in the set of locally returned ID's, and the ID's created in the siblings of the current node.
LoD for Fred (D. Orleans)
• The set of potential preferred suppliers to a message-send expression M in the body of a branch B is the union of the objects in the following sets:
• the argument list A of the decision point E that caused the invocation of B;
• the associated values of E, that is, – the results of message-send expressions M' in the body of B
before M whose argument lists A' intersect with A;– instances that were created in the control flow of the body of B
before M.
Fred (AOSD 02): simplest AOP language: decision points, branches
Map Dynamic Object Form (DOF) to LoD_JPF
• We use LoD_JPF pointcut to check DOF: – Dynamic join point model is mapped to JPT.
• Object is mapped to ID.
• Method invocations are mapped to JPF join points. The enclosing join point is the parent in the control flow.
Map Lexical Class Form (LCF) to LoD_JPF
• We use LoD_JPF to check LCF as follows. – Lexical join point model is mapped to JPT. Lexical join points
are nodes in the abstract syntax tree
– Class is mapped to ID.
– Join points are signatures of call sites. The enclosing join point is the signature of the method in which the call site resides. To run the aspect, a suitable ordering has to be given to the elements of children:
• all constructor calls, followed by local method calls, followed by the other join points.
AspectJ code
• In AOSD 2003 paper with David Lorenz and Pengcheng Wu
package lawOfDemeter;public abstract class Any { public pointcut scope(): !within(lawOfDemeter..*) && !cflow(withincode(* lawOfDemeter..*(..))); public pointcut StaticInitialization(): scope() && staticinitialization(*); public pointcut MethodCallSite(): scope() && call(* *(..)); public pointcut ConstructorCall(): scope() && call(*.new (..)); public pointcut MethodExecution(): scope() && execution(* *(..)); public pointcut ConstructorExecution(): scope() && execution(*.new (..)); public pointcut Execution(): ConstructorExecution() || MethodExecution(); public pointcut MethodCall(Object thiz, Object target): MethodCallSite() && this(thiz) && target(target);
public pointcut SelfCall(Object thiz, Object target): MethodCall(thiz, target) && if(thiz == target); public pointcut StaticCall(): scope() && call(static * *(..)); public pointcut Set(Object value): scope() && set(* *.*) && args(value); public pointcut Initialization(): scope() && initialization(*.new(..));}
aspect A { pointcut publicCall(): call(public Object *(..)); after() returning (Object o): publicCall() { System.out.println("Returned normally with " + o); } after() throwing (Exception e): publicCall() { System.out.println("Threw an exception: " + e); } after(): publicCall() { System.out.println("Returned or threw an Exception"); } }
The proceed form takes as arguments the context exposedby the around's pointcut, and returns whatever the around is declared to return. So the following around advice will double the second argument to foo whenever it is called, and then halve its result:
aspect A { int around(int i): call(int C.foo(Object, int)) && args(i) {int newi = proceed(i*2) return newi/2;} }
If the return value of around advice is typed to Object, then the result of proceed is converted to an object representation, even if it is originally a primitive value. And when the advice returns an Object value, that value is converted back to whatever representation it was originally. So another way to write the doubling and halving advice is: