From 8e9aff791604e8823fba7e4cd96f659940c0a62a Mon Sep 17 00:00:00 2001 From: Yaroslav Lepenkin Date: Mon, 23 Mar 2015 19:30:51 +0300 Subject: [PATCH] Corrected parameters order, which caused extra spaces formatting when performed on selected fragment. Formatter depending on the result of FormatterUtil.isFormatterCalledExplicitly decides whether to cut trailing spaces or not, and command name mismatch eliminated range correction. Test added. --- ...tSelection_DoNotTouchTrailingWhiteSpaces_after.java | 10 ++++++++++ ...Selection_DoNotTouchTrailingWhiteSpaces_before.java | 10 ++++++++++ .../actions/ReformatCodeActionInEditorTest.java | 5 +++++ .../codeInsight/actions/ReformatCodeProcessor.java | 2 +- 4 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 java/java-tests/testData/actions/reformatFileInEditor/formatSelection_DoNotTouchTrailingWhiteSpaces_after.java create mode 100644 java/java-tests/testData/actions/reformatFileInEditor/formatSelection_DoNotTouchTrailingWhiteSpaces_before.java diff --git a/java/java-tests/testData/actions/reformatFileInEditor/formatSelection_DoNotTouchTrailingWhiteSpaces_after.java b/java/java-tests/testData/actions/reformatFileInEditor/formatSelection_DoNotTouchTrailingWhiteSpaces_after.java new file mode 100644 index 000000000000..3dfde165f400 --- /dev/null +++ b/java/java-tests/testData/actions/reformatFileInEditor/formatSelection_DoNotTouchTrailingWhiteSpaces_after.java @@ -0,0 +1,10 @@ +public class T { + + + public void tutu() { + + } + + + public void test() {} +} \ No newline at end of file diff --git a/java/java-tests/testData/actions/reformatFileInEditor/formatSelection_DoNotTouchTrailingWhiteSpaces_before.java b/java/java-tests/testData/actions/reformatFileInEditor/formatSelection_DoNotTouchTrailingWhiteSpaces_before.java new file mode 100644 index 000000000000..c8d45129804d --- /dev/null +++ b/java/java-tests/testData/actions/reformatFileInEditor/formatSelection_DoNotTouchTrailingWhiteSpaces_before.java @@ -0,0 +1,10 @@ +public class T { + + + public void tutu() { + + } + + + public void test() {} +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/actions/ReformatCodeActionInEditorTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/actions/ReformatCodeActionInEditorTest.java index 058d165c3ddf..578ba79bad81 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/actions/ReformatCodeActionInEditorTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/actions/ReformatCodeActionInEditorTest.java @@ -102,4 +102,9 @@ public class ReformatCodeActionInEditorTest extends LightPlatformCodeInsightFixt public void testFormatOptimizeRearrangeVcsChanges() { doTest(new ReformatCodeRunOptions(VCS_CHANGED_TEXT).setOptimizeImports(true).setRearrangeCode(true)); } + + public void testFormatSelection_DoNotTouchTrailingWhiteSpaces() { + //todo actually test is not working, and working test is not working + doTest(new ReformatCodeRunOptions(SELECTED_TEXT)); + } } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/actions/ReformatCodeProcessor.java b/platform/lang-impl/src/com/intellij/codeInsight/actions/ReformatCodeProcessor.java index e9f80bd23fad..0bfb4cc31238 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/actions/ReformatCodeProcessor.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/actions/ReformatCodeProcessor.java @@ -54,7 +54,7 @@ public class ReformatCodeProcessor extends AbstractLayoutCodeProcessor { } public ReformatCodeProcessor(@NotNull PsiFile file, @NotNull SelectionModel selectionModel) { - super(file.getProject(), file, COMMAND_NAME, PROGRESS_TEXT, false); + super(file.getProject(), file, PROGRESS_TEXT, COMMAND_NAME, false); mySelectionModel = selectionModel; }