package jetbrains.mps.lang.modelapi.typesystem;

/*Generated by MPS */

import jetbrains.mps.lang.typesystem.runtime.AbstractNonTypesystemRule_Runtime;
import jetbrains.mps.lang.typesystem.runtime.NonTypesystemRule_Runtime;
import org.jetbrains.mps.openapi.model.SNode;
import jetbrains.mps.typesystem.inference.TypeCheckingContext;
import jetbrains.mps.lang.typesystem.runtime.IsApplicableStatus;
import org.jetbrains.mps.openapi.module.SRepository;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations;
import org.jetbrains.mps.openapi.module.SModule;
import jetbrains.mps.lang.modelapi.behavior.ModuleIdentity__BehaviorDescriptor;
import java.util.Objects;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SPropertyOperations;
import jetbrains.mps.errors.messageTargets.MessageTarget;
import jetbrains.mps.errors.messageTargets.PropertyMessageTarget;
import jetbrains.mps.errors.IErrorReporter;
import jetbrains.mps.errors.BaseQuickFixProvider;
import org.jetbrains.mps.openapi.language.SAbstractConcept;
import org.jetbrains.mps.openapi.language.SProperty;
import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory;
import org.jetbrains.mps.openapi.language.SConcept;

public class NameIsActualInModulePointer_NonTypesystemRule extends AbstractNonTypesystemRule_Runtime implements NonTypesystemRule_Runtime {
  public NameIsActualInModulePointer_NonTypesystemRule() {
  }
  public void applyRule(final SNode ptr, final TypeCheckingContext typeCheckingContext, IsApplicableStatus status) {
    SRepository repo = SNodeOperations.getModel(ptr).getRepository();
    if (repo == null) {
      return;
    }
    SModule resolved = ModuleIdentity__BehaviorDescriptor.toModuleReference_id1Bs_61$mqDd.invoke(ptr).resolve(repo);
    if (resolved == null) {
      return;
    }
    final String actualName = resolved.getModuleName();
    if (Objects.equals(SPropertyOperations.getString(ptr, PROPS.moduleName$RP9b), actualName)) {
      return;
    }
    {
      final MessageTarget errorTarget = new PropertyMessageTarget(PROPS.moduleName$RP9b);
      IErrorReporter _reporter_2309309498 = typeCheckingContext.reportInfo(ptr, String.format("Module name doesn't reflect actual value %s", actualName), "r:66a90408-763b-417f-b164-4efaf06432ea(jetbrains.mps.lang.modelapi.typesystem)", "2510235753679592683", null, errorTarget);
      {
        BaseQuickFixProvider intentionProvider = new BaseQuickFixProvider("jetbrains.mps.lang.modelapi.typesystem.UpdateModulePointerName_QuickFix", "2510235753679597037", false);
        intentionProvider.putArgument("actualName", actualName);
        _reporter_2309309498.addIntentionProvider(intentionProvider);
      }
    }
  }
  public SAbstractConcept getApplicableConcept() {
    return CONCEPTS.ModulePointer$7i;
  }
  public IsApplicableStatus isApplicableAndPattern(SNode argument) {
    return new IsApplicableStatus(argument.getConcept().isSubConceptOf(getApplicableConcept()), null);
  }
  public boolean overrides() {
    return false;
  }

  private static final class PROPS {
    /*package*/ static final SProperty moduleName$RP9b = MetaAdapterFactory.getProperty(0x446c26eb2b7b4bf0L, 0x9b35f83fa582753eL, 0x502fe7548a0e361L, 0x19dc9460645ae969L, "moduleName");
  }

  private static final class CONCEPTS {
    /*package*/ static final SConcept ModulePointer$7i = MetaAdapterFactory.getConcept(0x446c26eb2b7b4bf0L, 0x9b35f83fa582753eL, 0x502fe7548a0e361L, "jetbrains.mps.lang.modelapi.structure.ModulePointer");
  }
}
