2015-11-05 21 views
0

我正在使用Checkstyle 6.12。我想用這兩個模塊:無法使用參數註釋滿足Checkstyle ModifierOrder和FinalParameters

<module name="ModifierOrder"/> 
<module name="FinalParameters"/> 

我有一個看起來像這樣

@GET 
@Path("{thingId}") 
@Produces(MediaType.TEXT_PLAIN) 
public String getThing(
    final @PathParam("thingId") String thingId, 
) { 
    return "halp meh"; 
} 

的方法。如果我對這個運行的Checkstyle我得到這樣的輸出:

<checkstyle version="6.12"> 
    <error line="17" column="13" severity="error" 
     message="'@PathParam' annotation modifier does not precede non-annotation modifiers." 
     source="com.puppycrawl.tools.checkstyle.checks.modifier.ModifierOrderCheck"/> 
    ... 

如果我帶走final修飾符,我仍然收到錯誤:

<checkstyle version="6.12"> 
    <error line="17" column="7" severity="error" 
     message="Parameter version should be final." source="com.puppycrawl.tools.checkstyle.checks.FinalParametersCheck"/> 

這種情況讓我處於一種尷尬的境地,因爲我希望使用這兩種方法在我寫的代碼上強制執行一些代碼樣式。有沒有辦法配置Checkstyle在這種情況下工作?

+1

你不能做'@PathParam(「thingId」)最終字符串thingId'嗎? – awksp

+0

@awksp哦天啊,這是令人尷尬的......我「做了」,並且我得到了一個編譯器錯誤。我沒有意識到我有'@PathParam(「thingId」)final @PathParam(「thingId」)'。他們中有2人是這樣的問題是:(。 – mkobit

+0

:P嘿,這種事情發生在每個人身上,至少它已經解決了! – awksp

回答

0

由於awks指出,在final工作之前移動註釋。

@PathParam("thingId") final String thingId 

我沒有注意到這個原因是因爲當我試圖這樣做時,我收到了一個編譯器錯誤。問題是我有註解在那裏重複兩次:

@PathParam("thingId") final @PathParam("thingId")