Skip to main content

Efficiently Refactoring Java Applications to Use Generic Libraries

  • Conference paper

Part of the book series: Lecture Notes in Computer Science ((LNPSE,volume 3586))

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.

This is a preview of subscription content, log in via an institution.

Buying options

Chapter
USD   29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD   84.99
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD   109.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Learn about institutional subscriptions

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. 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)

    Google Scholar 

  2. Agesen, O.: Concrete Type Inference: Delivering Object-Oriented Applications. PhD thesis, Stanford University (December 1995)

    Google Scholar 

  3. Bäumer, D., Gamma, E., Kieżun, A.: Integrating refactoring support into a Java development tool. In: OOPSLA 2001 Companion (October 2001)

    Google Scholar 

  4. 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)

    Google Scholar 

  5. 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)

    Google Scholar 

  6. Omnicore codeguide. http://www.omnicore.com/codeguide.htm

  7. 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)

    Chapter  Google Scholar 

  8. 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)

    Google Scholar 

  9. Duggan, D.: Modular type-based reverse engineering of parameterized types in Java code. In: Proc. of OOPSLA, pp. 97–113 (1999)

    Google Scholar 

  10. Fowler, M.: Refactoring. Improving the Design of Existing Code. Addison-Wesley, Reading (1999)

    Google Scholar 

  11. Gosling, J., Joy, B., Steele, G., Bracha, G.: The Java Language Specification, 3rd edn. Addison-Wesley, Reading (2000)

    Google Scholar 

  12. JetBrains IntelliJ IDEA, http://www.intellij.com/idea/ .

  13. Igarashi, A., Pierce, B.C., Wadler, P.: Featherweight Java: a minimal core calculus for Java and GJ. ACM TOPLAS 23(3), 396–450 (2001)

    Article  Google Scholar 

  14. Langer, A., Kreft, K.: Arrays in Java Generics. Manuscript, http://www.langer.camelot.de

  15. Munsil, W.: Case study: Converting to Java 1.5 type-safe collections. Journal of Object Technology 3(8), 7–14 (2004)

    Article  Google Scholar 

  16. Odersky, M., Wadler, P.: Pizza into Java: Translating theory into practice. In: Proc. of POPL, pp. 146–159 (1997)

    Google Scholar 

  17. Palsberg, J., Schwartzbach, M.: Object-Oriented Type Systems. John Wiley & Sons, Chichester (1993)

    Google Scholar 

  18. Siff, M., Reps, T.W.: Program generalization for software reuse: From C to C++. Foundations of Software Engineering, 135–146 (1996)

    Google Scholar 

  19. 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)

    Google Scholar 

  20. Tip, F., Kieżun, A., Bäumer, D.: Refactoring for generalization using type constraints. In: Proc. of OOPSLA, Anaheim, CA, pp. 13–26 (2003)

    Google Scholar 

  21. 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)

    Google Scholar 

  22. Vitek, J., Horspool, R.N., Krall, A.: Efficient type inclusion tests. In: Proc. of OOPSLA. SIGPLAN Notices, vol. 32(10), pp. 142–157 (1997)

    Google Scholar 

  23. von Dincklage, D., Diwan, A.: Converting Java classes to use generics. In: Proc. of OOPSLA, Vancouver, BC, Canada, pp. 1–14 (2004)

    Google Scholar 

  24. 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)

    Chapter  Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Editor information

Editors and Affiliations

Rights and permissions

Reprints 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)

Publish with us

Policies and ethics