package jetbrains.mps.transformation.test.inputLang.generator05.templates;

/*Generated by MPS */

import jetbrains.mps.generator.runtime.Generated;
import jetbrains.mps.generator.runtime.TemplateDeclarationBase;
import org.jetbrains.mps.openapi.model.SNodeReference;
import jetbrains.mps.generator.runtime.TemplateContext;
import jetbrains.mps.generator.runtime.ApplySink;
import jetbrains.mps.generator.runtime.GenerationException;
import jetbrains.mps.generator.runtime.TemplateExecutionEnvironment;
import org.jetbrains.mps.openapi.model.SNode;
import java.util.List;
import java.util.ArrayList;
import jetbrains.mps.generator.template.SourceSubstituteMacroNodesContext;
import org.jetbrains.mps.openapi.model.SNodeAccessUtil;
import jetbrains.mps.generator.template.PropertyMacroContext;
import jetbrains.mps.generator.runtime.TemplateUtil;
import jetbrains.mps.generator.runtime.MetaObjectContainer;
import org.jetbrains.mps.openapi.language.SConcept;
import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory;
import org.jetbrains.mps.openapi.language.SProperty;
import org.jetbrains.mps.openapi.language.SReferenceLink;
import org.jetbrains.mps.openapi.language.SContainmentLink;
import jetbrains.mps.smodel.SNodePointer;

@Generated
public class Template_map_List extends TemplateDeclarationBase {

  public Template_map_List() {
    super(new MO());
  }

  public SNodeReference getTemplateNode() {
    return template;
  }

  @Override
  public void apply(TemplateContext context, ApplySink sink) throws GenerationException {
    final TemplateExecutionEnvironment environment = context.getEnvironment();
    final SNode tnode1 = environment.createOutputNode(myConcepts[0]);
    {
      environment.nodeCopied(context, tnode1, "tpl/r:5bb953f6-c4e2-4f24-bd95-d2817ceec639/6822924216795151911");
      tnode1.setProperty(myProperties[0], "map_List");
      TemplateContext context1 = context.subContext();
      {
        final SNode tnode2 = environment.createOutputNode(myConcepts[1]);
        {
          tnode2.setProperty(myProperties[0], "main");
          TemplateContext context2 = context1.subContext();
          {
            final SNode tnode3 = environment.createOutputNode(myConcepts[2]);
            {
              TemplateContext context3 = context2.subContext();
              {
                final List<SNode> tlist4 = new ArrayList<SNode>();
                final Iterable<SNode> loopList4 = QueriesGenerated.sourceNodesQuery_1_0(new SourceSubstituteMacroNodesContext(context3, loopMacroRef));
                int loopIndex_4 = 0;
                for (SNode itnode4 : loopList4) {
                  if (itnode4 == null) {
                    continue;
                  }
                  TemplateContext context4 = context3.subContext(itnode4);
                  context4 = context4.withVariable("loop:inputNode", context3.getInput());
                  context4 = context4.withVariable("loop:index", loopIndex_4);
                  loopIndex_4++;
                  final SNode tnode5 = environment.createOutputNode(myConcepts[3]);
                  {
                    TemplateContext context5 = context4.subContext();
                    {
                      final SNode tnode6 = environment.createOutputNode(myConcepts[4]);
                      {
                        TemplateContext context6 = context5.subContext();
                        {
                          final SNode tnode7 = environment.createOutputNode(myConcepts[5]);
                          environment.associate(tnode7, myAssociationLinks[0], "6354ebe7-c22a-4a0f-ac54-50b52ab9b065/java:java.lang(JDK/)", "~System.out");
                          environment.associate(tnode7, myAssociationLinks[1], "6354ebe7-c22a-4a0f-ac54-50b52ab9b065/java:java.lang(JDK/)", "~System");
                          environment.aggregate(tnode6, myAggregationLinks[0], tnode7);
                        }
                        {
                          final SNode tnode8 = environment.createOutputNode(myConcepts[6]);
                          {
                            environment.associate(tnode8, myAssociationLinks[2], "6354ebe7-c22a-4a0f-ac54-50b52ab9b065/java:java.io(JDK/)", "~PrintStream.println(java.lang.String)");
                            TemplateContext context7 = context6.subContext();
                            {
                              final SNode tnode9 = environment.createOutputNode(myConcepts[7]);
                              {
                                TemplateContext context8 = context7.subContext();
                                {
                                  final SNode tnode10 = environment.createOutputNode(myConcepts[7]);
                                  {
                                    TemplateContext context9 = context8.subContext();
                                    {
                                      final SNode tnode11 = environment.createOutputNode(myConcepts[8]);
                                      SNodeAccessUtil.setPropertyValue(tnode11, myProperties[1], QueriesGenerated.propertyMacro_GetValue_1_0(new PropertyMacroContext(context9, "counter", propertyMacro)));
                                      environment.aggregate(tnode10, myAggregationLinks[1], tnode11);
                                    }
                                    {
                                      final SNode tnode12 = environment.createOutputNode(myConcepts[8]);
                                      SNodeAccessUtil.setPropertyValue(tnode12, myProperties[1], QueriesGenerated.propertyMacro_GetValue_1_1(new PropertyMacroContext(context9, "parentName", propertyMacro1)));
                                      environment.aggregate(tnode10, myAggregationLinks[2], tnode12);
                                    }
                                  }
                                  environment.aggregate(tnode9, myAggregationLinks[2], tnode10);
                                }
                                {
                                  final SNode tnode13 = environment.createOutputNode(myConcepts[9]);
                                  SNodeAccessUtil.setPropertyValue(tnode13, myProperties[2], QueriesGenerated.propertyMacro_GetValue_1_2(new PropertyMacroContext(context8, "3", propertyMacro2)));
                                  environment.aggregate(tnode9, myAggregationLinks[1], tnode13);
                                }
                              }
                              environment.aggregate(tnode8, myAggregationLinks[3], tnode9);
                            }
                          }
                          environment.aggregate(tnode6, myAggregationLinks[4], tnode8);
                        }
                      }
                      environment.aggregate(tnode5, myAggregationLinks[5], tnode6);
                    }
                  }
                  tlist4.add(tnode5);
                }
                environment.aggregate(tnode3, myAggregationLinks[6], tlist4);
              }
            }
            environment.aggregate(tnode2, myAggregationLinks[7], tnode3);
          }
          {
            final SNode tnode14 = environment.createOutputNode(myConcepts[10]);
            environment.aggregate(tnode2, myAggregationLinks[8], tnode14);
          }
          {
            final SNode tnode15 = environment.createOutputNode(myConcepts[11]);
            environment.aggregate(tnode2, myAggregationLinks[9], tnode15);
          }
        }
        environment.aggregate(tnode1, myAggregationLinks[10], tnode2);
      }
      {
        final SNode tnode16 = environment.createOutputNode(myConcepts[10]);
        environment.aggregate(tnode1, myAggregationLinks[8], tnode16);
      }
    }
    sink.add(null, TemplateUtil.singletonList(tnode1));
  }

  /*package*/ static final class MO implements MetaObjectContainer {
    @Override
    public SConcept[] concepts() {
      SConcept[] rv = new SConcept[12];
      rv[0] = MetaAdapterFactory.getConcept(MetaAdapterFactory.getLanguage(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, "jetbrains.mps.baseLanguage"), 0xf8c108ca66L, "ClassConcept");
      rv[1] = MetaAdapterFactory.getConcept(MetaAdapterFactory.getLanguage(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, "jetbrains.mps.baseLanguage"), 0xfbbebabf0aL, "StaticMethodDeclaration");
      rv[2] = MetaAdapterFactory.getConcept(MetaAdapterFactory.getLanguage(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, "jetbrains.mps.baseLanguage"), 0xf8cc56b200L, "StatementList");
      rv[3] = MetaAdapterFactory.getConcept(MetaAdapterFactory.getLanguage(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, "jetbrains.mps.baseLanguage"), 0xf8cc56b213L, "ExpressionStatement");
      rv[4] = MetaAdapterFactory.getConcept(MetaAdapterFactory.getLanguage(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, "jetbrains.mps.baseLanguage"), 0x116b46a08c4L, "DotExpression");
      rv[5] = MetaAdapterFactory.getConcept(MetaAdapterFactory.getLanguage(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, "jetbrains.mps.baseLanguage"), 0xf940c80846L, "StaticFieldReference");
      rv[6] = MetaAdapterFactory.getConcept(MetaAdapterFactory.getLanguage(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, "jetbrains.mps.baseLanguage"), 0x118154a6332L, "InstanceMethodCallOperation");
      rv[7] = MetaAdapterFactory.getConcept(MetaAdapterFactory.getLanguage(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, "jetbrains.mps.baseLanguage"), 0xf8cc67c7fbL, "PlusExpression");
      rv[8] = MetaAdapterFactory.getConcept(MetaAdapterFactory.getLanguage(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, "jetbrains.mps.baseLanguage"), 0xf93d565d10L, "StringLiteral");
      rv[9] = MetaAdapterFactory.getConcept(MetaAdapterFactory.getLanguage(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, "jetbrains.mps.baseLanguage"), 0xf8cc59b314L, "IntegerConstant");
      rv[10] = MetaAdapterFactory.getConcept(MetaAdapterFactory.getLanguage(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, "jetbrains.mps.baseLanguage"), 0x10af9581ff1L, "PublicVisibility");
      rv[11] = MetaAdapterFactory.getConcept(MetaAdapterFactory.getLanguage(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, "jetbrains.mps.baseLanguage"), 0xf8cc6bf96dL, "VoidType");
      return rv;
    }

    @Override
    public SProperty[] properties() {
      SProperty[] rv = new SProperty[3];
      rv[0] = MetaAdapterFactory.getProperty(0xceab519525ea4f22L, 0x9b92103b95ca8c0cL, 0x110396eaaa4L, 0x110396ec041L, "name");
      rv[1] = MetaAdapterFactory.getProperty(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf93d565d10L, 0xf93d565d11L, "value");
      rv[2] = MetaAdapterFactory.getProperty(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8cc59b314L, 0xf8cc59b315L, "value");
      return rv;
    }

    @Override
    public SReferenceLink[] associations() {
      SReferenceLink[] rv = new SReferenceLink[3];
      rv[0] = MetaAdapterFactory.getReferenceLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8c77f1e98L, 0xf8cc6bf960L, "variableDeclaration");
      rv[1] = MetaAdapterFactory.getReferenceLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf940c80846L, 0x10a75869f9bL, "classifier");
      rv[2] = MetaAdapterFactory.getReferenceLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x11857355952L, 0xf8c78301adL, "baseMethodDeclaration");
      return rv;
    }

    @Override
    public SContainmentLink[] aggregations() {
      SContainmentLink[] rv = new SContainmentLink[11];
      rv[0] = MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x116b46a08c4L, 0x116b46a4416L, "operand");
      rv[1] = MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xfbdeb6fecfL, 0xfbdeb7a11bL, "rightExpression");
      rv[2] = MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xfbdeb6fecfL, 0xfbdeb7a11cL, "leftExpression");
      rv[3] = MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x11857355952L, 0xf8c78301aeL, "actualArgument");
      rv[4] = MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x116b46a08c4L, 0x116b46b36c4L, "operation");
      rv[5] = MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8cc56b213L, 0xf8cc56b214L, "expression");
      rv[6] = MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8cc56b200L, 0xf8cc6bf961L, "statement");
      rv[7] = MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8cc56b1fcL, 0xf8cc56b1ffL, "body");
      rv[8] = MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x112670d273fL, 0x112670d886aL, "visibility");
      rv[9] = MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8cc56b1fcL, 0xf8cc56b1fdL, "returnType");
      rv[10] = MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x101d9d3ca30L, 0x4a9a46de59132803L, "member");
      return rv;
    }
  }
  private static final SNodePointer template = new SNodePointer("r:5bb953f6-c4e2-4f24-bd95-d2817ceec639(jetbrains.mps.transformation.test.inputLang.generator05.templates@generator)", "6822924216795151911");
  private static final SNodePointer loopMacroRef = new SNodePointer("r:5bb953f6-c4e2-4f24-bd95-d2817ceec639(jetbrains.mps.transformation.test.inputLang.generator05.templates@generator)", "6822924216795152067");
  private static final SNodePointer propertyMacro = new SNodePointer("r:5bb953f6-c4e2-4f24-bd95-d2817ceec639(jetbrains.mps.transformation.test.inputLang.generator05.templates@generator)", "6822924216795160675");
  private static final SNodePointer propertyMacro1 = new SNodePointer("r:5bb953f6-c4e2-4f24-bd95-d2817ceec639(jetbrains.mps.transformation.test.inputLang.generator05.templates@generator)", "6822924216795154703");
  private static final SNodePointer propertyMacro2 = new SNodePointer("r:5bb953f6-c4e2-4f24-bd95-d2817ceec639(jetbrains.mps.transformation.test.inputLang.generator05.templates@generator)", "1521022997430071102");
}
