How to use JavaParser to walk over all the nodes of AST (abstract syntax tree) of some Java source code?

700 views Asked by At

I am trying to build a translator of Java source code to other object-oriented programming languages. For this I want to traverse the whole AST (generated by JavaParser) and gather each and every component of the Java source code and then correspondingly translate them to my target language. I did not find anything related to the traversal of the complete AST in online searches, though I did find about locating specific nodes such as 'class or interface declaration', etc. Any help would be appreciated.

1

There are 1 answers

0
code_blooded29 On

After going through the documentation, I realised that using getChildNodes() function will help us to visit each and every node of the Java source code AST from root to leaf nodes.