How to get an Abstract Syntax Tree from IntelliJ IDEA?
I've been trying to build a Java AST using IntelliJ IDEA, but I've had difficulty finding any information on doing so.
Can someone point me in the right direction with regards to this? I want to create the AST primarily for Java, and then potentially for other languages in future.
The idea is to create an AST for a project, then store the AST in a triplestore database.
The built-in PSI Viewer appears to provide something close to what I'm looking for, perhaps there is a way to create something like an AST using PSI objects?
Thanks for any suggestions.
Please sign in to leave a comment.
Hi,
Welcome to the community; You may find the following links useful
Psi/AST overview for Languages - http://confluence.jetbrains.com/display/IDEADEV/Developing+Custom+Language+Plugins+for+IntelliJ+IDEA
PsiCookbook - http://confluence.jetbrains.com/display/IDEADEV/PSI+Cookbook
Architectural Overview - http://confluence.jetbrains.net/display/IDEADEV/IntelliJ+IDEA+Architectural+Overview
In essence, all of this information exists for you already within a PSI file - the root of a PSI tree - and is accessible through the JavaPsiFacade.
If you really need access to the AST nodes, then you can access this via getNode() on a PsiElement.
Hope this helps :)
Alan
Thanks Alan, JavaPsiFacade was certainly the way to go.