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 59ecfc3d762..97fa4864705 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 @@ -2668,14 +2668,13 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, } while (isOverloadedLeftShift(binaryExpression)); Collections.reverse(elements); + Runnable tailFormatter = scribe.takeTailFormatter(); node.accept(this); scribe.printComment(); if (preferences.insert_space_before_binary_operator) { scribe.space(); } - Runnable tailFormatter = scribe.getTailFormatter(); - Alignment wrapperAlignment = null; if ((preferences.alignment_for_overloaded_left_shift_chain & Alignment.M_INDENT_ON_COLUMN) != 0) { wrapperAlignment = scribe.createAlignment( @@ -2751,7 +2750,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, private int visit(IASTLiteralExpression node) { if (node.getKind() == IASTLiteralExpression.lk_string_literal) { - // handle concatenation of string literals + // Handle concatenation of string literals int token; boolean needSpace= false; final int line= scribe.line; diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/Location.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/Location.java index dee4ec62c65..f464e3c7288 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/Location.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/Location.java @@ -34,20 +34,23 @@ public class Location { int editsIndex; OptimizedReplaceEdit textEdit; + public Runnable tailFormatter; + public Location(Scribe scribe, int sourceRestart){ update(scribe, sourceRestart); } public void update(Scribe scribe, int sourceRestart){ - this.outputColumn = scribe.column; - this.outputLine = scribe.line; this.inputOffset = sourceRestart; + this.outputLine = scribe.line; + this.outputColumn = scribe.column; this.outputIndentationLevel = scribe.indentationLevel; - this.lastNumberOfNewLines = scribe.lastNumberOfNewLines; this.needSpace = scribe.needSpace; this.pendingSpace = scribe.pendingSpace; - this.editsIndex = scribe.editsIndex; this.numberOfIndentations = scribe.numberOfIndentations; - textEdit = scribe.getLastEdit(); + this.lastNumberOfNewLines = scribe.lastNumberOfNewLines; + this.editsIndex = scribe.editsIndex; + this.textEdit = scribe.getLastEdit(); + this.tailFormatter = scribe.getTailFormatter(); } } 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 feaea1ef0f5..03dae128826 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 @@ -1686,19 +1686,19 @@ public class Scribe { currentAlignment= currentAlignment.enclosing; // pop currentLocation throw e; // rethrow } - // reset scribe/scanner to restart at this given location + // Reset scribe/scanner to restart at this given location resetAt(currentAlignment.location); scanner.resetTo(currentAlignment.location.inputOffset, scanner.eofPosition - 1); - // clean alignment chunkKind so it will think it is a new chunk again + // Clean alignment chunkKind so it will think it is a new chunk again currentAlignment.chunkKind= 0; currentAlignmentException= null; } void redoMemberAlignment(AlignmentException e) { - // reset scribe/scanner to restart at this given location + // Reset scribe/scanner to restart at this given location resetAt(memberAlignment.location); scanner.resetTo(memberAlignment.location.inputOffset, scanner.eofPosition - 1); - // clean alignment chunkKind so it will think it is a new chunk again + // Clean alignment chunkKind so it will think it is a new chunk again memberAlignment.chunkKind= 0; currentAlignmentException= null; } @@ -1714,14 +1714,15 @@ public class Scribe { line= location.outputLine; column= location.outputColumn; indentationLevel= location.outputIndentationLevel; - numberOfIndentations= location.numberOfIndentations; - lastNumberOfNewLines= location.lastNumberOfNewLines; needSpace= location.needSpace; pendingSpace= location.pendingSpace; + numberOfIndentations= location.numberOfIndentations; + lastNumberOfNewLines= location.lastNumberOfNewLines; editsIndex= location.editsIndex; if (editsIndex > 0) { edits[editsIndex - 1]= location.textEdit; } + setTailFormatter(location.tailFormatter); } private void resize() { 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 ed1d2bf0a6a..81e64e8cc5c 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 @@ -2129,6 +2129,33 @@ public class CodeFormatterTest extends BaseUITestCase { assertFormatterResult(); } + //class Stream { + //Stream& operator<<(const char* s); + //}; + //const char* function(); + // + //void text() { + //Stream() << "0123456789012345678" << function() << "0123456789012345678" << "0123"; + //int i; + //} + + //class Stream { + // Stream& operator<<(const char* s); + //}; + //const char* function(); + // + //void text() { + // Stream() << "0123456789012345678" << function() << "0123456789012345678" + // << "0123"; + // int i; + //} + public void testOverloadedLeftShiftChain_3() throws Exception { + fOptions.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, CCorePlugin.SPACE); + fOptions.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_OVERLOADED_LEFT_SHIFT_CHAIN, + Integer.toString(Alignment.M_COMPACT_SPLIT | Alignment.M_INDENT_ON_COLUMN)); + assertFormatterResult(); + } + //int main() { // std::vector> test; // // some comment