Formal Language Recognition with the Java Type Checker

This paper is a theoretical study of a practical problem: the automatic generation of Java Fluent APIs from their specification. We explain why the problem's core lies with the expressive power of Java generics. Our main result is that automatic generation is possible whenever the specification is an instance of the set of deterministic context-free languages, a set which contains most "practical" languages. Other contributions include a collection of techniques and idioms of the limited meta-programming possible with Java generics, and an empirical measurement demonstrating that the runtime of the "javac" compiler of Java may be exponential in the program's length, even for programs composed of a handful of lines and which do not rely on overly complex use of generics.

[1]  Donald E. Knuth,et al.  On the Translation of Languages from Left to Right , 1965, Inf. Control..

[2]  Martin Odersky,et al.  Making the future safe for the past: adding genericity to the Java programming language , 1998, OOPSLA '98.

[3]  Douglas Gregor,et al.  C++ Templates: The Complete Guide , 2002 .

[4]  Bruno Courcelle On jump-deterministic pushdown automata , 2005, Mathematical systems theory.

[5]  Nadine Gottschalk,et al.  Camel In Action , 2016 .

[6]  John Cocke,et al.  Programming languages and their compilers: Preliminary notes , 1969 .

[7]  Bjarne Stroustrup,et al.  C++ Programming Language , 1986, IEEE Softw..

[8]  Steve Freeman,et al.  Evolving an embedded domain-specific language in Java , 2006, OOPSLA '06.

[9]  Matthew H. Austern Generic programming and the STL - using and extending the C++ standard template library , 1999, Addison-Wesley professional computing series.

[10]  Peter Linz,et al.  An Introduction to Formal Languages and Automata , 1997 .

[11]  Robert Larsen Fluenty : A type safe query API , 2012 .

[12]  Jay Earley,et al.  An efficient context-free parsing algorithm , 1970, Commun. ACM.

[13]  Daniel H. Younger,et al.  Recognition and Parsing of Context-Free Languages in Time n^3 , 1967, Inf. Control..

[14]  Jean Berstel,et al.  Context-Free Languages and Pushdown Automata , 1997, Handbook of Formal Languages.

[15]  Jonathan Aldrich,et al.  An Empirical Study of Object Protocols in the Wild , 2011, ECOOP.

[16]  Adele Goldberg,et al.  Smalltalk-80 - the interactive programming environment , 1984 .

[17]  Jaakko Järvi,et al.  A comparative study of language support for generic programming , 2003, OOPSLA '03.

[18]  Martin Odersky,et al.  An Overview of the Scala Programming Language , 2004 .

[19]  Arie van Deursen,et al.  Domain-specific languages: an annotated bibliography , 2000, SIGP.

[20]  Eric Bodden TS4J: a fluent interface for defining and computing typestate analyses , 2014, SOAP '14.

[21]  Jevgeni Kabanov,et al.  Embedded typesafe domain specific languages for Java , 2008, PPPJ '08.

[22]  Brian Beckman,et al.  LINQ: reconciling object, relations and XML in the .NET framework , 2006, SIGMOD Conference.

[23]  Michael D. Ernst,et al.  Practical pluggable types for java , 2008, ISSTA '08.

[24]  David Abrahams,et al.  C++ Template Metaprogramming: Concepts, Tools, and Techniques from Boost and Beyond (C++ In-Depth Series) , 2004 .

[25]  James Gosling,et al.  The Java Programming Language" The Java Series , 1996 .

[26]  Joseph Gil,et al.  Compile Time Symbolic Derivation with C++ Templates , 1998, COOTS.

[27]  Jeffrey D. Ullman,et al.  Introduction to Automata Theory, Languages and Computation , 1979 .

[28]  Alexander A. Stepanov,et al.  Fundamentals of Generic Programming , 1998, Generic Programming.

[29]  Todd L. Veldhuizen,et al.  Expression templates , 1996 .

[30]  Eelco Visser,et al.  SugarJ: library-based language extensibility , 2011, OOPSLA Companion.

[31]  Alfred V. Aho,et al.  Compilers: Principles, Techniques, and Tools , 1986, Addison-Wesley series in computer science / World student series edition.

[32]  Jonathan Aldrich,et al.  Lightweight object specification with typestates , 2005, ESEC/FSE-13.

[33]  Alexander A. Stepanov,et al.  Generic Programming , 1988, ISSAC.

[34]  Jonathan Aldrich,et al.  Typestate-oriented programming , 2009, OOPSLA Companion.