Groovy for Domain-specific Languages - Second Edition

(nextflipdebug2) #1

Integrating It All


[ 334 ]

new Token(Types.EQUALS, "=", -1, -1),
new VariableExpression("session")
)
)
closureDelegateStatements << closureDelegateStatement
}

def blockStatement = new BlockStatement(
closureDelegateStatements, new VariableScope() )

def methodBody = new IfStatement(
new BooleanExpression (
new BinaryExpression(
new VariableExpression("session"),
new Token(Types.COMPARE_NOT_EQUAL, "!=", -1, -1),
new ConstantExpression(null)
)
),
blockStatement,
EmptyStatement.INSTANCE
)

def eventMethodNode = new MethodNode(
"setClosureDelegates",
Modifier.PUBLIC,
null,
[] as Parameter[],
null,
methodBody
)

pageClassNode[1].addMethod(eventMethodNode)
pageClassNode
}

Finally, we need to add the event handling closures to the page classes. These
are constructed as PropertyNode objects where the assignment expression is a
ClosureExpression. The closure is constructed with a BlockStatement object into
which we place the original statements parsed from the event: block in the original
DSL script:


def buildPageClassEventClosure(event, page, stateClassNode) {
def eventStatements = []
model.eventStatements["$event"].each {
eventStatements << it

http://www.ebook3000.com
Free download pdf