Groovy for Domain-specific Languages - Second Edition

(nextflipdebug2) #1
Chapter 12

[ 329 ]

),
new ExpressionStatement(
new BinaryExpression(
new VariableExpression("page"),
new Token(Types.EQUALS, "=", -1, -1),
new ConstructorCallExpression(
ClassHelper.make(
"${model.startPage}Page"
),
new ArgumentListExpression(
new VariableExpression('this')
)
),
)
)
],
new VariableScope()
)


def constructorNode = new ConstructorNode(
Modifier.PUBLIC,
[] as Parameter [],
[
ClassHelper.make(Exception, false),
ClassHelper.make(IOException, false)
] as ClassNode [],
blockStatement
)
sessionClassNode[1].addConstructor(constructorNode)


// Add Properties for each variable declaration in the DSL
model.stateDeclarations.each { stmnt ->
def statePropertyNode = new PropertyNode (
stmnt.expression.variableExpression.name,
Modifier.PUBLIC,
stmnt.expression.variableExpression.type,
ClassHelper.make("${className}Session"),
stmnt.expression.rightExpression,
null,
null
)
sessionClassNode[1].addProperty(statePropertyNode)
}
}

Free download pdf