Advertisement

Changing Programs Correctly: Refactoring with Specifications

  • Fabian Bannwart
  • Peter Müller
Part of the Lecture Notes in Computer Science book series (LNCS, volume 4085)

Abstract

Refactorings change the internal structure of code without changing its external behavior. For non-trivial refactorings, the preservation of external behavior depends on semantic properties of the program that are difficult to check automatically before the refactoring is applied. Therefore, existing refactoring tools either do not support non-trivial refactorings at all or force programmers to rely on (typically incomplete) test suites to check their refactorings.

The technique presented in the paper allows one to show the preservation of external behavior even for complex refactorings. For a given refactoring, we prove once and for all that the refactoring is an equivalence transformation, provided that the refactored program satisfies certain semantic correctness conditions. These conditions can be added automatically as assertions to the refactored program and checked at runtime or verified statically. Our technique allows tools to apply even complex refactorings safely, and refactorings automatically improve program documentation by generating assertions.

Keywords

Target Object Test Suite Correctness Condition Terminal State Operational Semantic 
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. 1.
    Banerjee, A., Naumann, D.A.: Ownership confinement ensures representation independence for object-oriented programs. J. ACM 52(6), 894–960 (2005)CrossRefMathSciNetGoogle Scholar
  2. 2.
    Bannwart, F.: Changing software correctly. Technical Report 509, Department of Computer Science, ETH Zürich (2006)Google Scholar
  3. 3.
    Barnett, M., Leino, K.R.M., Schulte, W.: The Spec# Programming System: An Overview. In: Barthe, G., Burdy, L., Huisman, M., Lanet, J.-L., Muntean, T. (eds.) CASSIS 2004. LNCS, vol. 3362, pp. 49–69. Springer, Heidelberg (2005)CrossRefGoogle Scholar
  4. 4.
    Bergstein, P.L.: Object-preserving class transformations. In: OOPSLA, pp. 299–313. ACM Press, New York (1991)Google Scholar
  5. 5.
    Clarke, D.G., Potter, J.M., Noble, J.: Ownership types for flexible alias protection. In: OOPSLA, pp. 48–64. ACM Press, New York (1998)Google Scholar
  6. 6.
    Cornélio, M.: Refactorings as Formal Refinements. PhD thesis, Universidade de Pernambuco (2004)Google Scholar
  7. 7.
    Dietl, W., Müller, P.: Universes: Lightweight ownership for JML. Journal of Object Technology (JOT) 4(8), 5–32 (2005)CrossRefGoogle Scholar
  8. 8.
    Fähndrich, M., DeLine, R.: Adoption and focus: practical linear types for imperative programming. In: PLDI, pp. 13–24. ACM Press, New York (2002)Google Scholar
  9. 9.
    Fähndrich, M., Leino, K.R.M.: Declaring and checking non-null types in an object-oriented language. In: OOPSLA, pp. 302–312. ACM Press, New York (2003)Google Scholar
  10. 10.
    Fowler, M.: Refactoring: improving the design of existing code. Addison-Wesley, Reading (1999)Google Scholar
  11. 11.
    Gheyi, R., Massoni, T., Borba, P.: An abstract equivalence notion for object models. Electr. Notes Theor. Comput. Sci. 130, 3–21 (2005)CrossRefGoogle Scholar
  12. 12.
    Kerievsky, J.: Refactoring to Patterns. Addison-Wesley Professional, Reading (2004)Google Scholar
  13. 13.
    Kiniry, J.R., Cok, D.R.: ESC/Java2: Uniting ESC/Java and JML. In: Barthe, G., Burdy, L., Huisman, M., Lanet, J.-L., Muntean, T. (eds.) CASSIS 2004. LNCS, vol. 3362, pp. 108–128. Springer, Heidelberg (2005)CrossRefGoogle Scholar
  14. 14.
    Lämmel, R.: Towards Generic Refactoring. In: Workshop on Rule-Based Programming (RULE). ACM Press, New York (2002)Google Scholar
  15. 15.
    Leavens, G.T., Baker, A.L., Ruby, C.: Preliminary design of JML: A behavioral interface specification language for Java. Technical Report 98-06-rev28, Iowa State University (2005)Google Scholar
  16. 16.
    Leino, K.R.M., Müller, P.: Object invariants in dynamic contexts. In: Odersky, M. (ed.) ECOOP 2004. LNCS, vol. 3086, pp. 491–515. Springer, Heidelberg (2004)CrossRefGoogle Scholar
  17. 17.
    Lieberherr, K.J., Hürsch, W.L., Xiao, C.: Object-extending class transformations. Formal Aspects of Computing (6), 391–416 (1994)MATHCrossRefGoogle Scholar
  18. 18.
    Logozzo, F., Cortesi, A.: Semantic hierarchy refactoring by abstract interpretation. In: Emerson, E.A., Namjoshi, K.S. (eds.) VMCAI 2006. LNCS, vol. 3855, pp. 313–331. Springer, Heidelberg (2005)CrossRefGoogle Scholar
  19. 19.
    Morgan, C.: Programming from specifications. Prentice-Hall, Englewood Cliffs (1990)MATHGoogle Scholar
  20. 20.
    Opdyke, W.F.: Refactoring object-oriented frameworks. PhD thesis, University of Illinois at Urbana-Champaign (1992)Google Scholar
  21. 21.
    Roberts, D.B.: Practical analysis for refactoring. PhD thesis, University of Illinois at Urbana-Champaign (1999)Google Scholar
  22. 22.
    Streckenbach, M., Snelting, G.: Refactoring class hierarchies with KABA. In: OOPSLA, pp. 315–330. ACM Press, New York (2004)Google Scholar
  23. 23.
    Tokuda, L., Batory, D.: Evolving object-oriented designs with refactorings. In: Automated Software Engineering, pp. 174–182. IEEE Computer Society, Los Alamitos (1999)Google Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2006

Authors and Affiliations

  • Fabian Bannwart
    • 1
  • Peter Müller
    • 1
  1. 1.ETH Zürich 

Personalised recommendations