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

Post on 17-Dec-2014

336 Views

Category:

Technology

1 Downloads

Preview:

Click to see full reader

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

Diagnosis and semi-automatic correction of

detected design inconsistencies in source code

Sergio CastroRELEASeD lab

Université catholique de Louvainsergio.castro@uclouvain.be

Advisor: Kim Mens

1

1Monday 31 August 2009

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

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

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

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

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

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

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

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

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

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

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

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

7

IntensiVE

( http://www.intensive.be )

Inconsistency detection

User-definedconsistency definitions

7Monday 31 August 2009

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

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

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

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

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

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

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

IntensiVE(consistency checking)

11

11Monday 31 August 2009

IntensiVE(consistency checking)

{

11

Classes that return true in the isUndoable method

11Monday 31 August 2009

IntensiVE(consistency checking)

{ {

11

Classes that return true in the isUndoable method

Classes that implement the

undoAction method

11Monday 31 August 2009

IntensiVE(consistency checking)

12

This class does not return true at the

isUndoable method

But implements an undoAction method

12Monday 31 August 2009

IntensiVE(consistency checking)

12

This class does not return true at the

isUndoable method

But implements an undoAction method

ExperimentalAction

12Monday 31 August 2009

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

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

Corrective framework

15

Diagnosing

Correcting

15Monday 31 August 2009

What is diagnosis?

16

Generating hypotheses explaining abnormal

observations

Abductive reasoning

16Monday 31 August 2009

What is diagnosis?

16

Generating hypotheses explaining abnormal

observations

Abductive reasoning

16Monday 31 August 2009

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

?-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

?-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

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

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

23

23Monday 31 August 2009

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

23

Abducible predicate:in(methodWithBooleanReturnStatement(+?

method,+?boolean))

23Monday 31 August 2009

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

24

24Monday 31 August 2009

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

24

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

asString)]]

24Monday 31 August 2009

Correcting inconsistencies

25

25Monday 31 August 2009

Correcting inconsistencies

25

Correct

25Monday 31 August 2009

The corrective browser

26

26Monday 31 August 2009

The corrective browser

26

Corrective action name

26Monday 31 August 2009

The corrective browser

26

Corrective action name

Textual description

26Monday 31 August 2009

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

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

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

Future work

• How to choose among different solutions.

• Detect solutions that could cause new inconsistencies.

28

28Monday 31 August 2009

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

Many Thanks !

Questions and feedback are welcomed

30

30Monday 31 August 2009

top related