package jetbrains.mps.baseLanguage.closures.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 jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations;
import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory;
import java.util.Collections;
import jetbrains.mps.intentions.AbstractIntentionExecutable;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SLinkOperations;
import jetbrains.mps.openapi.intentions.IntentionDescriptor;
import org.jetbrains.mps.openapi.persistence.PersistenceFacade;
import jetbrains.mps.smodel.SModelUtil_new;
import java.util.List;
import jetbrains.mps.lang.typesystem.runtime.HUtil;
public final class replace_invokeOperation_with_compactInvoke_Intention extends AbstractIntentionDescriptor implements IntentionFactory {
private Collection<IntentionExecutable> myCachedExecutable;
public replace_invokeOperation_with_compactInvoke_Intention() {
super(Kind.NORMAL, false, new SNodePointer("r:dda1964e-d5fa-4ee3-9168-3bfd25608c63(jetbrains.mps.baseLanguage.closures.intentions)", "1235748072133"));
}
@Override
public String getPresentation() {
return "replace_invokeOperation_with_compactInvoke";
}
@Override
public boolean isApplicable(final SNode node, final EditorContext editorContext) {
if (!(isApplicableToNode(node, editorContext))) {
return false;
}
return true;
}
private boolean isApplicableToNode(final SNode node, final EditorContext editorContext) {
return SNodeOperations.isInstanceOf(SNodeOperations.getParent(node), MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x116b46a08c4L, "jetbrains.mps.baseLanguage.structure.DotExpression"));
}
@Override
public boolean isSurroundWith() {
return false;
}
public Collection<IntentionExecutable> instances(final SNode node, final EditorContext context) {
if (myCachedExecutable == null) {
myCachedExecutable = Collections.<IntentionExecutable>singletonList(new replace_invokeOperation_with_compactInvoke_Intention.IntentionImplementation());
}
return myCachedExecutable;
}
/*package*/ final class IntentionImplementation extends AbstractIntentionExecutable {
public IntentionImplementation() {
}
@Override
public String getDescription(final SNode node, final EditorContext editorContext) {
return "Replace with Compact Invoke Expression";
}
@Override
public void execute(final SNode node, final EditorContext editorContext) {
SNode parent = SNodeOperations.cast(SNodeOperations.getParent(node), MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x116b46a08c4L, "jetbrains.mps.baseLanguage.structure.DotExpression"));
SNodeOperations.replaceWithAnother(parent, _quotation_createNode_7ste6_a0a1a0(SLinkOperations.getChildren(SNodeOperations.cast(SLinkOperations.getTarget(parent, MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x116b46a08c4L, 0x116b46b36c4L, "operation")), MetaAdapterFactory.getConcept(0xfd3920347849419dL, 0x907112563d152375L, 0x11d67349093L, "jetbrains.mps.baseLanguage.closures.structure.InvokeFunctionOperation")), MetaAdapterFactory.getContainmentLink(0xfd3920347849419dL, 0x907112563d152375L, 0x11d67349093L, 0x11d67375fccL, "parameter")), SLinkOperations.getTarget(parent, MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x116b46a08c4L, 0x116b46a4416L, "operand"))));
}
@Override
public IntentionDescriptor getDescriptor() {
return replace_invokeOperation_with_compactInvoke_Intention.this;
}
}
private static SNode _quotation_createNode_7ste6_a0a1a0(Object parameter_1, Object parameter_2) {
PersistenceFacade facade = PersistenceFacade.getInstance();
SNode quotedNode_3 = null;
SNode quotedNode_4 = null;
SNode quotedNode_5 = null;
quotedNode_3 = SModelUtil_new.instantiateConceptDeclaration(MetaAdapterFactory.getConcept(MetaAdapterFactory.getLanguage(0xfd3920347849419dL, 0x907112563d152375L, "jetbrains.mps.baseLanguage.closures"), 0x11fb8425aa8L, "CompactInvokeFunctionExpression"), null, null, false);
{
List<SNode> nodes = (List<SNode>) parameter_1;
for (SNode child : nodes) {
quotedNode_3.addChild(MetaAdapterFactory.getContainmentLink(0xfd3920347849419dL, 0x907112563d152375L, 0x11fb8425aa8L, 0x11fb842da3eL, "parameter"), HUtil.copyIfNecessary(child));
}
}
quotedNode_5 = (SNode) parameter_2;
if (quotedNode_5 != null) {
quotedNode_3.addChild(MetaAdapterFactory.getContainmentLink(0xfd3920347849419dL, 0x907112563d152375L, 0x11fb8425aa8L, 0x11fb842c1adL, "function"), HUtil.copyIfNecessary(quotedNode_5));
}
return quotedNode_3;
}
}