package jetbrains.mps.lang.actions.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.lang.smodel.query.runtime.QueryExecutionContext; import jetbrains.mps.internal.collections.runtime.CollectionSequence; import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory; import jetbrains.mps.internal.collections.runtime.IWhereFilter; import jetbrains.mps.editor.runtime.impl.cellActions.CommentUtil; import jetbrains.mps.internal.collections.runtime.IVisitor; import jetbrains.mps.lang.smodel.generator.smodelAdapter.SPropertyOperations; import jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations; import jetbrains.mps.lang.smodel.generator.smodelAdapter.AttributeOperations; import jetbrains.mps.lang.smodel.generator.smodelAdapter.IAttributeDescriptor; import jetbrains.mps.lang.smodel.generator.smodelAdapter.SLinkOperations; import jetbrains.mps.internal.collections.runtime.ListSequence; import jetbrains.mps.lang.migration.runtime.base.Problem; import jetbrains.mps.internal.collections.runtime.ISelector; import jetbrains.mps.lang.migration.runtime.base.NotMigratedNode; import jetbrains.mps.internal.collections.runtime.Sequence; import jetbrains.mps.lang.migration.runtime.base.MigrationScriptReference; public class RemoveOldActions extends MigrationScriptBase { public String getCaption() { return "Remove old (commented out) actions"; } @Override public boolean isRerunnable() { return true; } public SNode execute(final SModule m) { doExecute(m); return null; } public void doExecute(final SModule m) { { final SearchScope scope = CommandUtil.createScope(m); QueryExecutionContext context = new QueryExecutionContext() { public SearchScope getDefaultSearchScope() { return scope; } }; CollectionSequence.fromCollection(CommandUtil.instances(CommandUtil.createConsoleScope(null, false, context), MetaAdapterFactory.getConcept(0xaee9cad2acd44608L, 0xaef20004f6a1cdbdL, 0x102ebd2e9eaL, "jetbrains.mps.lang.actions.structure.NodeSubstituteActionsBuilder"), false)).where(new IWhereFilter<SNode>() { public boolean accept(SNode it) { return CommentUtil.isCommentedOut(it); } }).visitAll(new IVisitor<SNode>() { public void visit(SNode it) { // if old node has vPack and new node doesnt, set vPack to the new one (requested by Simon) if (isNotEmptyString(SPropertyOperations.getString(SNodeOperations.getContainingRoot(it), MetaAdapterFactory.getProperty(0xceab519525ea4f22L, 0x9b92103b95ca8c0cL, 0x10802efe25aL, 0x115eca8579fL, "virtualPackage")))) { SNode ma = AttributeOperations.getAttribute(it, new IAttributeDescriptor.NodeAttribute(MetaAdapterFactory.getConcept(0xaee9cad2acd44608L, 0xaef20004f6a1cdbdL, 0x7ce01982652a98aL, "jetbrains.mps.lang.actions.structure.MigratedToAnnotation"))); if ((ma != null)) { if (SLinkOperations.getTarget(ma, MetaAdapterFactory.getReferenceLink(0xaee9cad2acd44608L, 0xaef20004f6a1cdbdL, 0x7ce01982652a98aL, 0x7ce01982652a9f9L, "migratedTo")) != null && isEmptyString(SPropertyOperations.getString(SNodeOperations.getContainingRoot(SLinkOperations.getTarget(ma, MetaAdapterFactory.getReferenceLink(0xaee9cad2acd44608L, 0xaef20004f6a1cdbdL, 0x7ce01982652a98aL, 0x7ce01982652a9f9L, "migratedTo"))), MetaAdapterFactory.getProperty(0xceab519525ea4f22L, 0x9b92103b95ca8c0cL, 0x10802efe25aL, 0x115eca8579fL, "virtualPackage")))) { SPropertyOperations.set(SNodeOperations.getContainingRoot(SLinkOperations.getTarget(ma, MetaAdapterFactory.getReferenceLink(0xaee9cad2acd44608L, 0xaef20004f6a1cdbdL, 0x7ce01982652a98aL, 0x7ce01982652a9f9L, "migratedTo"))), MetaAdapterFactory.getProperty(0xceab519525ea4f22L, 0x9b92103b95ca8c0cL, 0x10802efe25aL, 0x115eca8579fL, "virtualPackage"), SPropertyOperations.getString(SNodeOperations.getContainingRoot(it), MetaAdapterFactory.getProperty(0xceab519525ea4f22L, 0x9b92103b95ca8c0cL, 0x10802efe25aL, 0x115eca8579fL, "virtualPackage"))); } } } SNodeOperations.deleteNode(SNodeOperations.getNodeAncestor(it, MetaAdapterFactory.getConcept(0xceab519525ea4f22L, 0x9b92103b95ca8c0cL, 0x3dcc194340c24debL, "jetbrains.mps.lang.core.structure.BaseCommentAttribute"), true, false)); } }); CollectionSequence.fromCollection(CommandUtil.instances(CommandUtil.createConsoleScope(null, false, context), MetaAdapterFactory.getConcept(0xaee9cad2acd44608L, 0xaef20004f6a1cdbdL, 0x102ebc25367L, "jetbrains.mps.lang.actions.structure.NodeSubstituteActions"), false)).where(new IWhereFilter<SNode>() { public boolean accept(SNode it) { return ListSequence.fromList(SLinkOperations.getChildren(it, MetaAdapterFactory.getContainmentLink(0xaee9cad2acd44608L, 0xaef20004f6a1cdbdL, 0x102ebc25367L, 0x102ebd353e0L, "actionsBuilder"))).isEmpty(); } }).visitAll(new IVisitor<SNode>() { public void visit(SNode it) { SNodeOperations.deleteNode(it); } }); CollectionSequence.fromCollection(CommandUtil.instances(CommandUtil.createConsoleScope(null, false, context), MetaAdapterFactory.getConcept(0xaee9cad2acd44608L, 0xaef20004f6a1cdbdL, 0x108facec6d2L, "jetbrains.mps.lang.actions.structure.SideTransformHintSubstituteActionsBuilder"), false)).where(new IWhereFilter<SNode>() { public boolean accept(SNode it) { return CommentUtil.isCommentedOut(it); } }).visitAll(new IVisitor<SNode>() { public void visit(SNode it) { // if old node has vPack and new node doesnt, set vPack to the new one (requested by Simon) if (isNotEmptyString(SPropertyOperations.getString(SNodeOperations.getContainingRoot(it), MetaAdapterFactory.getProperty(0xceab519525ea4f22L, 0x9b92103b95ca8c0cL, 0x10802efe25aL, 0x115eca8579fL, "virtualPackage")))) { SNode ma = AttributeOperations.getAttribute(it, new IAttributeDescriptor.NodeAttribute(MetaAdapterFactory.getConcept(0xaee9cad2acd44608L, 0xaef20004f6a1cdbdL, 0x7ce01982652a98aL, "jetbrains.mps.lang.actions.structure.MigratedToAnnotation"))); if ((ma != null)) { if (SLinkOperations.getTarget(ma, MetaAdapterFactory.getReferenceLink(0xaee9cad2acd44608L, 0xaef20004f6a1cdbdL, 0x7ce01982652a98aL, 0x7ce01982652a9f9L, "migratedTo")) != null && isEmptyString(SPropertyOperations.getString(SNodeOperations.getContainingRoot(SLinkOperations.getTarget(ma, MetaAdapterFactory.getReferenceLink(0xaee9cad2acd44608L, 0xaef20004f6a1cdbdL, 0x7ce01982652a98aL, 0x7ce01982652a9f9L, "migratedTo"))), MetaAdapterFactory.getProperty(0xceab519525ea4f22L, 0x9b92103b95ca8c0cL, 0x10802efe25aL, 0x115eca8579fL, "virtualPackage")))) { SPropertyOperations.set(SNodeOperations.getContainingRoot(SLinkOperations.getTarget(ma, MetaAdapterFactory.getReferenceLink(0xaee9cad2acd44608L, 0xaef20004f6a1cdbdL, 0x7ce01982652a98aL, 0x7ce01982652a9f9L, "migratedTo"))), MetaAdapterFactory.getProperty(0xceab519525ea4f22L, 0x9b92103b95ca8c0cL, 0x10802efe25aL, 0x115eca8579fL, "virtualPackage"), SPropertyOperations.getString(SNodeOperations.getContainingRoot(it), MetaAdapterFactory.getProperty(0xceab519525ea4f22L, 0x9b92103b95ca8c0cL, 0x10802efe25aL, 0x115eca8579fL, "virtualPackage"))); } } } SNodeOperations.deleteNode(SNodeOperations.getNodeAncestor(it, MetaAdapterFactory.getConcept(0xceab519525ea4f22L, 0x9b92103b95ca8c0cL, 0x3dcc194340c24debL, "jetbrains.mps.lang.core.structure.BaseCommentAttribute"), true, false)); } }); CollectionSequence.fromCollection(CommandUtil.instances(CommandUtil.createConsoleScope(null, false, context), MetaAdapterFactory.getConcept(0xaee9cad2acd44608L, 0xaef20004f6a1cdbdL, 0x108fad1c116L, "jetbrains.mps.lang.actions.structure.SideTransformHintSubstituteActions"), false)).where(new IWhereFilter<SNode>() { public boolean accept(SNode it) { return ListSequence.fromList(SLinkOperations.getChildren(it, MetaAdapterFactory.getContainmentLink(0xaee9cad2acd44608L, 0xaef20004f6a1cdbdL, 0x108fad1c116L, 0x108fad1c117L, "actionsBuilder"))).isEmpty(); } }).visitAll(new IVisitor<SNode>() { public void visit(SNode it) { SNodeOperations.deleteNode(it); } }); } } @Override public Iterable<Problem> check(SModule m) { { final SearchScope scope = CommandUtil.createScope(m); QueryExecutionContext context = new QueryExecutionContext() { public SearchScope getDefaultSearchScope() { return scope; } }; Iterable<Problem> first = CollectionSequence.fromCollection(CommandUtil.instances(CommandUtil.createConsoleScope(null, false, context), MetaAdapterFactory.getConcept(0xaee9cad2acd44608L, 0xaef20004f6a1cdbdL, 0x102ebd2e9eaL, "jetbrains.mps.lang.actions.structure.NodeSubstituteActionsBuilder"), false)).where(new IWhereFilter<SNode>() { public boolean accept(SNode it) { return CommentUtil.isCommentedOut(it); } }).select(new ISelector<SNode, Problem>() { public Problem select(SNode it) { return ((Problem) new NotMigratedNode(it) { public String getMessage() { return "This node should be removed"; } }); } }); Iterable<Problem> second = CollectionSequence.fromCollection(CommandUtil.instances(CommandUtil.createConsoleScope(null, false, context), MetaAdapterFactory.getConcept(0xaee9cad2acd44608L, 0xaef20004f6a1cdbdL, 0x108facec6d2L, "jetbrains.mps.lang.actions.structure.SideTransformHintSubstituteActionsBuilder"), false)).where(new IWhereFilter<SNode>() { public boolean accept(SNode it) { return CommentUtil.isCommentedOut(it); } }).select(new ISelector<SNode, Problem>() { public Problem select(SNode it) { return ((Problem) new NotMigratedNode(it) { public String getMessage() { return "This node should be removed"; } }); } }); return Sequence.fromIterable(first).concat(Sequence.fromIterable(second)); } } public MigrationScriptReference getDescriptor() { return new MigrationScriptReference(MetaAdapterFactory.getLanguage(0xaee9cad2acd44608L, 0xaef20004f6a1cdbdL, "jetbrains.mps.lang.actions"), 3); } private static boolean isEmptyString(String str) { return str == null || str.length() == 0; } private static boolean isNotEmptyString(String str) { return str != null && str.length() > 0; } }