0

I want my program to be able to read in a file of java code and be able to identify the different methods. Is this possible to do with a buffered reader or should I be doing something different? Since methods can return any type (String/void/int/etc) and can be of many different types of modifier (private/public etc) I don't see how I can identify them easily.

public returnType methodName(String s){

How can I get my program to read that in and automatically detect that it is of the same format as:

private Set<String> nextstates(int newInt)
Alex
  • 627
  • 3
  • 12
  • 32
  • have a look at [this](http://stackoverflow.com/questions/2206065/java-parse-java-source-code-extract-methods) – Hagai Oct 18 '14 at 11:44
  • 1
    You can use the Java Development Tools (http://www.vogella.com/tutorials/EclipseJDT/article.html) to get an Abstract Syntax Tree, which presents you with all the information you want. – Kulu Limpa Oct 18 '14 at 11:46

1 Answers1

1

You can use regular expressions to search the file for method definitions. You would just read in the file line by line using a BufferedReader for example and search in every line for matches with the regex. One possible regex is the one suggested in the following post by Georgios Gousios

Community
  • 1
  • 1
Turakar
  • 180
  • 2
  • 13