android checkstyle結果分析說明

來源:互聯網
上載者:User

標籤:

1.Missing a Javadoc comment:缺少JavaDoc注釋
2.First sentence should end with a period:你的注釋的第一行文字結束應該加上一個"."
3.Expected @throws tag for ‘Exception‘:在注釋中希望有@throws的說明,在方法前得注釋中添加這樣一行:* @throws Exception if has error(異常說明)
4.Parameter docType should be final:參數docType應該為final類型 解決方案:在參數docType前面加個final
5.Variable “ABC” must match pattern “^[a-z][a-zA-Z0-9]*$”變數“ABC”不符合命名規則“^[a-z][a-zA-Z0-9]*$”解決方案:把這個命名改成符合規則的命名 “aBC”
6.Utility classes should not have a public or default constructor. 介面中的內部類中不應該有公用的或者預設的構造方法
解決方案:在內部類中,定義一個私人的構造方法,然後內部類聲明為final類型。如果前面有static,那麼final還必須放在static之後
7.‘{‘ is not preceded with whitespace.大括弧後面必須空一格

8.‘public‘ modifier out of order with the JLS suggestions. public順序錯誤

9.Method ‘deleteChild‘ is not designed for extension - needs to be abstract, final or empty. 不是拓展或繼承的方法,必須指定abstract,final或空

1Type is missing a javadoc commentClass 缺少類型說明

2“{” should be on the previous line“{” 應該位於前一行。解決方案:把“{”放到上一行去

3Methos is missing a javadoc comment 方法前面缺少javadoc注釋。解決方案:添加javadoc注釋 類似這樣:

/**

* set default mock parameter.(方法說明)

* @param additionalParameters parameter additional(參數名稱)

* @return data manager(返回值說明)

* @throws Exception if has error(異常說明)

*/

4 Expected @throws tag for “Exception”在注釋中希望有@throws的說明

解決方案:在方法前得注釋中添加這樣一行:* @throws Exception if has error(異常說明)

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“}” 應該與下條語句位於同一行。解決方案:把“}”放到下一行的前面

10Unused @param tag for “unused”沒有參數“unused”,不需注釋

解決方案:“* @param unused parameter additional(參數名稱)” 把這行unused參數的注釋去掉“

11Variable “CA” missing javadoc變數“CA”缺少javadoc注釋

解決方案:在“CA“變數前添加javadoc注釋:/** CA. */(注意:一定記得加上“.”)

12Line longer than 80characters行長度超過80 。解決方案:把它分成多行寫。必要時候,可以ctrl+shift+f

13Line contains a tab character行含有”tab” 字元。快速解決方案:可以使用editplus中的format功能,把tab字元轉化為空白格,然後儲存Editplus英文版安裝檔案在我機子上有。需要的可以來拷貝。註冊Editplus,點擊安裝檔案中註冊的檔案


14Redundant “Public” modifier冗餘的“public” modifier 。解決方案:冗餘的“public”

15Final modifier out of order with the JSL suggestion Final modifier的順序錯誤

16Avoid using the “.*” form of importImport格式避免使用“.*”

17Redundant import from the same package從同一個包中Import內容

18Unused import-java.util.listImport進來的java.util.list沒有被使用。解決方案:去掉匯入的多餘的類

19Duplicate import to line 13重複Import同一個內容 解決方案:去掉匯入的多餘的類

20Import from illegal package從非法包中 Import內容

21“while” construct must use “{}” “while” 語句缺少“{}”

22Variable “sTest1” must be private and have accessor method變數“sTest1”應該是private的,並且有調用它的方法

23Variable “ABC” must match pattern “^[a-z][a-zA-Z0-9]*$”變數“ABC”不符合命名規則“^[a-z][a-zA-Z0-9]*$”解決方案:把這個命名改成符合規則的命名 “aBC”

24“(” is followed by whitespace“(” 後面不能有空格 25“)”is proceeded by whitespace“)” 前面不能有空格

解決方案:把前面或者後面的空格去掉

25、First sentence should end with a period.解決方案:你的注釋的第一行文字結束應該加上一個"."。


26、Redundant throws: ‘NameNotFoundException‘ is subclass of ‘NamingException‘. ‘NameNotFoundException ‘是‘NamingException‘的子類重複拋出異常。

解決方案:如果拋出兩個異常,一個異常類是另一個的子類,那麼只需要寫父類

去掉NameNotFoundException異常,對應的javadoc注釋異常注釋說明也需要去掉


27、Parameter docType should be final. 參數docType應該為final類型 解決方案:在參數docType前面加個final


28、Line has trailing spaces. 多餘的空行 解決方案:去掉這行空行


29.Must have at least one statement. 至少一個聲明

解決方案:} catch (NumberFormatException nfe) {

LOG.error("Auto Renews the agreement failed", nfe);//異常捕捉裡面不可為空,在異常裡面加一句話。如列印等等

30、‘>‘ is not followed by whitespace.並且又有 ‘(‘ is preceded with whitespace.

定義集合和枚舉的時候的時候,最後一個“>”後面要有空格,“(”前面不容許有空格。解決方案:去掉泛型


31、Got an exception - java.lang.RuntimeException: Unable to get class information for @throws tag ‘SystemException‘.原因:不合理的throws。

解決方案:要確保某些類型,如某些類、介面不被throws。把聲明的異常去掉。在實作類別中拋出異常


網上參考解決方案:1、這是CheckStyle報的錯。通常需要Refreh, clean/build這個Project. 如果不行,可以嘗試clean all projects, restart Eclipse.

2、因為編譯好的類沒有在checkstyle的classpath中.所以, 只要將編譯好的class配置到在<checkstyle/>的classpath中就沒有這個問題了.另外, 還發現checkstyle的line length好像也有點問題, 明明沒有超過120個字元, 卻還是報錯.無奈, 我把Eclipse中java > code style > formatter中的Maximum line with改成了100, 然後format一下, 基本就沒有問題了


32、File does not end with a newline.解決方案:刪掉報錯的類,建立一個同名的類,把代碼全部複製過去


33、Utility classes should not have a public or default constructor. 介面中的內部類中不應該有公用的或者預設的構造方法

解決方案:在內部類中,定義一個私人的構造方法,然後內部類聲明為final類型。如果前面有static,那麼final還必須放在static之後


34、Variable ‘functionCode‘ must be private and have accessor methods.變數要改成private然後提供訪問的方法

解決方案:給這些變數的修飾符改成private,然後提供set,get方法,並加上對應的方法javadoc注釋、參數注釋。並在返回值和參數類型前添加final。並把調用了這個變數的地方改成通過方法訪問


35. ‘X‘ hides a field.

public class Foo
{
private int bar;

public Foo(int bar)
{
this.bar = bar;
}

public final int getBar()
{
return bar;
}
}

全域private int bar;和局部public Foo(int bar)的bar變數名字重複。
解決方案:把方法裡面的參數名稱改變下就可以了public Foo(int newBar)
{
this.bar = newBar;
}。

36、Got an exception - Unexpected character 0xfffd in identifier

這是因為CheckStyle不能識別制定的編碼格式。

網上參考解決方案:

1、Eclipse中可以配置,在Other-->checker中可以指定

2、可以修改checkstyle設定檔:

<module name="Checker">

<property name="severity" value="warning"/>

<property name="charset" value="UTF-8"/>

<module name="TreeWalker">

如果是UTF-8的話,就添加加粗的那條語句,就可以了。

37、 Got an exception - java.lang.RuntimeException: Unable to get class information for @throws tag *whatever*.
網上參考解決方案:選中CheckSytle的JavaDoc --> Method JavaDoc --> logLoadErrors。如果是CheckStyle自己載入時出錯的,打個Log就可以了,不要整出Errors嚇人。
還有一處也可能包出同樣的錯誤。Coding Problems --> Redundant Throws --> logLoadErrors選中即可


38、Expected @param tag for ‘dataManager‘. 缺少dataManager參數的注釋 解決方案:在注釋中添加@param dataManager DataManager

網上一些其他錯誤的解答:
1. Parameter X should be final.
public class Foo
{
private int bar;

public Foo(int bar)
{
this.bar = bar;
}

public final int getBar()
{
return bar;
}
}

解釋:public Foo(int bar)的局部變數,被認為是不可改變的,檢查需要加上final關鍵字定義public Foo(final int bar)此錯誤,可以忽略不檢查。

2. Redundant ‘X‘ modifier.

public interface CacheHRTreeService extends Manager {

/**
* Organization Tree
* @param orgDto
* @return
* @throws Exception
*/
public void setOrganization(OrganizationDTO orgDto) throws Exception;

/**
* Organization Tree
* @return
* @throws Exception
*/
public OrganizationDTO getOrganization() throws Exception;
......
}

解釋:多餘的欄位。public OrganizationDTO getOrganization() throws Exception;此時public為多餘的欄位,因為interface定義的時候,就是public的。

需要檢查。

3. - Class X should be declared as final.

解釋:對於單例設計模式,要求返回唯一的類對象。但是HRFactory和ContextFactory為最佳化的兩個類,不需求檢查。
其他的單例類,依然需要進行檢查。

4. - Method ‘addChildrenId‘ is not designed for extension - needs to be
abstract, final or empty.

解釋:通過父類繼承的,此類有點特殊可以忽略此類。

5. Variable ‘id‘ must be private and have accessor methods.解釋:BaseHRDTO類,為父類,屬性給子類繼承,比較特殊。但是其他的類,聲名需要加上範圍‘private‘關鍵字。需要檢查。

6. -Array brackets at illegal position.解釋:代碼寫法,習慣不一樣。需要檢查,僅僅提示

android checkstyle結果分析說明

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.