I am trying to work on a code formatter for Apex. I need the AST to plug it into a popular Javascript formatter (prettier). Is there by any chance I can get the Apex AST and put it in JSON blob format?
My best guess would be to use apex-jorje (see this to learn how to use the jars from Maven) to parse the code into a Java AST, and then transverse the tree to convert each node to JS in whichever way you find fitting.
Parsing the code is straight-forward enough (see an example here), and once you have a Compilation
, you can transverse the AST.
Since this is not really a PMD issue, you can use the AST provided by Jorje, you don't need the adaptation to PMD's AST structures.