Skip to content
Clément Fournier edited this page May 31, 2019 · 18 revisions

Welcome to the pmd-designer wiki!

The rule designer

The rule designer is both a way to inspect the tree on which PMD rules run on, and to write XPath rules in an integrated manner. This page describes the features that enable this.

AST inspection

designer_top

You can enter source code in the middle zone.

  • Make sure to select the correct language and version for your source code with the cog icon on the top!
  • If the source is valid using this setting, the tree to the right will update to display the AST of the code
  • When selecting a node, the left panel updates with information about a node

Selecting nodes

There are several ways to focus a node for inspection:

  • From the tree view: just click on an item
  • From the crumb bar: the crumb bar below the code area shows the ancestors of the currently selected node, and is empty if you have no selection:

Ancestor crumb bar example

  • From the source code: maintain CTRL for a second until the code area becomes mostly blue. Then, each node you hover over on the code area will be selected automatically. Example:

Ctrl-hover selection example

Node inspection

The left panel displays the following information:

  • XPath attributes: this basically are all the attributes available in XPath queries. Those attributes are wrappers around a Java getter, so you can obtain documentation on the relevant Javadoc (that's not yet integrated into the designer)
  • Metrics: for nodes that support it, the values of metrics are displayed in this panel
  • Scopes: This is java specific and displays some representation of the symbol table. You mostly don't need it. If you select eg a variable id, its usages are already highlighted automatically without opening the panel:

Usages highlight example

XPath rule design

The bottom part of the UI is dedicated to designing XPath rules:

Bottom UI

The center is an XPath expression. As you type it, the matched nodes are updated on the right, and highlighted on the code area. Autocompletion is available on some languages.

The left panel may be used to define new properties for your prototype rule. (Note: this UI is about to be changed)

Exporting to an XML rule

The little export icon next to the gear icon opens a menu to export your rule. This menu lets you fill-in the metadata necessary for an XPath rule to be included in a ruleset.

Export example

Clone this wiki locally