luc*_*iet 4 java refactoring automated-refactoring
我正在寻找一种工具,该工具可自动在代码库上优化导入过程。大多数IDE(例如IntelliJ)都可以使用此工具,该工具可以删除未使用的导入并将任何。*导入扩展为代码专门使用的那些。
我想将其添加为MVN目标或Ant Task,或者将其添加为提交/推送之前可以运行的内容。
也许有一种在命令行上运行IntelliJ的方法来专门执行此功能,但是我还没有找到这样的命令。
如果您正在寻找优化Java导入的命令行工具,请查看Google Java样式格式化程序。它提供了一个修复导入的选项:
$ java -jar google-java-format-1.4-all-deps.jar
no files were provided
Usage: google-java-format [options] file(s)
Options:
-i, -r, -replace, --replace
Send formatted output back to files, not stdout.
-
Format stdin -> stdout
--aosp, -aosp, -a
Use AOSP style instead of Google Style (4-space indentation)
--fix-imports-only
Fix import order and remove any unused imports, but do no other formatting.
--skip-sorting-imports
Do not fix the import order. Unused imports will still be removed.
--skip-removing-unused-imports
Do not remove unused imports. Imports will still be sorted.
--length, -length
Character length to format.
--lines, -lines, --line, -line
Line range(s) to format, like 5:10 (1-based; default is all).
--offset, -offset
Character offset to format (0-based; default is all).
--help, -help, -h
Print this usage statement
--version, -version, -v
Print the version.
If -i is given with -, the result is sent to stdout.
The --lines, --offset, and --length flags may be given more than once.
The --offset and --length flags must be given an equal number of times.
If --lines, --offset, or --length are given, only one file (or -) may be given.
google-java-format: Version 1.0
https://github.com/google/google-java-format
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1429 次 |
| 最近记录: |