package jetbrains.mps.baseLanguage.editor;
/*Generated by MPS */
import jetbrains.mps.openapi.editor.cells.EditorCell;
import org.jetbrains.mps.openapi.model.SNode;
import jetbrains.mps.openapi.editor.EditorContext;
import jetbrains.mps.openapi.editor.cells.CellActionType;
import jetbrains.mps.editor.runtime.cells.AbstractCellAction;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.AttributeOperations;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.IAttributeDescriptor;
import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SPropertyOperations;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SLinkOperations;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations;
import jetbrains.mps.baseLanguage.behavior.ParenthesisUtil;
import jetbrains.mps.editor.runtime.selection.SelectionUtil;
import jetbrains.mps.openapi.editor.selection.SelectionManager;
public class DeleteParenthesisRight_Action {
public static void setCellActions(EditorCell editorCell, SNode node, EditorContext context) {
editorCell.setAction(CellActionType.DELETE, new DeleteParenthesisRight_Action.DeleteParenthesisRight_Action_DELETE(node));
editorCell.setAction(CellActionType.BACKSPACE, new DeleteParenthesisRight_Action.DeleteParenthesisRight_Action_BACKSPACE(node));
}
public static class DeleteParenthesisRight_Action_DELETE extends AbstractCellAction {
/*package*/ SNode myNode;
public DeleteParenthesisRight_Action_DELETE(SNode node) {
this.myNode = node;
}
public void execute(EditorContext editorContext) {
this.execute_internal(editorContext, this.myNode);
}
public void execute_internal(EditorContext editorContext, SNode node) {
int unmatchedLeftParens = ((AttributeOperations.getAttribute(node, new IAttributeDescriptor.NodeAttribute(MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x64a1ef64cd9b42ceL, "jetbrains.mps.baseLanguage.structure.IncompleteLeftParen"))) != null) ? SPropertyOperations.getInteger(AttributeOperations.getAttribute(node, new IAttributeDescriptor.NodeAttribute(MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x64a1ef64cd9b42ceL, "jetbrains.mps.baseLanguage.structure.IncompleteLeftParen"))), MetaAdapterFactory.getProperty(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xede3fe8510255edL, 0xede3fe8510255eeL, "count")) : 0);
int unmatchedRightParens = ((AttributeOperations.getAttribute(node, new IAttributeDescriptor.NodeAttribute(MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x2052c4520af308e1L, "jetbrains.mps.baseLanguage.structure.IncompleteRightParen"))) != null) ? SPropertyOperations.getInteger(AttributeOperations.getAttribute(node, new IAttributeDescriptor.NodeAttribute(MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x2052c4520af308e1L, "jetbrains.mps.baseLanguage.structure.IncompleteRightParen"))), MetaAdapterFactory.getProperty(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xede3fe8510255edL, 0xede3fe8510255eeL, "count")) : 0);
SNode replacing = SLinkOperations.getTarget(node, MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xfb4ed32b7fL, 0xfb4ed32b80L, "expression"));
if (replacing == null) {
SNodeOperations.deleteNode(node);
return;
}
SNode leftMostNode = EditorParenthesisUtil.findRightmostOrLeftmostLeafExpression(replacing, false);
SNodeOperations.replaceWithAnother(node, replacing);
SNode rightMostNode = EditorParenthesisUtil.findRightmostOrLeftmostLeafExpression(replacing, true);
ParenthesisUtil.checkWholeExpressionPriorities(replacing);
ParenthesisUtil.createUnmatchedLeftParenthesis(leftMostNode);
if (unmatchedLeftParens > 0) {
for (int i = 0; i < unmatchedLeftParens; i++) {
ParenthesisUtil.createUnmatchedLeftParenthesis(leftMostNode);
}
}
if (unmatchedRightParens > 0) {
for (int i = 0; i < unmatchedRightParens; i++) {
ParenthesisUtil.createUnmatchedRightParenthesis(rightMostNode);
}
}
SelectionUtil.selectLabelCellAnSetCaret(editorContext, rightMostNode, SelectionManager.LAST_CELL, -1);
}
}
public static class DeleteParenthesisRight_Action_BACKSPACE extends AbstractCellAction {
/*package*/ SNode myNode;
public DeleteParenthesisRight_Action_BACKSPACE(SNode node) {
this.myNode = node;
}
public void execute(EditorContext editorContext) {
this.execute_internal(editorContext, this.myNode);
}
public void execute_internal(EditorContext editorContext, SNode node) {
int unmatchedLeftParens = ((AttributeOperations.getAttribute(node, new IAttributeDescriptor.NodeAttribute(MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x64a1ef64cd9b42ceL, "jetbrains.mps.baseLanguage.structure.IncompleteLeftParen"))) != null) ? SPropertyOperations.getInteger(AttributeOperations.getAttribute(node, new IAttributeDescriptor.NodeAttribute(MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x64a1ef64cd9b42ceL, "jetbrains.mps.baseLanguage.structure.IncompleteLeftParen"))), MetaAdapterFactory.getProperty(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xede3fe8510255edL, 0xede3fe8510255eeL, "count")) : 0);
int unmatchedRightParens = ((AttributeOperations.getAttribute(node, new IAttributeDescriptor.NodeAttribute(MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x2052c4520af308e1L, "jetbrains.mps.baseLanguage.structure.IncompleteRightParen"))) != null) ? SPropertyOperations.getInteger(AttributeOperations.getAttribute(node, new IAttributeDescriptor.NodeAttribute(MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x2052c4520af308e1L, "jetbrains.mps.baseLanguage.structure.IncompleteRightParen"))), MetaAdapterFactory.getProperty(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xede3fe8510255edL, 0xede3fe8510255eeL, "count")) : 0);
SNode replacing = SLinkOperations.getTarget(node, MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xfb4ed32b7fL, 0xfb4ed32b80L, "expression"));
if (replacing == null) {
SNodeOperations.deleteNode(node);
return;
}
SNode leftMostNode = EditorParenthesisUtil.findRightmostOrLeftmostLeafExpression(replacing, false);
SNodeOperations.replaceWithAnother(node, replacing);
SNode rightMostNode = EditorParenthesisUtil.findRightmostOrLeftmostLeafExpression(replacing, true);
ParenthesisUtil.checkWholeExpressionPriorities(replacing);
ParenthesisUtil.createUnmatchedLeftParenthesis(leftMostNode);
if (unmatchedLeftParens > 0) {
for (int i = 0; i < unmatchedLeftParens; i++) {
ParenthesisUtil.createUnmatchedLeftParenthesis(leftMostNode);
}
}
if (unmatchedRightParens > 0) {
for (int i = 0; i < unmatchedRightParens; i++) {
ParenthesisUtil.createUnmatchedRightParenthesis(rightMostNode);
}
}
SelectionUtil.selectLabelCellAnSetCaret(editorContext, rightMostNode, SelectionManager.LAST_CELL, -1);
}
}
}