我的项目中有许多 Java 文件格式不正确。此外,由于强制执行通用风格,许多人引入了自己的编码风格。我想将所有这些代码采用一种一致的格式。是否有可用的自动格式化程序,我可以将其作为脚本在所有文件上运行。我想重新思考和微调以下选项:
用于缩进的空格数。
运算符周围有空格,例如 + - */等
括号之间的分隔符。
等等
我正在研究 Netbeans 自动格式,看起来很酷。此外,可以从选项对话框中设置参数。但是我无法完全掌握如何使用 API
最佳答案
您可以从命令行使用 Ellipse Java Code Formatter
:
The following example runs the formatting of code specified by the configuration file
D:/formatter.prefs
on the files Java belonging (directly or indirectly) to the directoryD:/tmp/src
:eclipse -application org.eclipse.jdt.core.JavaCodeFormatter -config D:/formatter.prefs D:/tmp/src
参见http://wiyoo.blogspot.com/2007/05/batch-formatting-java-source-code-with.html了解详情。
关于java - 自动漂亮地格式化大量 Java 源文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8547173/