core: fix line number references
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user