Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checkstyle whitespace checking

Tags:

checkstyle

I have this seemingly innocent looking code.

String str = (String)convert.fromBytes(bytes);

And I get 'cast' is not followed by whitespace. from checkstyle. So I add a space after (String) and I got ')' is followed by whitespace. ...

I've play around with the configure (and found many of them might involve this). After a while I got confused what I have changed (Hahaha) but I manage to have the warning gone for A SPACE after type cast. However, I prefer not to have space after type cast. So, can anyone tell me what exactly to set to remove the warning when I have NO SPACE after type case.

Edit:

Here is what I first wrote:

String str = (String)convert.fromBytes(bytes);

Then I get

'cast' is not followed by whitespace..

So I changed to

String str = (String) convert.fromBytes(bytes);

then I got

')' is followed by whitespace.

What I want is to write the following without any warning.

String str = (String)convert.fromBytes(bytes);

What option should I set?

P.S. I use CheckStyle plugin in Eclipse.

Thanks

like image 610
NawaMan Avatar asked Oct 16 '25 03:10

NawaMan


1 Answers

In Eclipse-CS, you can set a checkmark in Window ▶ Preferences ▶ Checkstyle ▶ Include Rule names in violation messages. Then, for each violation, you can see the rule that caused it.

In your case, you have Type Cast enabled in both the Whitespace After and the No Whitespace After rules. You will want to uncheck Type Cast for "Whitespace After" in order to support your formatting.

Eclipse-CS will generate the XML for you, but if you must set it manually, you can do so by specifying the tokens to check (example shows how TYPECAST ist left out):

<module name="WhitespaceAfter">
    <property name="tokens" value="COMMA, SEMI"/>
</module>
like image 187
barfuin Avatar answered Oct 19 '25 13:10

barfuin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!