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

Bug 409725

Summary: ASTRewrite inserts bad line break when changing 'else' statement with comment to block
Product: [Eclipse Project] JDT Reporter: Markus Keller <markus.kell.r>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: CLOSED WONTFIX QA Contact: Mateusz Matela <mateusz.matela>
Severity: normal    
Priority: P3 CC: dawnstar, jarthana, mateusz.matela
Version: 4.3   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard: stalebug

Description Markus Keller CLA 2013-06-03 09:18:04 EDT
- have code:

    void foo(boolean b) {
        if (b) {
            System.out.println("a");
        } else
            System.out.println("b"); // problem on "Change 'else' to block"
    }

- apply quick assist "Change 'else' to block"

- result:

        if (b) {
            System.out.println("a");
        }
        else {
            System.out.println("b"); // problem on "change 'else' to block"
        }

=> expected: "} else" should stay like it was (on the original line).
Comment 1 Dongqing Hu CLA 2013-06-21 05:09:04 EDT
I can also see it in ast rewrite (I call method CompilatioUnit.rewrite(...) ).

Then I try to force this but it doesn't work:
    options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_BEFORE_ELSE_IN_IF_STATEMENT, JavaCore.DO_NOT_INSERT); //It's default not to insert
Comment 2 Eclipse Genie CLA 2019-05-27 16:03:46 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 3 Jay Arthanareeswaran CLA 2019-05-28 00:28:18 EDT
Mateusz, do you know if this is still an issue or that we can close this now?
Comment 4 Mateusz Matela CLA 2019-09-22 17:28:40 EDT
Yes, still works as described here.
The formatter returns correct results, but they don't seem to be used properly.