Abstract
Java 1.5 generics enable the creation of reusable container classes with compiler-enforced type-safe usage. This eliminates the need for potentially unsafe down-casts when retrieving elements from containers. We present a refactoring that replaces raw references to generic library classes with parameterized references. The refactoring infers actual type parameters for allocation sites and declarations using an existing framework of type constraints, and removes casts that have been rendered redundant. The refactoring was implemented in Eclipse, a popular open-source development environment for Java, and laid the grounds for a similar refactoring in the forthcoming Eclipse 3.1 release. We evaluated our work by refactoring several Java programs that use the standard collections framework to use Java 1.5’s generic version instead. In these benchmarks, on average, 48.6% of the casts are removed, and 91.2% of the compiler warnings related to the use of raw types are eliminated. Our approach distinguishes itself from the state-of-the-art [8] by being more scalable, by its ability to accommodate user-defined subtypes of generic library classes, and by being incorporated in a popular integrated development environment.
Preview
Unable to display preview. Download preview PDF.
Similar content being viewed by others
References
Agesen, O.: The cartesian product algorithm: Simple and precise type inference of parametric polymorphism. In: Olthoff, W. (ed.) ECOOP 1995. LNCS, vol. 952, pp. 2–26. Springer, Heidelberg (1995)
Agesen, O.: Concrete Type Inference: Delivering Object-Oriented Applications. PhD thesis, Stanford University (December 1995)
Bäumer, D., Gamma, E., Kieżun, A.: Integrating refactoring support into a Java development tool. In: OOPSLA 2001 Companion (October 2001)
Bracha, G., Cohen, N., Kemper, C., Odersky, M., Stoutamire, D., Thorup, K., Wadler, P.: Adding generics to the Java programming language, final release. Tech. rep., Java Community Process JSR-000014 (September 2004)
Bracha, G., Odersky, M., Stoutamire, D., Wadler, P.: Making the future safe for the past: Adding genericity to the Java programming language. In: Proc. of OOPSLA, pp. 183–200 (1998)
Omnicore codeguide. http://www.omnicore.com/codeguide.htm
De Sutter, B., Tip, F., Dolby, J.: Customization of java library classes using type constraints and profile information. In: Odersky, M. (ed.) ECOOP 2004. LNCS, vol. 3086, pp. 585–610. Springer, Heidelberg (2004)
Donovan, A., Kieżun, A., Tschantz, M., Ernst, M.: Converting Java programs to use generic libraries. In: Proc. of OOPSLA, Vancouver, BC, Canada, pp. 15–34 (2004)
Duggan, D.: Modular type-based reverse engineering of parameterized types in Java code. In: Proc. of OOPSLA, pp. 97–113 (1999)
Fowler, M.: Refactoring. Improving the Design of Existing Code. Addison-Wesley, Reading (1999)
Gosling, J., Joy, B., Steele, G., Bracha, G.: The Java Language Specification, 3rd edn. Addison-Wesley, Reading (2000)
JetBrains IntelliJ IDEA, http://www.intellij.com/idea/ .
Igarashi, A., Pierce, B.C., Wadler, P.: Featherweight Java: a minimal core calculus for Java and GJ. ACM TOPLAS 23(3), 396–450 (2001)
Langer, A., Kreft, K.: Arrays in Java Generics. Manuscript, http://www.langer.camelot.de
Munsil, W.: Case study: Converting to Java 1.5 type-safe collections. Journal of Object Technology 3(8), 7–14 (2004)
Odersky, M., Wadler, P.: Pizza into Java: Translating theory into practice. In: Proc. of POPL, pp. 146–159 (1997)
Palsberg, J., Schwartzbach, M.: Object-Oriented Type Systems. John Wiley & Sons, Chichester (1993)
Siff, M., Reps, T.W.: Program generalization for software reuse: From C to C++. Foundations of Software Engineering, 135–146 (1996)
Tip, F., Fuhrer, R., Dolby, J., and Kieżun, A.: Refactoring techniques for migrating applications to generic Java container classes. Tech. Rep. Research Report RC 23238, IBM Research (June 2004)
Tip, F., Kieżun, A., Bäumer, D.: Refactoring for generalization using type constraints. In: Proc. of OOPSLA, Anaheim, CA, pp. 13–26 (2003)
Torgersen, M., Hansen, C.P., Ernst, E., von der Ahé, P., Bracha, G., Gafter, N.M.: Adding wildcards to the Java programming language. In: Proc. of ACM Symposium on Applied Computing (SAC), Nicosia, Cyprus, pp. 1289–1296 (2004)
Vitek, J., Horspool, R.N., Krall, A.: Efficient type inclusion tests. In: Proc. of OOPSLA. SIGPLAN Notices, vol. 32(10), pp. 142–157 (1997)
von Dincklage, D., Diwan, A.: Converting Java classes to use generics. In: Proc. of OOPSLA, Vancouver, BC, Canada, pp. 1–14 (2004)
Wang, T., Smith, S.F.: Precise constraint-based type inference for Java. In: Knudsen, J.L. (ed.) ECOOP 2001. LNCS, vol. 2072, pp. 99–117. Springer, Heidelberg (2001)
Author information
Authors and Affiliations
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2005 Springer-Verlag Berlin Heidelberg
About this paper
Cite this paper
Fuhrer, R., Tip, F., Kieżun, A., Dolby, J., Keller, M. (2005). Efficiently Refactoring Java Applications to Use Generic Libraries. In: Black, A.P. (eds) ECOOP 2005 - Object-Oriented Programming. ECOOP 2005. Lecture Notes in Computer Science, vol 3586. Springer, Berlin, Heidelberg. https://doi.org/10.1007/11531142_4
Download citation
DOI: https://doi.org/10.1007/11531142_4
Publisher Name: Springer, Berlin, Heidelberg
Print ISBN: 978-3-540-27992-1
Online ISBN: 978-3-540-31725-8
eBook Packages: Computer ScienceComputer Science (R0)