package me.coley.recaf.cfr;

import java.util.Map;

import org.objectweb.asm.tree.ClassNode;

import me.coley.recaf.Recaf;

/**
 * Lookup helper for CFR since it requests extra data <i>(Other classes)</i> for more accurate decompilation. 
 */
public class CFRResourceLookup {
	private final Recaf program = Recaf.INSTANCE;
	private final ClassNode override;
	
	public CFRResourceLookup() {
		this(null);
	}

	public CFRResourceLookup(ClassNode override) {
		this.override = override;
	}

	public byte[] get(String path) {
		byte[] bytes = null;
		try {
			if (override != null && path.equals(override.name)) {
				bytes = program.asm.toBytes(override);
			} else {
				Map<String, ClassNode> classes = program.jarData.classes;
				if (classes.containsKey(path)) {
					bytes = program.asm.toBytes(classes.get(path));
				} else {
					ClassNode runtime = program.asm.getNode(Class.forName(path.replace("/", ".")));
					if (runtime != null) {
						bytes = program.asm.toBytes(runtime);
					}
				}
			}
		} catch (Exception e) {
			program.gui.displayError(e);
		}
		return bytes;
	}

}

@@ -201,16 +201,19 @@
 %3C/i%3E for
+%0A *
  more ac
@@ -233,17 +233,16 @@
 ilation.
- 
 %0A */%0Apub
@@ -353,17 +353,16 @@
 erride;%0A
-%09
 %0A%09public
@@ -999,16 +999,72 @@
 %09%7D%0A%09%09%09%7D%0A
+%09%09%7D catch (ClassNotFoundException e) %7B%0A%09%09%09// Do nothing%0A
 %09%09%7D catc

Fix #24