简体   繁体   中英

Checkstyle - Whitespace inside curly brackets

I am working on checkstyle for our project, and i ran into problem which i am not able to solve.

What I need is to check if there is whitespace inside a curly brackets defining some array elements (between bracket and element).

Like this:

@SuppressWarnings({ "element1", "element2" })
                   ^                      ^

And it should throw violation if they are not present.

I am new to checkstyle, and I wasn't able to find any good way to do this.

For most problems, that do not have a direct checking rule, you will be able (with some effort) to setup one of Checkstyle's regular expression rules.

This might reach from a trivial regex for the shown case like \\{\\s and \\s\\} , but might get more complex, eg if you have enough elements to have line breaks in the code. Also the trivial rules shown might also highlight code elsewhere, where it's not intended. So knowledge in regular expressions will be needed to setup those rules.

BTW: If possible, spacing issues like this I would solve using Eclipse's (or whatever IDE you are using) formatter. This can be easily configured to omit or place whitespace at different positions in the code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM