mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-22 06:02:11 +02:00
Bug 547684 - Fix format assignment with init list
Change-Id: I4fbdc1c65eb25688231e8020bbc3baa750d97be0 Signed-off-by: Marco Stornelli <marco.stornelli@gmail.com>
This commit is contained in:
parent
90358f5374
commit
862e8222ea
2 changed files with 25 additions and 4 deletions
|
@ -3034,12 +3034,15 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
if (enclosedInMacroExpansion(node)) {
|
||||
return PROCESS_SKIP;
|
||||
}
|
||||
if (doNodeLocationsOverlap(node.getOperand1(), node.getOperand2())) {
|
||||
IASTNode op2 = node.getOperand2();
|
||||
if (op2 == null)
|
||||
op2 = node.getInitOperand2();
|
||||
if (doNodeLocationsOverlap(node.getOperand1(), op2)) {
|
||||
// Overlapping of operands is possible if the central part of the binary expression is
|
||||
// a result of macro expansion. There is no need to print the operator in such case,
|
||||
// so we simply delegate to each of the operands.
|
||||
node.getOperand1().accept(this);
|
||||
node.getOperand2().accept(this);
|
||||
op2.accept(this);
|
||||
return PROCESS_SKIP;
|
||||
}
|
||||
if (isAssignment(node)) {
|
||||
|
@ -3114,7 +3117,10 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
op1.accept(this);
|
||||
|
||||
// In case of macros we may have already passed the equal sign position.
|
||||
if (getCurrentPosition() < nodeOffset(node.getOperand2())) {
|
||||
IASTNode op2 = node.getOperand2();
|
||||
if (op2 == null)
|
||||
op2 = node.getInitOperand2();
|
||||
if (getCurrentPosition() < nodeOffset(op2)) {
|
||||
// Operator
|
||||
final int nextToken = peekNextToken();
|
||||
// In case of C++ alternative operators, like 'and', 'not', etc. a space
|
||||
|
@ -3137,7 +3143,9 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
|
||||
scribe.setTailFormatter(tailFormatter);
|
||||
// Operand 2
|
||||
final IASTExpression op2 = node.getOperand2();
|
||||
op2 = node.getOperand2();
|
||||
if (op2 == null)
|
||||
op2 = node.getInitOperand2();
|
||||
op2.accept(this);
|
||||
scribe.runTailFormatter();
|
||||
ok = true;
|
||||
|
|
|
@ -4324,4 +4324,17 @@ public class CodeFormatterTest extends BaseUITestCase {
|
|||
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_LABEL, CCorePlugin.INSERT);
|
||||
assertFormatterResult();
|
||||
}
|
||||
|
||||
//int main() {
|
||||
// int x;
|
||||
// x = {42};
|
||||
//}
|
||||
|
||||
//int main() {
|
||||
// int x;
|
||||
// x = { 42 };
|
||||
//}
|
||||
public void testAssigmentWithInitList_Bug547684() throws Exception {
|
||||
assertFormatterResult();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue