package me.coley.recaf.workspace;

import me.coley.recaf.parse.source.SourceCode;
import me.coley.recaf.parse.source.SourceCodeException;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.objectweb.asm.ClassReader;
import org.pmw.tinylog.Logger;

import java.io.*;
import java.util.*;

/**
 * Importable class resource.
 *
 * @author Matt
 */
public class ClassResource extends FileSystemResource {
	/**
	 * Constructs a class resource.
	 *
	 * @param file
	 * 		File reference to a class file.
	 */
	public ClassResource(File file) {
		super(ResourceKind.CLASS, file);
	}

	@Override
	protected Map<String, byte[]> loadClasses() throws IOException {
		try {
			// read & minimally parse for the name
			byte[] in = IOUtils.toByteArray(new FileInputStream(getFile()));
			String name = new ClassReader(in).getClassName();
			Map<String, byte[]> classes = new HashMap<>(1);
			classes.put(name, in);
			return classes;
		} catch(ArrayIndexOutOfBoundsException | IllegalArgumentException ex) {
			Logger.error("Invalid class \"{}\"", getFile().getName());
			return Collections.emptyMap();
		}
	}

	@Override
	protected Map<String, byte[]> loadResources() {
		return Collections.emptyMap();
	}

	@Override
	protected Map<String, SourceCode> loadSources(File file) throws IOException {
		try {
			SourceCode code = new SourceCode(this, FileUtils.readFileToString(file, "UTF-8"));
			code.analyze();
			return Collections.singletonMap(code.getInternalName(), code);
		} catch(IOException ex) {
			throw new IOException("Failed to read from source file: " + file, ex);
		} catch (SourceCodeException ex) {
			throw new IOException("Invalid source code file: " + file, ex);
		}
	}
}

@@ -861,99 +861,49 @@
 %0A%09%09%09
-Map%3CString, byte%5B%5D%3E classes = new HashMap%3C%3E(1);%0A%09%09%09classes.put(name, in);%0A%09%09%09return classes
+return Collections.singletonMap(name, in)
 ;%0A%09%09

Use Collections.singletonMap