Is there an option for Eclipse to issue a warning when code formatting does not match the current settings?
Also, how to can I find the best standards for formatting Java code?
I'm not sure that it'll show a warning. However, Eclipse can automatically format your code for you. You can select all using Ctrl+A, then hit Ctrl+Shift+F to auto-format your code.
Also, to see the Java conventions, you can go to Window, Preferences, Java, Code Style, Formatter. Then, under Active Profile, select "Java Conventions," which I think is the same as "Eclipse (built-in)". You can see a short example of what properly-formatted code should look like.
You can also see the document in its full gory detail at: http://www.oracle.com/technetwork/java/codeconv-138413.html
诸如Checkstyle之类的东西应该适合您的需求-如果需要,您可以配置规则。
You can also setup eclipse to automatically format your code when saving files:
Window > Preferences > Java > Editor > Save Actions
Check Perform the selected actions on save , then check Format source code and choose to format all lines , or edited lines
View: “Window” -> “Show View” -> “Problems”
Configuration: “Preferences” -> “Java” -> “Compiler” -> “Errors/Warnings”
You might take a look at the HTML Tidy Plug-in . Normally, Eclipse only displays compiler warnings and errors, and the compiler couldn't care less about style. However, you can set certain style warnings under Windows -> Preferences -> Java -> Compiler -> Errors/Warnings.
As far as guidelines go, there's this fairly comprehensive one published many years ago by Sun.
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.