package org.simantics.scl.compiler.internal.decompiler.impl; import java.io.IOException; import java.io.Writer; import org.simantics.scl.compiler.internal.decompilation.IDecompiler; import org.simantics.scl.compiler.runtime.MutableClassLoader; import com.strobel.assembler.metadata.Buffer; import com.strobel.assembler.metadata.ITypeLoader; import com.strobel.core.VerifyArgument; import com.strobel.decompiler.Decompiler; import com.strobel.decompiler.DecompilerSettings; import com.strobel.decompiler.PlainTextOutput; public class DecompilerImpl implements IDecompiler { @Override public void decompile(MutableClassLoader classLoader, String className, Writer output) { VerifyArgument.isNonNegative(3.0, "asd"); DecompilerSettings settings = DecompilerSettings.javaDefaults(); settings.setTypeLoader(new ITypeLoader() { @Override public boolean tryLoadType(String internalName, Buffer buffer) { byte[] bytes = classLoader.getBytes(internalName.replace('/', '.')); if(bytes == null) return false; buffer.reset(bytes.length); System.arraycopy(bytes, 0, buffer.array(), 0, bytes.length); return true; } }); Decompiler.decompile( className, new PlainTextOutput(output), settings); try { output.flush(); } catch (IOException e) { } } }