Creating Spacing Rule for synchronized(this)

20 views
Skip to first unread message

Elizabeth Lingg

unread,
Jan 5, 2016, 1:57:56 PM1/5/16
to checkstyle
I've spent some time investigating and I would like to create a rule to make sure there is no space before the left param for synchronized, i.e. I would like to have the style "synchronized(this)" instead of "synchronized (this)".

This rule below will not work, because it seems LITERAL_SYNCHRONIZED is not supported for NoWhitespaceAfter (see http://checkstyle.sourceforge.net/config_whitespace.html#NoWhitespaceAfter#NoWhitespaceAfter)

<module name="NoWhitespaceAfter">
            <property name="tokens" value="ARRAY_INIT, INC, DEC, UNARY_MINUS, UNARY_PLUS, BNOT,
                                           LNOT, DOT, ARRAY_DECLARATOR, INDEX_OP,
                                           LITERAL_SYNCHRONIZED"/>
        </module>

Any ideas on how to create this rule?

Thanks,
Elizabeth

R Veach

unread,
Jan 5, 2016, 6:30:29 PM1/5/16
to checkstyle
If you look at the properties section of http://checkstyle.sourceforge.net/config_whitespace.html#NoWhitespaceAfter , you will see that LITERAL_SYNCHRONIZED is not a supported token. All supported tokens are displayed for each check, and any ones you add that aren't listed won't work.

I would submit a feature for this to be added at https://github.com/checkstyle/checkstyle/issues/new .

If you wish to help add this feature, I would download checkstyle's source and look into NoWhitespaceAfterCheck.java  and add some test cases in NoWhitespaceAfterCheckTest.java and submit a pull request.
You will have to add it as an acceptable token, and examine visitToken to decipher where it will need to be added, if it is needed at all, for it to function correctly.

Elizabeth Lingg

unread,
Jan 5, 2016, 6:44:13 PM1/5/16
to checkstyle
Thanks! I have created the issue here, https://github.com/checkstyle/checkstyle/issues/2803.

-Elizabeth

Roman Ivanov

unread,
Jan 5, 2016, 7:31:46 PM1/5/16
to Elizabeth Lingg, checkstyle
to avoid wasting time of implementation , please wait till I put "approved" on issue. Some issues are so obvious.

...... We did that on purpose some time ago, I need to find that reason again, I do not remember what forced us to restrict allowed set of tokens.

--
You received this message because you are subscribed to the Google Groups "checkstyle" group.
To unsubscribe from this group and stop receiving emails from it, send an email to checkstyle+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages