Commit ab7b6fc2 authored by Skylot's avatar Skylot

refactor: don't use additional class for jadx warnings

parent 41973651
......@@ -18,7 +18,6 @@ import jadx.core.dex.attributes.AttrNode;
import jadx.core.dex.attributes.nodes.EnumClassAttr;
import jadx.core.dex.attributes.nodes.EnumClassAttr.EnumField;
import jadx.core.dex.attributes.nodes.JadxError;
import jadx.core.dex.attributes.nodes.JadxWarn;
import jadx.core.dex.attributes.nodes.LineAttrNode;
import jadx.core.dex.attributes.nodes.SourceFileAttr;
import jadx.core.dex.info.AccessInfo;
......@@ -327,7 +326,6 @@ public class ClassGen {
private void insertDecompilationProblems(CodeWriter code, AttrNode node) {
List<JadxError> errors = node.getAll(AType.JADX_ERROR);
List<JadxWarn> warns = node.getAll(AType.JADX_WARN);
if (!errors.isEmpty()) {
errors.forEach(err -> {
code.startLine("/* JADX ERROR: ").add(err.getError());
......@@ -340,8 +338,10 @@ public class ClassGen {
code.add("*/");
});
}
List<String> warns = node.getAll(AType.JADX_WARN);
if (!warns.isEmpty()) {
warns.forEach(warn -> code.startLine("/* JADX WARNING: ").addMultiLine(warn.getWarn()).add(" */"));
warns.stream().distinct()
.forEach(warn -> code.startLine("/* JADX WARNING: ").addMultiLine(warn).add(" */"));
}
}
......
......@@ -10,7 +10,6 @@ import jadx.core.dex.attributes.nodes.FieldReplaceAttr;
import jadx.core.dex.attributes.nodes.ForceReturnAttr;
import jadx.core.dex.attributes.nodes.IgnoreEdgeAttr;
import jadx.core.dex.attributes.nodes.JadxError;
import jadx.core.dex.attributes.nodes.JadxWarn;
import jadx.core.dex.attributes.nodes.JumpInfo;
import jadx.core.dex.attributes.nodes.LocalVarsDebugInfoAttr;
import jadx.core.dex.attributes.nodes.LoopInfo;
......@@ -37,7 +36,7 @@ public class AType<T extends IAttribute> {
public static final AType<AttrList<EdgeInsnAttr>> EDGE_INSN = new AType<>();
public static final AType<AttrList<JadxError>> JADX_ERROR = new AType<>(); // code failed to decompile completely
public static final AType<AttrList<JadxWarn>> JADX_WARN = new AType<>(); // mark code as inconsistent (code can be viewed)
public static final AType<AttrList<String>> JADX_WARN = new AType<>(); // mark code as inconsistent (code can be viewed)
public static final AType<AttrList<String>> COMMENTS = new AType<>(); // any additional info about decompilation
public static final AType<ExcHandlerAttr> EXC_HANDLER = new AType<>();
......
package jadx.core.dex.attributes.nodes;
import java.util.Objects;
public class JadxWarn {
private final String warn;
public JadxWarn(String warn) {
this.warn = Objects.requireNonNull(warn);
}
public String getWarn() {
return warn;
}
@Override
public String toString() {
return "JadxWarn: " + warn;
}
}
package jadx.core.utils;
import java.util.List;
import jadx.core.codegen.CodeWriter;
import jadx.core.dex.attributes.AType;
import jadx.core.dex.attributes.AttrNode;
......@@ -7,8 +9,10 @@ import jadx.core.dex.attributes.AttrNode;
public class CodegenUtils {
public static void addComments(CodeWriter code, AttrNode node) {
for (String comment : node.getAll(AType.COMMENTS)) {
code.startLine("/* ").addMultiLine(comment).add(" */");
List<String> comments = node.getAll(AType.COMMENTS);
if (!comments.isEmpty()) {
comments.stream().distinct()
.forEach(comment -> code.startLine("/* ").addMultiLine(comment).add(" */"));
}
}
}
......@@ -14,7 +14,6 @@ import jadx.core.dex.attributes.AFlag;
import jadx.core.dex.attributes.AType;
import jadx.core.dex.attributes.IAttributeNode;
import jadx.core.dex.attributes.nodes.JadxError;
import jadx.core.dex.attributes.nodes.JadxWarn;
import jadx.core.dex.nodes.ClassNode;
import jadx.core.dex.nodes.IDexNode;
import jadx.core.dex.nodes.MethodNode;
......@@ -60,7 +59,7 @@ public class ErrorsCounter {
warnNodes.add(node);
warnsCount++;
node.addAttr(AType.JADX_WARN, new JadxWarn(warn));
node.addAttr(AType.JADX_WARN, warn);
if (!node.contains(AType.JADX_ERROR)) {
node.add(AFlag.INCONSISTENT_CODE);
}
......
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