问题
Any way to configure eclipse to only wrap if statements in braces if it is multiple lines, and leave alone single line statements? e.g.
if (x == y) z();
if (x == y){
z();
}
回答1:
How would it know? If you have a default of always using braces for multiple or single, you will avoid errors of putting in code that is supposed to be part of the if statement but ends up not.
回答2:
Use can use //formatter:off and //formatter:on tags to switch on or switch off formatting in a given range of code lines.
Refer this post: How to use eclipse's code formatter to remove new lines after 'case'?
来源:https://stackoverflow.com/questions/5665247/eclipse-conditional-formatting-braces-only-for-multiple-lines