package jetbrains.mps.baseLanguage.lightweightdsl.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.Sequence;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.IAttributeDescriptor;
import jetbrains.mps.lang.migration.runtime.base.Problem;
import jetbrains.mps.baseLanguage.closures.runtime._FunctionTypes;
import jetbrains.mps.lang.migration.runtime.base.NotMigratedNode;
import jetbrains.mps.lang.migration.runtime.base.MigrationScriptReference;
import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory;
import org.jetbrains.mps.openapi.language.SInterfaceConcept;
import org.jetbrains.mps.openapi.language.SConcept;

public class RemoveOddAnnotations extends MigrationScriptBase {
  private final String description = "Remove @dslclass annotations from instances of AutoInitDSLClass";
  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_gqzzto_a0e = CommandUtil.createScope(m);
      final SearchScope scope_gqzzto_a0e_0 = new EditableFilteringScope(scope_gqzzto_a0e);
      QueryExecutionContext context = () -> scope_gqzzto_a0e_0;
      Sequence.fromIterable(SNodeOperations.ofConcept(CommandUtil.instances(CommandUtil.selectScope(null, context), CONCEPTS.AutoInitDSLClass$Ms, false), CONCEPTS.ClassConcept$bK)).where((it) -> (new IAttributeDescriptor.NodeAttribute(CONCEPTS.DSLAnnotation$zv).get(it) != null)).visitAll((it) -> SNodeOperations.deleteNode(new IAttributeDescriptor.NodeAttribute(CONCEPTS.DSLAnnotation$zv).get(it)));
    }
  }
  @Override
  public Iterable<Problem> check(SModule m) {
    {
      SearchScope scope_gqzzto_a0f = CommandUtil.createScope(m);
      final SearchScope scope_gqzzto_a0f_0 = new EditableFilteringScope(scope_gqzzto_a0f);
      QueryExecutionContext context = () -> scope_gqzzto_a0f_0;
      return Sequence.fromIterable(SNodeOperations.ofConcept(CommandUtil.instances(CommandUtil.selectScope(null, context), CONCEPTS.AutoInitDSLClass$Ms, false), CONCEPTS.ClassConcept$bK)).where((it) -> (new IAttributeDescriptor.NodeAttribute(CONCEPTS.DSLAnnotation$zv).get(it) != null)).select(new _FunctionTypes._return_P1_E0<Problem, SNode>() {
        public Problem invoke(SNode it) {
          return ((Problem) new NotMigratedNode(it) {
            public String getMessage() {
              return "Unnecessary @dslclass annotation was not migrated";
            }
          });
        }
      });
    }
  }
  public MigrationScriptReference getReference() {
    return new MigrationScriptReference(MetaAdapterFactory.getLanguage(0xc7d5b9dda05f4be2L, 0xbc73f2e16994cc67L, "jetbrains.mps.baseLanguage.lightweightdsl"), 0);
  }

  private static final class CONCEPTS {
    /*package*/ static final SInterfaceConcept AutoInitDSLClass$Ms = MetaAdapterFactory.getInterfaceConcept(0xc7d5b9dda05f4be2L, 0xbc73f2e16994cc67L, 0xea740fb893a13edL, "jetbrains.mps.baseLanguage.lightweightdsl.structure.AutoInitDSLClass");
    /*package*/ static final SConcept ClassConcept$bK = MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8c108ca66L, "jetbrains.mps.baseLanguage.structure.ClassConcept");
    /*package*/ static final SConcept DSLAnnotation$zv = MetaAdapterFactory.getConcept(0xc7d5b9dda05f4be2L, 0xbc73f2e16994cc67L, 0x3190d3f9f1cab0caL, "jetbrains.mps.baseLanguage.lightweightdsl.structure.DSLAnnotation");
  }
}
