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:
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;
|
boolean needSpace= false;
|
||||||
final int line= scribe.line;
|
final int line= scribe.line;
|
||||||
boolean indented= false;
|
boolean indented= false;
|
||||||
|
int indentationLevel = scribe.indentationLevel;
|
||||||
|
int numberOfIndentations = scribe.numberOfIndentations;
|
||||||
try {
|
try {
|
||||||
int[] stringLiterals = { Token.tSTRING, Token.tLSTRING, Token.tRSTRING };
|
final int[] stringLiterals = { Token.tSTRING, Token.tLSTRING, Token.tRSTRING };
|
||||||
while (true) {
|
while (true) {
|
||||||
scribe.printNextToken(stringLiterals, needSpace);
|
scribe.printNextToken(stringLiterals, needSpace);
|
||||||
token= peekNextToken();
|
token= peekNextToken();
|
||||||
|
@ -2670,15 +2672,23 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
||||||
}
|
}
|
||||||
scribe.printCommentPreservingNewLines();
|
scribe.printCommentPreservingNewLines();
|
||||||
if (!indented && line != scribe.line) {
|
if (!indented && line != scribe.line) {
|
||||||
indented= true;
|
Alignment alignment = scribe.currentAlignment;
|
||||||
scribe.indentForContinuation();
|
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;
|
needSpace= true;
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
if (indented) {
|
// Restore indentation.
|
||||||
scribe.unIndentForContinuation();
|
scribe.indentationLevel = indentationLevel;
|
||||||
}
|
scribe.numberOfIndentations = numberOfIndentations;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
scribe.printNextToken(peekNextToken());
|
scribe.printNextToken(peekNextToken());
|
||||||
|
|
|
@ -1472,7 +1472,7 @@ public class Scribe {
|
||||||
buffer.append('\t');
|
buffer.append('\t');
|
||||||
indentationsAsTab++;
|
indentationsAsTab++;
|
||||||
int complement= tabLength - ((column - 1) % tabLength); // amount of space
|
int complement= tabLength - ((column - 1) % tabLength); // amount of space
|
||||||
column+= complement;
|
column += complement;
|
||||||
needSpace= false;
|
needSpace= false;
|
||||||
} else {
|
} else {
|
||||||
buffer.append(' ');
|
buffer.append(' ');
|
||||||
|
|
|
@ -1059,6 +1059,26 @@ public class CodeFormatterTest extends BaseUITestCase {
|
||||||
assertFormatterResult();
|
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; \
|
//#define MY_MACRO int a; \
|
||||||
// int b; \
|
// int b; \
|
||||||
// int c();
|
// int c();
|
||||||
|
|
Loading…
Add table
Reference in a new issue