I like formatting my Java code in Eclipse. It keeps the code well indented and avoids problems with version systems. However, I can't find in Eclipse an option to maintain compact if-else statements and for loops with braces. I mean:
I get this one when I do the formatting:
if(a>6)
a=7;
else
a=8;
for (int i=0;i<=9;i++)
a=a+i;
And I want this one:
if(a>6){
a=7;
}
else{
a=8;
}
for (int i=0;i<=9;i++){
a=a+i;
}
Under "Preferences": Java > Editor > Save Actions
1) Check "Additional actions"
2) Click "Configure…"
3) Go to the "Code Style" tab
4) Check "Use blocks in if/while/for/do statements" and configure to your preferences
You can create a new format template here:
Menu Windows -> Preferences. Java -> Code Style -> Formatter.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.