How it works

PMD checks source code against rules and produces a report. Like this:

  • Something passes a file name and a RuleSet into PMD
  • PMD hands an InputStream to the file off to a JavaCC-generated parser
  • PMD gets a reference to an Abstract Syntax Tree back from the parser
  • PMD hands the AST off to the symbol table layer if any of the rules need it. The SymbolFacade then builds a bunch of Scope nodes and attaches them to the appropriate places in the AST.
  • Ditto for the data flow analysis layer, except this time it's DFA nodes that get built and attached.
  • Each Rule in the RuleSet gets to traverse the AST and check for problems. The Rules can also poke around the symbol table and DFA nodes.
  • The Report is now filled with RuleViolations, and those get printed out in XML or HTML or whatever

Not much detail here... if you think this document can be improved, please post here and let me know how. Thanks!