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 DeleteParenthesisLeft_Actions { public static void setCellActions(EditorCell editorCell, SNode node, EditorContext context) { editorCell.setAction(CellActionType.DELETE, new DeleteParenthesisLeft_Actions.DeleteParenthesisLeft_Actions_DELETE(node)); editorCell.setAction(CellActionType.BACKSPACE, new DeleteParenthesisLeft_Actions.DeleteParenthesisLeft_Actions_BACKSPACE(node)); } public static class DeleteParenthesisLeft_Actions_DELETE extends AbstractCellAction { /*package*/ SNode myNode; public DeleteParenthesisLeft_Actions_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 rightMostNode = EditorParenthesisUtil.findRightmostOrLeftmostLeafExpression(replacing, true); SNodeOperations.replaceWithAnother(node, replacing); SNode leftMostNode = EditorParenthesisUtil.findRightmostOrLeftmostLeafExpression(replacing, false); ParenthesisUtil.checkWholeExpressionPriorities(replacing); ParenthesisUtil.createUnmatchedRightParenthesis(rightMostNode); 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, leftMostNode, SelectionManager.FIRST_CELL, 0); } } public static class DeleteParenthesisLeft_Actions_BACKSPACE extends AbstractCellAction { /*package*/ SNode myNode; public DeleteParenthesisLeft_Actions_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 rightMostNode = EditorParenthesisUtil.findRightmostOrLeftmostLeafExpression(replacing, true); SNodeOperations.replaceWithAnother(node, replacing); SNode leftMostNode = EditorParenthesisUtil.findRightmostOrLeftmostLeafExpression(replacing, false); ParenthesisUtil.checkWholeExpressionPriorities(replacing); ParenthesisUtil.createUnmatchedRightParenthesis(rightMostNode); 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, leftMostNode, SelectionManager.FIRST_CELL, 0); } } }