Find Method Sign Line Number
2024-09-03 22:12:53
package java9; import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
import java.util.regex.Pattern; public class TTT { public static void main(String args[]) throws IOException { List<String> readAllLines = Files.readAllLines(Paths
.get("/Users/hongtaowang/git/spring-boot-jpa-demo/src/main/java/com/my/app/web/IndexController.java")); int issueLine = 29; String preMethodSignNumber = getPreMethodSignNumber(issueLine, readAllLines); System.out.println(preMethodSignNumber); String preSignEndChar = getPreSignEndChar(readAllLines, issueLine); System.out.println(preSignEndChar); } private static String getPreSignEndChar(List<String> readAllLines, int issueLine) {
int nextMethodSignLine = getNextMethodSignNumber(issueLine, readAllLines); for (int endLineNumber = nextMethodSignLine - 1; endLineNumber > 0; endLineNumber--) {
String endChar = readAllLines.get(endLineNumber - 1); if (endChar.contains("}")) {
return (endLineNumber) + " end line " + endChar;
} } return "";
} private static int getNextMethodSignNumber(int i, List<String> readAllLines) {
int j = i;
for (; j < readAllLines.size(); j++) {
String p = readAllLines.get(j - 1);
boolean extracted = matchMethodSign(p);
if (extracted) {
break;
} }
return j;
} private static String getPreMethodSignNumber(int currentLine, List<String> readAllLines) {
for (int preLine = currentLine - 1; preLine > 0; preLine--) {
String preLineSource = readAllLines.get(preLine - 1); if (matchMethodSign(preLineSource)) {
return (preLine) + " end line " + preLineSource;
} } return "";
} private static boolean matchMethodSign(String d) {
String pattern = ".*[A-z].* .*[A-z1-9]\\(.*";
boolean isMatch = Pattern.matches(pattern, d);
if (!isMatch) {
return false;
} if (d.contains("return")) {
return false;
} if (d.contains("=")) {
return false;
} return true;
} }
最新文章
- C语言 &#183; 矩阵乘法 &#183; 算法训练
- HTML 学习笔记 JavaScript (String)
- Logistic Regression - Formula Deduction
- linux6.*无法正常启动has进程解决方案
- 08JAVA多态
- 解决docker容器中文乱码,修改docker容器编码格式
- Xamarin开发Android笔记:背景操作
- Animator根骨骼运动原始实现代码
- time返回当前的 Unix 时间戳而$_SERVER[";REQUEST_TIME";]得到请求开始时的时间戳
- 灰色关联度Matlab代码
- YCSB性能测试工具使用
- LiveBlox无需代码的开发工具--支持win macos ubuntu等开发环境--
- BigDecimal 准确的 double , float 计算
- Web测试要点
- CentOS6.3升级Python到2.7.3版本
- C#MVC和cropper.js实现剪裁图片ajax上传的弹出层
- 手机端学习助手的说明书需求以及团队PM选择
- 水仙花数-python
- 914D Bash and a Tough Math Puzzle
- Mat_类