简体   繁体   English

Java Buffered Reader检测短语中的模式

[英]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. 我希望我的程序能够读取Java代码文件并能够识别不同的方法。 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. 由于方法可以返回任何类型(字符串/ void / int / etc),并且可以具有许多不同类型的修饰符(私有/公共等),所以我不知道如何轻松识别它们。

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. 例如,您只需要使用BufferedReader逐行读取文件,然后在每行中搜索与正则表达式的匹配项。 One possible regex is the one suggested in the following post by Georgios Gousios 一种可能的正则表达式是Georgios Gousios在以下帖子中建议的一种

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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