skip to main content
research-article

Refactoring Java generics by inferring wildcards, in practice

Published:15 October 2014Publication History
Skip Abstract Section

Abstract

Wildcard annotations can improve the generality of Java generic libraries, but require heavy manual effort. We present an algorithm for refactoring and inferring more general type instantiations of Java generics using wildcards. Compared to past approaches, our work is practical and immediately applicable: we assume no changes to the Java type system, while taking into account all its intricacies. Our system allows users to select declarations (variables, method parameters, return types, etc.) to generalize and considers declarations not declared in available source code. It then performs an inter-procedural flow analysis and a method body analysis, in order to generalize type signatures. We evaluate our technique on six Java generic libraries. We find that 34% of available declarations of variant type signatures can be generalized - i.e., relaxed with more general wildcard types. On average, 146 other declarations need to be updated when a declaration is generalized, showing that this refactoring would be too tedious and error-prone to perform manually.

Skip Supplemental Material Section

Supplemental Material

References

  1. J. Altidor, S. S. Huang, and Y. Smaragdakis. Taming the wildcards: Combining definition- and use-site variance. In Programming Language Design and Implementation (PLDI), 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. J. Altidor, C. Reichenbach, and Y. Smaragdakis. Java wildcards meet definition-site variance. In Proceedings of the European Conference on Object-Oriented Programming (ECOOP), 2012. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. Apache. Apache commons-collections library. http://larvalabs.com/collections/. Version 4.01.Google ScholarGoogle Scholar
  4. K. Boumillion and J. Levy. Guava: Google core libraries for Java 1.5+. http://code.google.com/p/guava-libraries/. Release 8.Google ScholarGoogle Scholar
  5. N. Cameron, S. Drossopoulou, and E. Ernst. A model for Java with wildcards. In European Conf. on Object-Oriented Programming (ECOOP), 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. P. Canning, W. Cook, W. Hill, W. Olthoff, and J. C. Mitchell. F-bounded polymorphism for object-oriented programming. In Proceedings of the Fourth International Conference on Functional Programming Languages and Computer Architecture, 1989. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. W.-N. Chin, F. Craciun, S.-C. Khoo, and C. Popeea. A flow-based approach for variant parametric types. In Proceedings of Conf. on Object-Oriented Programming Systems, Languages, and Applications (OOPSLA), 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. F. Craciun, W.-N. Chin, G. He, and S. Qin. An interval-based inference of variant parametric types. In Proceedings of the 18th European Symposium on Programming (ESOP), 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. J.-M. Dautelle et al. Jscience. http://jscience.org/. Version 4.3.Google ScholarGoogle Scholar
  10. E. Friedman and R. Eden. Gnu Trove: High-performance collections library for Java. http://trove4j.sourceforge.net/. Version 2.1.0.Google ScholarGoogle Scholar
  11. J. Gosling, B. Joy, G. Steele, G. Bracha, and A. Buckley. The Java Language Specification. California, USA, 7th edition, 2012.Google ScholarGoogle Scholar
  12. A. Igarashi, B. C. Pierce, and P.Wadler. Featherweight Java: A minimal core calculus for Java and GJ. ACM Trans. Program. Lang. Syst., 23(3):396--450, 2001. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. A. Igarashi and M. Viroli. Variant parametric types: A flexible subtyping scheme for generics. ACM Trans. Program. Lang. Syst., 28(5):795--847, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. A. Kennedy and B. Pierce. On decidability of nominal sub-typing with variance. FOOL/WOOD, 2007.Google ScholarGoogle Scholar
  15. A. Kiezun, M. D. Ernst, F. Tip, and R. M. Fuhrer. Refactoring for parameterizing Java classes. In Proceedings of the 29th International Conference on Software Engineering, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. M. Odersky. The Scala Language Specification v 2.9. http://www.scala-lang.org/docu/files/ScalaReference.pdf, 2014.Google ScholarGoogle Scholar
  17. A. Salcianu. Java program analysis utilities library. http://jpaul.sourceforge.net/. Version 2.5.1.Google ScholarGoogle Scholar
  18. R. Tate, A. Leung, and S. Lerner. Taming wildcards in Java's type system. In Programming Language Design and Implementation (PLDI), 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Refactoring Java generics by inferring wildcards, in practice

        Recommendations

        Comments

        Login options

        Check if you have access through your login credentials or your institution to get full access on this article.

        Sign in

        Full Access

        • Published in

          cover image ACM SIGPLAN Notices
          ACM SIGPLAN Notices  Volume 49, Issue 10
          OOPSLA '14
          October 2014
          907 pages
          ISSN:0362-1340
          EISSN:1558-1160
          DOI:10.1145/2714064
          • Editor:
          • Andy Gill
          Issue’s Table of Contents
          • cover image ACM Conferences
            OOPSLA '14: Proceedings of the 2014 ACM International Conference on Object Oriented Programming Systems Languages & Applications
            October 2014
            946 pages
            ISBN:9781450325851
            DOI:10.1145/2660193

          Copyright © 2014 ACM

          Publisher

          Association for Computing Machinery

          New York, NY, United States

          Publication History

          • Published: 15 October 2014

          Check for updates

          Qualifiers

          • research-article

        PDF Format

        View or Download as a PDF file.

        PDF

        eReader

        View online with eReader.

        eReader
        About Cookies On This Site

        We use cookies to ensure that we give you the best experience on our website.

        Learn more

        Got it!