From 8ccaca146ccf9be8fc837a63112aa045694442d7 Mon Sep 17 00:00:00 2001 From: Anton Leherbauer Date: Thu, 18 Nov 2010 12:56:32 +0000 Subject: [PATCH] Additional fix and test for bug 322776 --- .../cdt/internal/formatter/Scribe.java | 12 +++++++++- .../cdt/ui/tests/text/CodeFormatterTest.java | 22 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/Scribe.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/Scribe.java index 34fc136802a..dcc70a013cc 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/Scribe.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/Scribe.java @@ -65,6 +65,7 @@ public class Scribe { private boolean preserveNewLines; private boolean checkLineWrapping; public int lastNumberOfNewLines; + private boolean preserveLineBreakIndentation; boolean formatBrace; public int line; @@ -469,6 +470,10 @@ public class Scribe { if (currentAlignment != null && !formatBrace) { indentationLevel = currentAlignment.breakIndentationLevel; } + + // Set the flag to indicate that a specific indentation is currently in used + preserveLineBreakIndentation = true; + // Print the computed indentation in the buffer printIndentationIfNecessary(tempBuffer); @@ -1242,7 +1247,11 @@ public class Scribe { } if (lastNumberOfNewLines >= 1) { // ensure that the scribe is at the beginning of a new line - column = 1; + // only if no specific indentation has been previously set + if (!preserveLineBreakIndentation) { + column = 1; + } + this.preserveLineBreakIndentation = false; return; } addInsertEdit(insertPosition, lineSeparator); @@ -1251,6 +1260,7 @@ public class Scribe { column= 1; needSpace= false; pendingSpace= false; + preserveLineBreakIndentation = false; } public void printNextToken(int expectedTokenType) { 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 81dd235ffa8..9bcd2dad4b2 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 @@ -1446,6 +1446,28 @@ public class CodeFormatterTest extends BaseUITestCase { assertFormatterResult(); } + //#define X() { } + //void g() { + // X(); + // if (1) { + // x(); + // } + // z(); + //} + + //#define X() { } + //void g() { + // X(); + // if (1) { + // x(); + // } + // z(); + //} + public void testKeepWrappedLines_Bug322776_2() throws Exception { + fOptions.put(DefaultCodeFormatterConstants.FORMATTER_JOIN_WRAPPED_LINES, DefaultCodeFormatterConstants.FALSE); + assertFormatterResult(); + } + //void f() { //double confidence = 0.316030 // //- 0.016315 * C_Count //