Projects like jMock and Hibernate Criteria Query introduced embedded DSLs into Java. We describe two case studies in which we develop embedded typesafe DSLs for building SQL queries and engineering Java bytecode. We proceed to extract several patterns useful for developing typesafe DSLs for arbitrary domains. Unlike most previous Java DSLs we find that mixing the Fluent Interface idiom with static functions, metadata and closures provides for a better user experience than pure method chaining. We also make very liberal use of the Java 5 Generics to improve the type safety properties of the DSLs.
a b s t r a c tAlthough embedded DSLs are widely used in both functional and dynamic languages they are yet to be widely accepted in the Java community. The best available examples are projects like jMock and Hibernate Criteria Query. In this paper we introduce the design of three novel practical embedded DSLs that we designed to showcase the power of Java language and specifically the changes introduced in Java 5. One of those DSLs is fully implemented as an open source project and is gathering momentum in the community. We proceed to discuss the approaches that allow designing safe and flexible DSLs by extracting generic patterns where possible and describing more specific idioms where necessary. It is our goal that this paper would serve as a starting point for someone designing an embedded DSL that takes full advantage of the Java 5 features.
scite is a Brooklyn-based organization that helps researchers better discover and understand research articles through Smart Citations–citations that display the context of the citation and describe whether the article provides supporting or contrasting evidence. scite is used by students and researchers from around the world and is funded in part by the National Science Foundation and the National Institute on Drug Abuse of the National Institutes of Health.