#391 Switch-FallThroughCheck should respect "falls through"

release_4.0
closed
Check (274)
4
2012-10-10
2005-11-02
No

(This RFE is following up parts of RFE 1245942, which
contained two topics. Many thanks for the fix of RFE
1245942!)

According to Sun's conventions
http://java.sun.com/docs/codeconv/html/CodeConvention
s.doc6.html
in §7.8, every time when a case falls through
intentionally, a comment should be added where the
break statement would normally be. They suggest the
comment
/ falls through /
but I have seen different comments for this purpose, so
this should be a regexp parameter to the check.
Of course, the FallsThroughCheck should not alert if the
comment is there.

The obvious Checkstyle solution is to use a
SuppressionCommentFilter. But this is inferior, as this
filter has to be turned on - and later off again. Here is my
try, at least it is turning the check off as expected, and
any comment is turning it on again. But what if there is
no such comment?

<module name="SuppressionCommentFilter">
<property name="offCommentFormat" value=" falls through"/>
<property name="onCommentFormat" value=""/>
<property name="checkFormat" value="FallThroughCheck"/>
</module>

Accounting for the comment is not easy, I assume,
as the AST seems not to contain the comments
(although ANTLR could include them).

Discussion

  • Logged In: YES
    user_id=1227261

    Reduced the Priority as there is a workaround.

     
  • Logged In: YES
    user_id=746148

    Oops, I've missed this part :( sorry
    Will think about this feature over weekend.

     
  • Ralf
    Ralf
    2005-11-03

    Logged In: YES
    user_id=383599

    A while back, I played around with the FallThroughCheck and
    added a parameter that checks for "FALLTHROUGH" comments.
    The parameter is a regexp.

    Should I adopt it for 4.0 and provide a patch?

    Ralf

     
  • Logged In: YES
    user_id=746148

    The patch is always welcome :)
    I promised I will apply it asap ;)

     
  • Ralf
    Ralf
    2005-11-05

    Logged In: YES
    user_id=383599

    I uploaded the patch: 1348873

    Ralf

     
  • Logged In: YES
    user_id=746148

    The patch applied, thank you for suggestions and contributions