Skip to content
This repository has been archived by the owner on Nov 30, 2023. It is now read-only.

Commit

Permalink
#70
Browse files Browse the repository at this point in the history
  • Loading branch information
4ra1n committed Feb 2, 2023
1 parent 3ebec0c commit 5ae8af2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ Others:

更新内容:
- [important] [bug] 表达式搜索存在漏报 #67
- [important] [bug] 方法定位算法遇到范型时的问题 #70
- [important] [feat] 表达式搜索支持子类父类递归分析 #68
- [bug] 使用Fira字体在某些情况下有意外的问题 #74
- [feat] 表达式支持方法前后缀 #69
Expand Down
32 changes: 30 additions & 2 deletions src/main/java/com/chaitin/jar/analyzer/form/JarAnalyzerForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -862,15 +862,17 @@ public int find(String total, String methodName, int paramNum) {
for (int i = total.indexOf(methodName);
// 循环找直到找不到为止
i >= 0; i = total.indexOf(methodName, i + 1)) {
// 如果方法名上一位是空格且下一位是(字符
// 认为找到的方法的定义
// 如果方法名上一位是空格且下一位是字符
// 认为找到的方法(定义或某些情况的调用)
if (total.charAt(i - 1) == ' ' &&
total.charAt(i + methodName.length()) == '(') {
// 前第二位是空格这是方法调用
// 因为第二位如果不是空格那么必然不是方法定义
if (i - 2 > 0 && total.charAt(i - 2) == ' ') {
continue;
}
int curNum = 1;
// 不能使用数组因为不知道具体长度
List<Character> temp = new ArrayList<>();
for (int j = i + methodName.length() + 1; ; j++) {
temp.add(total.charAt(j));
Expand All @@ -885,22 +887,34 @@ public int find(String total, String methodName, int paramNum) {
return i;
} else {
if (paramNum > curNum) {
// 当参数不足当情况下
// 注解个数
int atNum = 0;
// 右括号默认是-1
// 因为参数最终一定以右括号结尾
int rightNum = -1;
for (Character character : temp) {
if (character == '@') {
// 遇到注解
atNum++;
}
if (character == ')') {
// 遇到右括号
rightNum++;
}
}
if (atNum == 0) {
// 已经遇到了右括号但不存在注解
// 且参数的数量不匹配
// 这不是预期直接跳出
break;
} else {
// 存在注解且右括号正好比注解多一个
if (rightNum == atNum) {
// 认为找到了
return i;
} else if (atNum > rightNum) {
// 没遇到注解和结尾情况应该继续走
continue;
}
}
Expand All @@ -910,6 +924,20 @@ public int find(String total, String methodName, int paramNum) {
} else if (total.charAt(j) == ',') {
// 已遍历参数数量+1
curNum++;
} else if (total.charAt(j) == '<') {
int dNum = -1;
while (true) {
j++;
if (total.charAt(j) == '>') {
if (dNum != -1) {
curNum -= dNum;
}
break;
}
if (total.charAt(j) == ',') {
dNum++;
}
}
}
}
}
Expand Down

0 comments on commit 5ae8af2

Please sign in to comment.