core: show missing class references only once

This commit is contained in:
Skylot
2016-01-31 15:20:07 +03:00
parent bc9164b952
commit e915f4fcd7
3 changed files with 21 additions and 7 deletions
@@ -248,6 +248,7 @@ public final class JadxDecompiler {
if (root == null) {
return;
}
root.getClsp().printMissingClasses();
root.getErrorsCounter().printReport();
}
@@ -5,6 +5,7 @@ import jadx.core.utils.exceptions.DecodeException;
import jadx.core.utils.exceptions.JadxRuntimeException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
@@ -25,6 +26,8 @@ public class ClspGraph {
private final Map<String, Set<String>> ancestorCache = new WeakHashMap<String, Set<String>>();
private Map<String, NClass> nameMap;
private final Set<String> missingClasses = new HashSet<String>();
public void load() throws IOException, DecodeException {
ClsSet set = new ClsSet();
set.load();
@@ -73,7 +76,7 @@ public class ClspGraph {
}
NClass cls = nameMap.get(implClsName);
if (cls == null) {
LOG.debug("Missing class: {}", implClsName);
missingClasses.add(clsName);
return null;
}
if (isImplements(clsName, implClsName)) {
@@ -104,7 +107,7 @@ public class ClspGraph {
}
NClass cls = nameMap.get(clsName);
if (cls == null) {
LOG.debug("Missing class: {}", clsName);
missingClasses.add(clsName);
return Collections.emptySet();
}
result = new HashSet<String>();
@@ -122,4 +125,19 @@ public class ClspGraph {
addAncestorsNames(p, result);
}
}
public void printMissingClasses() {
int count = missingClasses.size();
if (count == 0) {
return;
}
LOG.warn("Found {} references to unknown classes", count);
if (LOG.isDebugEnabled()) {
List<String> clsNames = new ArrayList<String>(missingClasses);
Collections.sort(clsNames);
for (String cls : clsNames) {
LOG.debug(" {}", cls);
}
}
}
}
@@ -27,11 +27,6 @@ public class ErrorsCounter {
return errorsCount;
}
public void reset() {
errorNodes.clear();
errorsCount = 0;
}
private void addError(IAttributeNode node, String msg, Throwable e) {
errorNodes.add(node);
errorsCount++;