Community
Participate
Working Groups
I20080617-2000 and HEAD ASTRewrite produces wrong indentation for a statement inserted before a SwitchCase: - have: switch (1) { case 1: System.out.println(); case 2: System.out.println(); } - format with Eclipse [built-in] formatter profile - enable warning for "'switch' case fall-through" - quick fix "Insert 'break' statement" => result: switch (1) { case 1: System.out.println(); break; case 2: System.out.println(); } => expected: same as when I format the result again: switch (1) { case 1: System.out.println(); break; case 2: System.out.println(); } The implementation in LocalCorrectionsSubProcessor.addFallThroughProposals(..) is trivial: listRewrite.insertBefore(ast.newBreakStatement(), switchCaseNode, null);
This one is annoying...
Same problem when you remove a statement in front of a SwitchCase, e.g. have: void m() { switch (1) { case 1: System.out.println("Hello"); break; System.out.println("Unreachable"); break; case 2: System.out.println("Hello3"); return; default: System.out.println("Hell4"); break; } } Quick Fix to remove unreachable code gives: void m() { switch (1) { case 1: System.out.println("Hello"); break; case 2: System.out.println("Hello3"); return; default: System.out.println("Hell4"); break; } } => "case 2:" should keep original indentation. See bug 257524 for a problem in the formatter with unreachable code.
Created attachment 124661 [details] Proposed fix All statements in a switch statement do not have the same indentation and ASTRewriteAnalyzer does not update this indentation when necessary. This patch improve ASTRewriteAnalyzer to produce correct indentation.
Created attachment 124662 [details] Correct patch I attached the wrong patch, the correct patch is this one.
Created attachment 124665 [details] Proposed patch for JDTUI tests Some JDTUI regressions test failed with the fix. This is a patch for these tests.
OK, will look at the patch once you've committed the JDT Core side.
Released for 3.5M6. Released jdtcore patch and added tests: ASTRewritingStatementsTest#testSwitchStatement2() -> testSwitchStatement10()
Looks good, I released the UI patch.
Verified for 3.5M6 using I20090310-0100.