google-java-format plugin should intercept the “Reformat Code” action in IDEA (Ctrl+Alt+L) and apply its own rules. However, it does not work with imports for some reason, so to fix that you have to import a Java Google Code Style XML file to your code style settings in IDEA.
1.下載Google Java Code Style在IntelliJ中的配置文件 https://github.com/google/styleguide
2.選擇”File”菜單組下的”Settings”菜單項:
3.選擇”Editor->Code Style”菜單項,並點擊圖示的”Intellij IDEA code style XML”導入第1步中下載的配置文件(可修改導入的配置名,此處使用默認的”GoogleStyle”):
4.將當前項目的”Schema:”設置為第3步中導入的”GoogleStyle”
5.”Editor->Code Style->Java->Imports->Names count to use static import with *”菜單項, 輸入1
6.Install google-java-format plugin (File -> Settings -> Plugins -> Browse repositories -> search for “google-java-format” and install)
After installation, the plugin has to be enabled per-project (it is disabled by default). To do that, open your project and go to File -> Settings -> Other Settings -> google-java-format Settings and check “Enable google-java-format”
