Migration and Refactoring - Identifying Overly Strong Conditions in Refactoring Implementations

24
Identifying overly strong conditions in refactoring implementations Gustavo Soares Melina Mongiovi Rohit Gheyi [email protected] Federal University of Campina Grande terça-feira, 11 de outubro de 2011

description

Paper: Identifying Overly Strong Conditions in Refactoring ImplementationsAuthors: Gustavo Soares, Melina Mongiovi and Rohit GheyiSession: Research Track Session 6: Migration and Refactoring

Transcript of Migration and Refactoring - Identifying Overly Strong Conditions in Refactoring Implementations

Page 1: Migration and Refactoring - Identifying Overly Strong Conditions in Refactoring Implementations

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

Page 2: Migration and Refactoring - Identifying Overly Strong Conditions in Refactoring Implementations

2

Employee

...

Engineer

...name

Salesman

...name

Duplicated code

terça-feira, 11 de outubro de 2011

Page 3: Migration and Refactoring - Identifying Overly Strong Conditions in Refactoring Implementations

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

Page 4: Migration and Refactoring - Identifying Overly Strong Conditions in Refactoring Implementations

preconditions

It’s difficult to specify and implement preconditions

4

terça-feira, 11 de outubro de 2011

Page 5: Migration and Refactoring - Identifying Overly Strong Conditions in Refactoring Implementations

preconditionsImplemented

Overly  weakcondi0ons  allow

unsafe  transforma+ons

Overly  strong  condi0onsprevent  safe  transforma+ons

Problem

5

terça-feira, 11 de outubro de 2011

Page 6: Migration and Refactoring - Identifying Overly Strong Conditions in Refactoring Implementations

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

Page 7: Migration and Refactoring - Identifying Overly Strong Conditions in Refactoring Implementations

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

Page 8: Migration and Refactoring - Identifying Overly Strong Conditions in Refactoring Implementations

Identifying overly strong conditions

An evaluation on 3 refactoring engines

JRRT

8

terça-feira, 11 de outubro de 2011

Page 9: Migration and Refactoring - Identifying Overly Strong Conditions in Refactoring Implementations

input

expected output

Testing

9

terça-feira, 11 de outubro de 2011

Page 10: Migration and Refactoring - Identifying Overly Strong Conditions in Refactoring Implementations

input

expected output

Testing

10

engine

output

Overly strong

terça-feira, 11 de outubro de 2011

Page 11: Migration and Refactoring - Identifying Overly Strong Conditions in Refactoring Implementations

input

Overly Strong

conditions

11

Differential testing

Overly StrongCondition

Exhaustively generating programs

terça-feira, 11 de outubro de 2011

Page 12: Migration and Refactoring - Identifying Overly Strong Conditions in Refactoring Implementations

2 Class, 2 Method, 2 Field

One subclass declaring a field

12

terça-feira, 11 de outubro de 2011

Page 13: Migration and Refactoring - Identifying Overly Strong Conditions in Refactoring Implementations

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

Page 14: Migration and Refactoring - Identifying Overly Strong Conditions in Refactoring Implementations

input

expected output

14

Differential testing

Overly StrongCondition

Exhaustively generating programs

terça-feira, 11 de outubro de 2011

Page 15: Migration and Refactoring - Identifying Overly Strong Conditions in Refactoring Implementations

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

Page 16: Migration and Refactoring - Identifying Overly Strong Conditions in Refactoring Implementations

Technique

Differentialtesting

Classifying

overly strongpreconditions

SPEC

16

terça-feira, 11 de outubro de 2011

Page 17: Migration and Refactoring - Identifying Overly Strong Conditions in Refactoring Implementations

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

Page 18: Migration and Refactoring - Identifying Overly Strong Conditions in Refactoring Implementations

Evaluation

18

terça-feira, 11 de outubro de 2011

Page 19: Migration and Refactoring - Identifying Overly Strong Conditions in Refactoring Implementations

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

Page 20: Migration and Refactoring - Identifying Overly Strong Conditions in Refactoring Implementations

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

Page 21: Migration and Refactoring - Identifying Overly Strong Conditions in Refactoring Implementations

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

Page 22: Migration and Refactoring - Identifying Overly Strong Conditions in Refactoring Implementations

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

Page 23: Migration and Refactoring - Identifying Overly Strong Conditions in Refactoring Implementations

Conclusions

preconditionsImplemented

DifferentialTesting

+

overly strong conditions + overly weak conditions

23

terça-feira, 11 de outubro de 2011

Page 24: Migration and Refactoring - Identifying Overly Strong Conditions in Refactoring Implementations

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