Skip to content

how to use PMD 5.8.1 Java API to create a rule and to raise a ruleviolation #3052

Answered by oowekyala
Neha-Dhonde asked this question in Q&A
Discussion options

You must be logged in to vote

@Neha-Dhonde That looks like an entirely different rule. It's advisable to create one rule for each type of violation you want to catch, mixing the detection logic for missing package statements and logger calls seems to ask for trouble imho.

I'd recommend making an XPath rule for your first rule, and another Java rule for logger call detection. You could use the symbol table to find the declaration of the logger and its type, like in ForLoopCanBeForeach, because unfortunately type resolution still loses some information in calls such as myLogger.info(..) (see #497).

Replies: 7 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by adangel
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #617 on January 15, 2021 09:43.