diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java index 0084ff277b9..09e19094aa3 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java @@ -1016,9 +1016,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, if (preferences.insert_new_line_before_colon_in_constructor_initializer_list) { scribe.printTrailingComment(); scribe.startNewLine(); - for (int i= 0; i < preferences.continuation_indentation; i++) { - scribe.indent(); - } + scribe.indentForContinuation(); } scribe.printNextToken(Token.tCOLON, !preferences.insert_new_line_before_colon_in_constructor_initializer_list); if (preferences.insert_new_line_before_colon_in_constructor_initializer_list) { @@ -1026,16 +1024,12 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, } else { scribe.printTrailingComment(); scribe.startNewLine(); - for (int i= 0; i < preferences.continuation_indentation; i++) { - scribe.indent(); - } + scribe.indentForContinuation(); } final ListAlignment align= new ListAlignment(preferences.alignment_for_constructor_initializer_list); align.fTieBreakRule = Alignment.R_OUTERMOST; formatList(Arrays.asList(constructorChain), align, false, false); - for (int i= 0; i < preferences.continuation_indentation; i++) { - scribe.unIndent(); - } + scribe.unIndentForContinuation(); } } @@ -1689,10 +1683,8 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, if (align.fSpaceAfterOpeningParen) { scribe.space(); } - final int continuationIndentation= - align.fContinuationIndentation >= 0 - ? align.fContinuationIndentation - : preferences.continuation_indentation; + final int continuationIndentation= align.fContinuationIndentation >= 0 ? + align.fContinuationIndentation : preferences.continuation_indentation; Alignment listAlignment = scribe.createAlignment( "listElements_" + (elements.isEmpty() ? "ellipsis" : elements.get(0).getClass().getSimpleName()), //$NON-NLS-1$ //$NON-NLS-2$ align.fMode, @@ -2309,13 +2301,13 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, scribe.printCommentPreservingNewLines(); if (!indented && line != scribe.line) { indented= true; - scribe.indent(); + scribe.indentForContinuation(); } needSpace= true; } } finally { if (indented) { - scribe.unIndent(); + scribe.unIndentForContinuation(); } } } else { 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 919f37abbef..7cc377f356b 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 @@ -692,9 +692,7 @@ public class Scribe { ++parenLevel; print(currentToken.getLength(), hasWhitespace); if (parenLevel > 0) { - for (int i= 0; i < preferences.continuation_indentation; i++) { - indent(); - } + indentForContinuation(); if (column <= indentationLevel) { // HACK: avoid indent in same line column= indentationLevel + 1; @@ -704,9 +702,7 @@ public class Scribe { case Token.tRPAREN: --parenLevel; if (parenLevel >= 0) { - for (int i= 0; i < preferences.continuation_indentation; i++) { - unIndent(); - } + unIndentForContinuation(); } print(currentToken.getLength(), hasWhitespace); break; @@ -746,6 +742,18 @@ public class Scribe { } } + public void indentForContinuation() { + for (int i= 0; i < preferences.continuation_indentation; i++) { + indent(); + } + } + + public void unIndentForContinuation() { + for (int i= 0; i < preferences.continuation_indentation; i++) { + unIndent(); + } + } + public void formatOpeningBrace(String bracePosition, boolean insertSpaceBeforeBrace) { if (DefaultCodeFormatterConstants.NEXT_LINE.equals(bracePosition)) { printNewLine(); diff --git a/core/org.eclipse.cdt.ui.tests/resources/formatter/bugs/After.cpp b/core/org.eclipse.cdt.ui.tests/resources/formatter/bugs/After.cpp index 171b1c8c6c4..5ab2449463b 100644 --- a/core/org.eclipse.cdt.ui.tests/resources/formatter/bugs/After.cpp +++ b/core/org.eclipse.cdt.ui.tests/resources/formatter/bugs/After.cpp @@ -26,7 +26,7 @@ int main(int argc, char **argv) { // handling of string concat char* s1 = "this " "is " "one " "string."; char* s2 = "this " "is " - "one " "string."; + "one " "string."; // macro definition with line comment #define ID(x) x // identity int main() {