package jetbrains.mps.transformation.test.inputLang.generator02.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 org.jetbrains.mps.openapi.model.SNodeAccessUtil;
import jetbrains.mps.generator.template.PropertyMacroContext;
import java.util.List;
import java.util.ArrayList;
import jetbrains.mps.generator.template.SourceSubstituteMacroNodesContext;
import java.util.Collection;
import jetbrains.mps.smodel.SNodePointer;
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;

@Generated
public class Template_C extends TemplateDeclarationBase {

  public Template_C() {
    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:3ae70081-5af6-4df2-938d-3936a0c7a546/2676503840832080254");
      SNodeAccessUtil.setPropertyValue(tnode1, myProperties[0], QueriesGenerated.propertyMacro_GetValue_6_1(new PropertyMacroContext(context, "C", propertyMacro)));
      TemplateContext context1 = context.subContext();
      {
        final List<SNode> tlist2 = new ArrayList<SNode>();
        final Iterable<SNode> loopList2 = QueriesGenerated.sourceNodesQuery_6_0(new SourceSubstituteMacroNodesContext(context1, loopMacroRef));
        for (SNode itnode2 : loopList2) {
          if (itnode2 == null) {
            continue;
          }
          TemplateContext context2 = context1.subContext("METHOD", itnode2);
          Collection<SNode> tlist3 = null;
          TemplateContext context3 = context2;
          {
            Collection<SNode> tlist4 = null;
            tlist4 = environment.callSite(new Template_reduce_Comment(), new SNodePointer("r:3ae70081-5af6-4df2-938d-3936a0c7a546(jetbrains.mps.transformation.test.inputLang.generator02.templates@generator)", "2676503840832206876")).apply(context3);
            context3 = environment.withCallSiteNode(new SNodePointer("r:3ae70081-5af6-4df2-938d-3936a0c7a546(jetbrains.mps.transformation.test.inputLang.generator02.templates@generator)", "2676503840832205243"), context3, tlist4);
          }
          tlist3 = environment.callSite(new Template_reduce_MethodDeclaration(), new SNodePointer("r:3ae70081-5af6-4df2-938d-3936a0c7a546(jetbrains.mps.transformation.test.inputLang.generator02.templates@generator)", "2676503840832205243")).apply(context3);
          environment.registerLabel(itnode2, tlist3, "METHOD");
          tlist2.addAll(tlist3);
        }
        environment.aggregate(tnode1, myAggregationLinks[0], tlist2);
      }
      {
        final SNode tnode5 = environment.createOutputNode(myConcepts[1]);
        environment.aggregate(tnode1, myAggregationLinks[0], tnode5);
      }
      {
        final List<SNode> tlist6 = new ArrayList<SNode>();
        final Iterable<SNode> loopList6 = QueriesGenerated.sourceNodesQuery_6_1(new SourceSubstituteMacroNodesContext(context1, loopMacroRef1));
        for (SNode itnode6 : loopList6) {
          if (itnode6 == null) {
            continue;
          }
          TemplateContext context4 = context1.subContext("TRACE", itnode6);
          final SNode tnode7 = environment.createOutputNode(myConcepts[2]);
          {
            SNodeAccessUtil.setPropertyValue(tnode7, myProperties[0], QueriesGenerated.propertyMacro_GetValue_6_0(new PropertyMacroContext(context4, "trace", propertyMacro1)));
            TemplateContext context5 = context4.subContext();
            {
              final SNode tnode8 = environment.createOutputNode(myConcepts[3]);
              environment.aggregate(tnode7, myAggregationLinks[1], tnode8);
            }
            {
              final SNode tnode9 = environment.createOutputNode(myConcepts[4]);
              environment.aggregate(tnode7, myAggregationLinks[2], tnode9);
            }
            {
              final SNode tnode10 = environment.createOutputNode(myConcepts[5]);
              environment.aggregate(tnode7, myAggregationLinks[3], tnode10);
            }
            {
              final SNode tnode11 = environment.createOutputNode(myConcepts[6]);
              {
                tnode11.setProperty(myProperties[0], "v");
                TemplateContext context6 = context5.subContext();
                {
                  final SNode tnode12 = environment.createOutputNode(myConcepts[7]);
                  environment.associate(tnode12, myAssociationLinks[0], "6354ebe7-c22a-4a0f-ac54-50b52ab9b065/java:java.lang(JDK/)", "~String");
                  environment.aggregate(tnode11, myAggregationLinks[4], tnode12);
                }
              }
              environment.aggregate(tnode7, myAggregationLinks[5], tnode11);
            }
          }
          environment.registerLabel(itnode6, tnode7, "TRACE");
          tlist6.add(tnode7);
        }
        environment.aggregate(tnode1, myAggregationLinks[0], tlist6);
      }
      {
        final SNode tnode13 = environment.createOutputNode(myConcepts[8]);
        environment.aggregate(tnode1, myAggregationLinks[2], tnode13);
      }
    }
    sink.add(null, TemplateUtil.singletonList(tnode1));
  }

  /*package*/ static final class MO implements MetaObjectContainer {
    @Override
    public SConcept[] concepts() {
      SConcept[] rv = new SConcept[9];
      rv[0] = MetaAdapterFactory.getConcept(MetaAdapterFactory.getLanguage(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, "jetbrains.mps.baseLanguage"), 0xf8c108ca66L, "ClassConcept");
      rv[1] = MetaAdapterFactory.getConcept(MetaAdapterFactory.getLanguage(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, "jetbrains.mps.baseLanguage"), 0x1458378889e6d166L, "PlaceholderMember");
      rv[2] = MetaAdapterFactory.getConcept(MetaAdapterFactory.getLanguage(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, "jetbrains.mps.baseLanguage"), 0xf8cc56b21dL, "InstanceMethodDeclaration");
      rv[3] = MetaAdapterFactory.getConcept(MetaAdapterFactory.getLanguage(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, "jetbrains.mps.baseLanguage"), 0xf8cc56b200L, "StatementList");
      rv[4] = MetaAdapterFactory.getConcept(MetaAdapterFactory.getLanguage(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, "jetbrains.mps.baseLanguage"), 0x10af9586f0cL, "PrivateVisibility");
      rv[5] = MetaAdapterFactory.getConcept(MetaAdapterFactory.getLanguage(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, "jetbrains.mps.baseLanguage"), 0xf8cc6bf96dL, "VoidType");
      rv[6] = MetaAdapterFactory.getConcept(MetaAdapterFactory.getLanguage(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, "jetbrains.mps.baseLanguage"), 0xf8c77f1e94L, "ParameterDeclaration");
      rv[7] = MetaAdapterFactory.getConcept(MetaAdapterFactory.getLanguage(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, "jetbrains.mps.baseLanguage"), 0x101de48bf9eL, "ClassifierType");
      rv[8] = MetaAdapterFactory.getConcept(MetaAdapterFactory.getLanguage(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, "jetbrains.mps.baseLanguage"), 0x10af9581ff1L, "PublicVisibility");
      return rv;
    }

    @Override
    public SProperty[] properties() {
      SProperty[] rv = new SProperty[1];
      rv[0] = MetaAdapterFactory.getProperty(0xceab519525ea4f22L, 0x9b92103b95ca8c0cL, 0x110396eaaa4L, 0x110396ec041L, "name");
      return rv;
    }

    @Override
    public SReferenceLink[] associations() {
      SReferenceLink[] rv = new SReferenceLink[1];
      rv[0] = MetaAdapterFactory.getReferenceLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x101de48bf9eL, 0x101de490babL, "classifier");
      return rv;
    }

    @Override
    public SContainmentLink[] aggregations() {
      SContainmentLink[] rv = new SContainmentLink[6];
      rv[0] = MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x101d9d3ca30L, 0x4a9a46de59132803L, "member");
      rv[1] = MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8cc56b1fcL, 0xf8cc56b1ffL, "body");
      rv[2] = MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x112670d273fL, 0x112670d886aL, "visibility");
      rv[3] = MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8cc56b1fcL, 0xf8cc56b1fdL, "returnType");
      rv[4] = MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x450368d90ce15bc3L, 0x4ed4d318133c80ceL, "type");
      rv[5] = MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8cc56b1fcL, 0xf8cc56b1feL, "parameter");
      return rv;
    }
  }
  private static final SNodePointer template = new SNodePointer("r:3ae70081-5af6-4df2-938d-3936a0c7a546(jetbrains.mps.transformation.test.inputLang.generator02.templates@generator)", "2676503840832080254");
  private static final SNodePointer propertyMacro = new SNodePointer("r:3ae70081-5af6-4df2-938d-3936a0c7a546(jetbrains.mps.transformation.test.inputLang.generator02.templates@generator)", "2676503840832080303");
  private static final SNodePointer loopMacroRef = new SNodePointer("r:3ae70081-5af6-4df2-938d-3936a0c7a546(jetbrains.mps.transformation.test.inputLang.generator02.templates@generator)", "2676503840832159994");
  private static final SNodePointer loopMacroRef1 = new SNodePointer("r:3ae70081-5af6-4df2-938d-3936a0c7a546(jetbrains.mps.transformation.test.inputLang.generator02.templates@generator)", "2676503840832428209");
  private static final SNodePointer propertyMacro1 = new SNodePointer("r:3ae70081-5af6-4df2-938d-3936a0c7a546(jetbrains.mps.transformation.test.inputLang.generator02.templates@generator)", "2676503840832430480");
}
