package jetbrains.mps.ide.java.actions; /*Generated by MPS */ import jetbrains.mps.workbench.action.BaseAction; import javax.swing.Icon; import com.intellij.openapi.actionSystem.AnActionEvent; import java.util.Map; import jetbrains.mps.nodeEditor.EditorComponent; import jetbrains.mps.internal.collections.runtime.MapSequence; import org.jetbrains.mps.openapi.model.SNode; import jetbrains.mps.editor.runtime.cells.ReadOnlyUtil; import jetbrains.mps.internal.collections.runtime.ListSequence; import jetbrains.mps.lang.smodel.generator.smodelAdapter.SLinkOperations; import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory; import jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations; import org.jetbrains.annotations.NotNull; import jetbrains.mps.ide.actions.MPSCommonDataKeys; import jetbrains.mps.ide.editor.MPSEditorDataKeys; import jetbrains.mps.openapi.editor.EditorContext; public class CommentLine_Action extends BaseAction { private static final Icon ICON = null; public CommentLine_Action() { super("Comment Line", "", ICON); this.setIsAlwaysVisible(true); this.setExecuteOutsideCommand(false); } @Override public boolean isDumbAware() { return true; } @Override public boolean isApplicable(AnActionEvent event, final Map<String, Object> _params) { if (((EditorComponent) MapSequence.fromMap(_params).get("editorComponent")).isReadOnly()) { return false; } SNode singleLineComment = CommentLine_Action.this.getSingleLineComment(_params); if (singleLineComment != null) { return !(ReadOnlyUtil.isCellOrSelectionReadOnlyInEditor(((EditorComponent) MapSequence.fromMap(_params).get("editorComponent")), ((EditorComponent) MapSequence.fromMap(_params).get("editorComponent")).findNodeCell(singleLineComment))) && ListSequence.fromList(SLinkOperations.getChildren(singleLineComment, MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x57d533a7af15ed3aL, 0x57d533a7af16ff73L, "commentPart"))).count() == 1 && SNodeOperations.isInstanceOf(ListSequence.fromList(SLinkOperations.getChildren(singleLineComment, MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x57d533a7af15ed3aL, 0x57d533a7af16ff73L, "commentPart"))).first(), MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x57d533a7af16ff67L, "jetbrains.mps.baseLanguage.structure.StatementCommentPart")); } return false; } @Override public void doUpdate(@NotNull AnActionEvent event, final Map<String, Object> _params) { this.setEnabledState(event.getPresentation(), this.isApplicable(event, _params)); } @Override protected boolean collectActionData(AnActionEvent event, final Map<String, Object> _params) { if (!(super.collectActionData(event, _params))) { return false; } { SNode node = event.getData(MPSCommonDataKeys.NODE); MapSequence.fromMap(_params).put("selectedNode", node); if (node == null) { return false; } } { EditorComponent editorComponent = event.getData(MPSEditorDataKeys.EDITOR_COMPONENT); if (editorComponent != null && editorComponent.isInvalid()) { editorComponent = null; } MapSequence.fromMap(_params).put("editorComponent", editorComponent); if (editorComponent == null) { return false; } } { EditorContext p = event.getData(MPSEditorDataKeys.EDITOR_CONTEXT); MapSequence.fromMap(_params).put("editorContext", p); if (p == null) { return false; } } return true; } @Override public void doExecute(@NotNull final AnActionEvent event, final Map<String, Object> _params) { SNode singleLineComment = CommentLine_Action.this.getSingleLineComment(_params); SNode currentNode; if (singleLineComment != null) { // uncommenting SNode innerStatement = SLinkOperations.getTarget(SNodeOperations.cast(ListSequence.fromList(SLinkOperations.getChildren(singleLineComment, MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x57d533a7af15ed3aL, 0x57d533a7af16ff73L, "commentPart"))).first(), MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x57d533a7af16ff67L, "jetbrains.mps.baseLanguage.structure.StatementCommentPart")), MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x57d533a7af16ff67L, 0x57d533a7af16ff68L, "commentedStatement")); SNodeOperations.replaceWithAnother(singleLineComment, innerStatement); SNodeOperations.deleteNode(singleLineComment); currentNode = innerStatement; } else { SNode statement = CommentLine_Action.this.getStatement(_params); assert statement != null : "Statement should not be null due to the isApplicable() constraints"; // commenting SNode comment = SNodeOperations.replaceWithNewChild(statement, MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x57d533a7af15ed3aL, "jetbrains.mps.baseLanguage.structure.SingleLineComment")); SNode commentPart = SLinkOperations.addNewChild(comment, MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x57d533a7af15ed3aL, 0x57d533a7af16ff73L, "commentPart"), MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x57d533a7af16ff67L, "jetbrains.mps.baseLanguage.structure.StatementCommentPart")); SLinkOperations.setTarget(commentPart, MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x57d533a7af16ff67L, 0x57d533a7af16ff68L, "commentedStatement"), statement); currentNode = comment; } if ((SNodeOperations.getNextSibling(currentNode) != null)) { ((EditorContext) MapSequence.fromMap(_params).get("editorContext")).select(SNodeOperations.getNextSibling(currentNode)); } } private SNode getStatement(final Map<String, Object> _params) { return SNodeOperations.getNodeAncestor(((SNode) MapSequence.fromMap(_params).get("selectedNode")), MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8cc56b215L, "jetbrains.mps.baseLanguage.structure.Statement"), true, false); } private SNode getSingleLineComment(final Map<String, Object> _params) { return SNodeOperations.getNodeAncestor(((SNode) MapSequence.fromMap(_params).get("selectedNode")), MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x57d533a7af15ed3aL, "jetbrains.mps.baseLanguage.structure.SingleLineComment"), true, false); } }