Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Static code parser for Java source code to extract methods / comments

I'm looking for a parser that can extract methods from a java class (static source code -> .java file) and method signature, comments / documentation, variables of each of the methods. Preferably in Java programming language.

Could someone please advise?

Thanks.

like image 614
Manish Mulani Avatar asked Jun 16 '12 03:06

Manish Mulani


2 Answers

You can use ASTParser by eclipse. Its super simple to use.

Find a quick standalone example here.

like image 181
Suraj Chandran Avatar answered Nov 12 '22 08:11

Suraj Chandran


Here is what I do to extract the method signatures from a java file/s:

I use Sublime Text 2, to the file I want to get the signatures from and the do a find Ctrl+F with regular expression set for the following Regex I made (I tested it on my code and it works, I hope it will work for you too)

((synchronized +)?(public|private|protected) +(static [a-Z\[\]]+|[a-Z\[\]]+) [a-Z]+\([a-Z ,\[\]]*\)\n?[a-Z ,\t\n]*\{)

After Sublime Text 2 highlight my results I click on "Find All" then copy Ctrl+C, open a new tab Ctrl+N and paste Ctrl+V.
You will then see all your methods signatures.

I hope it helped.

like image 44
Assaf Gamliel Avatar answered Nov 12 '22 08:11

Assaf Gamliel