package jetbrains.mps.lang.smodel.generator.baseLanguage.template.main;

/*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.smodel.SNodePointer;
import jetbrains.mps.generator.runtime.FragmentResult;
import org.jetbrains.annotations.NotNull;
import jetbrains.mps.generator.runtime.TemplateContext;
import jetbrains.mps.generator.runtime.GenerationException;
import jetbrains.mps.generator.runtime.TemplateExecutionEnvironment;
import org.jetbrains.mps.openapi.model.SNode;
import java.util.Collection;
import jetbrains.mps.generator.template.SourceSubstituteMacroNodeContext;
import jetbrains.mps.generator.runtime.TemplateUtil;
import jetbrains.mps.generator.impl.reference.RefResolver;
import java.util.Collections;
import jetbrains.mps.generator.runtime.ApplySink;
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.SReferenceLink;
import org.jetbrains.mps.openapi.language.SContainmentLink;

@Generated
public class Template_reduce_SPropertyAccess extends TemplateDeclarationBase {

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

  public SNodeReference getTemplateNode() {
    return new SNodePointer("r:00000000-0000-4000-0000-011c89590303(jetbrains.mps.lang.smodel.generator.baseLanguage.template.main@generator)", "1139275804866");
  }


  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();
      {
        Collection<SNode> tlist2 = null;
        final SNode copySrcInput2 = QueriesGenerated.sourceNodeQuery_128_0(new SourceSubstituteMacroNodeContext(context1, copySrcMacro));
        tlist2 = environment.copyNodes(TemplateUtil.singletonList(copySrcInput2), copySrcMacro, "tpl/r:00000000-0000-4000-0000-011c89590303/5834820604012843091", context1);
        environment.aggregate(tnode1, myAggregationLinks[0], tlist2);
      }
      {
        final SNode tnode3 = environment.createOutputNode(myConcepts[1]);
        {
          environment.associate(tnode3, myAssociationLinks[0], "r:c3548bac-30eb-4a2a-937c-0111d5697309(jetbrains.mps.lang.smodel.generator.smodelAdapter)", "6599163591527298519");
          environment.resolve(new RefResolver(tnode3, myAssociationLinks[1], context1, new SNodePointer("r:00000000-0000-4000-0000-011c89590303(jetbrains.mps.lang.smodel.generator.baseLanguage.template.main@generator)", "1139275804876"), "getString") {
            @Override
            public Object resolve() {
              return QueriesGenerated.referenceMacro_GetReferent_128_0(createQueryContext());
            }
          });
          TemplateContext context2 = context1.subContext();
          {
            Collection<SNode> tlist4 = null;
            final SNode copySrcInput4 = QueriesGenerated.sourceNodeQuery_128_1(new SourceSubstituteMacroNodeContext(context2, copySrcMacro1));
            tlist4 = environment.copyNodes(TemplateUtil.singletonList(copySrcInput4), copySrcMacro1, "tpl/r:00000000-0000-4000-0000-011c89590303/1139275804870", context2);
            environment.aggregate(tnode3, myAggregationLinks[1], tlist4);
          }
          {
            Collection<SNode> tlist5 = null;
            SNode callInputNode5 = QueriesGenerated.sourceNodeQuery_128_2(new SourceSubstituteMacroNodeContext(context2, callMacro));
            TemplateContext context3 = context2;
            context3 = context3.subContext(null, callInputNode5);
            if (callInputNode5 != null) {
              tlist5 = environment.callSite(new Template_reduce_PropertyDeclaration_SProperty(), new SNodePointer("r:00000000-0000-4000-0000-011c89590303(jetbrains.mps.lang.smodel.generator.baseLanguage.template.main@generator)", "633481135935145280")).apply(context3);
            } else {
              tlist5 = Collections.emptyList();
            }
            environment.aggregate(tnode3, myAggregationLinks[1], tlist5);
          }
        }
        environment.aggregate(tnode1, myAggregationLinks[2], tnode3);
      }
      {
        final SNode tnode6 = environment.createOutputNode(myConcepts[1]);
        {
          environment.associate(tnode6, myAssociationLinks[0], "6ed54515-acc8-4d1e-a16c-9fd6cfe951ea/java:jetbrains.mps.lang.smodel.generator.smodelAdapter(MPS.Core/)", "~SPropertyOperations");
          environment.resolve(new RefResolver(tnode6, myAssociationLinks[1], context1, new SNodePointer("r:00000000-0000-4000-0000-011c89590303(jetbrains.mps.lang.smodel.generator.baseLanguage.template.main@generator)", "5834820604012870031"), "stringPropRef") {
            @Override
            public Object resolve() {
              return QueriesGenerated.referenceMacro_GetReferent_128_1(createQueryContext());
            }
          });
          TemplateContext context4 = context1.subContext();
          {
            Collection<SNode> tlist7 = null;
            final SNode copySrcInput7 = QueriesGenerated.sourceNodeQuery_128_3(new SourceSubstituteMacroNodeContext(context4, copySrcMacro2));
            tlist7 = environment.copyNodes(TemplateUtil.singletonList(copySrcInput7), copySrcMacro2, "tpl/r:00000000-0000-4000-0000-011c89590303/5834820604012870998", context4);
            environment.aggregate(tnode6, myAggregationLinks[1], tlist7);
          }
          {
            Collection<SNode> tlist8 = null;
            SNode callInputNode8 = QueriesGenerated.sourceNodeQuery_128_4(new SourceSubstituteMacroNodeContext(context4, callMacro1));
            TemplateContext context5 = context4;
            context5 = context5.subContext(null, callInputNode8);
            if (callInputNode8 != null) {
              tlist8 = environment.callSite(new Template_reduce_PropertyDeclaration_SProperty(), new SNodePointer("r:00000000-0000-4000-0000-011c89590303(jetbrains.mps.lang.smodel.generator.baseLanguage.template.main@generator)", "5834820604012871007")).apply(context5);
            } else {
              tlist8 = Collections.emptyList();
            }
            environment.aggregate(tnode6, myAggregationLinks[1], tlist8);
          }
        }
        environment.aggregate(tnode1, myAggregationLinks[3], tnode6);
      }
      {
        final SNode tnode9 = environment.createOutputNode(myConcepts[1]);
        {
          environment.associate(tnode9, myAssociationLinks[0], "r:c3548bac-30eb-4a2a-937c-0111d5697309(jetbrains.mps.lang.smodel.generator.smodelAdapter)", "6599163591527298519");
          environment.resolve(new RefResolver(tnode9, myAssociationLinks[1], context1, new SNodePointer("r:00000000-0000-4000-0000-011c89590303(jetbrains.mps.lang.smodel.generator.baseLanguage.template.main@generator)", "5834820604012874896"), "assign") {
            @Override
            public Object resolve() {
              return QueriesGenerated.referenceMacro_GetReferent_128_2(createQueryContext());
            }
          });
          TemplateContext context6 = context1.subContext();
          {
            Collection<SNode> tlist10 = null;
            final SNode copySrcInput10 = QueriesGenerated.sourceNodeQuery_128_5(new SourceSubstituteMacroNodeContext(context6, copySrcMacro3));
            tlist10 = environment.copyNodes(TemplateUtil.singletonList(copySrcInput10), copySrcMacro3, "tpl/r:00000000-0000-4000-0000-011c89590303/5834820604012874880", context6);
            environment.aggregate(tnode9, myAggregationLinks[1], tlist10);
          }
          {
            Collection<SNode> tlist11 = null;
            SNode callInputNode11 = QueriesGenerated.sourceNodeQuery_128_6(new SourceSubstituteMacroNodeContext(context6, callMacro2));
            TemplateContext context7 = context6;
            context7 = context7.subContext(null, callInputNode11);
            if (callInputNode11 != null) {
              tlist11 = environment.callSite(new Template_reduce_PropertyDeclaration_SProperty(), new SNodePointer("r:00000000-0000-4000-0000-011c89590303(jetbrains.mps.lang.smodel.generator.baseLanguage.template.main@generator)", "5834820604012874889")).apply(context7);
            } else {
              tlist11 = Collections.emptyList();
            }
            environment.aggregate(tnode9, myAggregationLinks[1], tlist11);
          }
          {
            final SNode tnode12 = environment.createOutputNode(myConcepts[2]);
            environment.aggregate(tnode9, myAggregationLinks[1], tnode12);
          }
        }
        environment.aggregate(tnode1, myAggregationLinks[4], tnode9);
      }
    }
    FragmentResult rv = nodeFragment(5, tnode1);
    return rv;
  }
  @Override
  public void apply(TemplateContext context, ApplySink sink) throws GenerationException {
    applyPart0(context).reportTo(sink);
  }

  /*package*/ static final class MO implements MetaObjectContainer {
    @Override
    public SConcept[] concepts() {
      SConcept[] rv = new SConcept[3];
      rv[0] = MetaAdapterFactory.getConcept(MetaAdapterFactory.getLanguage(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, "jetbrains.mps.baseLanguage"), 0x53cc4e75e79ac233L, "GenericLValueExpression");
      rv[1] = MetaAdapterFactory.getConcept(MetaAdapterFactory.getLanguage(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, "jetbrains.mps.baseLanguage"), 0xfbbebabf09L, "StaticMethodCall");
      rv[2] = MetaAdapterFactory.getConcept(MetaAdapterFactory.getLanguage(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, "jetbrains.mps.baseLanguage"), 0x53cc4e75e79ac33aL, "ValueRef");
      return rv;
    }


    @Override
    public SReferenceLink[] associations() {
      SReferenceLink[] rv = new SReferenceLink[2];
      rv[0] = MetaAdapterFactory.getReferenceLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xfbbebabf09L, 0x10a7588b546L, "classConcept");
      rv[1] = MetaAdapterFactory.getReferenceLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x11857355952L, 0xf8c78301adL, "baseMethodDeclaration");
      return rv;
    }

    @Override
    public SContainmentLink[] aggregations() {
      SContainmentLink[] rv = new SContainmentLink[6];
      rv[0] = MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x53cc4e75e79ac233L, 0x723a3e657841dbf2L, "type");
      rv[1] = MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x11857355952L, 0xf8c78301aeL, "actualArgument");
      rv[2] = MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x53cc4e75e79ac233L, 0x53cc4e75e79ac302L, "getValueExpression");
      rv[3] = MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x53cc4e75e79ac233L, 0x5fc1cc47cb46233aL, "referenceExpression");
      rv[4] = MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x53cc4e75e79ac233L, 0x7e4df7e6620fe175L, "assignValueExression");
      rv[5] = MetaAdapterFactory.getContainmentLink(0xb401a68083254110L, 0x8fd384331ff25befL, 0xfe43cb41d0L, 0xfe43de823bL, "contentNode");
      return rv;
    }
  }
  private static final SNodePointer copySrcMacro = new SNodePointer("r:00000000-0000-4000-0000-011c89590303(jetbrains.mps.lang.smodel.generator.baseLanguage.template.main@generator)", "5834820604012843152");
  private static final SNodePointer copySrcMacro1 = new SNodePointer("r:00000000-0000-4000-0000-011c89590303(jetbrains.mps.lang.smodel.generator.baseLanguage.template.main@generator)", "1139275804871");
  private static final SNodePointer callMacro = new SNodePointer("r:00000000-0000-4000-0000-011c89590303(jetbrains.mps.lang.smodel.generator.baseLanguage.template.main@generator)", "633481135935145280");
  private static final SNodePointer copySrcMacro2 = new SNodePointer("r:00000000-0000-4000-0000-011c89590303(jetbrains.mps.lang.smodel.generator.baseLanguage.template.main@generator)", "5834820604012870999");
  private static final SNodePointer callMacro1 = new SNodePointer("r:00000000-0000-4000-0000-011c89590303(jetbrains.mps.lang.smodel.generator.baseLanguage.template.main@generator)", "5834820604012871007");
  private static final SNodePointer copySrcMacro3 = new SNodePointer("r:00000000-0000-4000-0000-011c89590303(jetbrains.mps.lang.smodel.generator.baseLanguage.template.main@generator)", "5834820604012874881");
  private static final SNodePointer callMacro2 = new SNodePointer("r:00000000-0000-4000-0000-011c89590303(jetbrains.mps.lang.smodel.generator.baseLanguage.template.main@generator)", "5834820604012874889");
}
