package org.jetbrains.mps.samples.IfAndUnless.intentions; /*Generated by MPS */ import jetbrains.mps.intentions.AbstractIntentionDescriptor; import jetbrains.mps.openapi.intentions.IntentionFactory; import java.util.Collection; import jetbrains.mps.openapi.intentions.IntentionExecutable; import jetbrains.mps.openapi.intentions.Kind; import jetbrains.mps.smodel.SNodePointer; import org.jetbrains.mps.openapi.model.SNode; import jetbrains.mps.openapi.editor.EditorContext; import java.util.Collections; import jetbrains.mps.intentions.AbstractIntentionExecutable; import jetbrains.mps.smodel.action.SNodeFactoryOperations; import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory; import java.util.List; import jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations; import jetbrains.mps.internal.collections.runtime.ListSequence; import jetbrains.mps.lang.smodel.generator.smodelAdapter.SLinkOperations; import jetbrains.mps.openapi.intentions.IntentionDescriptor; public final class SurroundWithUnless_Intention extends AbstractIntentionDescriptor implements IntentionFactory { private Collection<IntentionExecutable> myCachedExecutable; public SurroundWithUnless_Intention() { super(Kind.NORMAL, false, new SNodePointer("r:c94a864e-ad51-4b38-a592-c0d7623187a1(org.jetbrains.mps.samples.IfAndUnless.intentions)", "393299394024647596")); } @Override public String getPresentation() { return "SurroundWithUnless"; } @Override public boolean isApplicable(final SNode node, final EditorContext editorContext) { return true; } @Override public boolean isSurroundWith() { return true; } public Collection<IntentionExecutable> instances(final SNode node, final EditorContext context) { if (myCachedExecutable == null) { myCachedExecutable = Collections.<IntentionExecutable>singletonList(new SurroundWithUnless_Intention.IntentionImplementation()); } return myCachedExecutable; } /*package*/ final class IntentionImplementation extends AbstractIntentionExecutable { public IntentionImplementation() { } @Override public String getDescription(final SNode node, final EditorContext editorContext) { return "Unless"; } @Override public void execute(final SNode node, final EditorContext editorContext) { SNode unlessStatement = SNodeFactoryOperations.createNewNode(SNodeFactoryOperations.asInstanceConcept(MetaAdapterFactory.getConcept(0x67b828fd8fbc4496L, 0xb7f78b64ac097c62L, 0x57547b70f36dc0dL, "org.jetbrains.mps.samples.IfAndUnless.structure.UnlessStatement")), null); List<SNode> selectedNodes = editorContext.getSelectedNodes(); SNodeOperations.insertNextSiblingChild(ListSequence.fromList(selectedNodes).last(), unlessStatement); for (SNode selectedNode : ListSequence.fromList(selectedNodes)) { ListSequence.fromList(SLinkOperations.getChildren(SLinkOperations.getTarget(unlessStatement, MetaAdapterFactory.getContainmentLink(0x67b828fd8fbc4496L, 0xb7f78b64ac097c62L, 0x57547b70f36dc0dL, 0x57547b70f36dc1cL, "body")), MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8cc56b200L, 0xf8cc6bf961L, "statement"))).addElement(SNodeOperations.getNodeAncestor(selectedNode, MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8cc56b215L, "jetbrains.mps.baseLanguage.structure.Statement"), true, false)); } editorContext.select(SLinkOperations.getTarget(unlessStatement, MetaAdapterFactory.getContainmentLink(0x67b828fd8fbc4496L, 0xb7f78b64ac097c62L, 0x57547b70f36dc0dL, 0x57547b70f36dc0eL, "condition"))); } @Override public IntentionDescriptor getDescriptor() { return SurroundWithUnless_Intention.this; } } }