package jetbrains.mps.baseLanguage.collections.typesystem;

/*Generated by MPS */

import jetbrains.mps.lang.typesystem.runtime.AbstractInferenceRule_Runtime;
import jetbrains.mps.lang.typesystem.runtime.InferenceRule_Runtime;
import org.jetbrains.mps.openapi.model.SNode;
import jetbrains.mps.typesystem.inference.TypeCheckingContext;
import jetbrains.mps.lang.typesystem.runtime.IsApplicableStatus;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations;
import jetbrains.mps.typesystem.inference.EquationInfo;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SLinkOperations;
import org.jetbrains.mps.openapi.language.SAbstractConcept;
import org.jetbrains.mps.openapi.language.SConcept;
import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory;
import org.jetbrains.mps.openapi.language.SContainmentLink;

public class typeof_MapInitializer_InferenceRule extends AbstractInferenceRule_Runtime implements InferenceRule_Runtime {
  public typeof_MapInitializer_InferenceRule() {
  }
  public void applyRule(final SNode mapInitializer, final TypeCheckingContext typeCheckingContext, IsApplicableStatus status) {
    {
      final SNode shallowMapType = typeCheckingContext.typeOf(SNodeOperations.getParent(mapInitializer), "r:00000000-0000-4000-0000-011c8959032b(jetbrains.mps.baseLanguage.collections.typesystem)", "7830826264643290166", true);
      typeCheckingContext.whenConcrete(shallowMapType, () -> {
        // Only works if mapType is inferred to parent (in a shallow way so we do not make key and value type concrete)
        {
          final SNode mapType = typeCheckingContext.getExpandedNode(shallowMapType);
          if (SNodeOperations.isInstanceOf(mapType, CONCEPTS.MapType$h0)) {
            final SNode keyType_typevar_7830826264643295368 = typeCheckingContext.createNewRuntimeTypesVariable();
            final SNode valueType_typevar_7830826264643295454 = typeCheckingContext.createNewRuntimeTypesVariable();

            // Base assumptions
            {
              SNode _nodeToCheck_1029348928467 = mapInitializer;
              EquationInfo _info_12389875345 = new EquationInfo(_nodeToCheck_1029348928467, null, "r:00000000-0000-4000-0000-011c8959032b(jetbrains.mps.baseLanguage.collections.typesystem)", "7830826264672450777", 0, null);
              typeCheckingContext.createEquation((SNode) typeCheckingContext.getRepresentative(keyType_typevar_7830826264643295368), (SNode) SLinkOperations.getTarget(mapType, LINKS.keyType$cmqk), _info_12389875345);
            }
            {
              SNode _nodeToCheck_1029348928467 = mapInitializer;
              EquationInfo _info_12389875345 = new EquationInfo(_nodeToCheck_1029348928467, null, "r:00000000-0000-4000-0000-011c8959032b(jetbrains.mps.baseLanguage.collections.typesystem)", "7830826264672450929", 0, null);
              typeCheckingContext.createEquation((SNode) typeCheckingContext.getRepresentative(valueType_typevar_7830826264643295454), (SNode) SLinkOperations.getTarget(mapType, LINKS.valueType$hLQn), _info_12389875345);
            }

            // Added parameters
            for (SNode entry : SLinkOperations.getChildren(mapInitializer, LINKS.entries$Tv6F)) {
              {
                SNode _nodeToCheck_1029348928467 = SLinkOperations.getTarget(entry, LINKS.key$LlfT);
                EquationInfo _info_12389875345 = new EquationInfo(_nodeToCheck_1029348928467, null, "r:00000000-0000-4000-0000-011c8959032b(jetbrains.mps.baseLanguage.collections.typesystem)", "3116855336947089772", 0, null);
                typeCheckingContext.createLessThanInequality((SNode) typeCheckingContext.typeOf(_nodeToCheck_1029348928467, "r:00000000-0000-4000-0000-011c8959032b(jetbrains.mps.baseLanguage.collections.typesystem)", "3116855336947089775", true), (SNode) typeCheckingContext.getRepresentative(keyType_typevar_7830826264643295368), false, true, _info_12389875345);
              }
              {
                SNode _nodeToCheck_1029348928467 = SLinkOperations.getTarget(entry, LINKS.value$JmKo);
                EquationInfo _info_12389875345 = new EquationInfo(_nodeToCheck_1029348928467, null, "r:00000000-0000-4000-0000-011c8959032b(jetbrains.mps.baseLanguage.collections.typesystem)", "7830826264643335329", 0, null);
                typeCheckingContext.createLessThanInequality((SNode) typeCheckingContext.typeOf(_nodeToCheck_1029348928467, "r:00000000-0000-4000-0000-011c8959032b(jetbrains.mps.baseLanguage.collections.typesystem)", "7830826264643335333", true), (SNode) typeCheckingContext.getRepresentative(valueType_typevar_7830826264643295454), false, true, _info_12389875345);
              }
            }
          }
        }
      }, "r:00000000-0000-4000-0000-011c8959032b(jetbrains.mps.baseLanguage.collections.typesystem)", "7830826264643290112", true, false);
    }
  }
  public SAbstractConcept getApplicableConcept() {
    return CONCEPTS.MapInitializer$z8;
  }
  public IsApplicableStatus isApplicableAndPattern(SNode argument) {
    return new IsApplicableStatus(argument.getConcept().isSubConceptOf(getApplicableConcept()), null);
  }
  public boolean overrides() {
    return false;
  }

  private static final class CONCEPTS {
    /*package*/ static final SConcept MapType$h0 = MetaAdapterFactory.getConcept(0x8388864671ce4f1cL, 0x9c53c54016f6ad4fL, 0x116db7e6bcbL, "jetbrains.mps.baseLanguage.collections.structure.MapType");
    /*package*/ static final SConcept MapInitializer$z8 = MetaAdapterFactory.getConcept(0x8388864671ce4f1cL, 0x9c53c54016f6ad4fL, 0x118f2481867L, "jetbrains.mps.baseLanguage.collections.structure.MapInitializer");
  }

  private static final class LINKS {
    /*package*/ static final SContainmentLink keyType$cmqk = MetaAdapterFactory.getContainmentLink(0x8388864671ce4f1cL, 0x9c53c54016f6ad4fL, 0x116db7e6bcbL, 0x116db7f62a8L, "keyType");
    /*package*/ static final SContainmentLink valueType$hLQn = MetaAdapterFactory.getContainmentLink(0x8388864671ce4f1cL, 0x9c53c54016f6ad4fL, 0x116db7e6bcbL, 0x116db7f8516L, "valueType");
    /*package*/ static final SContainmentLink key$LlfT = MetaAdapterFactory.getContainmentLink(0x8388864671ce4f1cL, 0x9c53c54016f6ad4fL, 0x118f249550fL, 0x118f24b00ccL, "key");
    /*package*/ static final SContainmentLink value$JmKo = MetaAdapterFactory.getContainmentLink(0x8388864671ce4f1cL, 0x9c53c54016f6ad4fL, 0x118f249550fL, 0x118f24b224fL, "value");
    /*package*/ static final SContainmentLink entries$Tv6F = MetaAdapterFactory.getContainmentLink(0x8388864671ce4f1cL, 0x9c53c54016f6ad4fL, 0x118f2481867L, 0x118f24be244L, "entries");
  }
}
