diagnosis and semi-automatic correction of detected design inconsistencies in source code

66
Diagnosis and semi-automatic correction of detected design inconsistencies in source code Sergio Castro RELEASeD lab Université catholique de Louvain [email protected] Advisor: Kim Mens 1 1 Monday 31 August 2009

Upload: esug

Post on 17-Dec-2014

336 views

Category:

Technology


1 download

DESCRIPTION

Diagnosis and semi-automatic correction of detected design inconsistencies in source code by Sergio Castro, Johan Brichau and Kim Mens, ESUG09, Brest, France

TRANSCRIPT

Page 1: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

Diagnosis and semi-automatic correction of

detected design inconsistencies in source code

Sergio CastroRELEASeD lab

Université catholique de [email protected]

Advisor: Kim Mens

1

1Monday 31 August 2009

Page 2: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

An inconsistency example

AbstractAction

- (abstract) perform- isUndoable

^false.

- perform- isUndoable

^true.

- perform- undoAction

- perform- undoAction- isUndoable

^aBlock value.

- perform- undoAction- isUndoable

^true.

2

Dummy

Action

Experimental

Action

DrawAction QueryAction

2Monday 31 August 2009

Page 3: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

An inconsistency example

AbstractAction

- (abstract) perform- isUndoable

^false.

- perform- isUndoable

^true.

- perform- undoAction

- perform- undoAction- isUndoable

^aBlock value.

- perform- undoAction- isUndoable

^true.

2

Dummy

Action

Experimental

Action

DrawAction QueryAction

The command design pattern

2Monday 31 August 2009

Page 4: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

An inconsistency example

AbstractAction

- (abstract) perform- isUndoable

^false.

- perform- isUndoable

^true.

- perform- undoAction

- perform- undoAction- isUndoable

^aBlock value.

- perform- undoAction- isUndoable

^true.

2

Consistency property:! Action, an undoAction method should be provided

⇔ the isUndoable method returns true

Dummy

Action

Experimental

Action

DrawAction QueryAction

The command design pattern

2Monday 31 August 2009

Page 5: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

An inconsistency example

AbstractAction

- (abstract) perform- isUndoable

^false.

- perform- isUndoable

^true.

- perform- undoAction

- perform- undoAction- isUndoable

^aBlock value.

- perform- undoAction- isUndoable

^true.

2

Consistency property:! Action, an undoAction method should be provided

⇔ the isUndoable method returns true

Dummy

Action

Experimental

Action

DrawAction QueryAction

The command design pattern

2Monday 31 August 2009

Page 6: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

An inconsistency example

AbstractAction

- (abstract) perform- isUndoable

^false.

- perform- isUndoable

^true.

- perform- undoAction

- perform- undoAction- isUndoable

^aBlock value.

- perform- undoAction- isUndoable

^true.

2

Consistency property:! Action, an undoAction method should be provided

⇔ the isUndoable method returns true

Dummy

Action

Experimental

Action

DrawAction QueryAction

- isUndoable^true.

The command design pattern

2Monday 31 August 2009

Page 7: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

An inconsistency example

AbstractAction

- (abstract) perform- isUndoable

^false.

- perform- isUndoable

^true.

- perform- undoAction

- perform- undoAction- isUndoable

^aBlock value.

- perform- undoAction- isUndoable

^true.

2

Consistency property:! Action, an undoAction method should be provided

⇔ the isUndoable method returns true

Dummy

Action

Experimental

Action

DrawAction QueryAction

- isUndoable^true.

- undoAction

The command design pattern

2Monday 31 August 2009

Page 8: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

An inconsistency example

AbstractAction

- (abstract) perform- isUndoable

^false.

- perform- isUndoable

^true.

- perform- undoAction

- perform- undoAction- isUndoable

^aBlock value.?- perform- undoAction- isUndoable

^true.

2

Consistency property:! Action, an undoAction method should be provided

⇔ the isUndoable method returns true

Dummy

Action

Experimental

Action

DrawAction QueryAction

- isUndoable^true.

- undoAction

The command design pattern

2Monday 31 August 2009

Page 9: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

Consistency property:! Action, an undoAction method should be provided

⇔ the isUndoable method returns true

User-defined consistency

An inconsistency exampleThe command design pattern

3

3Monday 31 August 2009

Page 10: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

Inconsistency management activities

Predefined consistencydefinitions

Inconsistency detection

Diagnosing

Correcting

Many tools offering support for management of predefined

consistencies.

Such as Lint, CheckStyle, etc

4

4Monday 31 August 2009

Page 11: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

Inconsistency management activities

User-definedconsistency definitions

Inconsistency detection

Diagnosing

Correcting

We propose a general approach for the management of user-defined consistencies.

5

5Monday 31 August 2009

Page 12: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

Inconsistency management activities

Inconsistency detection

Diagnosing

Correcting

} IntensiVE

} Corrective framework

Explaining abnormal observations and

suggesting corrective actions

Defining and verifying consistency rules

6

Already used for inconsistency management in other areas of SE (e.g.,

requirements engineering, UML modelling, data bases)

User-definedconsistency definitions

6Monday 31 August 2009

Page 13: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

Inconsistency management activities

Inconsistency detection

Diagnosing

Correcting

} IntensiVE

} Corrective framework

Explaining abnormal observations and

suggesting corrective actions

Defining and verifying consistency rules

6

Already used for inconsistency management in other areas of SE (e.g.,

requirements engineering, UML modelling, data bases)

( http://www.intensive.be )

User-definedconsistency definitions

6Monday 31 August 2009

Page 14: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

7

IntensiVE

( http://www.intensive.be )

Inconsistency detection

User-definedconsistency definitions

7Monday 31 August 2009

Page 15: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

Defining and verifying constraints using IntensiVE

• Many kind of checks.

• Defined as relationships among sets of source code elements.

• Sets are intensionally defined and referred as Intensional Views.

8

with queries over source code

8Monday 31 August 2009

Page 16: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

View with classes returning

true in the isUndoable

method

View with classes

implementing the undoAction

method

Verification of the Undoable Actions constraint

9

Consistency property:! Action, an undoAction method should be provided

⇔ the isUndoable method returns true

9Monday 31 August 2009

Page 17: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

View with classes returning

true in the isUndoable

method

View with classes

implementing the undoAction

method

Verification of the Undoable Actions constraintQUERY:

classChainReallyUnderstandsMethodWithName(?class,?method,isUndoable),

methodReturnsBoolean(?method,[true])

9

Consistency property:! Action, an undoAction method should be provided

⇔ the isUndoable method returns true

9Monday 31 August 2009

Page 18: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

View with classes returning

true in the isUndoable

method

View with classes

implementing the undoAction

method

Verification of the Undoable Actions constraintQUERY:

classChainReallyUnderstandsMethodWithName(?class,?method,isUndoable),

methodReturnsBoolean(?method,[true])

QUERY:classChainReallyUnderstandsMethodWith

Name(?class,?,undoAction)

9

Consistency property:! Action, an undoAction method should be provided

⇔ the isUndoable method returns true

9Monday 31 August 2009

Page 19: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

View with classes returning

true in the isUndoable

method

View with classes

implementing the undoAction

method

If consistent, any class in the first view should be also in the

second, and vice versa

Verification of the Undoable Actions constraintQUERY:

classChainReallyUnderstandsMethodWithName(?class,?method,isUndoable),

methodReturnsBoolean(?method,[true])

QUERY:classChainReallyUnderstandsMethodWith

Name(?class,?,undoAction)

9

Consistency property:! Action, an undoAction method should be provided

⇔ the isUndoable method returns true

9Monday 31 August 2009

Page 20: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

Verification of alternative views

AbstractAddAction

AddClassificationAction

ExperimentalAction

View with classes returning true in the isUndoable method

View with classes implementing the

undoAction method

AbstractAddAction

AddClassificationAction

QUERY:classChainReallyUnderstandsMethodWith

Name(?class,?method,isUndoable), methodReturnsBoolean(?method,[true])

QUERY:classChainReallyUnderstandsMethodWith

Name(?class,?,undoAction)

10

Consistency property:! Action, an undoAction method should be provided

⇔ the isUndoable method returns true

10Monday 31 August 2009

Page 21: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

Verification of alternative views

AbstractAddAction

AddClassificationAction

ExperimentalAction

View with classes returning true in the isUndoable method

View with classes implementing the

undoAction method

AbstractAddAction

AddClassificationAction

?

QUERY:classChainReallyUnderstandsMethodWith

Name(?class,?method,isUndoable), methodReturnsBoolean(?method,[true])

QUERY:classChainReallyUnderstandsMethodWith

Name(?class,?,undoAction)

10

Consistency property:! Action, an undoAction method should be provided

⇔ the isUndoable method returns true

10Monday 31 August 2009

Page 22: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

IntensiVE(consistency checking)

11

11Monday 31 August 2009

Page 23: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

IntensiVE(consistency checking)

{

11

Classes that return true in the isUndoable method

11Monday 31 August 2009

Page 24: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

IntensiVE(consistency checking)

{ {

11

Classes that return true in the isUndoable method

Classes that implement the

undoAction method

11Monday 31 August 2009

Page 25: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

IntensiVE(consistency checking)

12

This class does not return true at the

isUndoable method

But implements an undoAction method

12Monday 31 August 2009

Page 26: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

IntensiVE(consistency checking)

12

This class does not return true at the

isUndoable method

But implements an undoAction method

ExperimentalAction

12Monday 31 August 2009

Page 27: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

IntensiVE(diagnosing inconsistencies)

13

Why ExperimentalAction is

not a result of the query defining this set?

OR: Why ExperimentalAction is a result of the query defining

this set?

ExperimentalAction

13Monday 31 August 2009

Page 28: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

Inconsistency management activities

Inconsistency detection

Diagnosing

Correcting

} IntensiVE

} Corrective framework

Explaining abnormal observations and

suggesting corrective actions

Defining and verifying consistency rules

14

Already used for inconsistency management in other areas of SE (e.g.,

requirements engineering, UML modelling, data bases)

( http://www.intensive.be )

User-definedconsistency definitions

14Monday 31 August 2009

Page 29: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

Corrective framework

15

Diagnosing

Correcting

15Monday 31 August 2009

Page 30: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

What is diagnosis?

16

Generating hypotheses explaining abnormal

observations

Abductive reasoning

16Monday 31 August 2009

Page 31: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

What is diagnosis?

16

Generating hypotheses explaining abnormal

observations

Abductive reasoning

16Monday 31 August 2009

Page 32: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

What is diagnosis?

16

Generating hypotheses explaining abnormal

observations

Abductive reasoning

one of the fundamental forms of

human reasoning according to Pierce

16Monday 31 August 2009

Page 33: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

Abduction is suitable for

• Generating hypotheses that would explain an evidence.

• Explanations expressed in terms of certain predicates, declared before hand as abducibles.

17

17Monday 31 August 2009

Page 34: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

Abduction is suitable for

• Generating hypotheses that would explain an evidence.

• Explanations expressed in terms of certain predicates, declared before hand as abducibles.

17

False predicates

that could be true

17Monday 31 August 2009

Page 35: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

Abduction is suitable for

• Generating hypotheses that would explain an evidence.

• Explanations expressed in terms of certain predicates, declared before hand as abducibles.

17

True predicates

that could be false

False predicates

that could be true

17Monday 31 August 2009

Page 36: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

Abducibles

Abduction is suitable for

• Generating hypotheses that would explain an evidence.

• Explanations expressed in terms of certain predicates, declared before hand as abducibles.

17

True predicates

that could be false

False predicates

that could be true

We can think in “Abducibles” as “Correctables”

17Monday 31 August 2009

Page 37: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

Abducibles

bird(?x).

broken-wing(?x).

An example of abduction

Theory:

flies(?x) if bird(?x), not (ab(?x))

ab(?x) if broken-wing(?x)

18

18Monday 31 August 2009

Page 38: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

Abducibles

bird(?x).

broken-wing(?x).

An example of abduction

Theory:

flies(?x) if bird(?x), not (ab(?x))

ab(?x) if broken-wing(?x)

18

Observation:

flies(opus)

18Monday 31 August 2009

Page 39: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

Abducibles

bird(?x).

broken-wing(?x).

An example of abduction

Theory:

flies(?x) if bird(?x), not (ab(?x))

ab(?x) if broken-wing(?x)

18

Observation:

flies(opus)

failing

18Monday 31 August 2009

Page 40: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

Abducibles

bird(?x).

broken-wing(?x).

An example of abduction

Theory:

flies(?x) if bird(?x), not (ab(?x))

ab(?x) if broken-wing(?x)

18

Observation:

flies(opus)

bird(opus)added to

our theory

failing

18Monday 31 August 2009

Page 41: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

Abducibles

bird(?x).

broken-wing(?x).

An example of abduction

Theory:

flies(?x) if bird(?x), not (ab(?x))

ab(?x) if broken-wing(?x)

18

Observation:

flies(opus)

bird(opus)added to

our theory

succeeding

18Monday 31 August 2009

Page 42: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

Abducibles

bird(?x).

broken-wing(?x).

An example of abduction

Theory:

flies(?x) if bird(?x), not (ab(?x))

ab(?x) if broken-wing(?x)

bird(tweety)

broken-wing(tweety)

19

19Monday 31 August 2009

Page 43: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

Abducibles

bird(?x).

broken-wing(?x).

An example of abduction

Theory:

flies(?x) if bird(?x), not (ab(?x))

ab(?x) if broken-wing(?x)

bird(tweety)

broken-wing(tweety)

19

Observation:

flies(tweety)

19Monday 31 August 2009

Page 44: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

Abducibles

bird(?x).

broken-wing(?x).

An example of abduction

Theory:

flies(?x) if bird(?x), not (ab(?x))

ab(?x) if broken-wing(?x)

bird(tweety)

broken-wing(tweety)

19

Observation:

flies(tweety)

failing

19Monday 31 August 2009

Page 45: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

Abducibles

bird(?x).

broken-wing(?x).

An example of abduction

Theory:

flies(?x) if bird(?x), not (ab(?x))

ab(?x) if broken-wing(?x)

bird(tweety)

broken-wing(tweety)

19

Observation:

flies(tweety)

retracted from our theory

failing

19Monday 31 August 2009

Page 46: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

Abducibles

bird(?x).

broken-wing(?x).

An example of abduction

Theory:

flies(?x) if bird(?x), not (ab(?x))

ab(?x) if broken-wing(?x)

bird(tweety)

broken-wing(tweety)

19

Observation:

flies(tweety)

retracted from our theory

succeeding

19Monday 31 August 2009

Page 47: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

How to choose abducible predicates

?-classChainReallyUnderstandMethodWithName(ExperimentalAction, ?m, undoAction),

methodWithBooleanReturnStatement(?m, true)

:-superclassOf(?s, ExperimentalAction),

classChainReallyUnderstandMethodWithName(?s, ?m, undoAction),

methodWithBooleanReturnStatement(?m, true)

:-methodWithNameInClass(?m, undoAction, ExperimentalAction),

methodWithBooleanReturnStatement(?m, true)

20

- predicates that denote basic structural relationships- we know for sure that they will be evaluated as part of the resolution process of the query

20Monday 31 August 2009

Page 48: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

How to choose abducible predicates

?-classChainReallyUnderstandMethodWithName(ExperimentalAction, ?m, undoAction),

methodWithBooleanReturnStatement(?m, true)

:-superclassOf(?s, ExperimentalAction),

classChainReallyUnderstandMethodWithName(?s, ?m, undoAction),

methodWithBooleanReturnStatement(?m, true)

:-methodWithNameInClass(?m, undoAction, ExperimentalAction),

methodWithBooleanReturnStatement(?m, true)

20

Primitive predicates that can be corrected

- predicates that denote basic structural relationships- we know for sure that they will be evaluated as part of the resolution process of the query

20Monday 31 August 2009

Page 49: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

?-classChainReallyUnderstandMethodWithName(ExperimentalAction, ?m, undoAction),

methodWithBooleanReturnStatement(?m, true)

:-superclassOf(?s, ExperimentalAction),

classChainReallyUnderstandMethodWithName(?s, ?m, undoAction),

methodWithBooleanReturnStatement(?m, true)

:-methodWithNameInClass(?m, undoAction, ExperimentalAction),

methodWithBooleanReturnStatement(?m, true)

21

Primitive predicates that can be corrected

How to choose abducible predicates

21Monday 31 August 2009

Page 50: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

?-classChainReallyUnderstandMethodWithName(ExperimentalAction, ?m, undoAction),

methodWithBooleanReturnStatement(?m, true)

:-superclassOf(?s, ExperimentalAction),

classChainReallyUnderstandMethodWithName(?s, ?m, undoAction),

methodWithBooleanReturnStatement(?m, true)

:-methodWithNameInClass(?m, undoAction, ExperimentalAction),

methodWithBooleanReturnStatement(?m, true)

21

Primitive predicates that can be corrected

How to choose abducible predicates

21Monday 31 August 2009

Page 51: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

Our framework allows ...

• The definition of abducible predicates.

• Declaration of multiple corrective actions.

• Generation of hypotheses explaining inconsistencies.

• Semi-automatic execution of corrective actions.

22

22Monday 31 August 2009

Page 52: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

Defining positive explanations(new facts will be added to the theory)

23

23Monday 31 August 2009

Page 53: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

Defining positive explanations(new facts will be added to the theory)

23

Abducible predicate:in(methodWithBooleanReturnStatement(+?

method,+?boolean))

23Monday 31 August 2009

Page 54: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

Defining positive explanations(new facts will be added to the theory)

24

24Monday 31 August 2009

Page 55: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

Defining positive explanations(new facts will be added to the theory)

24

Corrective action:[[?class compile: (?selector asString, ‘^’,?boolean

asString)]]

24Monday 31 August 2009

Page 56: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

Correcting inconsistencies

25

25Monday 31 August 2009

Page 57: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

Correcting inconsistencies

25

Correct

25Monday 31 August 2009

Page 58: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

The corrective browser

26

26Monday 31 August 2009

Page 59: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

The corrective browser

26

Corrective action name

26Monday 31 August 2009

Page 60: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

The corrective browser

26

Corrective action name

Textual description

26Monday 31 August 2009

Page 61: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

The corrective browser

26

Corrective action name

Textual description

Visualization in the proof three of where the

corrective action was found

26Monday 31 August 2009

Page 62: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

Visualisation of the nodes with corrective actions

27

Color code:•Red filling means failure.

•Thick green border means availability of corrective

actions.

27Monday 31 August 2009

Page 63: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

Visualisation of the nodes with corrective actions

27

Color code:•Red filling means failure.

•Thick green border means availability of corrective

actions.

27Monday 31 August 2009

Page 64: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

Future work

• How to choose among different solutions.

• Detect solutions that could cause new inconsistencies.

28

28Monday 31 August 2009

Page 65: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

Conclusions

• We can infer solutions from the rules that define consistencies.

• A library of “primitive” solutions to small problems should be provided.

• These solutions can be composed and reused across distinct problems.

29

29Monday 31 August 2009

Page 66: Diagnosis and semi-automatic correction of detected design inconsistencies in source code

Many Thanks !

Questions and feedback are welcomed

30

30Monday 31 August 2009