Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Deriving Refactorings for AspectJ Leonardo Cole Paulo Borba Informatics Center Federal University of Pernambuco Brazil.

Similar presentations


Presentation on theme: "1 Deriving Refactorings for AspectJ Leonardo Cole Paulo Borba Informatics Center Federal University of Pernambuco Brazil."— Presentation transcript:

1 1 Deriving Refactorings for AspectJ Leonardo Cole Paulo Borba (lcn,phmb@cin.ufpe.br) Informatics Center Federal University of Pernambuco Brazil

2 2 Problem Aspect-oriented developers are identifying common transformations for aspect-oriented programs Refactorings are generally complex and global It is difficult to verify if a defined refactoring preserves behaviour

3 3 Our Approach Primitive laws of programming simple, localized, intuitive and easier to understand Two transformations Bi-directional Guarded by pre-conditions We use the laws to - Derive complex and global refactorings - Verify that an existing refactoring preserves behaviour

4 4 Deriving Refactorings Composing Laws Refactoring

5 5 Outline Aspect-oriented programming laws Evaluation Conclusions

6 6 Aspect-Oriented Programming Laws Simple and localized Two transformations Bi-directional One direction may not increase code quality Our laws define equivalences between two programs given that the preconditions are respected

7 7 Make Aspect Privileged ts privileged aspect A { pcs as } = (  ) Advice bodies from as do not refer to private members declared in ts. ts aspect A { pcs as }

8 8 Add before-execution ts class C { fs ms T m(ps) { body’; body } ts class C { fs ms T m(ps) { body } = paspect A { pcs before(context) : exec(C.m) && bind(context) { body’ } as } paspect A { pcs as } (  ) body’ does not declare or use local variables; body’ does not call super ; …

9 9 Example public class Account { private double balance;... public void debit(double amount) { Access.check(new Permission(…)); //debit logic }... } privileged aspect PermissionAspect { } Source: Laddad, 2003 Aspect Oriented Refactoring Series

10 10 Applying Add Before-Execution Law public class Account { private double balance;... public void debit(double amount) { //debit logic }... } privileged aspect PermissionAspect { before(Account cthis, double amount): execution(void Account.debit(double) && this(cthis) && args(amount) { Access.check(new Permission(…)); }

11 11 Summary of laws LawNameLawName 1Add empty aspect16Remove argument parameter 2Make aspect privileged17Add catch for softened exception 3Add before-execution18Soften exception 4Add before-call19Remove exception from throws clause 5Add after-execution20Remove exception handling 6Add after-call21Move exception handling to aspect 7Add after returning-execution22Move field to aspect 8Add after returning-call23Move method to aspect 9Add after throwing-execution24Move implements declaration to aspect 10Add after throwing-call25Move extends declaration to aspect 11Add around-execution26Extract named pointcut 12Add around-call27Use named pointcut 13Merge advices28Move field introduction up to interface 14Remove this parameter29Move method introduction up to interface 15Remove target parameter30Remove method implementation

12 12 Evaluation We derived existing aspect-oriented refactorings from the laws We restructured two object-oriented applications modularizing crosscutting concerns with aspects

13 13 Refactorings: Extract Pointcut ts aspect A { pointcut p(ps) : exp … before(ps) : p (  ps) { body } … after(ps) : p (  ps) { body’ } … } = ts aspect A { … before(ps) : exp { body } … after(ps) : exp { body’ } … }

14 14 Extract Pointcut Preconditions Summary Law 12 – Extract named pointcut Law 32 – Use named poitncut (  ) There is no pointcut named p in pcs ; (  ) There is no reference to p in ts and A. Law 12Law 32

15 15 Extract Method Calls Summary Law 2 – Add before-execution Law 9 – Merge advices Law 27 – Remove this parameter Law 28 – Remove argument parameter Law 2Law 9 Law 27 Law 28 Extract Pointcut

16 16 Other Refactorings Extract Interface Implementation Extract Exception Handling Extract Concurrency Control Evolving Product Lines …

17 17 Refactoring to AspectJ General OO Refactorings + AO Derived Refactorings + Laws Before: OO After: AO

18 18 Applications Two commercial applications First Mobile Server Concurrency control Second HealthWatcher Distribution Problem with Extract Exception Handling

19 19 Conclusions AOP laws useful for deriving aspect- oriented refactorings Derivation of existing refactorings Some not derived Refactored applications Also useful to Education Transformation tools Provide deeper understanding of the language

20 20 Conclusions Hipotesys No packages, this is mandatory, … No abstract aspects, concurrency and reflection, … Soundness

21 21 Deriving Refactorings for AspectJ Leonardo Cole Paulo Borba (lcn,phmb@cin.ufpe.br) Informatics Center Federal University of Pernambuco Brazil

22 22 Remove this Parameter (  ) t is not referenced from body. = ts paspect A { … before(ps) : this(T) && … { body } … } ts paspect A { … before(T t, ps) : this(t) && … { body } … }

23 23 Merge Advices (  ) The set of join points captured by exp1 and exp2 are disjoint. … = ts paspect A {... before(ps) : exp1 || exp2 { body }... } ts paspect A {... before(ps): exp1 { body } before(ps): exp2 { body }... }

24 24 Move field to aspect (  ) The field field of class C does not appear in ts and ms. = ts class C { fs ms } paspect A { T C.field... } ts class C { fs; T field ms } paspect A {... }

25 25 Add before-execution ts class C { fs ms T m(ps) { body’; body } ts class C { fs ms T m(ps) { body } = paspect A { pcs bars before(context) : exec(C.m) && bind(context) { body’ } afs } paspect A { pcs bars afs }

26 26 Extract Method Calls Example public class Account { private double balance;... public void debit(double amount) { Access.check(new Permission(…)); //debit logic } public void credit(double amount) {…}... } public aspect PermissionAspect { }

27 27 Applying Add Before-Execution public class Account { private double balance;... public void debit(double amount) { //debit logic } public void credit(double amount) {…}... } public aspect PermissionAspect { before(…): execution(void Account.debit(double) && … { Access.check(new Permission(…)); } before(…): execution(void Account.credit(double) && … { Access.check(new Permission(…)); }

28 28 Another Example public class Bank { private Transaction transaction;... public void remove(Account account) { transaction.begin(…); try { // remove account logic transaction.end(…) } catch (…) { transaction.rollBack(…); }... }

29 29 Applying laws Add before-execution Add after-execution returning Add after-execution throwing public class Bank { private Transaction transaction;... public void remove(Account account) { // remove account logic }... } aspect TransactionAspect {…}


Download ppt "1 Deriving Refactorings for AspectJ Leonardo Cole Paulo Borba Informatics Center Federal University of Pernambuco Brazil."

Similar presentations


Ads by Google