skip to main content
10.1145/2371401.2371409acmconferencesArticle/Chapter ViewAbstractPublication PagesgpceConference Proceedingsconference-collections
research-article

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

Published: 26 September 2012 Publication History

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.
[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.
[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.
[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.
[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.
[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.
[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.
[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/.
[9]
Don Batory. A Tutorial on Feature Oriented Programming and the AHEAD Tool Suite. pages 3--35. 2006.
[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.
[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.
[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.
[13]
Torbjörn Ekman and Görel Hedin. The JastAdd extensible Java compiler. SIGPLAN Not., 42(10): 1--18, 2007.
[14]
Martin Fowler. Refactoring: improving the design of existing code. Addison-Wesley Longman Publishing Co., Inc., Boston, MA, USA, 1999.
[15]
E. Gamma, R. Helm, R. Johnson, and J. Vlissides. Design Patterns -Elements of Reusable Object-Oriented Software. Addison-Wesley, 1994.
[16]
James Gosling, Bill Joy, Guy Steele, Gilad Bracha, and Alex Buckley. The Java Language Specification, Java SE 7 Edition. Oracle America, Inc., 2011.
[17]
Shan Shan Huang and Yannis Smaragdakis. Expressive and safe static reflection with morphj. SIGPLAN Not., 43(6): 79--89, June 2008.
[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.
[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.
[20]
E. Murphy-Hill and A. P. Black. Refactoring tools: Fitness for purpose. Software, IEEE, 25(5): 38--44, sept.-oct. 2008.
[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.
[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.
[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.
[24]
William F. Opdyke. Refactoring Object-Oriented Frameworks. PhD thesis, University of Illinois, Urbana-Champaign, IL, USA, 1992.
[25]
Christian Prehofer. Feature-oriented programming: A fresh look at objects. In Proc. European Conference on Object-Oriented Programming, pages 419--443, 1997.
[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.
[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.
[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.
[29]
Stefan Wehr, Ralf Lämmel, and Peter Thiemann. JavaGI: Generalized Interfaces for Java. In ECOOP 2007, Proceedings, LNCS. Springer-Verlag, July 2007.
[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.

Cited By

View all

Index Terms

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

      Recommendations

      Comments

      Information & Contributors

      Information

      Published In

      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
      • 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
      Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected]

      Sponsors

      Publisher

      Association for Computing Machinery

      New York, NY, United States

      Publication History

      Published: 26 September 2012

      Permissions

      Request permissions for this article.

      Check for updates

      Author Tags

      1. Java
      2. templates
      3. transformations

      Qualifiers

      • Research-article

      Funding Sources

      Conference

      GPCE'12
      Sponsor:
      GPCE'12: Generative Programming and Component Engineering
      September 26 - 27, 2012
      Dresden, Germany

      Acceptance Rates

      Overall Acceptance Rate 56 of 180 submissions, 31%

      Contributors

      Other Metrics

      Bibliometrics & Citations

      Bibliometrics

      Article Metrics

      • Downloads (Last 12 months)3
      • Downloads (Last 6 weeks)0
      Reflects downloads up to 06 Jan 2025

      Other Metrics

      Citations

      Cited By

      View all

      View Options

      Login options

      View options

      PDF

      View or Download as a PDF file.

      PDF

      eReader

      View online with eReader.

      eReader

      Media

      Figures

      Other

      Tables

      Share

      Share

      Share this Publication link

      Share on social media