package jetbrains.mps.lang.editor.tooltips.generator.template.main;

/*Generated by MPS */

import jetbrains.mps.generator.runtime.Generated;
import jetbrains.mps.generator.impl.query.QueryProviderBase;
import jetbrains.mps.generator.template.CreateRootRuleContext;
import jetbrains.mps.internal.collections.runtime.ListSequence;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SModelOperations;
import jetbrains.mps.generator.template.BaseMappingRuleContext;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SLinkOperations;
import jetbrains.mps.generator.template.PropertyMacroContext;
import org.jetbrains.mps.openapi.model.SNode;
import jetbrains.mps.lang.editor.behavior.ConceptEditorHintDeclaration__BehaviorDescriptor;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SPropertyOperations;
import jetbrains.mps.lang.editor.behavior.EditorCellModel__BehaviorDescriptor;
import jetbrains.mps.generator.template.ReferenceMacroContext;
import jetbrains.mps.generator.template.SourceSubstituteMacroNodeContext;
import jetbrains.mps.generator.template.SourceSubstituteMacroNodesContext;
import java.util.Map;
import jetbrains.mps.generator.impl.query.ReductionRuleCondition;
import java.util.HashMap;
import org.jetbrains.annotations.NotNull;
import jetbrains.mps.generator.impl.query.QueryKey;
import jetbrains.mps.generator.template.ReductionRuleQueryContext;
import jetbrains.mps.generator.impl.GenerationFailureException;
import jetbrains.mps.generator.impl.query.MapRootRuleCondition;
import jetbrains.mps.generator.template.MapRootRuleContext;
import jetbrains.mps.generator.impl.query.CreateRootCondition;
import jetbrains.mps.generator.impl.query.SourceNodeQuery;
import org.jetbrains.annotations.Nullable;
import jetbrains.mps.generator.impl.query.SourceNodesQuery;
import java.util.Collection;
import jetbrains.mps.util.IterableUtil;
import jetbrains.mps.generator.impl.query.PropertyValueQuery;
import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory;
import org.jetbrains.mps.openapi.language.SProperty;
import jetbrains.mps.generator.impl.query.ReferenceTargetQuery;
import org.jetbrains.mps.openapi.language.SConcept;
import org.jetbrains.mps.openapi.language.SContainmentLink;
import org.jetbrains.mps.openapi.language.SReferenceLink;

@Generated
public class QueriesGenerated extends QueryProviderBase {
  public QueriesGenerated() {
    super(1);
  }
  public static boolean createRootRule_Condition_3_0(final CreateRootRuleContext _context) {
    return ListSequence.fromList(SModelOperations.nodes(_context.getInputModel(), CONCEPTS.CellModel_Tooltip$vF)).isNotEmpty();
  }
  public static boolean rule_Condition_3_0(final BaseMappingRuleContext _context) {
    return SNodeOperations.hasRole(_context.getNode(), LINKS.tooltipCell$kz$1) && !(SNodeOperations.isInstanceOf(_context.getNode(), CONCEPTS.AuxEditorCellWithRefToGeneratedHint$Aw));
  }
  public static boolean rule_Condition_3_1(final BaseMappingRuleContext _context) {
    return (SLinkOperations.getTarget(_context.getNode(), LINKS.tooltip$cjSW) != null);
  }
  public static boolean rule_Condition_3_2(final BaseMappingRuleContext _context) {
    return SNodeOperations.hasRole(_context.getNode(), LINKS.tooltipCell$kz$1) && (SLinkOperations.getTarget(_context.getNode(), LINKS.tooltip$cjSW) != null);
  }
  public static Object propertyMacro_GetValue_1_0(final PropertyMacroContext _context) {
    SNode popup = SLinkOperations.getTarget(_context.getNode(), LINKS.tooltipCell$kz$1);
    if (!(SNodeOperations.isInstanceOf(popup, CONCEPTS.AuxEditorCellWithRefToGeneratedHint$Aw))) {
      _context.showErrorMessage(_context.getNode(), "Internal contract of the generator is broken: tooltip must be of Aux concept");
      return null;
    }
    return ConceptEditorHintDeclaration__BehaviorDescriptor.getQualifiedName_id59ZEGVRaGvv.invoke(SLinkOperations.getTarget(SNodeOperations.cast(popup, CONCEPTS.AuxEditorCellWithRefToGeneratedHint$Aw), LINKS.hint$gLJA));
  }
  public static Object propertyMacro_GetValue_1_1(final PropertyMacroContext _context) {
    return SPropertyOperations.getBoolean(_context.getNode(), PROPS.lazy$JsTc);
  }
  public static Object propertyMacro_GetValue_1_2(final PropertyMacroContext _context) {
    return (String) EditorCellModel__BehaviorDescriptor.getFactoryMethodName_idhHfE2BD.invoke(_context.getNode(), _context);
  }
  public static Object propertyMacro_GetValue_2_0(final PropertyMacroContext _context) {
    return _context.createUniqueName("tooltipHint", _context.getNode());
  }
  public static Object referenceMacro_GetReferent_1_0(final ReferenceMacroContext _context) {
    return _context.getOutputNodeByInputNodeAndMappingLabel(SLinkOperations.getTarget(_context.getNode(), LINKS.visibleCell$VE5n), "cellFactory.factoryMethod");
  }
  public static Object referenceMacro_GetReferent_3_0(final ReferenceMacroContext _context) {
    return _context.getOutputNodeByInputNodeAndMappingLabel(SNodeOperations.cast(SNodeOperations.getParent(_context.getNode()), CONCEPTS.CellModel_Tooltip$vF), "Hint");
  }
  public static Object referenceMacro_GetReferent_3_1(final ReferenceMacroContext _context) {
    return SLinkOperations.getTarget(_context.getNode(), LINKS.hint$gLJA);
  }
  public static Object referenceMacro_GetReferent_4_0(final ReferenceMacroContext _context) {
    return SLinkOperations.getTarget(_context.getNode(), LINKS.hint$gLJA);
  }
  public static Object referenceMacro_GetReferent_4_1(final ReferenceMacroContext _context) {
    return SLinkOperations.getTarget(SNodeOperations.cast(SNodeOperations.getContainingRoot(_context.getNode()), CONCEPTS.AbstractComponent$YR), LINKS.conceptDeclaration$HJmJ);
  }
  public static Object referenceMacro_GetReferent_4_2(final ReferenceMacroContext _context) {
    return SLinkOperations.getTarget(_context.getNode(), LINKS.hint$gLJA);
  }
  public static SNode sourceNodeQuery_0_0(final SourceSubstituteMacroNodeContext _context) {
    return SLinkOperations.getTarget(_context.getNode(), LINKS.visibleCell$VE5n);
  }
  public static SNode sourceNodeQuery_3_0(final SourceSubstituteMacroNodeContext _context) {
    return _context.getNode();
  }
  public static SNode sourceNodeQuery_4_0(final SourceSubstituteMacroNodeContext _context) {
    return SLinkOperations.getTarget(_context.getNode(), LINKS.tooltip$cjSW);
  }
  public static Iterable<SNode> sourceNodesQuery_2_0(final SourceSubstituteMacroNodesContext _context) {
    return SModelOperations.nodes(_context.getInputModel(), CONCEPTS.CellModel_Tooltip$vF);
  }
  private final Map<String, ReductionRuleCondition> rrcMethods = new HashMap<String, ReductionRuleCondition>();
  {
    int i = 0;
    rrcMethods.put("672449538226801022", new RRC(i++));
    rrcMethods.put("8799695660251400968", new RRC(i++));
  }
  @Override
  @NotNull
  public ReductionRuleCondition getReductionRuleCondition(@NotNull QueryKey identity) {
    ReductionRuleCondition query = identity.forTemplateNode(rrcMethods);
    return (query != null ? query : super.getReductionRuleCondition(identity));
  }
  private static class RRC implements ReductionRuleCondition {
    private final int methodKey;
    public RRC(int methodKey) {
      this.methodKey = methodKey;
    }
    @Override
    public boolean check(ReductionRuleQueryContext ctx) throws GenerationFailureException {
      switch (methodKey) {
        case 0:
          return QueriesGenerated.rule_Condition_3_0(ctx);
        case 1:
          return QueriesGenerated.rule_Condition_3_1(ctx);
        default:
          throw new GenerationFailureException(String.format("Inconsistent QueriesGenerated: there's no condition method for rule %s (key: #%d)", ctx.getTemplateReference(), methodKey));
      }
    }
  }
  private final Map<String, MapRootRuleCondition> mrrcMethods = new HashMap<String, MapRootRuleCondition>();
  {
    int i = 0;
    mrrcMethods.put("3877544518697861786", new MRRC(i++));
  }
  @Override
  @NotNull
  public MapRootRuleCondition getMapRootRuleCondition(@NotNull QueryKey identity) {
    MapRootRuleCondition query = identity.forTemplateNode(mrrcMethods);
    return (query != null ? query : super.getMapRootRuleCondition(identity));
  }
  private static class MRRC implements MapRootRuleCondition {
    private final int methodKey;
    public MRRC(int methodKey) {
      this.methodKey = methodKey;
    }
    @Override
    public boolean check(@NotNull MapRootRuleContext ctx) throws GenerationFailureException {
      switch (methodKey) {
        case 0:
          return QueriesGenerated.rule_Condition_3_2(ctx);
        default:
          throw new GenerationFailureException(String.format("Inconsistent QueriesGenerated: there's no condition method for rule %s (key: #%d)", ctx.getTemplateReference(), methodKey));
      }
    }
  }
  private final Map<String, CreateRootCondition> crcMethods = new HashMap<String, CreateRootCondition>();
  {
    int i = 0;
    crcMethods.put("6637997329037488770", new CRC(i++));
  }
  @Override
  @NotNull
  public CreateRootCondition getCreateRootRuleCondition(@NotNull QueryKey identity) {
    CreateRootCondition query = identity.forTemplateNode(crcMethods);
    return (query != null ? query : super.getCreateRootRuleCondition(identity));
  }
  private static class CRC implements CreateRootCondition {
    private final int methodKey;
    public CRC(int methodKey) {
      this.methodKey = methodKey;
    }
    @Override
    public boolean check(@NotNull CreateRootRuleContext ctx) throws GenerationFailureException {
      switch (methodKey) {
        case 0:
          return QueriesGenerated.createRootRule_Condition_3_0(ctx);
        default:
          throw new GenerationFailureException(String.format("Inconsistent QueriesGenerated: there's no condition method for rule %s (key: #%d)", ctx.getTemplateReference(), methodKey));
      }
    }
  }
  private final Map<String, SourceNodeQuery> snqMethods = new HashMap<String, SourceNodeQuery>();
  {
    int i = 0;
    snqMethods.put("4772059062238773268", new SNQ(i++));
    snqMethods.put("672449538226981862", new SNQ(i++));
    snqMethods.put("8799695660251582065", new SNQ(i++));
  }
  @NotNull
  @Override
  public SourceNodeQuery getSourceNodeQuery(@NotNull QueryKey identity) {
    SourceNodeQuery query = identity.forFunctionNode(snqMethods);
    return (query != null ? query : super.getSourceNodeQuery(identity));
  }
  private static class SNQ implements SourceNodeQuery {
    private final int methodKey;
    public SNQ(int methodKey) {
      this.methodKey = methodKey;
    }
    @Nullable
    public SNode evaluate(@NotNull SourceSubstituteMacroNodeContext ctx) throws GenerationFailureException {
      switch (methodKey) {
        case 0:
          return QueriesGenerated.sourceNodeQuery_0_0(ctx);
        case 1:
          return QueriesGenerated.sourceNodeQuery_3_0(ctx);
        case 2:
          return QueriesGenerated.sourceNodeQuery_4_0(ctx);
        default:
          throw new GenerationFailureException(String.format("Inconsistent QueriesGenerated: there's no method for query %s (key: #%d)", ctx.getTemplateReference(), methodKey));
      }
    }
  }
  private final Map<String, SourceNodesQuery> snsqMethods = new HashMap<String, SourceNodesQuery>();
  {
    int i = 0;
    snsqMethods.put("3877544518697298332", new SNsQ(i++));
  }
  @NotNull
  @Override
  public SourceNodesQuery getSourceNodesQuery(@NotNull QueryKey identity) {
    SourceNodesQuery query = identity.forFunctionNode(snsqMethods);
    return (query != null ? query : super.getSourceNodesQuery(identity));
  }
  private static class SNsQ implements SourceNodesQuery {
    private final int methodKey;
    public SNsQ(int methodKey) {
      this.methodKey = methodKey;
    }
    @NotNull
    public Collection<SNode> evaluate(@NotNull SourceSubstituteMacroNodesContext ctx) throws GenerationFailureException {
      switch (methodKey) {
        case 0:
          return IterableUtil.asCollection(QueriesGenerated.sourceNodesQuery_2_0(ctx));
        default:
          throw new GenerationFailureException(String.format("Inconsistent QueriesGenerated: there's no method for query %s (key: #%d)", ctx.getTemplateReference(), methodKey));
      }
    }
  }
  private final Map<String, PropertyValueQuery> pvqMethods = new HashMap<String, PropertyValueQuery>();
  {
    int i = 0;
    pvqMethods.put("3877544518697345647", new PVQ(i++, MetaAdapterFactory.getProperty(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf93d565d10L, 0xf93d565d11L, "value"), "StringLiteral"));
    pvqMethods.put("8799695660253539473", new PVQ(i++, MetaAdapterFactory.getProperty(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8cc56b201L, 0xf8cc56b202L, "value"), "true"));
    pvqMethods.put("1097659235722", new PVQ(i++, MetaAdapterFactory.getProperty(0xceab519525ea4f22L, 0x9b92103b95ca8c0cL, 0x110396eaaa4L, 0x110396ec041L, "name"), "_cell_factory_method_"));
    pvqMethods.put("3877544518697333188", new PVQ(i++, MetaAdapterFactory.getProperty(0xceab519525ea4f22L, 0x9b92103b95ca8c0cL, 0x110396eaaa4L, 0x110396ec041L, "name"), "generatedHint"));
  }
  @NotNull
  @Override
  public PropertyValueQuery getPropertyValueQuery(@NotNull QueryKey identity) {
    PropertyValueQuery query = identity.forTemplateNode(pvqMethods);
    return (query != null ? query : super.getPropertyValueQuery(identity));
  }
  private static class PVQ extends PropertyValueQuery.Base {
    private final int methodKey;
    /*package*/ PVQ(int methodKey, SProperty property, String templateValue) {
      super(property, templateValue);
      this.methodKey = methodKey;
    }
    @Nullable
    public Object evaluate(@NotNull PropertyMacroContext ctx) throws GenerationFailureException {
      switch (methodKey) {
        case 0:
          return QueriesGenerated.propertyMacro_GetValue_1_0(ctx);
        case 1:
          return QueriesGenerated.propertyMacro_GetValue_1_1(ctx);
        case 2:
          return QueriesGenerated.propertyMacro_GetValue_1_2(ctx);
        case 3:
          return QueriesGenerated.propertyMacro_GetValue_2_0(ctx);
        default:
          throw new GenerationFailureException(String.format("Inconsistent QueriesGenerated: there's no method for query %s (key: #%d)", ctx.getTemplateReference(), methodKey));
      }
    }
  }
  private final Map<String, ReferenceTargetQuery> rtqMethods = new HashMap<String, ReferenceTargetQuery>();
  {
    rtqMethods.put("9185659875393648822", new RTQ(0, "cellFactory"));
    rtqMethods.put("672449538226829909", new RTQ(1, "generatedHint"));
    rtqMethods.put("8799695660251401511", new RTQ(2, "generatedHint"));
    rtqMethods.put("3877544518697559760", new RTQ(3, "generatedHint"));
    rtqMethods.put("6637997329037513942", new RTQ(4, "BaseConcept"));
    rtqMethods.put("4766463257084277441", new RTQ(5, "generatedHint"));
  }
  @NotNull
  @Override
  public ReferenceTargetQuery getReferenceTargetQuery(@NotNull QueryKey queryKey) {
    ReferenceTargetQuery query = queryKey.forTemplateNode(rtqMethods);
    return (query != null ? query : super.getReferenceTargetQuery(queryKey));
  }
  private static class RTQ extends ReferenceTargetQuery.Base {
    private final int methodKey;
    /*package*/ RTQ(int methodKey, String templateValue) {
      super(templateValue);
      this.methodKey = methodKey;
    }
    @Nullable
    public Object evaluate(@NotNull ReferenceMacroContext ctx) throws GenerationFailureException {
      switch (methodKey) {
        case 0:
          return QueriesGenerated.referenceMacro_GetReferent_1_0(ctx);
        case 1:
          return QueriesGenerated.referenceMacro_GetReferent_3_0(ctx);
        case 2:
          return QueriesGenerated.referenceMacro_GetReferent_3_1(ctx);
        case 3:
          return QueriesGenerated.referenceMacro_GetReferent_4_0(ctx);
        case 4:
          return QueriesGenerated.referenceMacro_GetReferent_4_1(ctx);
        case 5:
          return QueriesGenerated.referenceMacro_GetReferent_4_2(ctx);
        default:
          throw new GenerationFailureException(String.format("Inconsistent QueriesGenerated: there's no method for query %s (key: #%d)", ctx.getTemplateReference(), methodKey));
      }
    }
  }

  private static final class CONCEPTS {
    /*package*/ static final SConcept CellModel_Tooltip$vF = MetaAdapterFactory.getConcept(0xb1ab8c10c1184755L, 0xbf2acebab35cf533L, 0x11d794d84ece7c48L, "jetbrains.mps.lang.editor.tooltips.structure.CellModel_Tooltip");
    /*package*/ static final SConcept AuxEditorCellWithRefToGeneratedHint$Aw = MetaAdapterFactory.getConcept(0xb1ab8c10c1184755L, 0xbf2acebab35cf533L, 0x35cfce3215b739b5L, "jetbrains.mps.lang.editor.tooltips.structure.AuxEditorCellWithRefToGeneratedHint");
    /*package*/ static final SConcept AbstractComponent$YR = MetaAdapterFactory.getConcept(0x18bc659203a64e29L, 0xa83a7ff23bde13baL, 0x10f7df344a9L, "jetbrains.mps.lang.editor.structure.AbstractComponent");
  }

  private static final class LINKS {
    /*package*/ static final SContainmentLink tooltipCell$kz$1 = MetaAdapterFactory.getContainmentLink(0xb1ab8c10c1184755L, 0xbf2acebab35cf533L, 0x11d794d84ece7c48L, 0x35cfce3215bf1834L, "tooltipCell");
    /*package*/ static final SContainmentLink tooltip$cjSW = MetaAdapterFactory.getContainmentLink(0xb1ab8c10c1184755L, 0xbf2acebab35cf533L, 0x35cfce3215b739b5L, 0x955054acf64dc63L, "tooltip");
    /*package*/ static final SReferenceLink hint$gLJA = MetaAdapterFactory.getReferenceLink(0xb1ab8c10c1184755L, 0xbf2acebab35cf533L, 0x35cfce3215b739b5L, 0x35cfce3215b85a20L, "hint");
    /*package*/ static final SContainmentLink visibleCell$VE5n = MetaAdapterFactory.getContainmentLink(0xb1ab8c10c1184755L, 0xbf2acebab35cf533L, 0x11d794d84ece7c48L, 0x7f7a04fd2c64819dL, "visibleCell");
    /*package*/ static final SReferenceLink conceptDeclaration$HJmJ = MetaAdapterFactory.getReferenceLink(0x18bc659203a64e29L, 0xa83a7ff23bde13baL, 0x10f7df344a9L, 0x10f7df451aeL, "conceptDeclaration");
  }

  private static final class PROPS {
    /*package*/ static final SProperty lazy$JsTc = MetaAdapterFactory.getProperty(0xb1ab8c10c1184755L, 0xbf2acebab35cf533L, 0x11d794d84ece7c48L, 0x42ab886dda92b1ebL, "lazy");
  }
}
