p3c

阿里巴巴Java编码指南pmd实现和IDE插件。(Alibaba Java Coding Guidelines pmd implements and IDE plugin.)

Github星跟蹤圖

前言

我们很高兴推出阿里巴巴Java编码指南,这些指南巩固了多年来阿里巴巴集团技术团队的最佳编程实践。大量的Java编程团队对各个项目的代码质量提出了苛刻的要求,因为我们鼓励重用并更好地了解彼此的程序。过去我们已经看到很多编程问题。例如,有缺陷的数据库表结构和索引设计可能会导致软件体系结构缺陷和性能风险。另一个例子是令人困惑的代码结构难以维护。此外,没有身份验证的易受攻击的代码很容易受到黑客的攻击。为了解决这些问题,我们为阿里巴巴的Java开发人员开发了这个文档。

有关更多信息,请参阅阿里巴巴Java编码指南

介绍

该项目由三部分组成:

规则

基于PMD实现了49条规则,请参阅P3C-PMD文档以获取更多详细信息。在IDE插件(IDEA和Eclipse)中实现了四个规则,如下所示:

  • [Mandatory] 禁止使用已弃用的类或方法。
    注意:例如,应该使用decode(String source,String encode)来代替弃用的方法decode(String encodeStr)。一旦接口被弃用,接口提供者有义务提供一个新接口。同时,客户程序员有义务检查它的新实现是什么。
  • [Mandatory] 从接口或抽象类中重写的方法必须用@Override注解标记。 计数器示例:对于getObject()和get0bject(),第一个字母为'O',第二个为数字'0'。要准确确定覆盖是否成功,@Override注释是必需的。同时,一旦抽象类中的方法签名被更改,实现类将立即报告编译时错误。
  • [Mandatory] 静态字段或方法应该直接通过它的类名来引用,而不是相应的对象名。
  • [Mandatory] hashCode和equals的用法如下:
    1. 如果equals被覆盖,则覆盖hashCode。
    2. Set必须重写这两个方法,因为它们用于确保Set中不会插入重复的对象。
    3. 如果使用自定义对象作为Map的关键字,则必须重写这两个方法。 注意:由于这两个方法已被重写,字符串可以用作Map的键。

加入我们

如果您有任何问题或建议,请联系电子邮箱为caikang.ck@alibaba-inc.com的junlie,并请加入我们,让项目P3C更适合更多程序员。

请关注微信官方账号ali_yunxiao。

概覽

名稱與所有者alibaba/p3c
主編程語言Kotlin
編程語言Kotlin (語言數: 4)
平台Cross-platform, Linux, Mac, Windows
許可證Apache License 2.0
發布數27
最新版本名稱idea-plugin-2.1.0 (發布於 )
第一版名稱p3c-pmd-1.3.1 (發布於 )
創建於2017-06-23 06:15:51
推送於2024-01-09 09:47:22
最后一次提交2022-05-11 11:50:37
星數30.1k
關注者數1.3k
派生數8k
提交數290
已啟用問題?
問題數850
打開的問題數153
拉請求數62
打開的拉請求數26
關閉的拉請求數46
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?


2018年9月22日,在2018杭州云栖大会上,召开《码出高效:Java 开发手册》新书发布会,并宣布将图书所有收益均捐赠于技术公益项目“83行代码计划”。

阿里巴巴正式在2018杭州云栖大会《开发者生态峰会》上,由阿里巴巴高年级同学中间件负责人林昊、阿里巴巴研究员刘湘雯、阿里巴巴研究员刘国华,OpenJDK社区Committer杨晓峰,全栈视障工程师蔡勇斌,电子工业出版社博文视点出版公司总经理郭立以及两位图书作者杨冠宝(孤尽)和高海慧(鸣莎)重磅大咖联合发布新书《码出高效:Java开发手册》(跳转至天猫书店),并宣布将图书所有收益均捐赠于技术公益项目“83行代码计划”,第一个“83行代码计划”行动,将围绕着帮助盲人工程师,开发更多无障碍化产品,让盲人上网更便捷。未来,我们会坚持用技术为公益行业赋能,也希望更多人成为技术受益者<

2017年10月14日杭州云栖大会,Java代码规约扫描插件全球首发仪式正式启动,规范正式以插件形式公开走向业界,引领Java语言的规范之路。目前,插件已在云效公有云产品中集成,立即体验!(云效>公有云>设置->测试服务->阿里巴巴Java代码规约)。

P3C

License

Preface

We are pleased to present Alibaba Java Coding Guidelines which consolidates the best programming practices over the years from Alibaba Group's technical teams. A vast number of Java programming teams impose demanding requirements on code quality across projects as we encourage reuse and better understanding of each other's programs. We have seen many programming problems in the past. For example, defective database table structures and index designs may cause software architecture flaws and performance risks. Another example is confusing code structures being difficult to maintain. Furthermore, vulnerable code without authentication is prone to hackers’ attacks. To address these kinds of problems, we developed this document for Java developers at Alibaba.

For more information please refer the Alibaba Java Coding Guidelines:

Introduction

The project consists of 3 parts:

Rules

Forty-nine rules are realized based on PMD, please refer the P3C-PMD documentation for more detailed information. Four rules are implemented within IDE plugins (IDEA and Eclipse) as follows:

  • [Mandatory] Using a deprecated class or method is prohibited.
    Note: For example, decode(String source, String encode) should be used instead of the deprecated method decode(String encodeStr). Once an interface has been deprecated, the interface provider has the obligation to provide a new one. At the same time, client programmers have the obligation to check out what its new implementation is.

  • [Mandatory] An overridden method from an interface or abstract class must be marked with @Override annotation.
    Counter example: For getObject() and get0bject(), the first one has a letter 'O', and the second one has a number '0'. To accurately determine whether the overriding is successful, an @Override annotation is necessary. Meanwhile, once the method signature in the abstract class is changed, the implementation class will report a compile-time error immediately.

  • [Mandatory] A static field or method should be directly referred by its class name instead of its corresponding object name.

  • [Mandatory] The usage of hashCode and equals should follow:

    1. Override hashCode if equals is overridden.
    2. These two methods must be overridden for Set since they are used to ensure that no duplicate object will be inserted in Set.
    3. These two methods must be overridden if self-defined object is used as the key of Map.
      Note: String can be used as the key of Map since these two methods have been rewritten.

Join us

If you have any questions or comments, please contact junlie by email at caikang.ck@alibaba-inc.com, and please join us to make project P3C perfect for more programmers.

Please follow our WeChat official account as ali_yunxiao below:

去到頂部