protected FragmentResult applyPart0()

in languages/languageDesign/quotation/generator/source_gen/jetbrains/mps/lang/quotation/generator/baseLanguage/template/main/Template_NodeBuilder_to_methodCall.java [49:419]


  protected FragmentResult applyPart0(@NotNull final TemplateContext context) throws GenerationException {
    final TemplateExecutionEnvironment environment = context.getEnvironment();
    final SNode tnode1 = environment.createOutputNode(myConcepts[0]);
    {
      TemplateContext context1 = context.subContext();
      {
        final SNode tnode2 = environment.createOutputNode(myConcepts[1]);
        {
          environment.nodeCopied(context1, tnode2, "tpl/r:00000000-0000-4000-0000-011c8959034c/429601079676709245");
          SNodeAccessUtil.setPropertyValue(tnode2, myProperties[0], QueriesGenerated.propertyMacro_GetValue_3_1(new PropertyMacroContext(context1, "createNode", propertyMacro)));
          TemplateContext context2 = context1.subContext();
          {
            Collection<SNode> tlist3 = Collections.emptyList();
            if (QueriesGenerated.ifMacro_Condition_3_0(new IfMacroContext(context2, ifMacroRef))) {
              final List<SNode> tlist4 = new ArrayList<SNode>();
              final SNode sourceNode4 = QueriesGenerated.sourceNodeQuery_3_0(new SourceSubstituteMacroNodeContext(context2, mapsrcMacroRef));
              TemplateContext context3 = context2.subContext("parametersFromExpressionsL", sourceNode4);
              if (sourceNode4 != null) {
                final SNode tnode5 = environment.createOutputNode(myConcepts[2]);
                {
                  environment.nodeCopied(context3, tnode5, "tpl/r:00000000-0000-4000-0000-011c8959034c/429601079676709260");
                  tnode5.setProperty(myProperties[0], "modelToCreate");
                  TemplateContext context4 = context3.subContext();
                  {
                    final SNode tnode6 = environment.createOutputNode(myConcepts[3]);
                    environment.associate(tnode6, myAssociationLinks[0], "8865b7a8-5271-43d3-884c-6fd1d9cfdd34/java:org.jetbrains.mps.openapi.model(MPS.OpenAPI/)", "~SModel");
                    environment.aggregate(tnode5, myAggregationLinks[0], tnode6);
                  }
                }
                tlist4.add(tnode5);
                environment.registerLabel(context3.getInput(), tnode5, "parametersFromExpressionsL");
              }
              tlist3 = tlist4;
            }
            environment.aggregate(tnode2, myAggregationLinks[1], tlist3);
          }
          {
            Collection<SNode> tlist7 = Collections.emptyList();
            if (QueriesGenerated.ifMacro_Condition_3_1(new IfMacroContext(context2, ifMacroRef1))) {
              final List<SNode> tlist8 = new ArrayList<SNode>();
              final SNode sourceNode8 = QueriesGenerated.sourceNodeQuery_3_1(new SourceSubstituteMacroNodeContext(context2, mapsrcMacroRef1));
              TemplateContext context5 = context2.subContext("parametersFromExpressionsL", sourceNode8);
              if (sourceNode8 != null) {
                final SNode tnode9 = environment.createOutputNode(myConcepts[2]);
                {
                  environment.nodeCopied(context5, tnode9, "tpl/r:00000000-0000-4000-0000-011c8959034c/7191184120224376351");
                  tnode9.setProperty(myProperties[0], "nodeId");
                  TemplateContext context6 = context5.subContext();
                  {
                    final SNode tnode10 = environment.createOutputNode(myConcepts[3]);
                    environment.associate(tnode10, myAssociationLinks[0], "8865b7a8-5271-43d3-884c-6fd1d9cfdd34/java:org.jetbrains.mps.openapi.model(MPS.OpenAPI/)", "~SNodeId");
                    environment.aggregate(tnode9, myAggregationLinks[0], tnode10);
                  }
                }
                tlist8.add(tnode9);
                environment.registerLabel(context5.getInput(), tnode9, "parametersFromExpressionsL");
              }
              tlist7 = tlist8;
            }
            environment.aggregate(tnode2, myAggregationLinks[1], tlist7);
          }
          {
            final SNode tnode11 = environment.createOutputNode(myConcepts[4]);
            environment.aggregate(tnode2, myAggregationLinks[2], tnode11);
          }
          {
            final SNode tnode12 = environment.createOutputNode(myConcepts[5]);
            environment.aggregate(tnode2, myAggregationLinks[3], tnode12);
          }
          {
            final SNode tnode13 = environment.createOutputNode(myConcepts[6]);
            {
              TemplateContext context7 = context2.subContext();
              {
                Collection<SNode> tlist14 = Collections.emptyList();
                if (QueriesGenerated.ifMacro_Condition_3_2(new IfMacroContext(context7, ifMacroRef2))) {
                  final SNode tnode15 = environment.createOutputNode(myConcepts[7]);
                  {
                    TemplateContext context8 = context7.subContext();
                    {
                      final SNode tnode16 = environment.createOutputNode(myConcepts[8]);
                      {
                        tnode16.setProperty(myProperties[0], "facade");
                        TemplateContext context9 = context8.subContext();
                        {
                          final SNode tnode17 = environment.createOutputNode(myConcepts[9]);
                          environment.associate(tnode17, myAssociationLinks[1], "8865b7a8-5271-43d3-884c-6fd1d9cfdd34/java:org.jetbrains.mps.openapi.persistence(MPS.OpenAPI/)", "~PersistenceFacade.getInstance()");
                          environment.associate(tnode17, myAssociationLinks[2], "8865b7a8-5271-43d3-884c-6fd1d9cfdd34/java:org.jetbrains.mps.openapi.persistence(MPS.OpenAPI/)", "~PersistenceFacade");
                          environment.aggregate(tnode16, myAggregationLinks[4], tnode17);
                        }
                        {
                          final SNode tnode18 = environment.createOutputNode(myConcepts[3]);
                          environment.associate(tnode18, myAssociationLinks[0], "8865b7a8-5271-43d3-884c-6fd1d9cfdd34/java:org.jetbrains.mps.openapi.persistence(MPS.OpenAPI/)", "~PersistenceFacade");
                          environment.aggregate(tnode16, myAggregationLinks[0], tnode18);
                        }
                      }
                      environment.aggregate(tnode15, myAggregationLinks[5], tnode16);
                    }
                  }
                  tlist14 = TemplateUtil.singletonList(tnode15);
                }
                environment.aggregate(tnode13, myAggregationLinks[6], tlist14);
              }
              {
                Collection<SNode> tlist19 = null;
                TemplateContext context10 = context7;
                context10 = context10.withVariable("var:container", QueriesGenerated.varMacro_Value_3_0(new TemplateVarContext(context10, new SNodePointer("r:00000000-0000-4000-0000-011c8959034c(jetbrains.mps.lang.quotation.generator.baseLanguage.template.main@generator)", "78629976128307438"))));
                final SNode tnode20 = environment.createOutputNode(myConcepts[7]);
                {
                  TemplateContext context11 = context10.subContext();
                  {
                    final List<SNode> tlist21 = new ArrayList<SNode>();
                    final SNode sourceNode21 = QueriesGenerated.sourceNodeQuery_3_2(new SourceSubstituteMacroNodeContext(context11, mapsrcMacroRef2));
                    TemplateContext context12 = context11.subContext(null, sourceNode21);
                    if (sourceNode21 != null) {
                      Collection<SNode> tlist22 = null;
                      TemplateContext context13 = context12.subContext("nodeVariableL");
                      final SNode tnode23 = environment.createOutputNode(myConcepts[8]);
                      {
                        environment.nodeCopied(context13, tnode23, "tpl/r:00000000-0000-4000-0000-011c8959034c/78629976128307294");
                        SNodeAccessUtil.setPropertyValue(tnode23, myProperties[0], QueriesGenerated.propertyMacro_GetValue_3_0(new PropertyMacroContext(context13, "rootBuilder", propertyMacro1)));
                        TemplateContext context14 = context13.subContext();
                        {
                          final SNode tnode24 = environment.createOutputNode(myConcepts[3]);
                          environment.associate(tnode24, myAssociationLinks[0], "6ed54515-acc8-4d1e-a16c-9fd6cfe951ea/java:jetbrains.mps.smodel.builder(MPS.Core/)", "~SNodeBuilder");
                          environment.aggregate(tnode23, myAggregationLinks[0], tnode24);
                        }
                        {
                          final SNode tnode25 = environment.createOutputNode(myConcepts[10]);
                          {
                            TemplateContext context15 = context14.subContext();
                            {
                              final SNode tnode26 = environment.createOutputNode(myConcepts[11]);
                              {
                                TemplateContext context16 = context15.subContext();
                                {
                                  final SNode tnode27 = environment.createOutputNode(myConcepts[12]);
                                  {
                                    environment.associate(tnode27, myAssociationLinks[1], "6ed54515-acc8-4d1e-a16c-9fd6cfe951ea/java:jetbrains.mps.smodel.builder(MPS.Core/)", "~SNodeBuilder.<init>(org.jetbrains.mps.openapi.model.SModel,org.jetbrains.mps.openapi.model.SNodeId)");
                                    TemplateContext context17 = context16.subContext();
                                    {
                                      Collection<SNode> tlist28 = Collections.emptyList();
                                      if (QueriesGenerated.ifMacro_Condition_3_3(new IfMacroContext(context17, ifMacroRef3))) {
                                        final SNode tnode29 = environment.createOutputNode(myConcepts[13]);
                                        environment.resolve(new RefResolver(tnode29, myAssociationLinks[3], context17, new SNodePointer("r:00000000-0000-4000-0000-011c8959034c(jetbrains.mps.lang.quotation.generator.baseLanguage.template.main@generator)", "78629976128307317"), "modelToCreate") {
                                          @Override
                                          public Object resolve() {
                                            return QueriesGenerated.referenceMacro_GetReferent_3_0(createQueryContext());
                                          }
                                        });
                                        tlist28 = TemplateUtil.singletonList(tnode29);
                                      }
                                      environment.aggregate(tnode27, myAggregationLinks[7], tlist28);
                                    }
                                    {
                                      Collection<SNode> tlist30 = Collections.emptyList();
                                      if (QueriesGenerated.ifMacro_Condition_3_4(new IfMacroContext(context17, ifMacroRef4))) {
                                        final SNode tnode31 = environment.createOutputNode(myConcepts[13]);
                                        environment.resolve(new RefResolver(tnode31, myAssociationLinks[3], context17, new SNodePointer("r:00000000-0000-4000-0000-011c8959034c(jetbrains.mps.lang.quotation.generator.baseLanguage.template.main@generator)", "78629976128307368"), "nodeId") {
                                          @Override
                                          public Object resolve() {
                                            return QueriesGenerated.referenceMacro_GetReferent_3_1(createQueryContext());
                                          }
                                        });
                                        tlist30 = TemplateUtil.singletonList(tnode31);
                                      }
                                      environment.aggregate(tnode27, myAggregationLinks[7], tlist30);
                                    }
                                  }
                                  environment.aggregate(tnode26, myAggregationLinks[8], tnode27);
                                }
                              }
                              environment.aggregate(tnode25, myAggregationLinks[9], tnode26);
                            }
                            {
                              Collection<SNode> tlist32 = null;
                              try {
                                TemplateContext switchContext32 = context15;
                                switchContext32 = switchContext32.withVariable("targetConcept", null);
                                switchContext32 = switchContext32.withVariable("allowNull", ((Optional<Boolean>) QueriesGenerated.templateArgumentQuery_3_1(new TemplateArgumentContext(switchContext32, new SNodePointer("r:00000000-0000-4000-0000-011c8959034c(jetbrains.mps.lang.quotation.generator.baseLanguage.template.main@generator)", "78629976128307399")))));
                                tlist32 = environment.trySwitch(templateSwitchNodeNoInput, switchContext32);
                                if (tlist32 == null) {
                                  final SNode tnode33 = environment.createOutputNode(myConcepts[14]);
                                  {
                                    environment.associate(tnode33, myAssociationLinks[1], "6ed54515-acc8-4d1e-a16c-9fd6cfe951ea/java:jetbrains.mps.smodel.builder(MPS.Core/)", "~SNodeBuilder.init(org.jetbrains.mps.openapi.language.SConcept)");
                                    TemplateContext context18 = context15.subContext();
                                    {
                                      final SNode tnode34 = environment.createOutputNode(myConcepts[15]);
                                      environment.aggregate(tnode33, myAggregationLinks[7], tnode34);
                                    }
                                  }
                                  tlist32 = TemplateUtil.singletonList(tnode33);
                                }
                              } finally {
                              }
                              environment.aggregate(tnode25, myAggregationLinks[10], tlist32);
                            }
                          }
                          environment.aggregate(tnode23, myAggregationLinks[4], tnode25);
                        }
                      }
                      tlist22 = TemplateUtil.singletonList(tnode23);
                      environment.registerLabel(context12.getInput(), tlist22, "nodeVariableL");
                      tlist21.addAll(tlist22);
                    }
                    environment.aggregate(tnode20, myAggregationLinks[5], tlist21);
                  }
                }
                tlist19 = TemplateUtil.singletonList(tnode20);
                environment.aggregate(tnode13, myAggregationLinks[6], tlist19);
              }
              {
                final List<SNode> tlist35 = new ArrayList<SNode>();
                final Iterable<SNode> loopList35 = QueriesGenerated.sourceNodesQuery_3_0(new SourceSubstituteMacroNodesContext(context7, loopMacroRef));
                for (SNode itnode35 : loopList35) {
                  if (itnode35 == null) {
                    continue;
                  }
                  TemplateContext context19 = context7.subContext(itnode35);
                  Collection<SNode> tlist36 = null;
                  try {
                    TemplateContext switchContext36 = context19;
                    switchContext36 = switchContext36.withVariable("nodeBuilderNode", ((SNode) QueriesGenerated.templateArgumentQuery_3_0(new TemplateArgumentContext(switchContext36, templArgCall))));
                    tlist36 = environment.trySwitch(templateSwitchNodeNoInput1, switchContext36);
                    if (tlist36 == null) {
                      final SNode tnode37 = environment.createOutputNode(myConcepts[16]);
                      {
                        TemplateContext context20 = context19.subContext();
                        {
                          final SNode tnode38 = environment.createOutputNode(myConcepts[11]);
                          {
                            TemplateContext context21 = context20.subContext();
                            {
                              final SNode tnode39 = environment.createOutputNode(myConcepts[12]);
                              environment.associate(tnode39, myAssociationLinks[1], "6354ebe7-c22a-4a0f-ac54-50b52ab9b065/java:java.lang(JDK/)", "~UnsupportedOperationException.<init>()");
                              environment.aggregate(tnode38, myAggregationLinks[8], tnode39);
                            }
                          }
                          environment.aggregate(tnode37, myAggregationLinks[11], tnode38);
                        }
                      }
                      tlist36 = TemplateUtil.singletonList(tnode37);
                    }
                  } finally {
                  }
                  tlist35.addAll(tlist36);
                }
                environment.aggregate(tnode13, myAggregationLinks[6], tlist35);
              }
              {
                final SNode tnode40 = environment.createOutputNode(myConcepts[17]);
                {
                  TemplateContext context22 = context7.subContext();
                  {
                    final SNode tnode41 = environment.createOutputNode(myConcepts[10]);
                    {
                      TemplateContext context23 = context22.subContext();
                      {
                        final SNode tnode42 = environment.createOutputNode(myConcepts[13]);
                        environment.resolve(new RefResolver(tnode42, myAssociationLinks[3], context23, new SNodePointer("r:00000000-0000-4000-0000-011c8959034c(jetbrains.mps.lang.quotation.generator.baseLanguage.template.main@generator)", "1724959616550849549"), "rootBuilder") {
                          @Override
                          public Object resolve() {
                            return QueriesGenerated.referenceMacro_GetReferent_3_2(createQueryContext());
                          }
                        });
                        environment.aggregate(tnode41, myAggregationLinks[9], tnode42);
                      }
                      {
                        final SNode tnode43 = environment.createOutputNode(myConcepts[14]);
                        environment.associate(tnode43, myAssociationLinks[1], "6ed54515-acc8-4d1e-a16c-9fd6cfe951ea/java:jetbrains.mps.smodel.builder(MPS.Core/)", "~SNodeBuilder.getResult()");
                        environment.aggregate(tnode41, myAggregationLinks[10], tnode43);
                      }
                    }
                    environment.aggregate(tnode40, myAggregationLinks[12], tnode41);
                  }
                }
                environment.aggregate(tnode13, myAggregationLinks[6], tnode40);
              }
            }
            environment.aggregate(tnode2, myAggregationLinks[13], tnode13);
          }
          {
            final List<SNode> tlist44 = new ArrayList<SNode>();
            final Iterable<SNode> loopList44 = QueriesGenerated.sourceNodesQuery_3_1(new SourceSubstituteMacroNodesContext(context2, loopMacroRef1));
            int loopIndex_44 = 0;
            for (SNode itnode44 : loopList44) {
              if (itnode44 == null) {
                continue;
              }
              TemplateContext context24 = context2.subContext("parametersFromExpressionsL", itnode44);
              context24 = context24.withVariable("loop:index", loopIndex_44);
              loopIndex_44++;
              final SNode tnode45 = environment.createOutputNode(myConcepts[2]);
              {
                SNodeAccessUtil.setPropertyValue(tnode45, myProperties[0], QueriesGenerated.propertyMacro_GetValue_3_2(new PropertyMacroContext(context24, "param", propertyMacro2)));
                TemplateContext context25 = context24.subContext();
                {
                  Collection<SNode> tlist46 = null;
                  {
                    final SNode switchInput46 = QueriesGenerated.sourceNodeQuery_3_3(new SourceSubstituteMacroNodeContext(context25, switchMacroRef));
                    if (switchInput46 == null) {
                      tlist46 = Collections.emptyList();
                    } else {
                      TemplateContext switchContext46 = context25;
                      switchContext46 = switchContext46.subContext(null, switchInput46);
                      tlist46 = environment.trySwitch(templateSwitchNode, switchContext46);
                      if (tlist46 == null) {
                        final SNode tnode47 = environment.createOutputNode(myConcepts[3]);
                        environment.associate(tnode47, myAssociationLinks[0], "6354ebe7-c22a-4a0f-ac54-50b52ab9b065/java:java.lang(JDK/)", "~Object");
                        tlist46 = TemplateUtil.singletonList(tnode47);
                      }
                    }
                  }
                  environment.aggregate(tnode45, myAggregationLinks[0], tlist46);
                }
              }
              environment.registerLabel(itnode44, tnode45, "parametersFromExpressionsL");
              tlist44.add(tnode45);
            }
            environment.aggregate(tnode2, myAggregationLinks[1], tlist44);
          }
        }
        environment.aggregate(tnode1, myAggregationLinks[14], tnode2);
      }
      {
        final SNode tnode48 = environment.createOutputNode(myConcepts[18]);
        {
          environment.resolveInTemplateLater(tnode48, myAssociationLinks[1], templateNode, "tpl/r:00000000-0000-4000-0000-011c8959034c/429601079676709245", "createNode", context1);
          TemplateContext context26 = context1.subContext();
          {
            Collection<SNode> tlist49 = Collections.emptyList();
            if (QueriesGenerated.ifMacro_Condition_3_5(new IfMacroContext(context26, ifMacroRef5))) {
              Collection<SNode> tlist50 = null;
              final SNode copySrcInput50 = QueriesGenerated.sourceNodeQuery_3_4(new SourceSubstituteMacroNodeContext(context26, copySrcMacro));
              tlist50 = environment.copyNodes(TemplateUtil.singletonList(copySrcInput50), copySrcMacro, "tpl/r:00000000-0000-4000-0000-011c8959034c/2760023158766950556", context26);
              tlist49 = tlist50;
            }
            environment.aggregate(tnode48, myAggregationLinks[7], tlist49);
          }
          {
            Collection<SNode> tlist51 = Collections.emptyList();
            if (QueriesGenerated.ifMacro_Condition_3_6(new IfMacroContext(context26, ifMacroRef6))) {
              Collection<SNode> tlist52 = null;
              final SNode copySrcInput52 = QueriesGenerated.sourceNodeQuery_3_5(new SourceSubstituteMacroNodeContext(context26, copySrcMacro1));
              tlist52 = environment.copyNodes(TemplateUtil.singletonList(copySrcInput52), copySrcMacro1, "tpl/r:00000000-0000-4000-0000-011c8959034c/7191184120224413998", context26);
              tlist51 = tlist52;
            }
            environment.aggregate(tnode48, myAggregationLinks[7], tlist51);
          }
          {
            final List<SNode> tlist53 = new ArrayList<SNode>();
            final Iterable<SNode> loopList53 = QueriesGenerated.sourceNodesQuery_3_2(new SourceSubstituteMacroNodesContext(context26, loopMacroRef2));
            for (SNode itnode53 : loopList53) {
              if (itnode53 == null) {
                continue;
              }
              TemplateContext context27 = context26.subContext(itnode53);
              Collection<SNode> tlist54 = null;
              final SNode copySrcInput54 = context27.getInput();
              tlist54 = environment.copyNodes(TemplateUtil.singletonList(copySrcInput54), copySrcMacro2, "tpl/r:00000000-0000-4000-0000-011c8959034c/291641273397109128", context27);
              tlist53.addAll(tlist54);
            }
            environment.aggregate(tnode48, myAggregationLinks[7], tlist53);
          }
        }
        environment.aggregate(tnode1, myAggregationLinks[15], tnode48);
      }
    }
    FragmentResult rv = nodeFragment(16, tnode1);
    return rv;
  }