模板文件下載
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