Eclipse 中代码格式化警告
当代码格式与当前设置不匹配时,Eclipse 是否可以发出警告?
另外,如何找到格式化 Java 代码的最佳标准?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我不确定它会显示警告。不过,Eclipse 可以自动为您格式化代码。您可以使用 Ctrl+A 选择全部,然后按 Ctrl+Shift+F 自动设置代码格式。
另外,要查看 Java 约定,您可以转到“窗口”、“首选项”、“Java”、“代码样式”、“格式化程序”。然后,在 Active Profile 下,选择“Java Conventions”,我认为它与“Eclipse(内置)”相同。您可以查看一个简短的示例,了解格式正确的代码应该是什么样子。
您还可以在以下位置查看该文档的完整详细信息: http://www. oracle.com/technetwork/java/codeconv-138413.html
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 这样的东西应该适合您的需求 - 如果需要,您可以配置规则。
Something like Checkstyle should suit your needs - you can configure the rules if required.
您还可以设置 Eclipse 在保存文件时自动格式化代码:
Window >首选项>爪哇>编辑> 保存操作
选中保存时执行所选操作,然后选中格式化源代码并选择格式化所有行,或编辑行
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
视图:“窗口”-> “显示视图”-> “问题”
配置:“首选项”-> “Java”-> “编译器”-> “错误/警告”
View: “Window” -> “Show View” -> “Problems”
Configuration: “Preferences” -> “Java” -> “Compiler” -> “Errors/Warnings”
http://geosoft.no/development/javastyle.html#Layout%20of %20the%20推荐
http://geosoft.no/development/javastyle.html#Layout%20of%20the%20Recommendations
您可以查看 HTML Tidy 插件。通常,Eclipse 只显示编译器警告和错误,编译器不会关心样式。不过,你可以在Windows下设置某些样式警告->首选项-> Java->编译器->错误/警告。
就指南而言,有一个相当全面的指南 Sun 多年前发表。
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.