Examples / tutorials for usage of javax.lang.model or ANTLR JavaParser to get information on Java Source Code

与世无争的帅哥 提交于 2019-12-03 16:32:32

I would try that with Eclipse Xtext, it uses ANTLR under the hood, it is also (relative) easy to use it together with Eclipse GMF for visualization.

Is there a particular reason you want to generate a parser yourself? IMO, it would be easier to let an existing parser create an AST for you which you "simply" traverse in order to collect your data about the source file(s). Using your favorite search engine with the keywords "get ast java source" will result in many relevant hits.

At a first glance, these look like suitable candidates:

You could use ANTLR of course, there are many ANTLR grammars for Java available for you, but there is quite the learning curve when choosing this tool (or some other parser generator, for that matter). If you do choose ANTLR, I'm more than happy to answer any questions regarding it.

Best of luck!

I suggest you to go with Java Soot a Java Optimization Framework. Which will help you to parse the java source, can generate the CFG and various options available.

Also you can find eclipse plugin here

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!