Constraint-Based Refactoring Rename Field Problem Proven Correct - - PowerPoint PPT Presentation

constraint based refactoring
SMART_READER_LITE
LIVE PREVIEW

Constraint-Based Refactoring Rename Field Problem Proven Correct - - PowerPoint PPT Presentation

Constraint- Based Refactoring Hansruedi Patzen Refactoring Constraint-Based Refactoring Rename Field Problem Proven Correct Solution Constraint- Based Refactoring Hansruedi Patzen 1 Constraint Rules Generalize Type Implementation


slide-1
SLIDE 1

Constraint- Based Refactoring Hansruedi Patzen Refactoring Rename Field

Problem Solution

Constraint- Based Refactoring

Constraint Rules Generalize Type

Implementation Researchers Summary Discussion References

Constraint-Based Refactoring

Proven Correct Hansruedi Patzen1

University of Applied Sciences Rapperswil

14th January 2019

1hansruedi.patzen@hsr.ch

slide-2
SLIDE 2

Constraint- Based Refactoring Hansruedi Patzen Refactoring Rename Field

Problem Solution

Constraint- Based Refactoring

Constraint Rules Generalize Type

Implementation Researchers Summary Discussion References

Refactoring

Why even bother?

slide-3
SLIDE 3

Constraint- Based Refactoring Hansruedi Patzen Refactoring Rename Field

Problem Solution

Constraint- Based Refactoring

Constraint Rules Generalize Type

Implementation Researchers Summary Discussion References

Refactoring is everywhere

slide-4
SLIDE 4

Constraint- Based Refactoring Hansruedi Patzen Refactoring Rename Field

Problem Solution

Constraint- Based Refactoring

Constraint Rules Generalize Type

Implementation Researchers Summary Discussion References

Rename Field

1 class BankAccount { 2

int n; // the amount of money a customer has

3 } 4 5 class Customer { 6

BankAccount account;

7 8

void receiveMoney(int amount) {

9

account.n += amount;

10

}

11 }

slide-5
SLIDE 5

Constraint- Based Refactoring Hansruedi Patzen Refactoring Rename Field

Problem Solution

Constraint- Based Refactoring

Constraint Rules Generalize Type

Implementation Researchers Summary Discussion References

Rename Field

1 class BankAccount { 2

int n ; // the amount of money a customer has

3 } 4 5 class Customer { 6

BankAccount account;

7 8

void receiveMoney(int amount) {

9

  • account. n

+= amount;

10

}

11 }

slide-6
SLIDE 6

Constraint- Based Refactoring Hansruedi Patzen Refactoring Rename Field

Problem Solution

Constraint- Based Refactoring

Constraint Rules Generalize Type

Implementation Researchers Summary Discussion References

Rename Field

1 class BankAccount { 2

int balance ; // the amount of money a customer has

3 } 4 5 class Customer { 6

BankAccount account;

7 8

void receiveMoney(int amount) {

9

  • account. balance

+= amount;

10

}

11 }

slide-7
SLIDE 7

Constraint- Based Refactoring Hansruedi Patzen Refactoring Rename Field

Problem Solution

Constraint- Based Refactoring

Constraint Rules Generalize Type

Implementation Researchers Summary Discussion References

Constraint-Based Refactoring

slide-8
SLIDE 8

Constraint- Based Refactoring Hansruedi Patzen Refactoring Rename Field

Problem Solution

Constraint- Based Refactoring

Constraint Rules Generalize Type

Implementation Researchers Summary Discussion References

Constraint-Based Refactoring

slide-9
SLIDE 9

Constraint- Based Refactoring Hansruedi Patzen Refactoring Rename Field

Problem Solution

Constraint- Based Refactoring

Constraint Rules Generalize Type

Implementation Researchers Summary Discussion References

Constraint Rules

query(v) constraints(v)

slide-10
SLIDE 10

Constraint- Based Refactoring Hansruedi Patzen Refactoring Rename Field

Problem Solution

Constraint- Based Refactoring

Constraint Rules Generalize Type

Implementation Researchers Summary Discussion References

Constraint Rules

C# Specification: “The type of a field must be at least as accessible as the field itself.”

f ∈ Fields(P) f .type.accessability ≥ f .accessability

slide-11
SLIDE 11

Constraint- Based Refactoring Hansruedi Patzen Refactoring Rename Field

Problem Solution

Constraint- Based Refactoring

Constraint Rules Generalize Type

Implementation Researchers Summary Discussion References

Constraint-Based Refactoring

slide-12
SLIDE 12

Constraint- Based Refactoring Hansruedi Patzen Refactoring Rename Field

Problem Solution

Constraint- Based Refactoring

Constraint Rules Generalize Type

Implementation Researchers Summary Discussion References

Generalize Type

1 class Base { // declBase 2

Base b; // refBase, declb

3 } 4 class Sub extends Base { // declSub, refBase 5

Sub s ; // refSub, decls

6 }

slide-13
SLIDE 13

Constraint- Based Refactoring Hansruedi Patzen Refactoring Rename Field

Problem Solution

Constraint- Based Refactoring

Constraint Rules Generalize Type

Implementation Researchers Summary Discussion References

Generalize Type

1 class

Sub { // declSub

2

Sub b; // refSub, declb

3 } 4 class

NN extends Sub { // declNN, refSub

5

Sub s; // refSub, decls

6 }

slide-14
SLIDE 14

Constraint- Based Refactoring Hansruedi Patzen Refactoring Rename Field

Problem Solution

Constraint- Based Refactoring

Constraint Rules Generalize Type

Implementation Researchers Summary Discussion References

Generalize Type

1 class Base { // declBase 2

Base b; // refBase, declb

3 } 4 class Sub extends Base { // declSub, refBase 5

Base s; // refBase, decls

6 }

slide-15
SLIDE 15

Constraint- Based Refactoring Hansruedi Patzen Refactoring Rename Field

Problem Solution

Constraint- Based Refactoring

Constraint Rules Generalize Type

Implementation Researchers Summary Discussion References

Implementation Showcase: Eclipse JDT

slide-16
SLIDE 16

Constraint- Based Refactoring Hansruedi Patzen Refactoring Rename Field

Problem Solution

Constraint- Based Refactoring

Constraint Rules Generalize Type

Implementation Researchers Summary Discussion References

ChangeTypeRefactoring

1 public Collection <ITypeBinding > computeValidTypes (...) { 2

constraintVariable = findConstraintVariableForSelectedNode (...);

3

relevantVariables = findRelevantConstraintVars(constraintVariable , ...);

4

relevantConstraints= findRelevantConstraints(relevantVariables);

5

validTypes.addAll(computeValidTypes(selectionTypeBinding , relevantVariabless , relevantConstraints));

6

return validTypes;

7 }

slide-17
SLIDE 17

Constraint- Based Refactoring Hansruedi Patzen Refactoring Rename Field

Problem Solution

Constraint- Based Refactoring

Constraint Rules Generalize Type

Implementation Researchers Summary Discussion References

Notable Researchers

Friedrich Steimann Frank Tip

slide-18
SLIDE 18

Constraint- Based Refactoring Hansruedi Patzen Refactoring Rename Field

Problem Solution

Constraint- Based Refactoring

Constraint Rules Generalize Type

Implementation Researchers Summary Discussion References

Summary

Constraint-Based Refactoring...

  • ...can be proven correct.
  • ...can find multiple solutions for a refactoring.
  • ...needs to limit the number of solutions, by
  • tailoring the constraint rules
  • limiting the solutions space
  • ...needs a sufficient coverage of the target language
  • ...is used in the real world → Eclipse JDT
slide-19
SLIDE 19

Constraint- Based Refactoring Hansruedi Patzen Refactoring Rename Field

Problem Solution

Constraint- Based Refactoring

Constraint Rules Generalize Type

Implementation Researchers Summary Discussion References

Discussion: Constraint-Based Refactoring

slide-20
SLIDE 20

Constraint- Based Refactoring Hansruedi Patzen Refactoring Rename Field

Problem Solution

Constraint- Based Refactoring

Constraint Rules Generalize Type

Implementation Researchers Summary Discussion References

References I

  • F. Steimann, “Constraint-Based Refactoring”, ACM Trans. Program. Lang. Syst.,
  • vol. 40, no. 1, 2:1–2:40, Jan. 2018, issn: 0164-0925. doi: 10.1145/3156016.

[Online]. Available: http://doi.acm.org/10.1145/3156016. ——,“Constraint-based Model Refactoring”, in Proceedings of the 14th International Conference on Model Driven Engineering Languages and Systems,

  • ser. MODELS’11, Berlin, Heidelberg: Springer-Verlag, 2011, pp. 440–454, isbn:

978-3-642-24484-1. [Online]. Available:

http://dl.acm.org/citation.cfm?id=2050655.2050700.

  • F. Steimann and J. von Pilgrim, “Refactorings Without Names”, in Proceedings
  • f the 27th IEEE/ACM International Conference on Automated Sofware

Engineering, ser. ASE 2012, New York, NY, USA: ACM, 2012, pp. 290–293, isbn: 978-1-4503-1204-2. doi: 10.1145/2351676.2351726. [Online]. Available:

http://doi.acm.org/10.1145/2351676.2351726.

slide-21
SLIDE 21

Constraint- Based Refactoring Hansruedi Patzen Refactoring Rename Field

Problem Solution

Constraint- Based Refactoring

Constraint Rules Generalize Type

Implementation Researchers Summary Discussion References

References II

——,“Constraint-Based Refactoring with Foresight”, in Proceedings of the 26th European Conference on Object-Oriented Programming, ser. ECOOP’12, Berlin, Heidelberg: Springer-Verlag, 2012, pp. 535–559, isbn: 978-3-642-31056-0. doi:

10.1007/978-3-642-31057-7_24. [Online]. Available: http://dx.doi.org/10.1007/978-3-642-31057-7_24.

  • M. Fowler, K. Beck, and J. Brant, Refactoring: Improving the Design of Existing

Code, 1st ed. Addison-Wesley Professional, 1999, isbn: 978-0-201-48567-7.

  • F. Tip, R. M. Fuhrer, A. Kieżun, M. D. Ernst, I. Balaban, and B. D. Suter,

“Refactoring using type constraints”, ACM Transactions on Programming Languages and Systems, vol. 33, no. 3, pp. 1–47, 2011, issn: 01640925. doi:

10.1145/1961204.1961205. [Online]. Available: http://portal.acm.org/citation.cfm?doid=1961204.1961205.

  • F. Tip, Frank Tip, 2019. [Online]. Available: http://www.franktip.org/ (visited
  • n 01/09/2019).
slide-22
SLIDE 22

Constraint- Based Refactoring Hansruedi Patzen Refactoring Rename Field

Problem Solution

Constraint- Based Refactoring

Constraint Rules Generalize Type

Implementation Researchers Summary Discussion References

References III

  • F. Steimann, Prof. Dr. Friedrich Steimann, 2019. [Online]. Available:

https://www.fernuni-hagen.de/ps/team/friedrich.steimann.shtml (visited

  • n 01/09/2019).

Microsof, Restrictions on using accessibility levels (C# Reference), 2019. [Online]. Available: https://docs.microsoft.com/en-us/dotnet/csharp/language-

reference/keywords/restrictions-on-using-accessibility-levels (visited

  • n 01/13/2019).