skip to main content
research-article

Package templates: a definition by semantics-preserving source-to-source transformations to efficient Java code

Published:26 September 2012Publication History
Skip Abstract Section

Abstract

Package Templates (PT) is a mechanism designed for writing reusable modules, called templates, each consisting of a set of classes that can be adapted to their use in a program through compile-time specialization. A template must be instantiated in a program before its classes can be used. The mechanism supports type-safe renaming, merging, type parameterization and refinement in the form of static additions and overrides that are orthogonal to the corresponding concepts of ordinary inheritance.

In this paper, we consider PT as an extension to Java, and a PT program will then consist of a number of Java packages and templates, where templates are instantiated in packages or other templates. Our aim and main contribution is to define the meaning of such a program, and to show that this definition is consistent. We first show this for a core subset of PT, C-PT, and define a set of source-to-source transformations for converting C-PT programs to plain Java programs using semantics we have described informally in previous papers. We can then define the meaning of a C-PT program in terms of the resulting Java program. Thus, we have to verify that the transformations will always convert a legal C-PT program to a legal Java program. Finally, we briefly discuss how this approach can be extended to full PT.

A main challenge is to preserve externally visible names (for classes, methods and fields), and at the same time prevent unwanted subsequent rebindings caused e.g. by over-load resolution in the Java compiler. Names that are bound to declarations in a template should not be rebound to different declarations by subsequent compositions or adaptions.

In addition to defining the runtime semantics of PT constructs in terms of their translation to Java, the transformation rules can also be seen as a high-level approach to how a compiler for this language might be implemented.

References

  1. Sven Apel, Christian Kästner, and Christian Lengauer. Feature featherweight java: a calculus for feature-oriented programming and stepwise refinement. In Proceedings of the 7th international conference on Generative programming and component engineering, GPCE '08, pages 101--112, New York, NY, USA, 2008. ACM. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. Sven Apel, Christian Kastner, and Christian Lengauer. Featurehouse: Language-independent, automated software composition. In Proc. 31st International Conference on Software Engineering, ICSE '09, pages 221--231, Washington, DC, USA, 2009. IEEE Computer Society. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. Sven Apel and Christian Lengauer. Superimposition: a language-independent approach to software composition. In Proc. 7th international conference on Software composition, SC'08, pages 20--35, Berlin, Heidelberg, 2008. Springer-Verlag. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. Eyvind W. Axelsen and Stein Krogdahl. Groovy package templates: supporting reuse and runtime adaption of class hierarchies. In DLS '09: Proc. 5th symp. Dyn. lang., pages 15--26, New York, NY, USA, 2009. ACM. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. Eyvind W. Axelsen and Stein Krogdahl. Adaptable generic programming with required type specifications and package templates. In Proc. AOSD '12, AOSD '12, pages 83--94, New York, NY, USA, 2012. ACM. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. Eyvind W. Axelsen, Stein Krogdahl, and Birger Møller-Pedersen. Controlling dynamic module composition through an extensible meta-level API. In DLS 2010: Proc. 6th symp. Dyn. lang., New York, NY, USA, 2010. ACM. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. Eyvind W. Axelsen, Fredrik Sørensen, and Stein Krogdahl. A reusable observer pattern implementation using package templates. In ACP4IS '09, pages 37--42, New York, NY, USA, 2009. ACM. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. Eyvind W. Axelsen, Fredrik Sørensen, Stein Krogdahl, and Birger Møller-Pedersen. Challenges in the design of the package template mechanism. Transactions on Aspect-Oriented Programming, 2012. To appear, available now from http://swat.project.ifi.uio.no/.Google ScholarGoogle ScholarCross RefCross Ref
  9. Don Batory. A Tutorial on Feature Oriented Programming and the AHEAD Tool Suite. pages 3--35. 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Don Batory, Jacob Neal Sarvela, and Axel Rauschmayer. Scaling step-wise refinement. In Proc. 25th International Conference on Software Engineering, ICSE '03, pages 187--197, Washington, DC, USA, 2003. IEEE Computer Society. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. Alexandre Bergel, Stéphane Ducasse, and Oscar Nierstrasz. Classbox/j: controlling the scope of change in java. In Proc. 20th annual ACM SIGPLAN conference on Object-oriented programming, systems, languages, and applications, OOPSLA '05, pages 177--189, New York, NY, USA, 2005. ACM. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. Alexandre Bergel, Stephane Ducasse, and Roel Wuyts. Classboxes: A minimal module model supporting local rebinding. In Proc. JMLC 2003 (Joint modular languages conference), volume 2789 of LNCS, pages 122--131. Springer-Verlag, 2003.Google ScholarGoogle ScholarCross RefCross Ref
  13. Torbjörn Ekman and Görel Hedin. The JastAdd extensible Java compiler. SIGPLAN Not., 42(10): 1--18, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. Martin Fowler. Refactoring: improving the design of existing code. Addison-Wesley Longman Publishing Co., Inc., Boston, MA, USA, 1999. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. E. Gamma, R. Helm, R. Johnson, and J. Vlissides. Design Patterns -Elements of Reusable Object-Oriented Software. Addison-Wesley, 1994. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. James Gosling, Bill Joy, Guy Steele, Gilad Bracha, and Alex Buckley. The Java Language Specification, Java SE 7 Edition. Oracle America, Inc., 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. Shan Shan Huang and Yannis Smaragdakis. Expressive and safe static reflection with morphj. SIGPLAN Not., 43(6): 79--89, June 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. Atsushi Igarashi, Benjamin C. Pierce, and Philip Wadler. Featherweight java: a minimal core calculus for java and gj. ACM Trans. Program. Lang. Syst., 23(3): 396--450, May 2001. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. Stein Krogdahl, Birger Møller-Pedersen, and Fredrik Sørensen. Exploring the use of package templates for flexible re-use of collections of related classes. Journal of Obj. Tech., 8(7): 59--85, 2009.Google ScholarGoogle ScholarCross RefCross Ref
  20. E. Murphy-Hill and A. P. Black. Refactoring tools: Fitness for purpose. Software, IEEE, 25(5): 38--44, sept.-oct. 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. Emerson Murphy-Hill, Chris Parnin, and Andrew P. Black. How we refactor, and how we know it. In Proc. 31st Intl. Conf. Software Engineering, ICSE '09, pages 287--297, Washington, DC, USA, 2009. IEEE Computer Society. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. Nathaniel Nystrom, Michael R. Clarkson, and Andrew C. Myers. Polyglot: an extensible compiler framework for java. In Proc. 12th intl. conf. on Compiler construction, CC'03, pages 138--152, Berlin, Heidelberg, 2003. Springer-Verlag. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. W. Opdyke and R. E. Johnson. Refactoring, an aid in designing application frameworks and evolving object-oriented systems. In Proc. Symposium on Object Oriented Programming Emphasizing Practical Applications (SOOPA), 1990.Google ScholarGoogle Scholar
  24. William F. Opdyke. Refactoring Object-Oriented Frameworks. PhD thesis, University of Illinois, Urbana-Champaign, IL, USA, 1992. Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. Christian Prehofer. Feature-oriented programming: A fresh look at objects. In Proc. European Conference on Object-Oriented Programming, pages 419--443, 1997.Google ScholarGoogle Scholar
  26. Max Schäfer, Torbjörn Ekman, and Oege de Moor. Sound and extensible renaming for java. In Proc. OOPSLA '08, OOPSLA '08, pages 277--294, New York, NY, USA, 2008. ACM. Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. Håkon Stordahl. BooPT: Implementasjon av package templates for Boo. Master's thesis, Dept. of Informatics, Uni. Oslo, Gaustadalléen 23B, Postboks 1080 Blindern, 0316 Oslo, 2012.Google ScholarGoogle Scholar
  28. Alessandro Warth, Milan Stanojević, and Todd Millstein. Statically scoped object adaptation with expanders. In Proc. 21st annual ACM SIGPLAN conference on Object-oriented programming systems, languages, and applications, OOPSLA '06, pages 37--56, New York, NY, USA, 2006. ACM. Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. Stefan Wehr, Ralf Lämmel, and Peter Thiemann. JavaGI: Generalized Interfaces for Java. In ECOOP 2007, Proceedings, LNCS. Springer-Verlag, July 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. Stefan Wehr and Peter Thiemann. Javagi in the battlefield: practical experience with generalized interfaces. In Proc. eighth international conference on Generative programming and component engineering, GPCE '09, pages 65--74, New York, NY, USA, 2009. ACM. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Package templates: a definition by semantics-preserving source-to-source transformations to efficient Java code

      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 48, Issue 3
        GPCE '12
        March 2013
        140 pages
        ISSN:0362-1340
        EISSN:1558-1160
        DOI:10.1145/2480361
        Issue’s Table of Contents
        • cover image ACM Conferences
          GPCE '12: Proceedings of the 11th International Conference on Generative Programming and Component Engineering
          September 2012
          148 pages
          ISBN:9781450311298
          DOI:10.1145/2371401

        Copyright © 2012 ACM

        Publisher

        Association for Computing Machinery

        New York, NY, United States

        Publication History

        • Published: 26 September 2012

        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!