package jetbrains.mps.lang.test.scripts;

/*Generated by MPS */

import jetbrains.mps.lang.script.runtime.BaseMigrationScript;
import jetbrains.mps.lang.script.runtime.AbstractMigrationRefactoring;
import org.jetbrains.mps.openapi.language.SAbstractConcept;
import org.jetbrains.mps.openapi.model.SNode;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.IAttributeDescriptor;
import jetbrains.mps.components.ComponentHost;
import org.jetbrains.mps.openapi.model.SModel;
import jetbrains.mps.project.ProjectBase;
import jetbrains.mps.ide.project.ProjectHelper;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.mps.openapi.model.SNodeReference;
import org.jetbrains.mps.openapi.persistence.PersistenceFacade;
import org.jetbrains.mps.openapi.language.SConcept;
import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory;

public final class SpecifyRuleReferencesInTests_MigrationScript extends BaseMigrationScript {
  public SpecifyRuleReferencesInTests_MigrationScript() {
    super("Specify rule references in tests for tags 'has error' and 'has warning'");
    this.addRefactoring(new AbstractMigrationRefactoring() {
      @Override
      public String getName() {
        return "Specify Rule References";
      }
      @Override
      public String getAdditionalInfo() {
        return "Specify Rule References";
      }
      @Override
      public SAbstractConcept getApplicableConcept() {
        return CONCEPTS.BaseConcept$gP;
      }
      @Override
      public boolean isApplicableInstanceNode(SNode node) {
        return (new IAttributeDescriptor.NodeAttribute(CONCEPTS.NodeOperationsContainer$aj).get(node) != null);
      }
      @Override
      public void doUpdateInstanceNode(SNode node) {
        ComponentHost host = null;
        SModel model = ((SNode) node).getModel();
        if (model != null) {
          ProjectBase mpsProject = (ProjectBase) ProjectHelper.getProject(model.getRepository());
          if (mpsProject != null) {
            host = mpsProject.getPlatform();
          }
        }
        new SpecifyRuleMessagesHelper(node, host).fillContainerWithRuleMessages();
      }
      @Override
      public boolean isShowAsIntention() {
        return false;
      }
    });
  }

  @Nullable
  @Override
  public SNodeReference getScriptNode() {
    return PersistenceFacade.getInstance().createNodeReference("r:00000000-0000-4000-0000-011c89590387(jetbrains.mps.lang.test.scripts)/4098794966557888877");
  }

  private static final class CONCEPTS {
    /*package*/ static final SConcept BaseConcept$gP = MetaAdapterFactory.getConcept(0xceab519525ea4f22L, 0x9b92103b95ca8c0cL, 0x10802efe25aL, "jetbrains.mps.lang.core.structure.BaseConcept");
    /*package*/ static final SConcept NodeOperationsContainer$aj = MetaAdapterFactory.getConcept(0x8585453e6bfb4d80L, 0x98deb16074f1d86cL, 0x11b07a3d4b5L, "jetbrains.mps.lang.test.structure.NodeOperationsContainer");
  }
}
