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;
} }

最新文章

  1. C语言 &#183; 矩阵乘法 &#183; 算法训练
  2. HTML 学习笔记 JavaScript (String)
  3. Logistic Regression - Formula Deduction
  4. linux6.*无法正常启动has进程解决方案
  5. 08JAVA多态
  6. 解决docker容器中文乱码,修改docker容器编码格式
  7. Xamarin开发Android笔记:背景操作
  8. Animator根骨骼运动原始实现代码
  9. time返回当前的 Unix 时间戳而$_SERVER[&quot;REQUEST_TIME&quot;]得到请求开始时的时间戳
  10. 灰色关联度Matlab代码
  11. YCSB性能测试工具使用
  12. LiveBlox无需代码的开发工具--支持win macos ubuntu等开发环境--
  13. BigDecimal 准确的 double , float 计算
  14. Web测试要点
  15. CentOS6.3升级Python到2.7.3版本
  16. C#MVC和cropper.js实现剪裁图片ajax上传的弹出层
  17. 手机端学习助手的说明书需求以及团队PM选择
  18. 水仙花数-python
  19. 914D Bash and a Tough Math Puzzle
  20. Mat_类

热门文章

  1. 《python解释器源码剖析》第2章--python中的int对象
  2. js抽奖,跑马灯
  3. 第八章 watch监听 86 watch、computed、methods的对比
  4. NoSQL数据库技术实战-第1章 NoSQL与大数据简介 NoSQL数据库的类型
  5. Linux的信号管理
  6. ABC065D Built[最小生成树]
  7. ZAP笔记
  8. 51 Nod 1116 K进制下的大数
  9. 阿里云ECS新增端口
  10. python IO密集型为什么使用多线程