1 deriving refactorings for aspectj leonardo cole paulo borba (lcn,phmb@cin.ufpe.br) informatics...
Post on 19-Jan-2016
217 Views
Preview:
TRANSCRIPT
1
Deriving Refactorings for AspectJ
Leonardo Cole Paulo Borba
(lcn,phmb@cin.ufpe.br)
Informatics CenterFederal University of Pernambuco
Brazil
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
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
Deriving Refactorings
Composing
Laws Refactoring
5
Outline
Aspect-oriented programming laws Evaluation Conclusions
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
Make Aspect Privileged
tsprivileged aspect A { pcs as}
=
() Advice bodies from as do not refer to private members declared in ts.
tsaspect A { pcs as}
8
Add before-executiontsclass C { fs ms T m(ps) { body’; body }}
tsclass 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
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
Applying Add Before-Execution Lawpublic 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
Summary of lawsLaw Name Law Name
1 Add empty aspect 16 Remove argument parameter
2 Make aspect privileged 17 Add catch for softened exception
3 Add before-execution 18 Soften exception
4 Add before-call 19 Remove exception from throws clause
5 Add after-execution 20 Remove exception handling
6 Add after-call 21 Move exception handling to aspect
7 Add after returning-execution 22 Move field to aspect
8 Add after returning-call 23 Move method to aspect
9 Add after throwing-execution 24 Move implements declaration to aspect
10 Add after throwing-call 25 Move extends declaration to aspect
11 Add around-execution 26 Extract named pointcut
12 Add around-call 27 Use named pointcut
13 Merge advices 28 Move field introduction up to interface
14 Remove this parameter 29 Move method introduction up to interface
15 Remove target parameter 30 Remove method implementation
12
Evaluation
We derived existing aspect-oriented refactorings from the laws
We restructured two object-oriented applications modularizing crosscutting concerns with aspects
13
Refactorings: Extract Pointcut
tsaspect A { pointcut p(ps) : exp … before(ps) : p (ps) { body } … after(ps) : p (ps) { body’ } …}
=
tsaspect A { … before(ps) : exp { body } … after(ps) : exp { body’ } …}
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 12 Law 32
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 2 Law 9 Law 27 Law 28 Extract Pointcut
16
Other Refactorings
Extract Interface Implementation Extract Exception Handling Extract Concurrency Control Evolving Product Lines …
17
Refactoring to AspectJ
General OO Refactorings+
AO Derived Refactorings+
Laws
Before: OO After: AO
18
Applications
Two commercial applications First
• Mobile Server• Concurrency control
Second• HealthWatcher• Distribution• Problem with Extract Exception
Handling
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
Conclusions Hipotesys
• No packages, this is mandatory, …• No abstract aspects, concurrency and
reflection, … Soundness
21
Deriving Refactorings for AspectJ
Leonardo Cole Paulo Borba
(lcn,phmb@cin.ufpe.br)
Informatics CenterFederal University of Pernambuco
Brazil
22
Remove this Parameter
() t is not referenced from body.
=
tspaspect A { … before(ps) : this(T) && … { body } …}
tspaspect A { … before(T t , ps) : this(t) && … { body } …}
23
Merge Advices
() The set of join points captured by exp1 and exp2 are disjoint.…
=
tspaspect A { ... before(ps) : exp1 || exp2 { body } ...}
tspaspect A { ... before(ps): exp1 { body } before(ps): exp2 { body } ...}
24
Move field to aspect
() The field field of class C does not appear ints and ms.
=
tsclass C { fs ms}paspect A { T C.field ...}
tsclass C { fs; T field ms}paspect A { ...}
25
Add before-executiontsclass C { fs ms T m(ps) { body’; body }}
tsclass 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
Extract Method Calls Examplepublic 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
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
Another Examplepublic class Bank { private Transaction transaction; ... public void remove(Account account) { transaction.begin(…); try { // remove account logic transaction.end(…) } catch (…) { transaction.rollBack(…); } } ...}
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 {…}
top related