mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-07 09:46:02 +02:00
Formatting of multi-line string literals in function argument lists.
This commit is contained in:
parent
011be21212
commit
2a00a3219c
3 changed files with 37 additions and 7 deletions
|
@ -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());
|
||||
|
|
|
@ -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(' ');
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Add table
Reference in a new issue