From 199adb3ec55dbb839aab228415e1478ab1a6f760 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Wed, 16 Mar 2011 00:42:31 +0000 Subject: [PATCH] Improved formatting of function calls. --- .../internal/formatter/align/Alignment.java | 6 +++++ .../cdt/ui/tests/text/CodeFormatterTest.java | 23 ++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/align/Alignment.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/align/Alignment.java index 5f68e2ea0c6..f3137c74c07 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/align/Alignment.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/align/Alignment.java @@ -272,6 +272,12 @@ public class Alignment { case M_COMPACT_SPLIT: i = this.fragmentIndex; do { + if (i == 0 && (mode & M_INDENT_ON_COLUMN) != 0 && + name.startsWith(LIST_ELEMENTS_PREFIX)) { + // Don't split the line before the first element of the list if the list + // elements are indented on column. + break; + } if (this.fragmentBreaks[i] == NONE) { this.fragmentBreaks[i] = BREAK; this.fragmentIndentations[i] = this.breakIndentationLevel; diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java index 575456c313a..03c402206c9 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java @@ -1054,11 +1054,32 @@ public class CodeFormatterTest extends BaseUITestCase { // f1(100000, 200000, 300000, 400000, 500000, // f2(10, 20, 30, 40, 50, 60, 70000), 700000); //} - public void testFunctionCall() throws Exception { + public void testFunctionCall_1() throws Exception { fOptions.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, CCorePlugin.SPACE); assertFormatterResult(); } + //int function(int, int, int, int, int); + //int function_with_a_long_name(int, int); + // + //void test() { + //function_with_a_long_name(function(1000000, 2000000, 3000000, 4000000, 5000000), 6000000); + //} + + //int function(int, int, int, int, int); + //int function_with_a_long_name(int, int); + // + //void test() { + // function_with_a_long_name(function(1000000, 2000000, 3000000, 4000000, + // 5000000), 6000000); + //} + public void testFunctionCall_2() throws Exception { + fOptions.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, CCorePlugin.SPACE); + fOptions.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_METHOD_INVOCATION, + Integer.toString(Alignment.M_COMPACT_SPLIT | Alignment.M_INDENT_ON_COLUMN)); + assertFormatterResult(); + } + //void function(const char* s); // //void test() {