I am practicing with PMD plug-in and i want to write a rule in java for checking braces for if, while and for loops. Any id开发者_运维技巧ea? thanks in advance.
It is just a matter or understanding the ASTs. For example, if the body of a while statement has curly braces it will be a Block. If not, it will be some other kind of statement.
In fact, the "How to write a PMD rule" page uses while statement / curly braces as its example.
You could check out antlr. It may be overkill for just brace matching, but useful when you want to validate other parts of the grammer, like the if/while loops.
精彩评论