This repository has been archived by the owner on Nov 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 107
[important] 方法精确定位算法优化 #65
Labels
enhancement
New feature or request
Comments
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));
// 遇到结尾
if (total.charAt(j) == ')') {
// 参数为0个的情况
if (total.charAt(j - 1) == '(') {
curNum = 0;
}
// 参数匹配认为找到了
if (curNum == paramNum) {
return i;
} else {
if (paramNum > curNum) {
int atNum = 0;
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;
}
}
}
}
break;
} else if (total.charAt(j) == ',') {
// 已遍历参数数量+1
curNum++;
}
}
}
}
return 0;
} |
0.9 |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
某些情况会误报
The text was updated successfully, but these errors were encountered: