Skip to content

Commit

Permalink
[griddynamics#1028][feature] - Reusing code with macros: replacing va…
Browse files Browse the repository at this point in the history
…riables in class cast expressions too
  • Loading branch information
rsvato committed Sep 3, 2013
1 parent 9ea793b commit 2ca9c3e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ class ApplyVariablesVisitor(values: Map[String, Expression], replacements: mutab
}
case constant: ConstantExpression if constant.getText.startsWith("$") =>
values.get(constant.getText).getOrElse(constant)
case cast: CastExpression => {
new CastExpression(cast.getType, transform(cast.getExpression), cast.isIgnoringAutoboxing)
}
case other => other
}
}
Expand Down
4 changes: 4 additions & 0 deletions backend/src/test/resources/groovy/Macros.genesis
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ template {

def MY_CONSTANT = "Set from constant"

def xxx = {"Call from closure"}

defmacro "create_steps": { $message = "default" ->
1 + 2
teststep {
text = $message
skip = ($message as Boolean)
}
}

Expand Down Expand Up @@ -72,6 +75,7 @@ template {
macro:create_steps($message: "Set with map")
macro:create_steps()
macro:simple()
macro:create_steps($message: xxx)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ class MacrosTest extends AssertionsForJUnit with MockitoSugar with DSLTestUniver
val template: Option[TemplateDefinition] = templateService.findTemplate(0, "Macros", "0.1", 0)
val workflow = template.flatMap(_.getWorkflow("macros")).get
val steps = workflow.embody(Map())
expectResult(5)(steps.regular.size)
expectResult(6)(steps.regular.size)
val initialPhase: Option[StepBuilder] = steps.regular.find(_.phase == "auto_0")
val secondPhase: Option[StepBuilder] = steps.regular.find(_.phase == "auto_1")
assert(initialPhase.isDefined)
assert(initialPhase.get.getPrecedingPhases.isEmpty)
assert(secondPhase.isDefined)
assert(secondPhase.get.getPrecedingPhases.contains("auto_0"))
steps.regular.zip(Seq("Static", "Passed from macro call",
"Set with map", "default", "Set from constant")).map({
"Set with map", "default", "Set from constant", "Call from closure")).map({
case (step, message) => step.newStep.actualStep match {
case nothing: DoNothingStep => expectResult(message)(nothing.name)
}
Expand Down

0 comments on commit 2ca9c3e

Please sign in to comment.