Add methods to submit class file directly as byte array

This commit is contained in:
Alexey Andreev 2015-10-29 16:13:47 +03:00
parent c7d640a2af
commit 6d45f57a39
2 changed files with 14 additions and 0 deletions

View File

@ -44,6 +44,10 @@ public class DependencyAgent implements DependencyInfo, ServiceRepository {
return checker.generateClassName();
}
public String submitClassFile(byte[] data) {
return checker.submitClassFile(data);
}
public void submitClass(ClassHolder cls) {
checker.submitClass(cls);
}

View File

@ -25,6 +25,7 @@ import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Set;
import org.objectweb.asm.tree.ClassNode;
import org.teavm.callgraph.CallGraph;
import org.teavm.callgraph.DefaultCallGraph;
import org.teavm.callgraph.DefaultCallGraphNode;
@ -52,6 +53,7 @@ import org.teavm.model.ValueType;
import org.teavm.model.util.ModelUtils;
import org.teavm.model.util.ProgramUtils;
import org.teavm.optimization.UnreachableBasicBlockEliminator;
import org.teavm.parsing.Parser;
/**
*
@ -157,6 +159,14 @@ public class DependencyChecker implements DependencyInfo {
return "$$teavm_generated_class$$" + classNameSuffix++;
}
public String submitClassFile(byte[] data) {
ClassNode node = new ClassNode();
org.objectweb.asm.ClassReader reader = new org.objectweb.asm.ClassReader(data);
reader.accept(node, 0);
submitClass(Parser.parseClass(node));
return node.name;
}
public void submitClass(ClassHolder cls) {
if (completing) {
throw new IllegalStateException("Can't submit class during completion phase");