0

How do you set checkstyle to enforce the following:

int i = 0;
if(i == 0) {
    // do something
}
if(i > 0) {
    // do something
}

instead of:

int i=0;
if(i==0) {
    // do something
}
if(i>0) {
    // do something
}
4

2 回答 2

5

规则名称是WhitespaceAround,您可以在 checkstyle xml 文件中这样设置:

<module name="WhitespaceAround">
  <property name="tokens" value="ASSIGN,BAND,BAND_ASSIGN,BOR,BOR_ASSIGN,BSR,BSR_ASSIGN,BXOR,BXOR_ASSIGN,COLON,DIV,DIV_ASSIGN,EQUAL,GE,GT,LAND,LE,LITERAL_ASSERT,LITERAL_CATCH,LITERAL_DO,LITERAL_ELSE,LITERAL_FINALLY,LITERAL_FOR,LITERAL_IF,LITERAL_RETURN,LITERAL_SYNCHRONIZED,LITERAL_TRY,LITERAL_WHILE,LOR,LT,MINUS,MINUS_ASSIGN,MOD,MOD_ASSIGN,NOT_EQUAL,PLUS,PLUS_ASSIGN,QUESTION,SL,SLIST,SL_ASSIGN,SR,SR_ASSIGN,STAR,STAR_ASSIGN,LITERAL_ASSERT,TYPE_EXTENSION_AND,WILDCARD_TYPE"/>
</module>

可以参考以下网址: http ://checkstyle.sourceforge.net/config_whitespace.html

于 2013-05-15T05:45:11.137 回答
1

xml中的用户类似配置

<module name="Checker">
    <module name="TreeWalker">
      <module name="WhitespaceAfter"/>
      <module name="WhitespaceAround"/>
   </module>
</module>
于 2013-05-15T06:31:46.317 回答