Search in sources :

Example 1 with SourceMapping

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);
    }
}
Also used : STJSRuntimeException(org.stjs.generator.STJSRuntimeException) SourceMapParseException(com.google.debugging.sourcemap.SourceMapParseException) IOException(java.io.IOException) SourceMapping(com.google.debugging.sourcemap.SourceMapping) URL(java.net.URL)

Aggregations

SourceMapParseException (com.google.debugging.sourcemap.SourceMapParseException)1 SourceMapping (com.google.debugging.sourcemap.SourceMapping)1 IOException (java.io.IOException)1 URL (java.net.URL)1 STJSRuntimeException (org.stjs.generator.STJSRuntimeException)1