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

Bug 534974

Summary: [formatter] No option for inline braceless if statements (one line, not two)
Product: [Eclipse Project] JDT Reporter: John Doe <birds.o.feather>
Component: CoreAssignee: Mateusz Matela <mateusz.matela>
Status: CLOSED INVALID QA Contact:
Severity: minor    
Priority: P3 CC: mateusz.matela
Version: 4.7.3   
Target Milestone: 4.8 RC2   
Hardware: PC   
OS: Linux   
Whiteboard:

Description John Doe CLA 2018-05-22 18:09:14 EDT
Why is there no option to leave braceless if statements on one line, not two?  All of the following

if (true) x = 0;
if (true) return;
if (true) throw new Exception();
if (true) while (true) {
    // do stuff
}

are incorrectly formatted as

if (true)
    x = 0;
if (true)
    return;
if (true)
    throw new Exception();
if (true)
    while (true) {
    // do stuff
    }

This was not a problem in the OldJavaFormatter.javaFormatter from Eclipse 3.*.
Comment 1 Mateusz Matela CLA 2018-05-23 16:45:09 EDT
The setting is there in the Control Statements tab: Keep 'then' statement on same line.
Comment 2 John Doe CLA 2018-05-24 09:38:51 EDT
That option does not work. The 'then' statement is still moved to the second line.

I have narrowed the scope from All/All to PC/Linux, since this is the Oxygen 4.7.3a 64-bit Linux tar.gz downloaded straight from the website.
Comment 3 John Doe CLA 2018-05-24 11:24:49 EDT
I found the problem. I had set Line Wrapping > Compact If-Else set to the following:

    org.eclipse.jdt.core.formatter.alignment_for_compact_if=49
    Wrap all elements, every element on a new line
    Force split = yes

The Force Split was the culprit. Setting back to this:

    org.eclipse.jdt.core.formatter.alignment_for_compact_if=16
    Wrap where necessary
    Force split = no