开发者

how to make logic for checking braces for conditional statements in java?

开发者 https://www.devze.com 2023-02-20 05:35 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消