@Nullable
  private Collection<SNode> apply(
      TemplateContext context, @NotNull TemplateExecutionEnvironment environment)
      throws DismissTopMappingRuleException, AbandonRuleInputException, GenerationFailureException,
          GenerationCanceledException {

    if (myRuleConsequence == null) {
      environment
          .getGenerator()
          .showErrorMessage(
              context.getInput(),
              null,
              ruleNode,
              "error processing reduction rule: no rule consequence");
      return null;
    }

    RuleConsequenceProcessor rcp = new RuleConsequenceProcessor(environment);
    if (!rcp.prepare(myRuleConsequence, ruleNode, context)) {
      environment
          .getGenerator()
          .showErrorMessage(
              context.getInput(),
              null,
              myRuleConsequence,
              "error processing reduction rule consequence");
      return null;
    }

    List<SNode> result = rcp.processRuleConsequence(ruleMappingName);
    return result;
  }
  @Override
  public Collection<SNode> tryToApply(
      TemplateExecutionEnvironment environment, TemplateContext context)
      throws GenerationException {
    if (!checkCondition(context, environment.getGenerator())) {
      return null;
    }

    environment.getTracer().pushRule(myNodePointer);
    try {
      if (environment.getGenerator().isIncremental()) {
        // turn off tracing
        NodeReadEventsCaster.setNodesReadListener(null);
      }

      return apply(context, environment.getEnvironment(context.getInput(), this));
    } catch (AbandonRuleInputException e) {
      return Collections.emptyList();
    } finally {
      if (environment.getGenerator().isIncremental()) {
        // restore tracing
        NodeReadEventsCaster.removeNodesReadListener();
      }
      environment.getTracer().closeRule(myNodePointer);
    }
  }
Example #3
0
 @Override
 public Collection<SNode> apply(@NotNull final TemplateContext context)
     throws GenerationException {
   final TemplateExecutionEnvironment environment = context.getEnvironment();
   Collection<SNode> result = new Template_map_RootConcept().apply(environment, context);
   environment.registerLabel(context.getInput(), result, "map_RootConcept");
   return result;
 }
Example #4
0
 public Collection<SNode> weave(
     @NotNull TemplateExecutionEnvironment environment,
     @NotNull TemplateContext context,
     @NotNull SNode outputContextNode)
     throws GenerationException {
   TemplateContext contextWithParams = context.subContext(getParametersAsMap());
   SNode tnodepart0 = applyPart0(environment, contextWithParams);
   SNodeReference weaveTf0 = weaveTfConst_nofsa1_a0c0g;
   environment.weaveNode(
       outputContextNode, "initializer", tnodepart0, weaveTf0, contextWithParams.getInput());
   return TemplateUtil.singletonList(tnodepart0);
 }
 @Override
 public Collection<SNode> apply(TemplateExecutionEnvironment environment, TemplateContext context)
     throws GenerationException {
   if (templateNode != null) {
     return new TemplateProcessor(environment.getGenerator(), environment.getReductionContext())
         .apply(ruleMappingName, templateNode, context);
   } else {
     environment
         .getGenerator()
         .showErrorMessage(
             context.getInput(), null, ruleNode, "no template is defined for the rule");
   }
   return null;
 }
  @Override
  public void processNull(
      TemplateExecutionEnvironment environment,
      SNodeReference templateSwitch,
      TemplateContext context) {

    SNode generatorMessage = RuleUtil.getSwitch_NullInputMessage(mySwitch);
    if (generatorMessage != null) {
      GeneratorUtilEx.processGeneratorMessage(
          generatorMessage,
          context.getInput(),
          templateSwitch.resolve(MPSModuleRepository.getInstance()),
          null,
          environment.getGenerator());
    }
  }
  @Override
  public boolean isApplicable(TemplateExecutionEnvironment environment, TemplateContext context)
      throws GenerationFailureException {
    SNode condition = RuleUtil.getDropRuleCondition(ruleNode);
    if (condition == null) {
      // condition is not required
      return true;
    }

    String methodName = TemplateFunctionMethodName.dropRootRule_Condition(condition);
    try {
      return (Boolean)
          QueryMethodGenerated.invoke(
              methodName,
              environment.getGenerator().getGeneratorSessionContext(),
              new DropRootRuleContext(context.getInput(), ruleNode, environment.getGenerator()),
              ruleNode.getModel(),
              true);
    } catch (ClassNotFoundException e) {
      environment
          .getGenerator()
          .getLogger()
          .warning(
              condition, "cannot find condition method '" + methodName + "' : evaluate to TRUE");
    } catch (NoSuchMethodException e) {
      environment
          .getGenerator()
          .getLogger()
          .warning(
              condition, "cannot find condition method '" + methodName + "' : evaluate to TRUE");
    } catch (Throwable t) {
      environment.getGenerator().getLogger().handleException(t);
      environment
          .getGenerator()
          .getLogger()
          .error(condition, "error executing condition " + methodName + " (see exception)");
      throw new GenerationFailureException(t);
    }
    // in this case 'true' is better default
    return true;
  }
  @Override
  public boolean isApplicable(TemplateExecutionEnvironment environment, TemplateContext context)
      throws GenerationFailureException {
    try {
      if (conditionMethod == null) {
        return true;
      }

      return (Boolean)
          QueryMethodGenerated.invoke(
              conditionMethod,
              environment.getGenerator().getGeneratorSessionContext(),
              new BaseMappingRuleContext(context.getInput(), ruleNode, environment.getGenerator()),
              ruleNode.getModel(),
              true);
    } catch (ClassNotFoundException e) {
      environment
          .getGenerator()
          .getLogger()
          .warning(
              ruleNode,
              "cannot find condition method '" + conditionMethod + "' : evaluate to FALSE");
    } catch (NoSuchMethodException e) {
      environment
          .getGenerator()
          .getLogger()
          .warning(
              ruleNode,
              "cannot find condition method '" + conditionMethod + "' : evaluate to FALSE");
    } catch (Throwable t) {
      environment.getGenerator().getLogger().handleException(t);
      environment
          .getGenerator()
          .getLogger()
          .error(ruleNode, "error executing condition " + conditionMethod + " (see exception)");
      throw new GenerationFailureException(t);
    }
    return false;
  }
Example #9
0
  public Collection<SNode> apply(
      @NotNull final TemplateExecutionEnvironment environment,
      @NotNull final TemplateContext context)
      throws GenerationException {
    final SNode tnode1 = new SNode("jetbrains.mps.baseLanguage.structure.ClassConcept");
    try {
      environment.getTracer().pushTemplateNode(templateNode_kyghau_a0a0a1a1);
      environment.nodeCopied(
          context, tnode1, "tpl/r:00000000-0000-4000-0000-011c89590606/4146564171992412775");
      tnode1.setProperty("name", "RootCustom");

      {
        final SNode tnode2 = new SNode("jetbrains.mps.baseLanguage.structure.FieldDeclaration");
        try {
          environment.getTracer().pushTemplateNode(templateNode_kyghau_a0a0a1a4a1a1);
          environment.nodeCopied(
              context, tnode2, "tpl/r:00000000-0000-4000-0000-011c89590606/5015072279636761135");
          tnode2.setProperty("name", "q");

          {
            final SNode tnode3 =
                new SNode("jetbrains.mps.baseLanguage.structure.PrivateVisibility");
            try {
              environment.getTracer().pushTemplateNode(templateNode_kyghau_a0a0a1a4a1a4a1a1);
              environment.nodeCopied(
                  context,
                  tnode3,
                  "tpl/r:00000000-0000-4000-0000-011c89590606/5015072279636761136");

            } finally {
              environment
                  .getTracer()
                  .pushOutputNode(
                      GenerationTracerUtil.getSNodePointer(environment.getOutputModel(), tnode3));
              environment.getTracer().closeTemplateNode(templateNode_kyghau_a0a0a1a4a1a4a1a1);
            }
            if (tnode3 != null) {
              tnode2.addChild("visibility", tnode3);
            }
            // TODO validate child
          }
          {
            final SNode tnode4 = new SNode("jetbrains.mps.baseLanguage.structure.IntegerType");
            try {
              environment.getTracer().pushTemplateNode(templateNode_kyghau_a0a0a1a5a1a4a1a1);
              environment.nodeCopied(
                  context,
                  tnode4,
                  "tpl/r:00000000-0000-4000-0000-011c89590606/5015072279636761138");

            } finally {
              environment
                  .getTracer()
                  .pushOutputNode(
                      GenerationTracerUtil.getSNodePointer(environment.getOutputModel(), tnode4));
              environment.getTracer().closeTemplateNode(templateNode_kyghau_a0a0a1a5a1a4a1a1);
            }
            if (tnode4 != null) {
              tnode2.addChild("type", tnode4);
            }
            // TODO validate child
          }
        } finally {
          environment
              .getTracer()
              .pushOutputNode(
                  GenerationTracerUtil.getSNodePointer(environment.getOutputModel(), tnode2));
          environment.getTracer().closeTemplateNode(templateNode_kyghau_a0a0a1a4a1a1);
        }
        if (tnode2 != null) {
          tnode1.addChild("field", tnode2);
        }
        // TODO validate child
      }
      {
        final SNode tnode5 =
            new SNode("jetbrains.mps.baseLanguage.structure.InstanceMethodDeclaration");
        try {
          environment.getTracer().pushTemplateNode(templateNode_kyghau_a0a0a1a5a1a1);
          environment.nodeCopied(
              context, tnode5, "tpl/r:00000000-0000-4000-0000-011c89590606/4146564171992412782");
          tnode5.setProperty("name", "main");

          {
            final SNode tnode6 = new SNode("jetbrains.mps.baseLanguage.structure.VoidType");
            try {
              environment.getTracer().pushTemplateNode(templateNode_kyghau_a0a0a1a4a1a5a1a1);
              environment.nodeCopied(
                  context,
                  tnode6,
                  "tpl/r:00000000-0000-4000-0000-011c89590606/4146564171992412783");

            } finally {
              environment
                  .getTracer()
                  .pushOutputNode(
                      GenerationTracerUtil.getSNodePointer(environment.getOutputModel(), tnode6));
              environment.getTracer().closeTemplateNode(templateNode_kyghau_a0a0a1a4a1a5a1a1);
            }
            if (tnode6 != null) {
              tnode5.addChild("returnType", tnode6);
            }
            // TODO validate child
          }
          {
            final SNode tnode7 = new SNode("jetbrains.mps.baseLanguage.structure.PublicVisibility");
            try {
              environment.getTracer().pushTemplateNode(templateNode_kyghau_a0a0a1a5a1a5a1a1);
              environment.nodeCopied(
                  context,
                  tnode7,
                  "tpl/r:00000000-0000-4000-0000-011c89590606/4146564171992412784");

            } finally {
              environment
                  .getTracer()
                  .pushOutputNode(
                      GenerationTracerUtil.getSNodePointer(environment.getOutputModel(), tnode7));
              environment.getTracer().closeTemplateNode(templateNode_kyghau_a0a0a1a5a1a5a1a1);
            }
            if (tnode7 != null) {
              tnode5.addChild("visibility", tnode7);
            }
            // TODO validate child
          }
          {
            Collection<SNode> tlist8 = null;
            try {
              environment.getTracer().pushMacro(copySrcMacro_kyghau_a0a0a1a6a1a5a1a1);
              final SNode copySrcInput8 =
                  QueriesGenerated.sourceNodeQuery_4146564171992412788(
                      environment.getOperationContext(),
                      new SourceSubstituteMacroNodeContext(
                          context.getInput(),
                          copySrcMacro_kyghau_a0a0a1a6a1a5a1a1,
                          context,
                          environment.getGenerator()));
              tlist8 =
                  environment.copyNodes(
                      TemplateUtil.singletonList(copySrcInput8),
                      copySrcMacro_kyghau_a0a0a1a6a1a5a1a1,
                      "tpl/r:00000000-0000-4000-0000-011c89590606/4146564171992412785",
                      null,
                      context);
            } finally {
              environment.getTracer().closeMacro(copySrcMacro_kyghau_a0a0a1a6a1a5a1a1);
            }
            for (SNode child9 : TemplateUtil.asNotNull(tlist8)) {
              tnode5.addChild("body", child9);
            }
            // TODO validate child
          }
        } finally {
          environment
              .getTracer()
              .pushOutputNode(
                  GenerationTracerUtil.getSNodePointer(environment.getOutputModel(), tnode5));
          environment.getTracer().closeTemplateNode(templateNode_kyghau_a0a0a1a5a1a1);
        }
        if (tnode5 != null) {
          tnode1.addChild("method", tnode5);
        }
        // TODO validate child
      }
      {
        final SNode tnode10 = new SNode("jetbrains.mps.baseLanguage.structure.PublicVisibility");
        try {
          environment.getTracer().pushTemplateNode(templateNode_kyghau_a0a0a1a6a1a1);
          environment.nodeCopied(
              context, tnode10, "tpl/r:00000000-0000-4000-0000-011c89590606/4146564171992412776");

        } finally {
          environment
              .getTracer()
              .pushOutputNode(
                  GenerationTracerUtil.getSNodePointer(environment.getOutputModel(), tnode10));
          environment.getTracer().closeTemplateNode(templateNode_kyghau_a0a0a1a6a1a1);
        }
        if (tnode10 != null) {
          tnode1.addChild("visibility", tnode10);
        }
        // TODO validate child
      }
      {
        final SNode tnode11 =
            new SNode("jetbrains.mps.baseLanguage.structure.ConstructorDeclaration");
        try {
          environment.getTracer().pushTemplateNode(templateNode_kyghau_a0a0a1a7a1a1);
          environment.nodeCopied(
              context, tnode11, "tpl/r:00000000-0000-4000-0000-011c89590606/4146564171992412777");

          {
            final SNode tnode12 = new SNode("jetbrains.mps.baseLanguage.structure.VoidType");
            try {
              environment.getTracer().pushTemplateNode(templateNode_kyghau_a0a0a1a3a1a7a1a1);
              environment.nodeCopied(
                  context,
                  tnode12,
                  "tpl/r:00000000-0000-4000-0000-011c89590606/4146564171992412778");

            } finally {
              environment
                  .getTracer()
                  .pushOutputNode(
                      GenerationTracerUtil.getSNodePointer(environment.getOutputModel(), tnode12));
              environment.getTracer().closeTemplateNode(templateNode_kyghau_a0a0a1a3a1a7a1a1);
            }
            if (tnode12 != null) {
              tnode11.addChild("returnType", tnode12);
            }
            // TODO validate child
          }
          {
            final SNode tnode13 =
                new SNode("jetbrains.mps.baseLanguage.structure.PublicVisibility");
            try {
              environment.getTracer().pushTemplateNode(templateNode_kyghau_a0a0a1a4a1a7a1a1);
              environment.nodeCopied(
                  context,
                  tnode13,
                  "tpl/r:00000000-0000-4000-0000-011c89590606/4146564171992412779");

            } finally {
              environment
                  .getTracer()
                  .pushOutputNode(
                      GenerationTracerUtil.getSNodePointer(environment.getOutputModel(), tnode13));
              environment.getTracer().closeTemplateNode(templateNode_kyghau_a0a0a1a4a1a7a1a1);
            }
            if (tnode13 != null) {
              tnode11.addChild("visibility", tnode13);
            }
            // TODO validate child
          }
          {
            final SNode tnode14 = new SNode("jetbrains.mps.baseLanguage.structure.StatementList");
            try {
              environment.getTracer().pushTemplateNode(templateNode_kyghau_a0a0a1a5a1a7a1a1);
              environment.nodeCopied(
                  context,
                  tnode14,
                  "tpl/r:00000000-0000-4000-0000-011c89590606/4146564171992412780");

              {
                final SNode tnode15 =
                    new SNode(
                        "jetbrains.mps.baseLanguage.structure.LocalVariableDeclarationStatement");
                try {
                  environment
                      .getTracer()
                      .pushTemplateNode(templateNode_kyghau_a0a0a1a3a1a5a1a7a1a1);
                  environment.nodeCopied(
                      context,
                      tnode15,
                      "tpl/r:00000000-0000-4000-0000-011c89590606/5015072279636761102");

                  {
                    Collection<SNode> tlist16 = null;
                    try {
                      environment
                          .getTracer()
                          .pushMacro(varMacroRef_kyghau_a0a0a1a3a1a3a1a5a1a7a1a1);
                      final Object varValue16 =
                          QueriesGenerated.insertMacro_varValue_5015072279636761109(
                              environment.getOperationContext(),
                              new TemplateVarContext(
                                  context.getInput(),
                                  varMacroRef_kyghau_a0a0a1a3a1a3a1a5a1a7a1a1,
                                  context,
                                  environment.getGenerator()));
                      TemplateContext context16 =
                          context.subContext(
                              Collections.<String, Object>singletonMap("var:var1", varValue16));
                      final SNode tnode17 =
                          new SNode(
                              "jetbrains.mps.baseLanguage.structure.LocalVariableDeclaration");
                      try {
                        environment
                            .getTracer()
                            .pushTemplateNode(templateNode_kyghau_a0a0a4a1a3a1a3a1a5a1a7a1a1);
                        environment.nodeCopied(
                            context16,
                            tnode17,
                            "tpl/r:00000000-0000-4000-0000-011c89590606/5015072279636761103");
                        tnode17.setProperty("name", "i");

                        {
                          final SNode tnode18 =
                              new SNode("jetbrains.mps.baseLanguage.structure.IntegerType");
                          try {
                            environment
                                .getTracer()
                                .pushTemplateNode(
                                    templateNode_kyghau_a0a0a1a4a4a1a3a1a3a1a5a1a7a1a1);
                            environment.nodeCopied(
                                context16,
                                tnode18,
                                "tpl/r:00000000-0000-4000-0000-011c89590606/5015072279636761104");

                          } finally {
                            environment
                                .getTracer()
                                .pushOutputNode(
                                    GenerationTracerUtil.getSNodePointer(
                                        environment.getOutputModel(), tnode18));
                            environment
                                .getTracer()
                                .closeTemplateNode(
                                    templateNode_kyghau_a0a0a1a4a4a1a3a1a3a1a5a1a7a1a1);
                          }
                          if (tnode18 != null) {
                            tnode17.addChild("type", tnode18);
                          }
                          // TODO validate child
                        }
                        {
                          final SNode tnode19 =
                              new SNode("jetbrains.mps.baseLanguage.structure.IntegerConstant");
                          try {
                            environment
                                .getTracer()
                                .pushTemplateNode(
                                    templateNode_kyghau_a0a0a1a5a4a1a3a1a3a1a5a1a7a1a1);
                            environment.nodeCopied(
                                context16,
                                tnode19,
                                "tpl/r:00000000-0000-4000-0000-011c89590606/5015072279636761106");
                            tnode19.setProperty(
                                "value",
                                TemplateUtil.asString(
                                    QueriesGenerated
                                        .propertyMacro_GetPropertyValue_2721957369897795324(
                                            environment.getOperationContext(),
                                            new PropertyMacroContext(
                                                context16.getInput(),
                                                "0",
                                                propertyMacro_kyghau_c0b0b0a2a1a5a4a1a3a1a3a1a5a1a7a1a1,
                                                context16,
                                                environment.getGenerator()))));

                          } finally {
                            environment
                                .getTracer()
                                .pushOutputNode(
                                    GenerationTracerUtil.getSNodePointer(
                                        environment.getOutputModel(), tnode19));
                            environment
                                .getTracer()
                                .closeTemplateNode(
                                    templateNode_kyghau_a0a0a1a5a4a1a3a1a3a1a5a1a7a1a1);
                          }
                          if (tnode19 != null) {
                            tnode17.addChild("initializer", tnode19);
                          }
                          // TODO validate child
                        }
                      } finally {
                        environment
                            .getTracer()
                            .pushOutputNode(
                                GenerationTracerUtil.getSNodePointer(
                                    environment.getOutputModel(), tnode17));
                        environment
                            .getTracer()
                            .closeTemplateNode(templateNode_kyghau_a0a0a4a1a3a1a3a1a5a1a7a1a1);
                      }
                      tlist16 = TemplateUtil.singletonList(tnode17);
                    } finally {
                      environment
                          .getTracer()
                          .closeMacro(varMacroRef_kyghau_a0a0a1a3a1a3a1a5a1a7a1a1);
                    }
                    for (SNode child20 : TemplateUtil.asNotNull(tlist16)) {
                      tnode15.addChild("localVariableDeclaration", child20);
                    }
                    // TODO validate child
                  }
                } finally {
                  environment
                      .getTracer()
                      .pushOutputNode(
                          GenerationTracerUtil.getSNodePointer(
                              environment.getOutputModel(), tnode15));
                  environment
                      .getTracer()
                      .closeTemplateNode(templateNode_kyghau_a0a0a1a3a1a5a1a7a1a1);
                }
                if (tnode15 != null) {
                  tnode14.addChild("statement", tnode15);
                }
                // TODO validate child
              }
              {
                final SNode tnode21 =
                    new SNode("jetbrains.mps.baseLanguage.structure.ExpressionStatement");
                try {
                  environment
                      .getTracer()
                      .pushTemplateNode(templateNode_kyghau_a0a0a1a4a1a5a1a7a1a1);
                  environment.nodeCopied(
                      context,
                      tnode21,
                      "tpl/r:00000000-0000-4000-0000-011c89590606/5015072279636761140");

                  {
                    final SNode tnode22 =
                        new SNode("jetbrains.mps.baseLanguage.structure.AssignmentExpression");
                    try {
                      environment
                          .getTracer()
                          .pushTemplateNode(templateNode_kyghau_a0a0a1a3a1a4a1a5a1a7a1a1);
                      environment.nodeCopied(
                          context,
                          tnode22,
                          "tpl/r:00000000-0000-4000-0000-011c89590606/5015072279636761142");

                      {
                        final SNode tnode23 =
                            new SNode(
                                "jetbrains.mps.baseLanguage.structure.LocalInstanceFieldReference");
                        try {
                          environment
                              .getTracer()
                              .pushTemplateNode(templateNode_kyghau_a0a0a1a3a1a3a1a4a1a5a1a7a1a1);
                          environment.nodeCopied(
                              context,
                              tnode23,
                              "tpl/r:00000000-0000-4000-0000-011c89590606/5015072279636761141");
                          environment.resolveInTemplateLater(
                              tnode23,
                              "variableDeclaration",
                              new SNodePointer(
                                  "r:00000000-0000-4000-0000-011c89590606(jetbrains.mps.transformation.test.outputLang.generator.baseLanguage.template.main@generator)",
                                  "5015072279636761141"),
                              "tpl/r:00000000-0000-4000-0000-011c89590606/5015072279636761135",
                              "q",
                              context);

                        } finally {
                          environment
                              .getTracer()
                              .pushOutputNode(
                                  GenerationTracerUtil.getSNodePointer(
                                      environment.getOutputModel(), tnode23));
                          environment
                              .getTracer()
                              .closeTemplateNode(templateNode_kyghau_a0a0a1a3a1a3a1a4a1a5a1a7a1a1);
                        }
                        if (tnode23 != null) {
                          tnode22.addChild("lValue", tnode23);
                        }
                        // TODO validate child
                      }
                      {
                        final SNode tnode24 =
                            new SNode(
                                "jetbrains.mps.baseLanguage.structure.LocalVariableReference");
                        try {
                          environment
                              .getTracer()
                              .pushTemplateNode(templateNode_kyghau_a0a0a1a4a1a3a1a4a1a5a1a7a1a1);
                          environment.nodeCopied(
                              context,
                              tnode24,
                              "tpl/r:00000000-0000-4000-0000-011c89590606/5015072279636761145");
                          environment.resolveInTemplateLater(
                              tnode24,
                              "variableDeclaration",
                              new SNodePointer(
                                  "r:00000000-0000-4000-0000-011c89590606(jetbrains.mps.transformation.test.outputLang.generator.baseLanguage.template.main@generator)",
                                  "5015072279636761145"),
                              "tpl/r:00000000-0000-4000-0000-011c89590606/5015072279636761103",
                              "i",
                              context);

                        } finally {
                          environment
                              .getTracer()
                              .pushOutputNode(
                                  GenerationTracerUtil.getSNodePointer(
                                      environment.getOutputModel(), tnode24));
                          environment
                              .getTracer()
                              .closeTemplateNode(templateNode_kyghau_a0a0a1a4a1a3a1a4a1a5a1a7a1a1);
                        }
                        if (tnode24 != null) {
                          tnode22.addChild("rValue", tnode24);
                        }
                        // TODO validate child
                      }
                    } finally {
                      environment
                          .getTracer()
                          .pushOutputNode(
                              GenerationTracerUtil.getSNodePointer(
                                  environment.getOutputModel(), tnode22));
                      environment
                          .getTracer()
                          .closeTemplateNode(templateNode_kyghau_a0a0a1a3a1a4a1a5a1a7a1a1);
                    }
                    if (tnode22 != null) {
                      tnode21.addChild("expression", tnode22);
                    }
                    // TODO validate child
                  }
                } finally {
                  environment
                      .getTracer()
                      .pushOutputNode(
                          GenerationTracerUtil.getSNodePointer(
                              environment.getOutputModel(), tnode21));
                  environment
                      .getTracer()
                      .closeTemplateNode(templateNode_kyghau_a0a0a1a4a1a5a1a7a1a1);
                }
                if (tnode21 != null) {
                  tnode14.addChild("statement", tnode21);
                }
                // TODO validate child
              }
            } finally {
              environment
                  .getTracer()
                  .pushOutputNode(
                      GenerationTracerUtil.getSNodePointer(environment.getOutputModel(), tnode14));
              environment.getTracer().closeTemplateNode(templateNode_kyghau_a0a0a1a5a1a7a1a1);
            }
            if (tnode14 != null) {
              tnode11.addChild("body", tnode14);
            }
            // TODO validate child
          }
        } finally {
          environment
              .getTracer()
              .pushOutputNode(
                  GenerationTracerUtil.getSNodePointer(environment.getOutputModel(), tnode11));
          environment.getTracer().closeTemplateNode(templateNode_kyghau_a0a0a1a7a1a1);
        }
        if (tnode11 != null) {
          tnode1.addChild("constructor", tnode11);
        }
        // TODO validate child
      }
    } finally {
      environment
          .getTracer()
          .pushOutputNode(
              GenerationTracerUtil.getSNodePointer(environment.getOutputModel(), tnode1));
      environment.getTracer().closeTemplateNode(templateNode_kyghau_a0a0a1a1);
    }
    return TemplateUtil.singletonList(tnode1);
  }
  @Override
  public Collection<SNode> applyDefault(
      TemplateExecutionEnvironment environment,
      SNodeReference templateSwitch,
      String mappingName,
      TemplateContext context)
      throws GenerationException {
    SNode defaultConsequence = RuleUtil.getSwitchDefaultConsequence(mySwitch);
    if (defaultConsequence == null) {
      SNodeReference modifies = getModifiesSwitch();
      if (modifies == null) {
        return null;
      }
      TemplateSwitchMapping switchMapping = environment.getGenerator().getSwitch(modifies);
      if (switchMapping == null) {
        return null;
      }
      return switchMapping.applyDefault(environment, templateSwitch, mappingName, context);
    }

    List<SNode> collection = new ArrayList<SNode>();
    try {
      List<Pair<SNode, String>> nodeAndMappingNamePairs =
          GeneratorUtilEx.getTemplateNodesFromRuleConsequence(
              defaultConsequence,
              context.getInput(),
              templateSwitch.resolve(MPSModuleRepository.getInstance()),
              environment.getReductionContext(),
              environment.getGenerator());
      if (nodeAndMappingNamePairs == null) {
        environment
            .getGenerator()
            .showErrorMessage(
                context.getInput(),
                templateSwitch.resolve(MPSModuleRepository.getInstance()),
                defaultConsequence,
                "error processing $SWITCH$/default");
        return null;
      }

      for (Pair<SNode, String> nodeAndMappingNamePair : nodeAndMappingNamePairs) {
        SNode altTemplateNode = nodeAndMappingNamePair.o1;
        String innerMappingName =
            nodeAndMappingNamePair.o2 != null ? nodeAndMappingNamePair.o2 : mappingName;
        try {
          TemplateProcessor templateProcessor =
              new TemplateProcessor(environment.getGenerator(), environment.getReductionContext());
          collection.addAll(templateProcessor.apply(innerMappingName, altTemplateNode, context));
        } catch (TemplateProcessingFailureException e) {
          environment
              .getGenerator()
              .showErrorMessage(
                  context.getInput(),
                  templateSwitch.resolve(MPSModuleRepository.getInstance()),
                  "error processing template fragment");
        }
      }
    } catch (AbandonRuleInputException e) {
      // it's ok. just ignore
    }
    return collection;
  }
 public SNode getInputNode() {
   return myContext == null ? null : myContext.getInput();
 }