Eclipse插件CheckStyle安裝使用

一、CheckStyle簡介
   Checkstyle是一款檢查Java程序源代碼樣式的工具,它能夠有效的幫助咱們檢視代碼以便更好的遵循代碼編寫標準,特別適用於小組開發時彼此間的樣式規範和統一。Checkstyle提供了高可配置性,以便適用於各類代碼規範,因此除了使用它提供的幾種常見標準以外,你也能夠定製本身的標準.
最新版本下載地址:http://sourceforge.net/projects/eclipse-cs/?source=directory
 
二、在Eclipse中安裝插件
  一.在線安裝
     安裝地址:http://eclipse-cs.sourceforge.net/update/
  二. 下載Eclipse plugin 的版本,解壓zip文件。
    下載後,把裏面的兩個文件夾plugins和 features下面的文件分別拷貝到eclipse目錄下面對應的plugins和features目錄,從新啓動Eclipse .
 
PS:直接啓動eclipse 可能會出現ClassNotFoundExceptions 等錯誤,在啓動eclipse的時候加上一個參數 -clean. 這樣eclipse就能夠更新它當前安裝的許多插件信息
 
三、 CheckStyle 使用
 
  選中工程,右鍵選擇checkstyle->check code with checkstyle,檢查錯誤便可
 
四、Checkstyle 的結果輸出
  1 Type is missing a javadoc commentClass  缺乏類型說明
  2 「{」 should be on the previous line 「{」 應該位於前一行
  3 Methos is missing a javadoc comment方法前面缺乏javadoc註釋
  4 Expected @throws tag for 「Exception」在註釋中但願有@throws的說明
  5 「.」 Is preceeded with whitespace 「.」 前面不能有空格
  6 「.」 Is followed by whitespace「.」 後面不能有空格
  7 「=」 is not preceeded with whitespace「=」 前面缺乏空格
  8「=」 is not followed with whitespace「=」 後面缺乏空格
  9 「}」 should be on the same line「}」 應該與下條語句位於同一行
  10 Unused @param tag for 「unused」沒有參數「unused」,不需註釋
  11 Variable 「CA」 missing javadoc變量「CA」缺乏javadoc註釋
  12 Line longer than 80characters行長度超過80
  13 Line contains a tab character行含有」tab」 字符
  14 Redundant 「Public」 modifier冗餘的「public」 modifier
  15 Final modifier out of order with the JSL suggestionFinal modifier的順序錯誤
  16 Avoid using the 「.*」 form of importImport格式避免使用「.*」
  17 Redundant import from the same package從同一個包中Import內容
  18 Unused import-java.util.listImport進來的java.util.list沒有被使用
  19 Duplicate import to line 13重複Import同一個內容
  20 Import from illegal package從非法包中 Import內容
  21 「while」 construct must use 「{}」「while」 語句缺乏「{}」
  22 Variable 「sTest1」 must be private and have accessor method變量「sTest1」應該是private的,而且有調用它的方法
  23 Variable 「ABC」 must match pattern 「^[a-z][a-zA-Z0-9]*$」變量「ABC」不符合命名規則「^[a-z][a-zA-Z0-9]*$」
  24 「(」 is followed by whitespace「(」 後面不能有空格 25「)」 is proceeded by whitespace「)」 前面不能有空格
 
參考文檔:
  CheckStyle官網:http://checkstyle.sourceforge.net
相關文章
相關標籤/搜索