Refactoring for Parameterizing Java Classes

Type safety and expressiveness of many existing Java libraries and their client applications would improve, if the libraries were upgraded to define generic classes. Efficient and accurate tools exist to assist client applications to use generic libraries, but so far the libraries themselves must be parameterized manually, which is a tedious, time-consuming, and error-prone task. We present a type- constraint-based algorithm for converting non-generic libraries to add type parameters. The algorithm handles the full Java language and preserves backward compatibility, thus making it safe for existing clients. Among other features, it is capable of inferring wildcard types and introducing type parameters for mutually-dependent classes. We have implemented the algorithm as a fully automatic refactoring in Eclipse. We evaluated our work in two ways. First, our tool parameterized code that was lacking type parameters. We contacted the developers of several of these applications, and in all cases they confirmed that the resulting parameterizations were correct and useful. Second, to better quantify its effectiveness, our tool parameterized classes from already-generic libraries, and we compared the results to those that were created by the libraries' authors. Our tool performed the refactoring accurately-in 87% of cases the results were as good as those created manually by a human expert, in 9% of cases the tool results were better, and in 4% of cases the tool results were worse.

[1]  Koen De Bosschere,et al.  Sifting out the mud: low level C++ code reuse , 2002, OOPSLA '02.

[2]  Martin Odersky,et al.  Making the future safe for the past: adding genericity to the Java programming language , 1998, OOPSLA '98.

[3]  Michael D. Ernst,et al.  Converting java programs to use generic libraries , 2004, OOPSLA '04.

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

[5]  Peter Buneman,et al.  Static type inference for parametric classes , 1989, OOPSLA '89.

[6]  Friedrich Steimann,et al.  Decoupling classes with inferred interfaces , 2006, SAC.

[7]  Johan Jeuring,et al.  Type Inference for Generic Haskell , 2005 .

[8]  Guy L. Steele,et al.  Java(TM) Language Specification, The (3rd Edition) (Java (Addison-Wesley)) , 2005 .

[9]  Simon L. Peyton Jones,et al.  Simple unification-based type inference for GADTs , 2006, ICFP '06.

[10]  Frank Tip,et al.  Refactoring support for class library migration , 2005, OOPSLA '05.

[11]  Michael D. Ernst,et al.  Inference of generic types in Java , 2003 .

[12]  J. J. Whelan,et al.  5th international conference on software engineering , 1981, SOEN.

[13]  Dominic Duggan Modular type-based reverse engineering of parameterized types in Java code , 1999, OOPSLA '99.

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

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

[16]  Thomas W. Reps,et al.  Program generalization for software reuse: from C to C++ , 1996, SIGSOFT '96.

[17]  Craig Chambers The Cecil Language - Specification and Rationale - Version 3.0 , 1995 .

[18]  Jens Palsberg,et al.  Object-oriented type systems , 1994, Wiley professional computing.

[19]  Emmanuel Coquery,et al.  Typing constraint logic programs , 2001, Theory Pract. Log. Program..

[20]  Amer Diwan,et al.  Converting Java classes to use generics , 2004, OOPSLA '04.

[21]  Peter Buneman,et al.  OOPSLA '89 Conference proceedings on Object-oriented programming systems, languages and applications , 1989 .

[22]  Frank Tip,et al.  Efficiently Refactoring Java Applications to Use Generic Libraries , 2005, ECOOP.

[23]  David B. MacQueen,et al.  The Definition of Standard ML (Revised) , 1997 .

[24]  Frank Tip,et al.  Customization of Java Library Classes Using Type Constraints and Profile Information , 2004, ECOOP.