自动漂亮地格式化大量 Java 源文件
我的项目中有许多 Java 文件格式不正确。此外,由于强制执行通用风格,许多人引入了自己的编码风格。我想将所有这些代码采用一种一致的格式。是否有可用的自动格式化程序,我可以将其作为脚本在所有文件上运行。我想重新考虑和微调以下选项:
用于缩进的空格数。
运算符周围的空格,如 + - * / 等。
括号之间的分隔。
etc.
我正在研究 Netbeans 自动格式,看起来很酷。此外,可以从选项对话框中设置参数。但是我无法完全掌握如何使用 API
I have many Java files from a project which have not been formatted properly. Also due to enforcement of a common style many people have introduced their own coding style. I want to bring all this code to one consistent format. Are there any auto-formatters available which I can run as script on all the files. I would like to rethink and fine tune following options:
Number of spaces used for indentation.
Spaces around operators like + - * / etc.
Separation between parentheses.
etc.
I was looking at Netbeans auto format and looked cool. Moreover the parameters can be set from the option dialog. However I am not able to completely grasp how to use the API
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以从命令行使用 Eclipse
JavaCodeFormatter
:参见 http://wiyoo.blogspot.com/2007/05/batch-formatting-java-source-code-with.html 了解详细信息。
You can use the Eclipse
JavaCodeFormatter
from the command line:See http://wiyoo.blogspot.com/2007/05/batch-formatting-java-source-code-with.html for details.
为什么使用 API?将其作为 NetBeans 项目引入。与 Eclipse 或 IntelliJ 相同;它们都可以格式化项目中的所有源文件。
对于独立版,请尝试 Jalopy。它还可以设置为作为构建的一部分运行,作为提交挂钩等。
Why use the API? Bring it in as a NetBeans project. Same with Eclipse or IntelliJ; they can all format all source files in a project.
For standalone, try Jalopy. It can also be set up to run as part of a build, as a commit hook, etc.
尝试 JIndent。或者这里有一堆 Java 开源代码格式化程序,其中一些可以作为独立产品运行,其他产品可以作为 IDE(Eclipse、NetBeans)内的插件运行。
Try JIndent. Or here're a bunch of open source code formatters for Java, some of them can be run as standalone products, others as plugins inside an IDE (Eclipse, NetBeans).
好吧,我不知道你是否使用 Eclipse,但是要进行间距和括号,你只需按 ctrl + shift + f 并执行 auto缩进为 ctrl + i
Well I don't know if you use eclipse, but to do spacing and parenthasis you just press ctrl + shift + f and to do auto indentation is ctrl + i