From 5c2e25c3d5b232cfbdd62252f9b2dcde1b45658a Mon Sep 17 00:00:00 2001 From: Valentin Fondaratov Date: Mon, 30 Jun 2014 15:54:09 +0400 Subject: [PATCH] ruby true multiline execution with multiline history --- .../console/ConsoleExecuteAction.java | 13 +- ...MultilineHandlingExecuteActionHandler.java | 158 ------------------ 2 files changed, 12 insertions(+), 159 deletions(-) delete mode 100644 platform/lang-impl/src/com/intellij/execution/console/MultilineHandlingExecuteActionHandler.java diff --git a/platform/lang-impl/src/com/intellij/execution/console/ConsoleExecuteAction.java b/platform/lang-impl/src/com/intellij/execution/console/ConsoleExecuteAction.java index b9e504642e5e..00c717faf9df 100644 --- a/platform/lang-impl/src/com/intellij/execution/console/ConsoleExecuteAction.java +++ b/platform/lang-impl/src/com/intellij/execution/console/ConsoleExecuteAction.java @@ -156,11 +156,22 @@ public class ConsoleExecuteAction extends DumbAwareAction { myAddToHistory = addCurrentToHistory; } + /** + * @deprecated + */ protected void beforeExecution(@NotNull LanguageConsoleImpl console) { } - final void runExecuteAction(@NotNull LanguageConsoleImpl console, @Nullable LanguageConsoleView consoleView) { + protected boolean shouldExecute(@NotNull LanguageConsoleImpl console) { + //noinspection deprecation beforeExecution(console); + return true; + } + + final void runExecuteAction(@NotNull LanguageConsoleImpl console, @Nullable LanguageConsoleView consoleView) { + if (!shouldExecute(console)) { + return; + } String text = console.prepareExecuteAction(myAddToHistory, myPreserveMarkup, true); ((UndoManagerImpl)UndoManager.getInstance(console.getProject())).invalidateActionsFor(DocumentReferenceManager.getInstance().create(console.getCurrentEditor().getDocument())); diff --git a/platform/lang-impl/src/com/intellij/execution/console/MultilineHandlingExecuteActionHandler.java b/platform/lang-impl/src/com/intellij/execution/console/MultilineHandlingExecuteActionHandler.java deleted file mode 100644 index 0b0a63fd164d..000000000000 --- a/platform/lang-impl/src/com/intellij/execution/console/MultilineHandlingExecuteActionHandler.java +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Copyright 2000-2014 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.execution.console; - -import com.intellij.openapi.util.text.StringUtil; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Collection; - -public abstract class MultilineHandlingExecuteActionHandler extends BaseConsoleExecuteActionHandler { - @NotNull - private BaseConsoleExecuteActionHandler myDelegateHandler; - @Nullable - private String myMultilineToken = null; - @NotNull - protected StringBuilder myInputBuffer; - - public MultilineHandlingExecuteActionHandler(@NotNull BaseConsoleExecuteActionHandler delegateHandler, boolean preserveMarkup) { - super(preserveMarkup); - myDelegateHandler = delegateHandler; - initInputBuffer(); - } - - @NotNull - protected abstract Collection getMultilineTokens(); - - protected abstract boolean startsAnotherCodeFragment(@NotNull String line); - - protected abstract void onMultilineEnter(); - - protected abstract void onMultilineExit(); - - protected abstract void onLineContinuation(); - - protected abstract boolean processLineIfShouldNotExecute(@NotNull String line); - - - @Nullable - protected String getOpeningMultilineToken(@NotNull String line) { - for (String token : getMultilineTokens()) { - if (isMultilineStarts(line, token)) { - return token; - } - } - return null; - } - - protected boolean closesThisMultilineToken(@NotNull String line, @NotNull String token) { - return isMultilineStarts(line, token); - } - - @Override - protected void execute(@NotNull String text, @NotNull LanguageConsoleView console) { - if (text.isEmpty()) { - processOneLine(text, console); - } - else { - if (StringUtil.countNewLines(text.trim()) > 0) { - executeMultiLine(text, console); - } - else { - processOneLine(text, console); - } - } - } - - protected final void executeMultiLine(@NotNull String text, @NotNull LanguageConsoleView console) { - myInputBuffer.append(text); - - myDelegateHandler.execute(myInputBuffer.toString(), console); - } - - protected final void processOneLine(@NotNull String line, @NotNull LanguageConsoleView console) { - line = StringUtil.trimTrailing(line); - if (StringUtil.isEmptyOrSpaces(line)) { - doProcessLine("\n", console); - } - else if (startsAnotherCodeFragment(line)) { - doProcessLine("\n", console); - doProcessLine(line, console); - } - else { - doProcessLine(line, console); - } - } - - protected final void doProcessLine(@NotNull final String line, @NotNull LanguageConsoleView console) { - if (!StringUtil.isEmptyOrSpaces(line)) { - myInputBuffer.append(line); - if (!line.endsWith("\n")) { - myInputBuffer.append("\n"); - } - } - else if (StringUtil.isEmptyOrSpaces(myInputBuffer.toString())) { - myInputBuffer.append(""); - } - - // multiline strings handling - if (myMultilineToken == null) { - myMultilineToken = getOpeningMultilineToken(line); - - if (myMultilineToken != null) { - // change language - onMultilineEnter(); - return; - } - } - else { - if (closesThisMultilineToken(line, myMultilineToken)) { - myMultilineToken = null; - // restore language - onMultilineExit(); - } - else { - if(line.equals("\n")) { - myInputBuffer.append("\n"); - } - return; - } - } - - // Process line continuation - if (line.endsWith("\\")) { - onLineContinuation(); - return; - } - - if (processLineIfShouldNotExecute(line)) { - return; - } - - myDelegateHandler.execute(myInputBuffer.toString(), console); - initInputBuffer(); - } - - private void initInputBuffer() { - myInputBuffer = new StringBuilder(); - } - - private static boolean isMultilineStarts(String line, String token) { - return StringUtil.getOccurrenceCount(line, token) % 2 == 1; - } - -}