Creating a metric for a custom rule in Java #4788
-
I am wondering how you would go about creating a metric to be used in a custom rule. We currently have a way to detect and collect the data that we need, but we are having trouble adding the violation in the correct spot as PMD only parses the tree once. Is there a way that we can collect all this data as a metric then call it statically within the custom rule? Or is there a way that we can force PMD to parse twice and take in these data points? We are using a stripped down version for Java rules specifically that can be found here - https://github.com/pmd/pmd-examples/tree/main/custom-rules/maven-java |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
No, PMD doesn't support this currently. We have some proposals in the backlog to tackle this eventually (#3920), but won't happen before PMD 7.0.0 at the earliest. |
Beta Was this translation helpful? Give feedback.
Hi sorry for the late reply, we were able to find a way to track the metrics that we needed. We needed to keep track of methods that were called by other methods so we stored the ASTMethodDeclaration nodes in a hash map along with how many times they were called by other methods. Hopefully this helps for anyone looking to do the same thing.