阿里p3c

一、说明

代码规范检查插件p3c,是根据《阿里巴巴Java开发手册》转化而成的自动化插件。

(高级黑:P-3C“Orion”,反潜巡逻机,阿里大概取p3c先进,监测,发现潜在问题的意思)

阿里p3c(代码规范,eclipse插件、模版,idea插件)_JDK阿里p3c(代码规范,eclipse插件、模版,idea插件)_CodeStyle_02

二、源码地址

​https://github.com/alibaba/p3c​


阿里巴巴Java开发手册

一、说明

《阿里巴巴Java开发手册》旨在码出高效,码出质量。

二、目的

标准化,正规化,高效协同。

三、下载

​阿里巴巴Java开发手册(详尽版).pdf​


阿里代码规范设置

一、eclipse

【​​https://www.eclipse.org/downloads/​​】

二、eclipse代码规范

1. 下载

【p3c-formatter】:【​​https://github.com/alibaba/p3c/tree/master/p3c-formatter​​】

阿里p3c(代码规范,eclipse插件、模版,idea插件)_java经验集锦_03

2. 导入代码格式化样式

阿里p3c(代码规范,eclipse插件、模版,idea插件)_通用实践_04

3. 导入代码格式文件

 阿里p3c(代码规范,eclipse插件、模版,idea插件)_IDEA_05

三、eclipse插件

1. 下载

【p3c-eclipse-plugin】:【​​https://p3c.alibaba.com/plugin/eclipse/update​​】

阿里p3c(代码规范,eclipse插件、模版,idea插件)_IDEA_06

2. 将【features】及【plugins】复制到eclipse目录,重启eclipse

3. 编写测试文件



阿里p3c(代码规范,eclipse插件、模版,idea插件)_通用实践_07

/**
* @author lsysy
* @date 2018/11/13
*/
public class Test {
public static void main(String[] args) {
String Ba = "Ba";
if ("Ba" == Ba) {
System.out.println(Ba);
}
}
}


阿里p3c(代码规范,eclipse插件、模版,idea插件)_IDEA_08


4. 点击阿里p3c(代码规范,eclipse插件、模版,idea插件)_通用实践_09进行阿里编码规约扫描(如果不可用,点击阿里p3c(代码规范,eclipse插件、模版,idea插件)_CodeStyle_10切换语言,再切换回来,重启即可)

 阿里p3c(代码规范,eclipse插件、模版,idea插件)_CodeStyle_11 

5. 可选(设置eclipse保存时自动格式化)

阿里p3c(代码规范,eclipse插件、模版,idea插件)_JDK_12

四、idea

【javascript:void(0)】

五、idea插件

1. 下载

【p3c-idea-plugin】:【​​https://plugins.jetbrains.com/plugin/10046-alibaba-java-coding-guidelines​​】

阿里p3c(代码规范,eclipse插件、模版,idea插件)_JDK_13

【eclipse-code-formatter】:【​​https://plugins.jetbrains.com/plugin/6546-eclipse-code-formatter​​】

 阿里p3c(代码规范,eclipse插件、模版,idea插件)_java经验集锦_14

【save-actions-plugin】:【​​https://plugins.jetbrains.com/plugin/7642-save-actions​​】

阿里p3c(代码规范,eclipse插件、模版,idea插件)_JDK_15

2. 安装

阿里p3c(代码规范,eclipse插件、模版,idea插件)_通用实践_16

3. 使用

阿里p3c(代码规范,eclipse插件、模版,idea插件)_JDK_17

六、idea代码规范

1. 准备


阿里p3c(代码规范,eclipse插件、模版,idea插件)_IDEA_18阿里p3c(代码规范,eclipse插件、模版,idea插件)_通用实践_19


/**
* @author ${USER}
* @date ${DATE}
*/

FileHeader

2. 写入文件头注释

阿里p3c(代码规范,eclipse插件、模版,idea插件)_java经验集锦_20

3. 导入代码格式化样式(导入eclipse-codestyle.xml)

阿里p3c(代码规范,eclipse插件、模版,idea插件)_JDK_21

4. 可选(设置idea保存时自动格式化)

阿里p3c(代码规范,eclipse插件、模版,idea插件)_JDK_22