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

/*Generated by MPS */

import jetbrains.mps.generator.runtime.Generated;
import jetbrains.mps.generator.runtime.TemplateSwitchBase;
import jetbrains.mps.generator.runtime.TemplateSwitchMapping;
import jetbrains.mps.generator.runtime.TemplateReductionRule;
import jetbrains.mps.generator.runtime.TemplateUtil;
import org.jetbrains.mps.openapi.model.SNodeReference;
import jetbrains.mps.smodel.SNodePointer;
import java.util.Collection;
import org.jetbrains.mps.openapi.model.SNode;
import jetbrains.mps.generator.runtime.TemplateContext;
import jetbrains.mps.generator.runtime.GenerationException;
import jetbrains.mps.generator.runtime.TemplateExecutionEnvironment;
import jetbrains.mps.generator.impl.DismissTopMappingRuleException;
import jetbrains.mps.generator.runtime.ReductionRuleBase;
import org.jetbrains.annotations.NotNull;
import jetbrains.mps.generator.template.SourceSubstituteMacroNodeContext;
import java.util.Collections;
import org.jetbrains.mps.openapi.model.SNodeAccessUtil;
import jetbrains.mps.generator.template.PropertyMacroContext;
import jetbrains.mps.generator.template.IfMacroContext;
import jetbrains.mps.generator.impl.reference.RefResolver;
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 Switch_switch_EnumOperation_Old extends TemplateSwitchBase implements TemplateSwitchMapping {
  private final Iterable<TemplateReductionRule> rules;
  public Switch_switch_EnumOperation_Old() {
    super(new MO());
    rules = TemplateUtil.<TemplateReductionRule>asIterable(new ReductionRule0(), new ReductionRule1(), new ReductionRule2(), new ReductionRule3());
  }
  public SNodeReference getSwitchNode() {
    return new SNodePointer("r:00000000-0000-4000-0000-011c89590303(jetbrains.mps.lang.smodel.generator.baseLanguage.template.main@generator)", "2733396919552946201");
  }
  public SNodeReference getModifiesSwitch() {
    return null;
  }
  public Iterable<TemplateReductionRule> getReductionRules() {
    return rules;
  }
  public Collection<SNode> applyDefault(final TemplateContext context) throws GenerationException {
    final TemplateExecutionEnvironment environment = context.getEnvironment();
    DismissTopMappingRuleException ex_r2nkwx_a = new DismissTopMappingRuleException(DismissTopMappingRuleException.MessageType.error, "Unsupported enum operation");
    ex_r2nkwx_a.setTemplateContext(context);
    ex_r2nkwx_a.setTemplateModelLocation(new SNodePointer("r:00000000-0000-4000-0000-011c89590303(jetbrains.mps.lang.smodel.generator.baseLanguage.template.main@generator)", "2733396919552952274"));
    throw ex_r2nkwx_a;
  }
  /*package*/ final class ReductionRule0 extends ReductionRuleBase {
    public ReductionRule0() {
      super(new SNodePointer("r:00000000-0000-4000-0000-011c89590303(jetbrains.mps.lang.smodel.generator.baseLanguage.template.main@generator)", "2733396919552951783"), CONCEPTS.SEnum_MemberOperation_Old$my, true);
    }
    @Override
    public Collection<SNode> apply(@NotNull final TemplateContext context) throws GenerationException {
      final TemplateExecutionEnvironment environment = context.getEnvironment();
      final SNode tnode1 = environment.createOutputNode(myConcepts[0]);
      {
        environment.associate(tnode1, myAssociationLinks[0], "r:c3548bac-30eb-4a2a-937c-0111d5697309(jetbrains.mps.lang.smodel.generator.smodelAdapter)", "1101499704720825413");
        environment.associate(tnode1, myAssociationLinks[1], "r:c3548bac-30eb-4a2a-937c-0111d5697309(jetbrains.mps.lang.smodel.generator.smodelAdapter)", "1421157252385165433");
        TemplateContext context1 = context.subContext();
        {
          Collection<SNode> tlist2 = null;
          SNode callInputNode2 = QueriesGenerated.sourceNodeQuery_115_0(new SourceSubstituteMacroNodeContext(context1, callMacro));
          TemplateContext context2 = context1;
          context2 = context2.subContext(null, callInputNode2);
          if (callInputNode2 != null) {
            tlist2 = environment.callSite(new Template_reduce_EnumDeclaration_indentityValueSequence(), new SNodePointer("r:00000000-0000-4000-0000-011c89590303(jetbrains.mps.lang.smodel.generator.baseLanguage.template.main@generator)", "2733396919553278886")).apply(context2);
          } else {
            tlist2 = Collections.emptyList();
          }
          environment.aggregate(tnode1, myAggregationLinks[0], tlist2);
        }
        {
          final SNode tnode3 = environment.createOutputNode(myConcepts[1]);
          SNodeAccessUtil.setPropertyValue(tnode3, myProperties[0], QueriesGenerated.propertyMacro_GetValue_115_0(new PropertyMacroContext(context1, "1L", propertyMacro)));
          environment.aggregate(tnode1, myAggregationLinks[0], tnode3);
        }
        {
          Collection<SNode> tlist4 = Collections.emptyList();
          if (QueriesGenerated.ifMacro_Condition_115_0(new IfMacroContext(context1, ifMacroRef))) {
            final SNode tnode5 = environment.createOutputNode(myConcepts[2]);
            SNodeAccessUtil.setPropertyValue(tnode5, myProperties[1], QueriesGenerated.propertyMacro_GetValue_115_1(new PropertyMacroContext(context1, "v", propertyMacro1)));
            tlist4 = TemplateUtil.singletonList(tnode5);
          } else {
            final SNode tnode6 = environment.createOutputNode(myConcepts[3]);
            tlist4 = TemplateUtil.singletonList(tnode6);
          }
          environment.aggregate(tnode1, myAggregationLinks[0], tlist4);
        }
      }
      return TemplateUtil.singletonList(tnode1);
    }
  }
  /*package*/ final class ReductionRule1 extends ReductionRuleBase {
    public ReductionRule1() {
      super(new SNodePointer("r:00000000-0000-4000-0000-011c89590303(jetbrains.mps.lang.smodel.generator.baseLanguage.template.main@generator)", "2733396919552952244"), CONCEPTS.SEnum_MembersOperation_Old$gb, true);
    }
    @Override
    public Collection<SNode> apply(@NotNull final TemplateContext context) throws GenerationException {
      final TemplateExecutionEnvironment environment = context.getEnvironment();
      final SNode tnode1 = environment.createOutputNode(myConcepts[0]);
      {
        environment.associate(tnode1, myAssociationLinks[0], "r:c3548bac-30eb-4a2a-937c-0111d5697309(jetbrains.mps.lang.smodel.generator.smodelAdapter)", "1101499704720825413");
        environment.resolve(new RefResolver(tnode1, myAssociationLinks[1], context, new SNodePointer("r:00000000-0000-4000-0000-011c89590303(jetbrains.mps.lang.smodel.generator.baseLanguage.template.main@generator)", "5171076324157707645"), "getMembers") {
          @Override
          public Object resolve() {
            return QueriesGenerated.referenceMacro_GetReferent_115_0(createQueryContext());
          }
        });
        TemplateContext context1 = context.subContext();
        {
          Collection<SNode> tlist2 = null;
          SNode callInputNode2 = QueriesGenerated.sourceNodeQuery_115_1(new SourceSubstituteMacroNodeContext(context1, callMacro1));
          TemplateContext context2 = context1;
          context2 = context2.subContext(null, callInputNode2);
          if (callInputNode2 != null) {
            tlist2 = environment.callSite(new Template_reduce_EnumDeclaration_indentityValueSequence(), new SNodePointer("r:00000000-0000-4000-0000-011c89590303(jetbrains.mps.lang.smodel.generator.baseLanguage.template.main@generator)", "5171076324157703563")).apply(context2);
          } else {
            tlist2 = Collections.emptyList();
          }
          environment.aggregate(tnode1, myAggregationLinks[0], tlist2);
        }
      }
      return TemplateUtil.singletonList(tnode1);
    }
  }
  /*package*/ final class ReductionRule2 extends ReductionRuleBase {
    public ReductionRule2() {
      super(new SNodePointer("r:00000000-0000-4000-0000-011c89590303(jetbrains.mps.lang.smodel.generator.baseLanguage.template.main@generator)", "2733396919552952250"), CONCEPTS.SEnum_MemberForNameOperation_Old$mz, true);
    }
    @Override
    public Collection<SNode> apply(@NotNull final TemplateContext context) throws GenerationException {
      final TemplateExecutionEnvironment environment = context.getEnvironment();
      final SNode tnode1 = environment.createOutputNode(myConcepts[0]);
      {
        environment.associate(tnode1, myAssociationLinks[0], "r:c3548bac-30eb-4a2a-937c-0111d5697309(jetbrains.mps.lang.smodel.generator.smodelAdapter)", "1101499704720825413");
        environment.associate(tnode1, myAssociationLinks[1], "r:c3548bac-30eb-4a2a-937c-0111d5697309(jetbrains.mps.lang.smodel.generator.smodelAdapter)", "1007227851265433449");
        TemplateContext context1 = context.subContext();
        {
          Collection<SNode> tlist2 = null;
          final SNode copySrcInput2 = QueriesGenerated.sourceNodeQuery_115_2(new SourceSubstituteMacroNodeContext(context1, copySrcMacro));
          tlist2 = environment.copyNodes(TemplateUtil.singletonList(copySrcInput2), copySrcMacro, "tpl/r:00000000-0000-4000-0000-011c89590303/2733396919553280458", context1);
          environment.aggregate(tnode1, myAggregationLinks[0], tlist2);
        }
        {
          Collection<SNode> tlist3 = null;
          SNode callInputNode3 = QueriesGenerated.sourceNodeQuery_115_3(new SourceSubstituteMacroNodeContext(context1, callMacro2));
          TemplateContext context2 = context1;
          context2 = context2.subContext(null, callInputNode3);
          if (callInputNode3 != null) {
            tlist3 = environment.callSite(new Template_reduce_EnumDeclaration_indentityValueSequence(), new SNodePointer("r:00000000-0000-4000-0000-011c89590303(jetbrains.mps.lang.smodel.generator.baseLanguage.template.main@generator)", "2733396919553280585")).apply(context2);
          } else {
            tlist3 = Collections.emptyList();
          }
          environment.aggregate(tnode1, myAggregationLinks[0], tlist3);
        }
      }
      return TemplateUtil.singletonList(tnode1);
    }
  }
  /*package*/ final class ReductionRule3 extends ReductionRuleBase {
    public ReductionRule3() {
      super(new SNodePointer("r:00000000-0000-4000-0000-011c89590303(jetbrains.mps.lang.smodel.generator.baseLanguage.template.main@generator)", "2733396919552952258"), CONCEPTS.SEnum_MemberForValueOperation_Old$Nz, true);
    }
    @Override
    public Collection<SNode> apply(@NotNull final TemplateContext context) throws GenerationException {
      final TemplateExecutionEnvironment environment = context.getEnvironment();
      final SNode tnode1 = environment.createOutputNode(myConcepts[0]);
      {
        environment.associate(tnode1, myAssociationLinks[1], "r:c3548bac-30eb-4a2a-937c-0111d5697309(jetbrains.mps.lang.smodel.generator.smodelAdapter)", "2733396919552565911");
        environment.associate(tnode1, myAssociationLinks[0], "r:c3548bac-30eb-4a2a-937c-0111d5697309(jetbrains.mps.lang.smodel.generator.smodelAdapter)", "1101499704720825413");
        TemplateContext context1 = context.subContext();
        {
          Collection<SNode> tlist2 = Collections.emptyList();
          if (QueriesGenerated.ifMacro_Condition_115_1(new IfMacroContext(context1, ifMacroRef1))) {
            final SNode tnode3 = environment.createOutputNode(myConcepts[4]);
            {
              TemplateContext context2 = context1.subContext();
              {
                final SNode tnode4 = environment.createOutputNode(myConcepts[2]);
                tnode4.setProperty(myProperties[1], "");
                environment.aggregate(tnode3, myAggregationLinks[1], tnode4);
              }
              {
                Collection<SNode> tlist5 = null;
                final SNode copySrcInput5 = QueriesGenerated.sourceNodeQuery_115_5(new SourceSubstituteMacroNodeContext(context2, copySrcMacro1));
                tlist5 = environment.copyNodes(TemplateUtil.singletonList(copySrcInput5), copySrcMacro1, "tpl/r:00000000-0000-4000-0000-011c89590303/2733396919553298545", context2);
                environment.aggregate(tnode3, myAggregationLinks[2], tlist5);
              }
            }
            tlist2 = TemplateUtil.singletonList(tnode3);
          } else {
            Collection<SNode> tlist6 = null;
            final SNode copySrcInput6 = QueriesGenerated.sourceNodeQuery_115_4(new SourceSubstituteMacroNodeContext(context1, copySrcMacro2));
            tlist6 = environment.copyNodes(TemplateUtil.singletonList(copySrcInput6), copySrcMacro2, "tpl/r:00000000-0000-4000-0000-011c89590303/2733396919553298532", context1);
            tlist2 = tlist6;
          }
          environment.aggregate(tnode1, myAggregationLinks[0], tlist2);
        }
        {
          Collection<SNode> tlist7 = null;
          SNode callInputNode7 = QueriesGenerated.sourceNodeQuery_115_6(new SourceSubstituteMacroNodeContext(context1, callMacro3));
          TemplateContext context3 = context1;
          context3 = context3.subContext(null, callInputNode7);
          if (callInputNode7 != null) {
            tlist7 = environment.callSite(new Template_reduce_EnumDeclaration_indentityValueSequence(), new SNodePointer("r:00000000-0000-4000-0000-011c89590303(jetbrains.mps.lang.smodel.generator.baseLanguage.template.main@generator)", "2733396919553281070")).apply(context3);
          } else {
            tlist7 = Collections.emptyList();
          }
          environment.aggregate(tnode1, myAggregationLinks[0], tlist7);
        }
      }
      return TemplateUtil.singletonList(tnode1);
    }
  }

  /*package*/ static final class MO implements MetaObjectContainer {
    @Override
    public SConcept[] concepts() {
      SConcept[] rv = new SConcept[5];
      rv[0] = MetaAdapterFactory.getConcept(MetaAdapterFactory.getLanguage(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, "jetbrains.mps.baseLanguage"), 0xfbbebabf09L, "StaticMethodCall");
      rv[1] = MetaAdapterFactory.getConcept(MetaAdapterFactory.getLanguage(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, "jetbrains.mps.baseLanguage"), 0x3b418722717710b4L, "LongLiteral");
      rv[2] = MetaAdapterFactory.getConcept(MetaAdapterFactory.getLanguage(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, "jetbrains.mps.baseLanguage"), 0xf93d565d10L, "StringLiteral");
      rv[3] = MetaAdapterFactory.getConcept(MetaAdapterFactory.getLanguage(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, "jetbrains.mps.baseLanguage"), 0xf940cd6167L, "NullLiteral");
      rv[4] = MetaAdapterFactory.getConcept(MetaAdapterFactory.getLanguage(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, "jetbrains.mps.baseLanguage"), 0xf8cc67c7fbL, "PlusExpression");
      return rv;
    }

    @Override
    public SProperty[] properties() {
      SProperty[] rv = new SProperty[2];
      rv[0] = MetaAdapterFactory.getProperty(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x3b418722717710b4L, 0x3b418722717710b5L, "value");
      rv[1] = MetaAdapterFactory.getProperty(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf93d565d10L, 0xf93d565d11L, "value");
      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[3];
      rv[0] = MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x11857355952L, 0xf8c78301aeL, "actualArgument");
      rv[1] = MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xfbdeb6fecfL, 0xfbdeb7a11cL, "leftExpression");
      rv[2] = MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xfbdeb6fecfL, 0xfbdeb7a11bL, "rightExpression");
      return rv;
    }
  }
  private static final SNodePointer callMacro = new SNodePointer("r:00000000-0000-4000-0000-011c89590303(jetbrains.mps.lang.smodel.generator.baseLanguage.template.main@generator)", "2733396919553278886");
  private static final SNodePointer propertyMacro = new SNodePointer("r:00000000-0000-4000-0000-011c89590303(jetbrains.mps.lang.smodel.generator.baseLanguage.template.main@generator)", "2733396919553278888");
  private static final SNodePointer propertyMacro1 = new SNodePointer("r:00000000-0000-4000-0000-011c89590303(jetbrains.mps.lang.smodel.generator.baseLanguage.template.main@generator)", "2733396919553278913");
  private static final SNodePointer ifMacroRef = new SNodePointer("r:00000000-0000-4000-0000-011c89590303(jetbrains.mps.lang.smodel.generator.baseLanguage.template.main@generator)", "5374941486721969419");
  private static final SNodePointer callMacro1 = new SNodePointer("r:00000000-0000-4000-0000-011c89590303(jetbrains.mps.lang.smodel.generator.baseLanguage.template.main@generator)", "5171076324157703563");
  private static final SNodePointer copySrcMacro = new SNodePointer("r:00000000-0000-4000-0000-011c89590303(jetbrains.mps.lang.smodel.generator.baseLanguage.template.main@generator)", "2733396919553294540");
  private static final SNodePointer callMacro2 = new SNodePointer("r:00000000-0000-4000-0000-011c89590303(jetbrains.mps.lang.smodel.generator.baseLanguage.template.main@generator)", "2733396919553280585");
  private static final SNodePointer copySrcMacro1 = new SNodePointer("r:00000000-0000-4000-0000-011c89590303(jetbrains.mps.lang.smodel.generator.baseLanguage.template.main@generator)", "2733396919553298546");
  private static final SNodePointer ifMacroRef1 = new SNodePointer("r:00000000-0000-4000-0000-011c89590303(jetbrains.mps.lang.smodel.generator.baseLanguage.template.main@generator)", "2733396919553298520");
  private static final SNodePointer copySrcMacro2 = new SNodePointer("r:00000000-0000-4000-0000-011c89590303(jetbrains.mps.lang.smodel.generator.baseLanguage.template.main@generator)", "2733396919553298533");
  private static final SNodePointer callMacro3 = new SNodePointer("r:00000000-0000-4000-0000-011c89590303(jetbrains.mps.lang.smodel.generator.baseLanguage.template.main@generator)", "2733396919553281070");

  private static final class CONCEPTS {
    /*package*/ static final SConcept SEnum_MemberOperation_Old$my = MetaAdapterFactory.getConcept(0x7866978ea0f04cc7L, 0x81bc4d213d9375e1L, 0x120ed37e691L, "jetbrains.mps.lang.smodel.structure.SEnum_MemberOperation_Old");
    /*package*/ static final SConcept SEnum_MembersOperation_Old$gb = MetaAdapterFactory.getConcept(0x7866978ea0f04cc7L, 0x81bc4d213d9375e1L, 0x120ed37e6b4L, "jetbrains.mps.lang.smodel.structure.SEnum_MembersOperation_Old");
    /*package*/ static final SConcept SEnum_MemberForNameOperation_Old$mz = MetaAdapterFactory.getConcept(0x7866978ea0f04cc7L, 0x81bc4d213d9375e1L, 0x120ed37e60cL, "jetbrains.mps.lang.smodel.structure.SEnum_MemberForNameOperation_Old");
    /*package*/ static final SConcept SEnum_MemberForValueOperation_Old$Nz = MetaAdapterFactory.getConcept(0x7866978ea0f04cc7L, 0x81bc4d213d9375e1L, 0x120ed37e64eL, "jetbrains.mps.lang.smodel.structure.SEnum_MemberForValueOperation_Old");
  }
}
