Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 459304

Summary: Improve line breaking when formatting ternary operators
Product: [Eclipse Project] JDT Reporter: Roland Illig <rillig>
Component: CoreAssignee: Mateusz Matela <mateusz.matela>
Status: RESOLVED DUPLICATE QA Contact: Manoj N Palat <manoj.palat>
Severity: minor    
Priority: P3 CC: jarthana, mateusz.matela
Version: 4.4   
Target Milestone: 4.5 M6   
Hardware: All   
OS: All   
Whiteboard: To be verified for 4.6 M6

Description Roland Illig CLA 2015-02-06 06:43:11 EST

    
Comment 1 Roland Illig CLA 2015-02-06 06:48:46 EST
When I have this ternary operator …

    public String toString(boolean b) {
      return b
        ? "true"
        : "false";
    }

… the formatter converts it to …

    public String toString(boolean b) {
      return b ? "true" : "false";
    }

When I want to keep the line breaks, I can insert empty comments at the end of the line.

    public String toString(boolean b) {
      return b //
        ? "true" //
        : "false";
    }

The formatter converts this to:

    public String toString(boolean b) {
      return b //
      ? "true" //
          : "false";
    }

The question mark and the colon should be aligned in the same column.
Comment 2 Jay Arthanareeswaran CLA 2015-02-10 02:02:10 EST
Thanks for the report, but we are not going to have the time to look at this any time soon. If anyone is willing to provide a patch, we can take a look at.
Comment 3 Mateusz Matela CLA 2016-02-17 17:43:06 EST
This problem no longer occurs after the formatter redesign.

*** This bug has been marked as a duplicate of bug 303519 ***