package jetbrains.mps.lang.structure.migration;

/*Generated by MPS */

import jetbrains.mps.lang.migration.runtime.base.MigrationScriptBase;
import org.jetbrains.mps.openapi.model.SNode;
import org.jetbrains.mps.openapi.module.SModule;
import org.jetbrains.mps.openapi.module.SearchScope;
import jetbrains.mps.lang.smodel.query.runtime.CommandUtil;
import jetbrains.mps.project.EditableFilteringScope;
import jetbrains.mps.lang.smodel.query.runtime.QueryExecutionContext;
import jetbrains.mps.internal.collections.runtime.CollectionSequence;
import java.util.List;
import jetbrains.mps.internal.collections.runtime.ListSequence;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SLinkOperations;
import jetbrains.mps.baseLanguage.closures.runtime._FunctionTypes;
import jetbrains.mps.smodel.SNodePointer;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations;
import jetbrains.mps.lang.migration.runtime.base.MigrationScriptReference;
import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory;
import org.jetbrains.mps.openapi.language.SConcept;
import org.jetbrains.mps.openapi.language.SContainmentLink;
import org.jetbrains.mps.openapi.language.SReferenceLink;

public class Removing_IDontSubstituteByDefault extends MigrationScriptBase {
  private final String description = "Removing IDontSubstituteByDefault from Concept Implemented Interfaces";
  public String getCaption() {
    return description;
  }
  @Override
  public boolean isRerunnable() {
    return true;
  }
  public SNode execute(final SModule m) {
    doExecute(m);
    return null;
  }
  public void doExecute(final SModule m) {
    {
      SearchScope scope_c264be_a0e = CommandUtil.createScope(m);
      final SearchScope scope_c264be_a0e_0 = new EditableFilteringScope(scope_c264be_a0e);
      QueryExecutionContext context = () -> scope_c264be_a0e_0;
      CollectionSequence.fromCollection(CommandUtil.instances(CommandUtil.selectScope(null, context), CONCEPTS.ConceptDeclaration$gH, false)).visitAll((it) -> {
        List<SNode> toRemove = ListSequence.fromList(SLinkOperations.getChildren(it, LINKS.implements$u_P2)).where(new _FunctionTypes._return_P1_E0<Boolean, SNode>() {
          public Boolean invoke(SNode it) {
            return SLinkOperations.hasPointer(it, LINKS.intfc$zM4e, new SNodePointer("r:00000000-0000-4000-0000-011c89590288(jetbrains.mps.lang.core.structure)", "1835621062190663819"));
          }
        }).toList();
        ListSequence.fromList(toRemove).visitAll(new _FunctionTypes._void_P1_E0<SNode>() {
          public void invoke(SNode it) {
            SNodeOperations.deleteNode(it);
          }
        });
      });
      CollectionSequence.fromCollection(CommandUtil.instances(CommandUtil.selectScope(null, context), CONCEPTS.InterfaceConceptDeclaration$CG, false)).visitAll((it) -> {
        List<SNode> toRemove = ListSequence.fromList(SLinkOperations.getChildren(it, LINKS.extends$nawU)).where(new _FunctionTypes._return_P1_E0<Boolean, SNode>() {
          public Boolean invoke(SNode it) {
            return SLinkOperations.hasPointer(it, LINKS.intfc$zM4e, new SNodePointer("r:00000000-0000-4000-0000-011c89590288(jetbrains.mps.lang.core.structure)", "1835621062190663819"));
          }
        }).toList();
        ListSequence.fromList(toRemove).visitAll(new _FunctionTypes._void_P1_E0<SNode>() {
          public void invoke(SNode it) {
            SNodeOperations.deleteNode(it);
          }
        });
      });
    }
  }
  public MigrationScriptReference getReference() {
    return new MigrationScriptReference(MetaAdapterFactory.getLanguage(0xc72da2b97cce4447L, 0x8389f407dc1158b7L, "jetbrains.mps.lang.structure"), 6);
  }

  private static final class CONCEPTS {
    /*package*/ static final SConcept ConceptDeclaration$gH = MetaAdapterFactory.getConcept(0xc72da2b97cce4447L, 0x8389f407dc1158b7L, 0xf979ba0450L, "jetbrains.mps.lang.structure.structure.ConceptDeclaration");
    /*package*/ static final SConcept InterfaceConceptDeclaration$CG = MetaAdapterFactory.getConcept(0xc72da2b97cce4447L, 0x8389f407dc1158b7L, 0x1103556dcafL, "jetbrains.mps.lang.structure.structure.InterfaceConceptDeclaration");
  }

  private static final class LINKS {
    /*package*/ static final SContainmentLink implements$u_P2 = MetaAdapterFactory.getContainmentLink(0xc72da2b97cce4447L, 0x8389f407dc1158b7L, 0xf979ba0450L, 0x110358d693eL, "implements");
    /*package*/ static final SReferenceLink intfc$zM4e = MetaAdapterFactory.getReferenceLink(0xc72da2b97cce4447L, 0x8389f407dc1158b7L, 0x110356fc618L, 0x110356fe029L, "intfc");
    /*package*/ static final SContainmentLink extends$nawU = MetaAdapterFactory.getContainmentLink(0xc72da2b97cce4447L, 0x8389f407dc1158b7L, 0x1103556dcafL, 0x110356e9df4L, "extends");
  }
}
