Book Image

Groovy for Domain-Specific Languages, Second Edition

By : Fergal Dearle
Book Image

Groovy for Domain-Specific Languages, Second Edition

By: Fergal Dearle

Overview of this book

Table of Contents (20 chapters)
Groovy for Domain-specific Languages Second Edition
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Free Chapter
1
Introduction to DSLs and Groovy
Index

BuilderSupport


Under the hood, all of Groovy's own Builders are implemented using the invokeMethod or methodMissing methods and delegate techniques that we have described in the previous section. We can choose to start creating our own builder classes by using these features alone. Perhaps the biggest challenge when creating a builder with these features alone is that the MOP concepts of pretended methods and delegate handling don't fit well with the task at hand—namely, the construction of complex objects. It would be nice to have APIs that reflected the task at hand in a better way.

Thankfully, the complexities of managing invokeMethod or methodMissing calls and figuring out who the delegate should be, are encapsulated into the builder support classes provided in the Groovy packages. The most basic support class is groovy.util.BuilderSupport.

BuilderSupport hook methods

BuilderSupport provides an interface to the building process that nicely mirrors the node-based construction process on...