1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-07 17:56:01 +02:00

Formatting of multi-line string literals in function argument lists.

This commit is contained in:
Sergey Prigogin 2011-03-15 17:06:31 +00:00
parent 011be21212
commit 2a00a3219c
3 changed files with 37 additions and 7 deletions

View file

@ -2660,8 +2660,10 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
boolean needSpace= false;
final int line= scribe.line;
boolean indented= false;
int indentationLevel = scribe.indentationLevel;
int numberOfIndentations = scribe.numberOfIndentations;
try {
int[] stringLiterals = { Token.tSTRING, Token.tLSTRING, Token.tRSTRING };
final int[] stringLiterals = { Token.tSTRING, Token.tLSTRING, Token.tRSTRING };
while (true) {
scribe.printNextToken(stringLiterals, needSpace);
token= peekNextToken();
@ -2670,15 +2672,23 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
}
scribe.printCommentPreservingNewLines();
if (!indented && line != scribe.line) {
indented= true;
scribe.indentForContinuation();
Alignment alignment = scribe.currentAlignment;
if (alignment != null && (alignment.mode & Alignment.M_INDENT_ON_COLUMN) != 0) {
scribe.indentationLevel= alignment.breakIndentationLevel;
} else if (alignment != null && (alignment.mode & Alignment.M_INDENT_BY_ONE) != 0) {
indented = true;
scribe.indent();
} else {
indented = true;
scribe.indentForContinuation();
}
}
needSpace= true;
}
} finally {
if (indented) {
scribe.unIndentForContinuation();
}
// Restore indentation.
scribe.indentationLevel = indentationLevel;
scribe.numberOfIndentations = numberOfIndentations;
}
} else {
scribe.printNextToken(peekNextToken());

View file

@ -1472,7 +1472,7 @@ public class Scribe {
buffer.append('\t');
indentationsAsTab++;
int complement= tabLength - ((column - 1) % tabLength); // amount of space
column+= complement;
column += complement;
needSpace= false;
} else {
buffer.append(' ');

View file

@ -1059,6 +1059,26 @@ public class CodeFormatterTest extends BaseUITestCase {
assertFormatterResult();
}
//void function(const char* s);
//
//void test() {
//function("string literal"
//"continuation of the string literal");
//}
//void function(const char* s);
//
//void test() {
// function("string literal"
// "continuation of the string literal");
//}
public void testFunctionCallWithMultilineStringLiteral() 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();
}
//#define MY_MACRO int a; \
// int b; \
// int c();