如何设置checkstyle以强制执行以下操作:
int i = 0;
if(i == 0) {
// do something
}
if(i > 0) {
// do something
}
而不是:
int i=0;
if(i==0) {
// do something
}
if(i>0) {
// do something
}
答案 0 :(得分: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
答案 1 :(得分:1)
xml中的用户类似配置
<module name="Checker">
<module name="TreeWalker">
<module name="WhitespaceAfter"/>
<module name="WhitespaceAround"/>
</module>
</module>