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 0bc0e2be60c..63c1a1f6af8 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 @@ -2539,9 +2539,11 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, if (isAssignment(node)) { return formatAssignment(node); } + Alignment expressionAlignment= scribe.createAlignment( Alignment.BINARY_EXPRESSION, preferences.alignment_for_binary_expression, + Alignment.R_OUTERMOST, 2, scribe.scanner.getCurrentPosition()); @@ -2549,12 +2551,11 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, boolean ok = false; do { try { - scribe.alignFragment(expressionAlignment, 0); final IASTExpression op1= node.getOperand1(); - // operand 1 + // Left operand op1.accept(this); - scribe.printTrailingComment(); + scribe.alignFragment(expressionAlignment, 1); // In case of macros we may have already passed the operator position. @@ -2577,7 +2578,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, } } - // operand 2 + // Right operand final IASTExpression op2= node.getOperand2(); op2.accept(this); diff --git a/core/org.eclipse.cdt.ui.tests/resources/formatter/bugs/After.cpp b/core/org.eclipse.cdt.ui.tests/resources/formatter/bugs/After.cpp index 5ab2449463b..9294a64417a 100644 --- a/core/org.eclipse.cdt.ui.tests/resources/formatter/bugs/After.cpp +++ b/core/org.eclipse.cdt.ui.tests/resources/formatter/bugs/After.cpp @@ -46,9 +46,9 @@ void bug183220() { if (((rtc_hdw_cr_sync_next != rtc_hdw_cr_sync) || rtc_hdw_cr_resync_enable) && !rtc_s2000_src_pending && !rtc_s2000_cr_sync_pending) { if (!identify_hdw_fvr_master() || !rtc_hdw_current_clock->external - || !rtc_hdw_cr_sync_next || ((rtc_hdw_current_clock->external - && rtc_hdw_cr_sync_next && rtc_s2000_clock_source_state - != RTC_CLOCK_PLL))) { + || !rtc_hdw_cr_sync_next + || ((rtc_hdw_current_clock->external && rtc_hdw_cr_sync_next + && rtc_s2000_clock_source_state != RTC_CLOCK_PLL))) { } } } 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 550f87a8d27..b8d64d61a26 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 @@ -1870,6 +1870,35 @@ public class CodeFormatterTest extends BaseUITestCase { assertFormatterResult(); } + //class Stream { + //Stream& operator <<(const char*); + //Stream& operator <<(int); + //}; + // + //Stream stream; + // + //void test() { + // // Breaking at << is preferred to breaking at +. + //stream << "text text text text text text text text text" << 1000000 + 2000000; + //} + + //class Stream { + // Stream& operator <<(const char*); + // Stream& operator <<(int); + //}; + // + //Stream stream; + // + //void test() { + // // Breaking at << is preferred to breaking at +. + // stream << "text text text text text text text text text" + // << 1000000 + 2000000; + //} + public void testBreakingPrecedence() throws Exception { + fOptions.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, CCorePlugin.SPACE); + assertFormatterResult(); + } + //#define m() f() //void f() { //if (1) f();