提交 4d305107 编写于 作者: S Skylot

core: fix line number references

上级 ee74c4d8
......@@ -14,6 +14,7 @@ import org.slf4j.LoggerFactory;
import jadx.api.CodePosition;
import jadx.core.dex.attributes.nodes.LineAttrNode;
import jadx.core.utils.StringUtils;
import jadx.core.utils.files.FileUtils;
import jadx.core.utils.files.ZipSecurity;
......@@ -93,6 +94,15 @@ public class CodeWriter {
return this;
}
public CodeWriter addMultiLine(String str) {
buf.append(str);
if (str.contains(NL)) {
line += StringUtils.countMatches(str, NL);
offset = 0;
}
return this;
}
public CodeWriter add(String str) {
buf.append(str);
offset += str.length();
......
......@@ -170,7 +170,7 @@ public class MethodGen {
if (cause != null) {
code.newLine();
code.add("/*");
code.newLine().add("Error: ").add(Utils.getStackTrace(cause));
code.newLine().add("Error: ").addMultiLine(Utils.getStackTrace(cause));
code.add("*/");
}
}
......
......@@ -202,4 +202,18 @@ public class StringUtils {
public static boolean notEmpty(String str) {
return str != null && !str.isEmpty();
}
public static int countMatches(String str, String subStr) {
if (str == null || str.isEmpty() || subStr == null || subStr.isEmpty()) {
return 0;
}
int subStrLen = subStr.length();
int count = 0;
int idx = 0;
while ((idx = str.indexOf(subStr, idx)) != -1) {
count++;
idx += subStrLen;
}
return count;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册