Eclipse 强制执行严格的 java 代码格式
确保 Java 代码遵循一组严格的格式化准则的最佳方法是什么?它需要是可配置的,以便我们可以执行我们自己的指南(主要基于 Sun 的原始指南文档)。
我厌倦了即使在不同的方法中也有不同格式的类,具体取决于更改该特定方法的开发人员。
当我说严格时,我的意思是,绝对所有内容都按照标准格式化。
What is the best way to ensure that Java code follows a strict set of formatting guidelines. It needs to be configurable so that we can enforce our own guidelines (which are mostly based on Suns original guidelines document).
Im sick of having classes that even in different methods have different formatting depending on the developer who altered that particular method.
When I say strict, I mean, absolutely everything is formatted to a standard.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 Eclipse 中,您可以设置自己的一组准则。转到“窗口/首选项”并搜索“格式”,您将在菜单树中的某个位置找到代码格式化程序。要将格式应用于文件,只需在编辑器中按 Ctrl+Shift+F 即可。
然后,您可以与整个团队共享代码格式化配置文件,每个人都可以以完全相同的方式格式化代码。
In Eclipse, you can set up your own set of guidelines. Go to Window/Preferences and search for "format", and you'll find Code Formatter somewhere in the menu tree. To apply formatting to a file, just hit Ctrl+Shift+F in the editor.
Then you can share the code formatting profile with the entire team, and everybody will be able to format the code the exact same way.
某些源代码管理系统可以配置为对所有签入的代码运行命令行格式化程序。
Some source code management systems can be configured to run a command-line formatter on all code being checked in.
如果想单独依赖Eclipse,可以在
Java -> 下的首选项中进行配置。编译器->错误/警告
来捕获基本的样式问题,您可以配置格式化程序以根据您的规范格式化代码。从风格角度来看,Eclipse 选项非常有限,因此最好使用外部工具,例如 Checkstye 和 Findbugs 可以将其配置为构建过程的一部分,并且也可以与 Eclipse 很好地配合使用。
If you want to rely on Eclipse alone, you can configure it in the preferences under
Java -> Compiler -> Errors/Warnings
to catch basic style problems and you can configure the formatter to format the code to your specification.From style perspective, Eclipse options are quite limited so it is better to use external tools like Checkstye and Findbugs which can be configured as part of your build process and also work well with Eclipse.