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