use of com.google.debugging.sourcemap.SourceMapping in project st-js by st-js.
the class JavascriptToJava method getJavaLine.
/**
* <p>getJavaLine.</p>
*
* @param path a {@link java.lang.String} object.
* @param lineNumber a int.
* @return a int.
*/
public int getJavaLine(String path, int lineNumber) {
String sourceMapFile = path.replaceAll("\\.js$", ".map");
URL url = classLoader.getResource(sourceMapFile.substring(1));
if (url == null) {
return lineNumber;
}
String contents;
try {
contents = Resources.toString(url, Charsets.UTF_8);
SourceMapping mapping = SourceMapConsumerFactory.parse(contents);
return mapping.getMappingForLine(lineNumber, 1).getLineNumber();
} catch (IOException e) {
throw new STJSRuntimeException(e);
} catch (SourceMapParseException e) {
throw new STJSRuntimeException(e);
}
}
Aggregations