diff options
author | Marco Stornelli | 2019-05-30 16:28:33 +0000 |
---|---|---|
committer | Marco Stornelli | 2019-05-31 05:00:07 +0000 |
commit | 862e8222ea12a3342ff8bc2fea2f2b3da3cc3820 (patch) | |
tree | c98306cb78ec701ad3b7cd8a5dd2a7db745a8f9e | |
parent | 90358f53746e2227005c82d5412a8fca1c83b9cd (diff) | |
download | org.eclipse.cdt-862e8222ea12a3342ff8bc2fea2f2b3da3cc3820.tar.gz org.eclipse.cdt-862e8222ea12a3342ff8bc2fea2f2b3da3cc3820.tar.xz org.eclipse.cdt-862e8222ea12a3342ff8bc2fea2f2b3da3cc3820.zip |
Bug 547684 - Fix format assignment with init list
Change-Id: I4fbdc1c65eb25688231e8020bbc3baa750d97be0
Signed-off-by: Marco Stornelli <marco.stornelli@gmail.com>
2 files changed, 25 insertions, 4 deletions
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java index 8de7f59fa77..61dcd0e17bd 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java @@ -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; diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java index 2922ba63733..903653c03d5 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java @@ -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(); + } } |