Skip to content

Commit

Permalink
gui: fix class members expand
Browse files Browse the repository at this point in the history
  • Loading branch information
skylot committed Mar 25, 2014
1 parent d0aa191 commit 18a1788
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 19 deletions.
41 changes: 30 additions & 11 deletions jadx-core/src/main/java/jadx/api/Decompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public final class Decompiler {

private RootNode root;
private List<IDexTreeVisitor> passes;
private List<JavaClass> classes;

public Decompiler() {
this.args = new DefaultJadxArgs();
Expand Down Expand Up @@ -95,6 +96,7 @@ public void loadFiles(List<File> files) throws IOException, DecodeException {
public void save() {
try {
ExecutorService ex = getSaveExecutor();
ex.shutdown();
ex.awaitTermination(1, TimeUnit.DAYS);
} catch (InterruptedException e) {
LOG.error("Save interrupted", e);
Expand Down Expand Up @@ -122,23 +124,24 @@ public void run() {
}
});
}
executor.shutdown();
return executor;
}

public List<JavaClass> getClasses() {
List<ClassNode> classNodeList = root.getClasses(false);
List<JavaClass> classes = new ArrayList<JavaClass>(classNodeList.size());
for (ClassNode classNode : classNodeList) {
classes.add(new JavaClass(this, classNode));
if (classes == null) {
List<ClassNode> classNodeList = root.getClasses(false);
List<JavaClass> clsList = new ArrayList<JavaClass>(classNodeList.size());
for (ClassNode classNode : classNodeList) {
clsList.add(new JavaClass(this, classNode));
}
classes = Collections.unmodifiableList(clsList);
}
return Collections.unmodifiableList(classes);
return classes;
}

public List<JavaPackage> getPackages() {
List<JavaClass> classes = getClasses();
Map<String, List<JavaClass>> map = new HashMap<String, List<JavaClass>>();
for (JavaClass javaClass : classes) {
for (JavaClass javaClass : getClasses()) {
String pkg = javaClass.getPackage();
List<JavaClass> clsList = map.get(pkg);
if (clsList == null) {
Expand Down Expand Up @@ -168,14 +171,18 @@ public int getErrorsCount() {
}

void parse() throws DecodeException {
ClassInfo.clearCache();
ErrorsCounter.reset();

reset();
root = new RootNode();
LOG.info("loading ...");
root.load(inputFiles);
}

private void reset() {
ClassInfo.clearCache();
ErrorsCounter.reset();
classes = null;
}

void processClass(ClassNode cls) {
LOG.info("processing class {} ...", cls);
ProcessClass.process(cls, passes);
Expand All @@ -184,4 +191,16 @@ void processClass(ClassNode cls) {
RootNode getRoot() {
return root;
}

JavaClass findJavaClass(ClassNode cls) {
if (cls == null) {
return null;
}
for (JavaClass javaClass : getClasses()) {
if (javaClass.getClassNode().equals(cls)) {
return javaClass;
}
}
return null;
}
}
22 changes: 15 additions & 7 deletions jadx-core/src/main/java/jadx/api/JavaClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ public void decompile() {
}
}

ClassNode getClassNode() {
return cls;
}

private void load() {
int inClsCount = cls.getInnerClasses().size();
if (inClsCount != 0) {
Expand Down Expand Up @@ -92,7 +96,7 @@ public int compare(JavaMethod o1, JavaMethod o2) {
}

private Map<CodePosition, Object> getCodeAnnotations() {
getCode();
decompile();
return cls.getCode().getAnnotations();
}

Expand All @@ -108,13 +112,17 @@ public CodePosition getDefinitionPosition(int line, int offset) {
} else if (obj instanceof FieldNode) {
clsNode = ((FieldNode) obj).getParentClass();
}
if (clsNode != null) {
clsNode = clsNode.getParentClass();
JavaClass jCls = new JavaClass(decompiler, clsNode);
jCls.decompile();
int defLine = ((LineAttrNode) obj).getDecompiledLine();
return new CodePosition(jCls, defLine, 0);
if (clsNode == null) {
return null;
}
clsNode = clsNode.getParentClass();
JavaClass jCls = decompiler.findJavaClass(clsNode);
if (jCls == null) {
return null;
}
jCls.decompile();
int defLine = ((LineAttrNode) obj).getDecompiledLine();
return new CodePosition(jCls, defLine, 0);
}
return null;
}
Expand Down
1 change: 1 addition & 0 deletions jadx-gui/src/main/java/jadx/gui/JadxWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public void run() {
try {
decompiler.setOutputDir(dir);
ThreadPoolExecutor ex = decompiler.getSaveExecutor();
ex.shutdown();
while (ex.isTerminating()) {
long total = ex.getTaskCount();
long done = ex.getCompletedTaskCount();
Expand Down
2 changes: 1 addition & 1 deletion jadx-gui/src/main/java/jadx/gui/treemodel/JClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public synchronized void load() {
if (!loaded) {
cls.decompile();
loaded = true;
update();
}
update();
}

public synchronized void update() {
Expand Down

0 comments on commit 18a1788

Please sign in to comment.