阿里巴巴Java開發手冊(華山版)


插件下載地址:

https://github.com/alibaba/p3c

 

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:

 

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 

Eclipse Plugin


Prepare

  • Eclipse Juno+
  • maven3.+
  • JDK 1.7+

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 

eclipse 文檔 JPA問題說明

 
 

首先非常感謝大家對插件的支持與意見,Eclipse的功能相對來說比較簡單,希望有更多的同學加入進來一起完善。

插件安裝

環境:JDK1.8,Eclipse4+。有同學遇到過這樣的情況,安裝插件重啟后,發現沒有對應的菜單項,從日志上也看不到相關的異常信息,最后把JDK從1.6升級到1.8解決問題。

Help -> Install New Software...

輸入Update Site地址:https://p3c.alibaba.com/plugin/eclipse/update 回車,然后勾選Ali-CodeAnalysis,再一直點Next Next...按提示走下去就好。 然后就是提示重啟了,安裝完畢。

注意:有同學反映插件掃描會觸發很多 "JPA Java Change Event Handler (Waiting)" 的任務,這個是Eclipse的一個bug,因為插件在掃描的時候會對文件進行標記,所以觸發了JPA的任務。卸載JPA插件,或者嘗試升級到最新版的Eclipse。附:JPA project Change Event Handler問題解決

插件使用

目前插件實現了開發手冊中的53條規則,大部分基於PMD實現,其中有4條規則基於Eclipse實現,支持4條規則的QuickFix功能。

* 所有的覆寫方法,必須加@Override注解, 
* if/for/while/switch/do等保留字與左右括號之間都必須加空格,
* long或者Long初始賦值時,必須使用大寫的L,不能是小寫的l)
* Object的equals方法容易拋空指針異常,應使用常量或確定有值的對象來調用equals。

目前不支持代碼實時檢測,需要手動觸發,希望更多的人加入進來一起把咱們的插件做得越來越好,盡量提升研發的使用體驗。

代碼掃描

可以通過右鍵菜單、Toolbar按鈕兩種方式手動觸發代碼檢測。同時結果面板中可以對部分實現了QuickFix功能的規則進行快速修復。

觸發掃描

在當前編輯的文件中點擊右鍵,可以在彈出的菜單中觸發對該文件的檢測。

在左側的Project目錄樹種點擊右鍵,可以觸發對整個工程或者選擇的某個目錄、文件進行檢測。

也可以通過Toolbar中的按鈕來觸發檢測,目前Toolbar的按鈕觸發的檢測范圍與您IDE當時的焦點有關,如當前編輯的文件或者是Project目錄樹選中的項,是不是感覺與右鍵菜單的檢測范圍類似呢。

掃描結果

簡潔的結果面板,按規則等級分類,等級->規則->文件->違規項。同時還提供一個查看規則詳情的界面。

清除結果標記更方便,支持上面提到的4條規則QuickFix。

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM