Indent case blocks within switch statements
See original GitHub issuevscode-java does not honor Eclipse formatting preferences for indenting statements within ‘switch’ blocks
Environment
- Operating System: Windows 10
- JDK version: 1.8.0_171-b11
- Visual Studio Code version: 1.26.1 493869ee8e8a846b0855873886fc79d480d342de x64
- Java extension version: 0.29.0
Steps To Reproduce
- Create a new Java project in Eclipse
- Create a
Main.java
with a simple switch statement:
public static void main(String [] args) {
int x = 0;
switch (x) {
case 0:
return;
}
}
- Change project-specific formatting settings: indent
case
statements as seen above (case
is indented further thanswitch
)- Indentation > Indented elements > Statements within ‘switch’ body [checked]
- Format the project in Eclipse, noting how the indentation is preserved
- Open the project in Visual Studio code, and note how the code is reformatted
Current Result
Code is reformatted so case
statements align with switch
statements:
switch (x) {
case 0:
return;
}
Expected Result
Eclipse settings are honored, and VS Code formats the same as Eclipse:
switch (x) {
case 0:
return;
}
Additional Informations
The checkbox changes the following line in org.eclipse.jdt.core.prefs
:
org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=true
(true
when checked, false
when unchecked)
Issue Analytics
- State:
- Created 5 years ago
- Comments:7
Top Results From Across the Web
java - Why the strange indentation on switch statements?
In 4 words: no blocks, no indentation. Cases are not opening a block. ... case statements are not indented relative to the switch...
Read more >Automatically Indent Switch Statement Cases in Xcode
Automatically Indent Switch Statement Cases in Xcode · Xcode menu · Preferences · Text Editing tab · Indentation sub-tab.
Read more >D43183 clang-format: introduce `CaseBlockIndent` to ... - LLVM
CaseBlockIndent = Block : add an extra level of indent for the ... case blocks in switch statements can have curly braces or...
Read more >Reason for non-indented case statements in switch (go fmt)
The general trend is: indent code within curly braces one level. But this isn't the case with the switch statement. Is there a...
Read more >The switch Statement (The Java™ Tutorials > Learning the ...
A statement in the switch block can be labeled with one or more case or default labels. The switch statement evaluates its expression,...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@ZinoKader see #1261
@mark-wiemer Ah, you replied by email, so you didn’t see my answer to what
eclipse-formatter.xml
is doing. Just repeating what I said earlier. 👍