Commit fc58022d authored by Skylot's avatar Skylot

misc: show shorter exception stacktrace in code

parent ed9fe8a5
...@@ -17,10 +17,12 @@ import org.jetbrains.annotations.Nullable; ...@@ -17,10 +17,12 @@ import org.jetbrains.annotations.Nullable;
import jadx.api.JadxDecompiler; import jadx.api.JadxDecompiler;
import jadx.core.codegen.CodeWriter; import jadx.core.codegen.CodeWriter;
import jadx.core.dex.visitors.DepthTraversal;
public class Utils { public class Utils {
public static final String JADX_API_PACKAGE = JadxDecompiler.class.getPackage().getName(); private static final String JADX_API_PACKAGE = JadxDecompiler.class.getPackage().getName();
private static final String STACKTRACE_STOP_CLS_NAME = DepthTraversal.class.getName();
private Utils() { private Utils() {
} }
...@@ -140,19 +142,15 @@ public class Utils { ...@@ -140,19 +142,15 @@ public class Utils {
private static void filter(Throwable th) { private static void filter(Throwable th) {
StackTraceElement[] stackTrace = th.getStackTrace(); StackTraceElement[] stackTrace = th.getStackTrace();
int cutIndex = -1;
int length = stackTrace.length; int length = stackTrace.length;
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
StackTraceElement stackTraceElement = stackTrace[i]; StackTraceElement stackTraceElement = stackTrace[i];
if (stackTraceElement.getClassName().startsWith(JADX_API_PACKAGE)) { String clsName = stackTraceElement.getClassName();
cutIndex = i; if (clsName.equals(STACKTRACE_STOP_CLS_NAME)
} else if (cutIndex > 0) { || clsName.startsWith(JADX_API_PACKAGE)) {
cutIndex = i; th.setStackTrace(Arrays.copyOfRange(stackTrace, 0, i));
break; return;
}
} }
if (cutIndex > 0 && cutIndex < length) {
th.setStackTrace(Arrays.copyOfRange(stackTrace, 0, cutIndex));
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment