IDEA 代码格式化设置
模板文件下載
IDEA 代碼格式化設置,使用 Eclipse 設置,設置成阿里巴巴規范
阿里巴巴格式化模板文件下載地址:
https://github.com/alibaba/p3c
eclipse-codestyle.xml 是代碼格式化時用的模板
eclipse-codetemplate.xml 是注釋模板
我們需要的是 p3c/p3c-formatter/eclipse-codestyle.xml 文件
IDEA 格式化設置
因為阿里配置文件是針對 Eclipse 的,所有要導入配置文件需要額外安裝 EclipseFormatter 插件
在線安裝
點擊:File -> Settings -> Plugins,搜索 Eclipse Code Formatter 并安裝
離線安裝
下載插件文件,https://github.com/krasa/EclipseCodeFormatter/releases
然后在 Plugins 界面中選擇 Install plugin from disk,選擇已下載好的 EclipseCodeFormatter.zip 文件即可
導入 eclipse-codestyle.xml
點擊:File -> Settings -> Other Settings -> Eclipse Code Formatter
選中右側的 Use the Eclipse code formatter,然后在 Eclipse Java Formatter config file 處選擇剛剛下載的 eclipse-codestyle.xml 文件,點擊確認即可
Eclipse 格式化設置
格式化模板導入
點擊:Window -> Preferences -> Java -> Code Style -> Formatter -> Import
選擇 eclipse-codestyle.xml 文件,確定
默認在 Active profile 中選擇新導入的 P3C-CodeStyle,如未選擇,請手動選擇
點擊 Apply 完成配置
注釋模板導入
點擊:Window -> Preferences -> Java -> Code Style -> Code Templates -> Import
勾選 Automatically add comments for new methods and types
點擊 Apply 完成配置
作者 Github : tojohnonly , 博客 : EnskDeCode
總結
以上是生活随笔為你收集整理的IDEA 代码格式化设置的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: idea代码格式化详细总结(快捷键、格式
- 下一篇: idea代码格式化的自定义