@SuppressWarnings doesn't work on import statement?

1,273 views
Skip to first unread message

acm...@gmail.com

unread,
Jul 19, 2014, 11:46:55 PM7/19/14
to check...@googlegroups.com
I use the following test environments, but got CheckStyle exception on "Unexpected token: import"
May I do something wrong? 

It works on other java statements but import, is it a limitation or not support or forbidden usage?

@SuppressWarnings("checkstyle:avoidstartimport")
import android.*;

config.xml
<module name="Checker">
    <module name="TreeWalker">
        <module name="SuppressWarningsHolder">
    </module>
    <module name="SuppressWarningsFilter">
</module>

java -jar checkstyle-5.7-all.jar -c config.xml -f xml -o output.xml -r src

Thanks a lot

acm...@gmail.com

unread,
Jul 20, 2014, 12:05:50 AM7/20/14
to check...@googlegroups.com
Although it does filter out AvoidStarImport, but if I change "checkstyle:avoidstartimport" to "typo", it still filter out AvoidStarImport
I think this is a bug
@SuppressWarnings("typo")
import android.*;

Roman Ivanov

unread,
Jul 21, 2014, 12:36:48 AM7/21/14
to check...@googlegroups.com
Hi,


import is not a token that this Check support:
CLASS_DEF,INTERFACE_DEF,ENUM_DEF,
ANNOTATION_DEF,ANNOTATION_FIELD_DEF,
ENUM_CONSTANT_DEF,METHOD_DEF,CTOR_DEF

Most likely imports are minimal priority of interest for Checkstyle, splitting imports order by annotations is weird to my mind.
Trailing comment for on IMPORTs is also strange as imports are managed by IDE mostly - so comment always removed.

If you need to put suppress on import .... I would recommend you to use SuppressWithNearbyCommentFilter
or the best solution to my mind is SuppressionFilter.

thanks,
Roman Ivanov

acm...@gmail.com

unread,
Jul 29, 2014, 6:07:48 AM7/29/14
to check...@googlegroups.com
Dear Roman Ivanov:

Thanks for your response

Roman Ivanov於 2014年7月21日星期一UTC+8下午12時36分48秒寫道:
Reply all
Reply to author
Forward
0 new messages