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

Bug 314095

Summary: [formatter/matcher] formatting of quick fix produces wrong layout
Product: [Modeling] TMF Reporter: Henrik Lindberg <henrik.lindberg>
Component: XtextAssignee: Project Inbox <tmf.xtext-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: btickets, moritz.eysholdt
Version: 1.0.0   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:

Description Henrik Lindberg CLA 2010-05-24 07:17:03 EDT
I have set up formatting of a small part of the b3 grammar.
When formatting the entire document I get this:
function foo ( ) {
    switch true
        case "c" : "c"
        case "a" : "b"
        default : 11
    endswitch;
}
(woo hoo - nice!)

When facing this (faulty) construct:

function foo ( ) {
    switch true
        default : 11
        case "c" : "c"
        case "a" : "b"
    endswitch;
}

A quick fix is offered to move the default last. The quickfix does this with a semantic change by using 'move' on the EList caselist of the switch statement.
As the change takes place, the switch statement is automatically reformatted, and the result looks like this:

function foo ( ) {
    switch true
    case "c" : "c"
        case "a" : "b"
    default : 11
endswitch;
}

Wooops! only one case correctly indented (case "a"), all the other are wrong (off by one indent to the left).

Here is the relevant part from the formatter configuration:

// SWITCH
c.setIndentation(
    f.getSwitchExpressionAccess().getSwitchKeyword_1(),
    f.getSwitchExpressionAccess().getEndswitchKeyword_4());

c.setLinewrap().before(f.getCaseAccess().getCaseKeyword_1_0_0());
c.setLinewrap().before(f.getCaseAccess().getDefaultKeyword_1_1());
c.setLinewrap().before(f.getSwitchExpressionAccess().getEndswitchKeyword_4());
Comment 1 Moritz Eysholdt CLA 2011-02-07 09:21:58 EST
hi Hendrik,

do you still have the grammar that led to this behavior?

cheers,
  Moritz
Comment 2 Henrik Lindberg CLA 2011-02-08 12:58:12 EST
This can be reproduced with the Eclipse b3 grammar checked into the Eclipse SVN. (I just tried it, and the problem is still there).
I think Sebastian keeps a workspace around with the b3 stuff... - let me know if you need more details where to get b3.
Comment 3 Moritz Eysholdt CLA 2016-07-21 04:23:50 EDT
won't fix because it affects the old formatter infrastructure