Java How to beautify the java code inside Eclipse

2020-05-23 09:52发布

I am using Eclipse Helios Version as an IDE and developing code using Java.

The good thing for me is that the code works well, but the bad thing is that the code doesn't look good ( I mean spaces and brackets used in control structures used in if-else statments as well as for and while loops scattered here and there )

I have used Ctrl + Shift + F , as well as an online tool (http://www.prettyprinter.de/) for formatting , and with this it looks more worse.

As a lot of developers are out here, how do you arrange your code properly and how you make it look good.

Please tell me , I am worried as some senior person might review the code .

3条回答
Lonely孤独者°
2楼-- · 2020-05-23 10:10

Try to change Window->Preferences->Java->Code Formatter->LineSplittin-> Maximum Line length up to 120 or 140 symbols.

查看更多
劳资没心,怎么记你
3楼-- · 2020-05-23 10:13

To change the settings of the code formatter, go into the following menu:

  • Windows
  • Preferences
  • Java
  • Code Style
  • Formatter

And then create your own format in however a form you choose.

查看更多
萌系小妹纸
4楼-- · 2020-05-23 10:23

You can install PMD and FindBugs plugins. The PMD tools can help you to optimize code.

The quote:

PMD scans Java source code and looks for potential problems like:

Possible bugs - empty try/catch/finally/switch statements
Dead code - unused local variables, parameters and private methods
Suboptimal code - wasteful String/StringBuffer usage
Overcomplicated expressions - unnecessary if statements, for loops that could be while loops
Duplicate code - copied/pasted code means copied/pasted bugs
查看更多
登录 后发表回答