简体   繁体   中英

Java Buffered Reader detecting patterns in phrases

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)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM