Eclipse Code Formatter
When it comes to writing Java code, the two most popular IDE’s are probably Eclipse and IntelliJ. The problem is that some developers prefer Eclipse while others prefer IntelliJ. And once they prefer an IDE, they’re used to developing in it. This makes it challenging to pick the right one because, ultimately, it could have an effect on developers’ productivity and efficiency.
With the Eclipse Code Formatter plugin, this doesn’t need to be a problem. This is because it allows you to use Eclipse’s Java Code Formatter directly in IntelliJ. In this way, developers can use the tools they’re used to, and it makes it easier to manage code style when both IDEs are used.
导入配置文件 elicpse-codestyle.xml(https://github.com/alibaba/p3c/blob/master/p3c-formatter/eclipse-codestyle.xml)
二、格式化代码只格式化我修改的代码不格式化未修改的代码
只格式化自己写的代码,不格式化版本仓库里面的代码,防止代码评审或者代码对比出现大量不一致的代码 快捷键:Ctrl+Shift+Alt+L
-
在默认情况下,Scope 选项是 Whole file ,也就是格式化当前窗口的全部代码
-
Only changes uncommitted to VCS 表示只格式化我修改的,不格式化我未修改的代码
-
我们也可以设置在自动保存的时候触发代码格式化。 操作方法:File->Settings->Tools->Actions on Save 中进行设置。 注意在勾选完 Reformat code 之后后面的 Whole file 这里要改为 Changed lines