在IDEA里使用Google Java Format
官网传送门:GitHub - google/google-java-format: Reformats Java source code to comply with Google Java Style.
1.在你的IDEA里打开File->Setting->Plugins->搜索google-java-format->Install->重启IDEA
2.重启后再次进入File->Settings->google-java-format->勾选Enable google-java-format
3.点击Help->Edit Custom VM Options把下面这些贴进去
--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
重启IDEA,然后就可以使用了,你可以打开一个java文件,按下 Ctrl + Alt + L就可以看见格式变化了。