From 2ca9c3ea138f24e28a197d9c0db371d43a7ee6ae Mon Sep 17 00:00:00 2001 From: Svyatoslav Reyentenko Date: Tue, 3 Sep 2013 17:42:27 +0400 Subject: [PATCH] [#1028][feature] - Reusing code with macros: replacing variables in class cast expressions too --- .../dsl/groovy/transformations/MacroASTTransformation.scala | 3 +++ backend/src/test/resources/groovy/Macros.genesis | 4 ++++ .../com/griddynamics/genesis/service/impl/MacrosTest.scala | 4 ++-- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/backend/src/main/scala/com/griddynamics/genesis/template/dsl/groovy/transformations/MacroASTTransformation.scala b/backend/src/main/scala/com/griddynamics/genesis/template/dsl/groovy/transformations/MacroASTTransformation.scala index 18bd07a87..2d7cc8d53 100644 --- a/backend/src/main/scala/com/griddynamics/genesis/template/dsl/groovy/transformations/MacroASTTransformation.scala +++ b/backend/src/main/scala/com/griddynamics/genesis/template/dsl/groovy/transformations/MacroASTTransformation.scala @@ -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 } } diff --git a/backend/src/test/resources/groovy/Macros.genesis b/backend/src/test/resources/groovy/Macros.genesis index 40cdddacf..97014aca2 100644 --- a/backend/src/test/resources/groovy/Macros.genesis +++ b/backend/src/test/resources/groovy/Macros.genesis @@ -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) } } @@ -72,6 +75,7 @@ template { macro:create_steps($message: "Set with map") macro:create_steps() macro:simple() + macro:create_steps($message: xxx) } } diff --git a/backend/src/test/scala/com/griddynamics/genesis/service/impl/MacrosTest.scala b/backend/src/test/scala/com/griddynamics/genesis/service/impl/MacrosTest.scala index 8ef877679..96123e2b4 100644 --- a/backend/src/test/scala/com/griddynamics/genesis/service/impl/MacrosTest.scala +++ b/backend/src/test/scala/com/griddynamics/genesis/service/impl/MacrosTest.scala @@ -38,7 +38,7 @@ 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) @@ -46,7 +46,7 @@ class MacrosTest extends AssertionsForJUnit with MockitoSugar with DSLTestUniver 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) }