万本电子书0元读

万本电子书0元读

顶部广告

Groovy for Domain-specific Languages - Second Edition电子书

售       价:¥

9人正在读 | 0人评论 9.8

作       者:Fergal Dearle

出  版  社:Packt Publishing

出版时间:2015-09-28

字       数:499.2万

所属分类: 进口书 > 外文原版书 > 电脑/网络

温馨提示:数字商品不支持退换货,不提供源文件,不支持导出打印

为你推荐

  • 读书简介
  • 目录
  • 累计评论(0条)
  • 读书简介
  • 目录
  • 累计评论(0条)
Extend and enhance your Java applications with domain-specific *ing in Groovy About This Book Build domain-specific mini languages in Groovy that integrate seamlessly with your Java apps with this hands-on guide Increase stakeholder participation in the development process with domain-specific *ing in Groovy Get up to speed with the newest features in Groovy using this second edition and integrate Groovy-based DSLs into your existing Java applications. Who This Book Is For This book is for Java software developers who have an interest in building domain *ing into their Java applications. No knowledge of Groovy is required, although it will be helpful. This book does not teach Groovy, but quickly introduces the basic ideas of Groovy. An experienced Java developer should have no problems with these and move quickly on to the more involved aspects of creating DSLs with Groovy. No experience of creating a DSL is required. What You Will Learn Familiarize yourself with Groovy *ing and work with Groovy closures Use the meta-programming features in Groovy to build mini languages Employ Groovy mark-up and builders to simplify application development Familiarize yourself with Groovy mark-up and build your own Groovy builders Build effective DSLs with operator overloading, command chains, builders, and a host of other Groovy language features Integrate Groovy with your Java and JVM based applications In Detail The times when developing on the JVM meant you were a Java programmer have long passed. The JVM is now firmly established as a polyglot development environment with many projects opting for alternative development languages to Java such as Groovy, Scala, Clojure, and JRuby. In this pantheon of development languages, Groovy stands out for its excellent DSL enabling features which allows it to be manipulated to produce mini languages that are tailored to a project’s needs. A comprehensive tutorial on designing and developing mini Groovy based Domain Specific Languages, this book will guide you through the development of several mini DSLs that will help you gain all the skills needed to develop your own Groovy based DSLs with confidence and ease. Starting with the bare basics, this book will focus on how Groovy can be used to construct domain specific mini languages, and will go through the more complex meta-programming features of Groovy, including using the Abstract Syntax Tree (AST). Practical examples are used throughout this book to de-mystify these seemingly complex language features and to show how they can be used to create simple and elegant DSLs. Packed with examples, including several fully worked DSLs, this book will serve as a springboard for developing your own DSLs. Style and approach This book is a hands-on guide that will walk you through examples for building DSLs with Groovy rather than just talking about "metaprogramming with Groovy". The examples in this book have been designed to help you gain a good working knowledge of the techniques involved and apply these to producing your own Groovy based DSLs.
目录展开

Groovy for Domain-specific Languages Second Edition

Table of Contents

Groovy for Domain-specific Languages Second Edition

Credits

About the Author

Acknowledgments

About the Reviewers

www.PacktPub.com

Support files, eBooks, discount offers, and more

Why subscribe?

Free access for Packt account holders

Preface

What this book covers

What you need for this book

Who this book is for

Conventions

Reader feedback

Customer support

Downloading the example code

Errata

Piracy

Questions

1. Introduction to DSLs and Groovy

DSL – a new name for an old idea

The evolution of programming languages

General-purpose languages

Spreadsheets and 4GLs

Language-oriented programming

Who are DSLs for?

A DSL for process engineers

Stakeholder participation

DSL design and implementation

External versus internal DSLs

Operator overloading

Groovy

A natural fit with the JVM

Groovy language features

Static and optional typing

Native support for lists and maps

Closures

Groovy operator overloading

Regular expression support

Optional syntax

Groovy markup

Summary

2. Groovy Quick Start

Installing Groovy with GVM

Installing GVM

Installing GVM on Windows

How to find and install Groovy from binaries

Running Groovy

The Groovy script engine – groovy

Shebang scripts

The Groovy shell – groovysh

The Groovy console – groovyConsole

The Groovy compiler – groovyc

The Groovy IDE and editor integration

NetBeans

Eclipse

Spring STS

IntelliJ IDEA

Other IDEs and editors

Summary

3. Essential Groovy DSLs

Installing Gradle

Gradle basics

Gradle build scripts

Gradle tasks

Adding actions to tasks

Default tasks

Creating task dependencies

Built-in tasks and plugins

Plugins

The Gradle Groovy plugin

The IDEA plugin

The Eclipse plugin

Repositories

Dependencies

Spock tests

Given, when, then

Spock specification structure

Feature methods

Blocks

Fields

Fixture methods

Helper methods

Where blocks

Fixture blocks

Testing Gradle using Spock

Further reading

Summary

4. The Groovy Language

Introducing the Groovy language

The module structure

Groovy shorthand

Implicit imports

Default visibility, optional semicolon

Optional parentheses

The optional dot in method chains

Dynamic types

The optional return keyword

Properties and GroovyBeans

Assertions

Autoboxing

Strings

Regular expressions

Methods and closures

Control structures

Groovy Truth

Ternary and Elvis operators

Spaceship and Elvis operators

The switch statement

Loops

Collections

Ranges

Lists

Maps

Operators

Spread and spread-dot

Null safe dereference

Operator overloading

Summary

5. Groovy Closures

What is a closure?

Closures and collection methods

Closures as method parameters

Method parameters as DSL

Forwarding parameters

Calling closures

The implicit doCall method

Finding a named closure field

Closure parameters

Enforcing zero parameters

Parameters and the doCall method

Passing multiple parameters

Default parameter values

Implementing closures in Java

Curried parameters

Closure return values

The closure scope

The this, owner, and delegate variables

Closure composition

Closure trampoline

Closure memoization

Summary

6. Example DSL – GeeTwitter

Twitter

Working with the Twitter APIs

Using Twitter4J Java APIs

Tweeting

Direct messages

Searching

Following

Groovy improvements

A Groovier way to find friends

Groovy searching

Removing the boilerplate

Refactoring

Fleshing out GeeTwitter

Improving search

Adding a command-line interface

Adding built-in methods

Summary

7. Power Groovy DSL Features

Named parameters

Named parameters in DSLs

Command chains

Builders

The builder design pattern

Using Groovy builders

MarkupBuilder

Namespaced XML

The GroovyMarkup syntax

GroovyMarkup and HTML

Using program logic with builders

Builders for every occasion

NodeBuilder

Using GPath to navigate a node tree

SwingBuilder

Method pointers

Metaprogramming and the Groovy MOP

Reflection

Groovy reflection shortcuts

Expandos

Categories

Traits

MetaClass

Pretended methods – MetaClass.invokeMethod

Understanding this, delegate, and owner

How builders work

ExpandoMetaClasses

Replacing methods

Adding or overriding static methods

Dynamic method naming

Adding overloaded methods

Adding constructors

Summary

8. AST Transformations

What is an AST

Compiler phases

Local AST transformations

Using ASTBuilder

Build from code

Build from Spec

Traits to the rescue

Global AST transformations

A finite state machine DSL

The state machine pattern

A state machine AST transformation

Handling errors – compile errors

Building the new AST nodes

Testing the state machine DSL

Compiling and packaging an AST transformation

Summary

9. Existing Groovy DSLs

Grails object relational mapping – GORM

Grails quick start

The grails-app directory

Building a GORM model

Using domain classes

Modeling relationships

Associations

One-to-one

Constraints

One-to-many

Many-to-many

Composition

Inheritance

Mapping

Querying

Dynamic finders

GORM as a DSL

Spock as a DSL

Spock

JUnit

Summary

10. Building a Builder

The builder code structure

Closure method calls

The resolve strategy – OWNER_FIRST

Pretended methods

invokeMethod

methodMissing

The closure delegate

BuilderSupport

BuilderSupport hook methods

A database builder

FactoryBuilderSupport

Summary

11. Implementing a Rules DSL

Groovy bindings

Exploiting bindings in DSLs

Closures as built-in methods

Closures as repeatable blocks

Using a specification parameter

Closures as singleton blocks

Using binding properties to form context

Storing and communicating results

Building a rewards DSL

Designing the DSL

BroadbandPlus

Reward types

The reward DSL

Handling events – deferred execution

Convenience methods and shorthand

The offers

The RewardService class

The BroadbandPlus application classes

Testing with Spock

Summary

12. Integrating It All

Groovy as a teaching language

Hiding complexity

A game DSL for kids

A game DSL – goals

Architecture and technology choices

TicTacToe in a DSL

Implementing the AST transform

Building the game engine pattern

Testing the DSL

Class loading issues

Gradle subprojects

Debugging

The game server

Integrating with Spring Boot server

Controller annotations

JSONP

Loading the DSL

Spring Data mapping for MongoDB

The Game UI

Summary

Index

累计评论(0条) 0个书友正在讨论这本书 发表评论

发表评论

发表评论,分享你的想法吧!

买过这本书的人还买过

读了这本书的人还在读

回顶部