package xyz.wbsite.dbtool.javafx.tool; import xyz.wbsite.dbtool.javafx.po.ApiMethod; import java.io.*; import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; public class ApiClassReader { private File javaClass; private List methodList; public ApiClassReader(File javaClass) throws IOException { this.javaClass = javaClass; methodList = new ArrayList<>(); read(); } private void read() throws IOException { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(javaClass), "utf-8")); String line = null; Pattern compile = Pattern.compile("\\s+public (.*Response)\\s+(.*)\\((.*Request) request\\) \\{"); while ((line = bufferedReader.readLine()) != null) { Matcher matcher = compile.matcher(line); if (matcher.find()) { ApiMethod apiMethod = new ApiMethod(); apiMethod.setResponse(matcher.group(1)); apiMethod.setMethod(matcher.group(2)); apiMethod.setRequest(matcher.group(3)); methodList.add(apiMethod); } } bufferedReader.close(); } public File getJavaClass() { return javaClass; } public void setJavaClass(File javaClass) { this.javaClass = javaClass; } public List getMethodList() { return methodList; } public void setMethodList(List methodList) { this.methodList = methodList; } public static void main(String[] args) throws IOException { ApiClassReader javaClassReader = new ApiClassReader(new File("D:\\wangbing\\Project\\dbtool\\target\\project\\EXAMPLE-WEB\\src\\main\\java\\com\\example\\action\\api\\system\\DictApi.java")); System.out.println(); } }