package jetbrains.mps.baseLanguage.collections.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 org.jetbrains.mps.openapi.language.SProperty;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations;
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 MigrationToUpdateAllConstants_MigrationScript extends BaseMigrationScript {
  public MigrationToUpdateAllConstants_MigrationScript() {
    super("AllConstantsMigration");
    this.addRefactoring(new AbstractMigrationRefactoring() {
      @Override
      public String getName() {
        return "Re-inserts the AllConstants concept to fix the missing value property";
      }
      @Override
      public String getAdditionalInfo() {
        return "Re-inserts the AllConstants concept to fix the missing value property";
      }
      @Override
      public SAbstractConcept getApplicableConcept() {
        return CONCEPTS.AllConstant$My;
      }
      @Override
      public boolean isApplicableInstanceNode(SNode node) {
        for (SProperty prop : node.getProperties()) {
          if (prop.getName().equals("value")) {
            return true;
          }
        }
        return false;
      }
      @Override
      public void doUpdateInstanceNode(SNode node) {
        SNodeOperations.replaceWithNewChild(node, CONCEPTS.AllConstant$My);
      }
      @Override
      public boolean isShowAsIntention() {
        return false;
      }
    });
  }

  @Nullable
  @Override
  public SNodeReference getScriptNode() {
    return PersistenceFacade.getInstance().createNodeReference("r:00000000-0000-4000-0000-011c8959032d(jetbrains.mps.baseLanguage.collections.scripts)/3600688056589376389");
  }

  private static final class CONCEPTS {
    /*package*/ static final SConcept AllConstant$My = MetaAdapterFactory.getConcept(0x8388864671ce4f1cL, 0x9c53c54016f6ad4fL, 0x12031a066ecL, "jetbrains.mps.baseLanguage.collections.structure.AllConstant");
  }
}
