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

Bug 569034

Summary: SwitchCase.expressions() breaks the formatting
Product: [Eclipse Project] JDT Reporter: Fabrice Tiercelin <fabrice.tiercelin>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: CLOSED WONTFIX QA Contact: Manoj N Palat <manoj.palat>
Severity: major    
Priority: P3    
Version: 4.17   
Target Milestone: 4.19   
Hardware: All   
OS: All   
Whiteboard:

Description Fabrice Tiercelin CLA 2020-11-22 09:15:49 EST
- If you create a SwitchStatement with single-expression case, the formatting will be good.
 - If you create a SwitchStatement with multi-expression case (Java 12), the formatting will be broken:

switch (i1){case 0:// Keep this comment too
        i = 0;
        // Keep this comment also
break;case 1:i = 10;break;case 2:i = 20;break;case 3:i = 25;i = 30;break;case 4:i = 40;break;case 5, 6:i = 60;break;case 7, 8:i = 80;break;case 9, 10:i = 100;break;case 11, 12, 13:i = 130;break;case 14:if (i2 == 1) {
            i = 140;
        }break;default:if (i2 == 2) {
            i = 150;
        }break;}

To test it, look at this gerrit that enables the Java 12 feature in a cleanup rule (a rule that converts an if/else if chain into switch):
https://git.eclipse.org/r/c/jdt/eclipse.jdt.ui/+/171024/146/

The build result is here:
https://ci.eclipse.org/jdt/job/eclipse.jdt.ui-Gerrit/7796/console

The output code is good, only the formatting is broken.
Comment 1 Sarika Sinha CLA 2020-11-23 02:29:41 EST
@Mateusz,
Can you look into this?
Comment 2 Mateusz Matela CLA 2020-12-19 16:30:00 EST
The formatter receives this error from the parser: Pb(1719) Multi-constant case labels supported from Java 14 onwards only

Multi-expression case was only a preview feature in Java 12. The formatter uses the CompilerOptions.OPTION_EnablePreviews, but in Parser this option is only respected if sourceLevel == ClassFileConstants.getLatestJDKLevel().

So it looks like this test and the whole cleanup should be limited to Java 14+.
Comment 3 Fabrice Tiercelin CLA 2020-12-20 00:24:37 EST
OK, in other words, we should not use this feature as it is not released.

I close the ticket.