code-analyzer ast-dump

Dump the Abstract Syntax Tree (AST) for a given source file.

Generate and display the AST that PMD produces when parsing a source file. This is useful for understanding how PMD interprets your code and for developing custom PMD rules. The command supports Apex, Visualforce, HTML, XML, and JavaScript files.

Flag Name (Long)Flag Name (Short)Description
‑‑fileN/AType: Value
Required

Path to the source file to parse.

The file whose AST you want to generate. The file must exist and be a regular file (not a directory). If you don’t specify the --language flag, the language is auto-detected from the file extension.
‑‑flags‑dirN/AType: Value

Import flag values from a directory.
‑‑formatN/AType: Value
Valid Values: json, xml
Default value: xml

Output format for the AST.

Choose between xml (default) or json. The XML format outputs the raw PMD AST XML, preserving the full tree structure. The JSON format provides a flat array of nodes with names, attributes, parent, and ancestor information.
‑‑jsonN/AType: Boolean

Format output as json.
‑‑language‑lType: Value
Valid Values: apex, visualforce, html, xml, javascript
Default value: apex

Language of the source file.

Explicitly specify the language of the source file. Defaults to apex. Supported languages are: apex, visualforce, html, xml, and javascript.
‑‑output‑fileN/AType: Value

Path to the file where the AST output is written.

If specified, the AST output is written to this file instead of being displayed in the terminal. The content format depends on the --format flag.

Dump the AST for an Apex class file in JSON format (default):

Dump the AST in XML format:

Dump the AST and write the output to a file:

Explicitly specify the language when the file extension is ambiguous: