java - 自动漂亮地格式化大量 Java 源文件

标签 java netbeans autoformatting

我的项目中有许多 Java 文件格式不正确。此外,由于强制执行通用风格,许多人引入了自己的编码风格。我想将所有这些代码采用一种一致的格式。是否有可用的自动格式化程序,我可以将其作为脚本在所有文件上运行。我想重新思考和微调以下选项:

  1. 用于缩进的空格数。

  2. 运算符周围有空格,例如 + - */等

  3. 括号之间的分隔符。

  4. 等等

我正在研究 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 directory D:/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/

相关文章:

java方法内部变量上没有 "this"参数

c++ - Astyle 每次都在文件末尾添加新行

java - Eclipse 自动格式化变量初始化

notepad++ - Notepad++按需自动完成XML/HTML标签

java - Java 的 JEditorPane 是否有一个好的替代品?

java - 如何计算一行中作为方法参数给出的正值的数量?

java - 带有条件 api 的子查询和别名

web-services - 使用 Netbeans 平台使用 Web 服务

Java Swing 文本字段问题

java - Netbeans 中的 "Convert to try-with-resources"- Cool Beans?