janasainik
janasainik

Reputation: 831

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

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 idea? thanks in advance.

Upvotes: 0

Views: 211

Answers (2)

Stephen C
Stephen C

Reputation: 719436

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.

Upvotes: 2

qwerty
qwerty

Reputation: 3869

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.

Upvotes: 0

Related Questions