package jetbrains.mps.baseLanguage.editor; /*Generated by MPS */ import jetbrains.mps.editor.runtime.cells.KeyMapImpl; import jetbrains.mps.openapi.editor.cells.KeyMapAction; import jetbrains.mps.editor.runtime.cells.KeyMapActionImpl; import jetbrains.mps.openapi.editor.EditorContext; import jetbrains.mps.openapi.editor.cells.EditorCell; import org.jetbrains.mps.openapi.model.SNode; import java.util.List; import jetbrains.mps.internal.collections.runtime.ListSequence; import jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations; import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory; import jetbrains.mps.openapi.editor.cells.CellTraversalUtil; import jetbrains.mps.smodel.action.SNodeFactoryOperations; public class TypeVariableDeclaration_addAuxBoundAfterBound_KeyMap extends KeyMapImpl { public TypeVariableDeclaration_addAuxBoundAfterBound_KeyMap() { this.setApplicableToEveryModel(false); KeyMapAction action; action = new TypeVariableDeclaration_addAuxBoundAfterBound_KeyMap.TypeVariableDeclaration_addAuxBoundAfterBound_KeyMap_Action0(); this.putAction("any", "&", action); } public static class TypeVariableDeclaration_addAuxBoundAfterBound_KeyMap_Action0 extends KeyMapActionImpl { public TypeVariableDeclaration_addAuxBoundAfterBound_KeyMap_Action0() { super.setCaretPolicy(KeyMapAction.CARET_AT_LAST_POSITION); this.setShownInPopupMenu(false); } public boolean isMenuAlwaysShown() { return false; } public boolean canExecute(final EditorContext editorContext) { EditorCell contextCell = editorContext.getContextCell(); if ((contextCell == null)) { return false; } SNode contextNode = contextCell.getSNode(); if (contextNode == null) { return false; } return this.canExecute_internal(editorContext, contextNode, this.getSelectedNodes(editorContext)); } public void execute(final EditorContext editorContext) { EditorCell contextCell = editorContext.getContextCell(); this.execute_internal(editorContext, contextCell.getSNode(), this.getSelectedNodes(editorContext)); } private boolean canExecute_internal(final EditorContext editorContext, final SNode node, final List<SNode> selectedNodes) { if (ListSequence.fromList(selectedNodes).count() != 1) { return false; } // Selected node should be within TypeVariableDeclaration SNode selectedNode = ListSequence.fromList(selectedNodes).first(); SNode typeVarDeclaration = SNodeOperations.getNodeAncestor(selectedNode, MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x1024639ed74L, "jetbrains.mps.baseLanguage.structure.TypeVariableDeclaration"), true, false); if (typeVarDeclaration == null) { return false; } // Next cell should belong to some other SNode, not our typeVarDeclaration EditorCell selectedCell = editorContext.getSelectedCell(); EditorCell nextLeaf = CellTraversalUtil.getNextLeaf(selectedCell); if (nextLeaf == null) { return false; } SNode nextCellNode = (SNode) nextLeaf.getSNode(); return nextCellNode != null && nextCellNode != typeVarDeclaration; } private void execute_internal(final EditorContext editorContext, final SNode node, final List<SNode> selectedNodes) { SNode typeVarDeclaration = SNodeOperations.getNodeAncestor(ListSequence.fromList(selectedNodes).first(), MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x1024639ed74L, "jetbrains.mps.baseLanguage.structure.TypeVariableDeclaration"), true, false); SNodeFactoryOperations.addNewChild(typeVarDeclaration, MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x1024639ed74L, 0x11ae913a476L, "auxBounds"), SNodeFactoryOperations.asInstanceConcept(MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x101de48bf9eL, "jetbrains.mps.baseLanguage.structure.ClassifierType"))); } public String getKeyStroke() { return " &"; } } }