Find Method Sign Line Number

Posted wblade

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Find Method Sign Line Number相关的知识,希望对你有一定的参考价值。

 1 package java9;
 2 
 3 import java.io.IOException;
 4 import java.nio.file.Files;
 5 import java.nio.file.Paths;
 6 import java.util.List;
 7 import java.util.regex.Pattern;
 8 
 9 public class TTT 
10 
11     public static void main(String args[]) throws IOException 
12 
13         List<String> readAllLines = Files.readAllLines(Paths
14                 .get("/Users/hongtaowang/git/spring-boot-jpa-demo/src/main/java/com/my/app/web/IndexController.java"));
15 
16         int issueLine = 29;
17 
18         String preMethodSignNumber = getPreMethodSignNumber(issueLine, readAllLines);
19 
20         System.out.println(preMethodSignNumber);
21 
22         String preSignEndChar = getPreSignEndChar(readAllLines, issueLine);
23 
24         System.out.println(preSignEndChar);
25 
26     
27 
28     private static String getPreSignEndChar(List<String> readAllLines, int issueLine) 
29         int nextMethodSignLine = getNextMethodSignNumber(issueLine, readAllLines);
30 
31         for (int endLineNumber = nextMethodSignLine - 1; endLineNumber > 0; endLineNumber--) 
32             String endChar = readAllLines.get(endLineNumber - 1);
33 
34             if (endChar.contains("")) 
35                 return (endLineNumber) + " end     line " + endChar;
36             
37 
38         
39 
40         return "";
41     
42 
43     private static int getNextMethodSignNumber(int i, List<String> readAllLines) 
44         int j = i;
45         for (; j < readAllLines.size(); j++) 
46             String p = readAllLines.get(j - 1);
47             boolean extracted = matchMethodSign(p);
48             if (extracted) 
49                 break;
50             
51 
52         
53         return j;
54     
55 
56     private static String getPreMethodSignNumber(int currentLine, List<String> readAllLines) 
57         for (int preLine = currentLine - 1; preLine > 0; preLine--) 
58             String preLineSource = readAllLines.get(preLine - 1);
59 
60             if (matchMethodSign(preLineSource)) 
61                 return (preLine) + " end     line " + preLineSource;
62             
63 
64         
65 
66         return "";
67     
68 
69     private static boolean matchMethodSign(String d) 
70         String pattern = ".*[A-z].* .*[A-z1-9]\\(.*";
71         boolean isMatch = Pattern.matches(pattern, d);
72         if (!isMatch) 
73             return false;
74         
75 
76         if (d.contains("return")) 
77             return false;
78         
79 
80         if (d.contains("=")) 
81             return false;
82         
83 
84         return true;
85     
86 
87 

 

以上是关于Find Method Sign Line Number的主要内容,如果未能解决你的问题,请参考以下文章

C语言如何判断输入数字的个数

cisco packet tracer_sign up(基于临时邮箱/qq邮箱注册并成功在软件中登录)(2021.9实践)(应对Sorry, we can‘t find a NetAcad...)(代

php对接登陆的三两片语

js懒加载异步操作解决办法

APK Downgrade Method not working on LINE 6.6.1

Finance API文档