Bug 545439 - [dom ast] case statement rewrite formatting
Summary: [dom ast] case statement rewrite formatting
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.11   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact: Sarika Sinha CLA
URL:
Whiteboard: stalebug
Keywords: helpwanted
Depends on:
Blocks:
 
Reported: 2019-03-15 07:23 EDT by Manoj N Palat CLA
Modified: 2023-11-18 12:35 EST (History)
2 users (show)

See Also:


Attachments
Test case patch (3.39 KB, patch)
2019-03-15 07:29 EDT, Manoj N Palat CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Manoj N Palat CLA 2019-03-15 07:23:29 EDT
Consider the following code:

package test1;
public class X {
    static int foo(int i) {
        int tw = 0;
        switch (i) {
            case 1 : {
                 int z = 100;
                 break;
            }
            default : {
                break;
            }
        }
        return tw;
    }
    public static void main(String[] args) {
        System.out.print(foo(1));
    }
}

Now add  case 100: with a block having a singleton break;

The resulting code looks like:
package test1;
public class X {
    static int foo(int i) {
        int tw = 0;
        switch (i) {
            case 1 : {
                 int z = 100;
                 break;
            }
            case 100:
                {
                    break;
                }
            default : {
                break;
            }
        }
        return tw;
    }
    public static void main(String[] args) {
        System.out.print(foo(1));
    }
}

The case 100: block format is different. 
It would be good to address this when the preview feature switch expression becomes a full feature.
Comment 1 Manoj N Palat CLA 2019-03-15 07:29:38 EDT
Created attachment 277881 [details]
Test case patch

Dev Notes: A complete test case patch is attached above - Please apply the above to master and run the ASTRSTes to observe the stated behavior.
Comment 2 Eclipse Genie CLA 2019-03-16 15:20:03 EDT
New Gerrit change created: https://git.eclipse.org/r/138889
Comment 3 Sarika Sinha CLA 2019-03-16 15:25:34 EDT
(In reply to Eclipse Genie from comment #2)
> New Gerrit change created: https://git.eclipse.org/r/138889

Another sample test case failing for switch case formatting.
Comment 4 Manoj N Palat CLA 2019-03-17 23:19:32 EDT
(In reply to Sarika Sinha from comment #3)
> (In reply to Eclipse Genie from comment #2)
> > New Gerrit change created: https://git.eclipse.org/r/138889
> 
> Another sample test case failing for switch case formatting.

This is an inherited issue :) - essentially, the same issue as that pointed out in the description and nothing to do with Switch Expression in particular.
Comment 5 Sarika Sinha CLA 2019-05-21 02:07:17 EDT
Another sample test case failing -
From https://bugs.eclipse.org/bugs/show_bug.cgi?id=545261#c10
- Applying the quick assist on 'case 400, 4000' results in bad formatting.
  	public static void foo1(int num) {
 		int res = switch (num) {
 		case 100 -> 1;
 		case 200 -> 2;
 		case 300, 3000 -> 3;
 		case 400, 4000 -> {
 			break 4;
 		}
 		};
 	}
Comment 6 Sarika Sinha CLA 2019-08-27 03:24:24 EDT
Moving to 4.14
Comment 7 Manoj N Palat CLA 2019-11-25 10:49:08 EST
Bulk move out of 4.14
Comment 8 Eclipse Genie CLA 2021-11-25 00:23:05 EST
New Gerrit change created: https://git.eclipse.org/r/c/jdt/eclipse.jdt.core/+/187125
Comment 9 Jay Arthanareeswaran CLA 2021-11-25 00:24:22 EST
(In reply to Eclipse Genie from comment #8)
> New Gerrit change created:
> https://git.eclipse.org/r/c/jdt/eclipse.jdt.core/+/187125

Cherry-picked from the other one. But conflicts need to resolved before any further work.
Comment 10 Eclipse Genie CLA 2023-11-18 12:35:55 EST
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.