How to generate AST from Java source-code? [closed]

Regarding your second question, there are dozens of Java parsers available in addition to Sun’s. Here is a small sample:

  • Eclipse’s org.eclipse.jdt.core.dom package.
  • Spoon outputs a very nice annotated parse tree with type information and variable binding (and uses Eclipse’s parser internally)
  • ANTLR is a parser-generator, but there are grammars for Java available
  • javaparser (which I have not used)

My best advice is to try each of them to see which works best for your needs.

Leave a Comment