Identifying overly strong conditions in refactoring implementations
Gustavo SoaresMelina Mongiovi
Rohit Gheyi
[email protected] University of Campina Grande
terça-feira, 11 de outubro de 2011
2
Employee
...
Engineer
...name
Salesman
...name
Duplicated code
terça-feira, 11 de outubro de 2011
Pull Up Field Refactoring
3
Employee
...
Engineer
...name
Salesman
...name
Employee
...name
Engineer
...
Salesman
...
Refactoring engines
Precondition The name field is not declared in class Employee
terça-feira, 11 de outubro de 2011
preconditions
It’s difficult to specify and implement preconditions
4
terça-feira, 11 de outubro de 2011
preconditionsImplemented
Overly weakcondi0ons allow
unsafe transforma+ons
Overly strong condi0onsprevent safe transforma+ons
Problem
5
terça-feira, 11 de outubro de 2011
Motivating example
A
B
private int fint getF() : f
Pull up field
JRRT
GetF() cannot access variable f
6
terça-feira, 11 de outubro de 2011
A
B
private int fint getF() : f
Pull up field
JRRT
GetF() cannot access variable f
A
B
private int fint getF() : f
Pull up field
A
protected int f
B
int getF() : f
7
Overly strong
terça-feira, 11 de outubro de 2011
Identifying overly strong conditions
An evaluation on 3 refactoring engines
JRRT
8
terça-feira, 11 de outubro de 2011
input
expected output
Testing
9
terça-feira, 11 de outubro de 2011
input
expected output
Testing
10
engine
output
Overly strong
terça-feira, 11 de outubro de 2011
input
Overly Strong
conditions
11
Differential testing
Overly StrongCondition
Exhaustively generating programs
terça-feira, 11 de outubro de 2011
2 Class, 2 Method, 2 Field
One subclass declaring a field
12
terça-feira, 11 de outubro de 2011
public class Class0 {public int method2(){ return 10; }}class Class1 extends Class0 { public int method1(){ return 20; } public int method2(){ super.k(); }}
public class Class0 {public int method2(){ return 10; }}class Class1 extends Class0 { public int method1(){ return 20; } public int method2(){ super.k(); }}
public class Class0 {public int method2(){ return 10; }}class Class1 extends Class0 { public int method1(){ return 20; } public int method2(){ super.k(); }}
Java Meta model Alloy Solutions Java programs
2 Class, 2 Method, 2 Field
One subclass declaring a field
13
terça-feira, 11 de outubro de 2011
input
expected output
14
Differential testing
Overly StrongCondition
Exhaustively generating programs
terça-feira, 11 de outubro de 2011
B.getF
No behavioral change was found
0/4 0/4
A
B
private int fint getF() : f
A
protected int f
B
int getF() : f4
15
terça-feira, 11 de outubro de 2011
Technique
Differentialtesting
Classifying
overly strongpreconditions
SPEC
16
terça-feira, 11 de outubro de 2011
Classifying overly strong conditions
A.test cannot access method A.k
B.m cannot access method B.n
C.test cannot access method C.k
cannot access method
OTC
17
terça-feira, 11 de outubro de 2011
Evaluation
18
terça-feira, 11 de outubro de 2011
Up to 10 refactoringsRefactoring Eclipse JRRT NetBeansRename Class X X X
Rename Method X X XRename Field X X X
Push Down Method X X XPush Down Field X X XPull Up Method X X XPull Up Field X X X
Encapsulate Field X XMove Method X XAdd Parameter X X
2 Packages, 3 classes, 4 methods, 2 fields19
terça-feira, 11 de outubro de 2011
ResultsRefactoring Program
Rejected Beh. Pres.Rejected Beh. Pres.Rejected Beh. Pres. Overly Strong ConditionOverly Strong ConditionOverly Strong ConditionRefactoring Program
Ecl JRRT NetB Ecl JRRT NetBRename Class 4660 446 0 0 2 0 0
Rename Method 4752 4802 419 0 4 1 0Rename Field 3168 200 0 0 2 0 0
Push Down Method 9366 59 40 0 1 1 0Push Down Field 4800 0 0 0 0 0 0Pull Up Method 10322 251 398 0 2 2 0Pull Up Field 4320 744 584 0 1 1 0
Encapsulate Field 900 176 1536 - 1 1 -Move Method 3002 367 135 - 2 1 -Add Parameter 4279 79 0 - 2 0 -
Total 42774 7124 3112 0 17 7 0
20
terça-feira, 11 de outubro de 2011
JRRT feedbackRefactoring Strong conditions
Rename Method overriding has changed
Push Down Method cannot access method
Pull Up Methodmethod is used
Pull Up Methodcannot access method
Pull Up Field cannot access variable
Encapsulate Field cannot insert method here
Move Method cannot inline ambiguous method call
21
terça-feira, 11 de outubro de 2011
JRRT feedbackRefactoring Strong conditions Cause
Rename Method overriding has changed precondi+on
Push Down Method cannot access method incorrect analysis
Pull Up Methodmethod is used incorrect analysis
Pull Up Methodcannot access method incorrect analysis
Pull Up Field cannot access variable feature not implemented
Encapsulate Field cannot insert method here feature not implemented
Move Method cannot inline ambiguous method call incorrect analysis
22
terça-feira, 11 de outubro de 2011
Conclusions
preconditionsImplemented
DifferentialTesting
+
overly strong conditions + overly weak conditions
23
terça-feira, 11 de outubro de 2011
Identifying overly strong conditions in refactoring implementations
Gustavo SoaresMelina Mongiovi
Rohit Gheyi
[email protected] University of Campina Grande
24
terça-feira, 11 de outubro de 2011
Top Related