260 likes | 271 Views
This study focuses on proving the aspect-oriented programming laws for deriving complex refactorings, using a bi-directional transformation approach. The study also introduces the AspectJ laws and defines an equivalence notion for aspect-oriented programs. The effectiveness of the laws is evaluated through a comparison of the evaluation trees.
E N D
Informatics Center Federal University of Pernambuco Brazil Proving aspect-oriented programming laws Leonardo Cole Paulo Borba Alexandre Mota (lcn,phmb,acm@cin.ufpe.br)
Deriving Refactorings • Primitive laws of programming • simple, localized, intuitive and easier to understand • Two transformations • Bi-directional • Guarded by pre-conditions • We compose the laws to • Derive complex and global refactorings • Verify that an existingrefactoring preserves behaviour
ts privileged aspectA { pcs as } ts aspectA { pcs as } = () Advice bodies from as do not refer to private members declared in ts. Make Aspect Privileged
Problem • Current definition relies on the simplicity and intuition of the laws It is necessary to formallyprove the laws to increase the confidence that they preserve behaviour
Solution • Aspect-oriented semantics for Method Call Interception (MCI) • Equivalence notion for aspect-oriented programs
Outline • AspectJ Laws • MCI • Equivalence Notion • Add Before Execution Law • Conclusions
ts classC { fs ms Tm(ps) { body } } paspect A { ... before(context) : exec(C.m) && bind(context) { body’ } ... } ts classC { fs ms Tm(ps) { body’; body } } paspectA { ... } = Add before-execution () body’ does not declare or use local variables; body’ does not call super; …
Example publicclass Account { privatedouble balance; ... public void debit(double amount) { Access.check(new Permission(…)); //debit logic } ... } publicaspectPermissionAspect{ }
Applying Add Before-Execution Law publicclass Account { privatedouble balance; ... public void debit(double amount) { //debit logic } ... } privilegedaspect PermissionAspect { before(Account cthis, double amount): execution(void Account.debit(double) && this(cthis) && args(amount) { Access.check(new Permission(…)); } }
Method Call Interception - MCI • Operational semantics • Extends an object-oriented language to introduce aspect-oriented features • Superimpose construct • On dispatch • On enter • On exit
Equivalence Notion • We compare field values (heaps) resulting from the two program’s execution • Strong notion (equal heaps) • Same number of objects • Same number of fields • Simplest notion to our objective • The laws do not change program’s data structure First component of the object-store must be equal for both programs
Mapping AspectJ to MCI • Before-call x On dispatch • Before-execution x On enter • After-execution x On exit • args, this and target • Aspect x Main method
ts classC { fs ms Tm(ps) { body } } classM { voidmain() { superimposebody’ onenter classC&& methodm&& argumentps; sis; mainBody } } ts classC { fs ms Tm(ps) { body’; body } } classM { voidmain() { sis; mainBody } } = MCI Add Before Execution
Comparing Trees Circled nodes may update object-store
Comparing • Circled nodes are syntactically equal in both sides • The order of execution is the same • Pre-conditions not necessary for the MCI law
Other Laws • Add before-call • Add after-execution returning • Merge advices • Remove target parameter • Remove this parameter
Conclusions • Increase confidence that aspect-oriented programming laws preserve behaviour • Equivalence notion for aspect-oriented programs • Formal argumentation about the soundness of some laws
Conclusions • Static semantics not considered • Formal proof using induction • Prove the remaining laws • Extend MCI • Choose another semantics
Informatics Center Federal University of Pernambuco Brazil Proving aspect-oriented programming laws Leonardo Cole Paulo Borba Alexandre Mota (lcn,phmb,acm@cin.ufpe.br) Software Productivity Group http://www.cin.ufpe.br/spg