mittelmania
mittelmania

Reputation: 3561

Using ANTLR4 to find all methods in a Java project

I'm trying to write a short program that can extract all methods from a Java project (I have the source files).

After doing a little bit of research I came to realize that doing so using regular expressions is a bad idea, since Java is a context-free language and since it will be problematic to correctly match all the curly braces. The next step was to find an alternative way, and I learned that using the ANTLR parser would be the best idea. I found many examples (some older than the others) but I was unable to find an example for how to extract all the methods in a project (including their body).

Can anyone write a short example, so I can know how I should get started?

Upvotes: 1

Views: 1248

Answers (1)

Terence Parr
Terence Parr

Reputation: 5962

You can easily just use the parse tree and a listener to trigger a call to your code. Have you looked at the doc? It has essentially your exact solution.

Upvotes: 1

Related Questions