Class.getResourceAsStream can find the generated resource

This commit is contained in:
Jaroslav Tulach 2015-12-24 07:53:36 +01:00
parent d9ee68315e
commit ecfdcd34c3

View File

@ -22,6 +22,7 @@ import java.util.Map;
import org.teavm.classlib.impl.DeclaringClassMetadataGenerator; import org.teavm.classlib.impl.DeclaringClassMetadataGenerator;
import org.teavm.classlib.java.lang.annotation.TAnnotation; import org.teavm.classlib.java.lang.annotation.TAnnotation;
import org.teavm.classlib.java.lang.reflect.TAnnotatedElement; import org.teavm.classlib.java.lang.reflect.TAnnotatedElement;
import org.teavm.jso.JSBody;
import org.teavm.platform.Platform; import org.teavm.platform.Platform;
import org.teavm.platform.PlatformClass; import org.teavm.platform.PlatformClass;
import org.teavm.platform.metadata.ClassResource; import org.teavm.platform.metadata.ClassResource;
@ -268,7 +269,22 @@ public class TClass<T> extends TObject implements TAnnotatedElement {
} }
} }
@JSBody(params = "res", script =
"if (!window.teaVMResources) return null;\n"
+ "var data = window.teaVMResources[res];\n"
+ "return data ? data : null;\n"
)
private static native String readResource(String message);
public InputStream getResourceAsStream(String name) { public InputStream getResourceAsStream(String name) {
throw new IllegalStateException("Cannot read resource " + name); TString clazzName = getName();
int lastDot = clazzName.lastIndexOf('.');
String resName;
if (lastDot == -1) {
resName = name;
} else {
resName = clazzName.substring(0, lastDot).replace('.', '/') + "/" + name;
}
throw new IllegalStateException("Read resource " + resName + " yields " + readResource(resName));
} }
} }