mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-15 12:15:47 +02:00
Formatting bug fixes.
This commit is contained in:
parent
56690dafd4
commit
32d0894ce1
4 changed files with 44 additions and 14 deletions
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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<std::vector<int>> test;
|
||||
// // some comment
|
||||
|
|
Loading…
Add table
Reference in a new issue