From Public to Private to Absent: Refactoring Java Programs under Constrained Accessibility

Contemporary refactoring tools for Java aiding in the restructuring of programs have problems with respecting access modifiers such as public and private : while some tools provide hints that referenced elements may become inaccessible due to the intended restructuring, none we have tested prevent changes that alter the meaning of a program, and none take steps that counteract such alterations. To address these problems, we formalize accessibility in Java as a set of constraint rules, and show how the constraints obtained from applying these rules to a program and an intended refactoring allow us to check the preconditions of the refactoring, as well as to compute the changes of access modifiers necessary to preserve the behaviour of the refactored program. We have implemented our framework as a proof of concept in Eclipse , and demonstrated how it improves applicability and success of an important refactoring in a number of sample programs. That our approach is not limited to Java is shown by comparison with the constraint rules for C# and Eiffel .

[1]  Martin Fowler,et al.  Refactoring - Improving the Design of Existing Code , 1999, Addison Wesley object technology series.

[2]  Peter H. Golde,et al.  C# Language Specification , 2003 .

[3]  Peter Müller,et al.  Kapselung und Methodenbindung: Javas Designprobleme und ihre Korrektur , 1998, Java-Informations-Tage.

[4]  簡聰富,et al.  物件導向軟體之架構(Object-Oriented Software Construction)探討 , 1989 .

[5]  Bertrand Meyer,et al.  Object-Oriented Software Construction, 2nd Edition , 1997 .

[6]  Frank Tip,et al.  Refactoring using type constraints , 2011, TOPL.

[7]  Frank Tip,et al.  Refactoring for generalization using type constraints , 2003, OOPSLA '03.

[8]  Darko Marinov,et al.  Automated testing of refactoring engines , 2007, ESEC-FSE '07.

[9]  Norbert Schirmer Analysing the Java Package/Access Concepts in , 2003 .

[10]  Friedrich Steimann,et al.  Controlling Accessibility in Agile Projects with the Access Modifier Modifier , 2008, TOOLS.

[11]  Norbert Schirmer Analysing the Java package/access concepts in Isabelle/HOL , 2004, Concurr. Pract. Exp..

[12]  D. L. Parnas,et al.  On the criteria to be used in decomposing systems into modules , 1972, Software Pioneers.

[13]  Guy L. Steele,et al.  The Java Language Specification , 1996 .

[14]  Jens Palsberg,et al.  Encapsulating objects with confined types , 2001, TOPL.

[15]  Norbert Schirmer Analysing the Java package-access concepts in Isabelle-HOL: Research Articles , 2004 .

[16]  M. Fowler Improving the Design of Existing Code , 2000 .

[17]  William F. Opdyke,et al.  Refactoring object-oriented frameworks , 1992 .

[18]  Slim Abdennadher,et al.  Essentials of Constraint Programming , 2010, Cognitive Technologies.

[19]  Friedrich Steimann,et al.  Systematically refactoring inheritance to delegation in java , 2008, 2008 ACM/IEEE 30th International Conference on Software Engineering.

[20]  Marco Pistoia,et al.  Access rights analysis for Java , 2002, OOPSLA '02.

[21]  Torbjörn Ekman,et al.  Sound and extensible renaming for java , 2008, OOPSLA.

[22]  Martin Fowler. Refactoring Improving the Design of Existing Code , 1999 .