Search in sources :

Example 1 with SourceMapParseException

use of com.google.debugging.sourcemap.SourceMapParseException in project closure-compiler by google.

the class SourceMapInput method getSourceMap.

/**
 * Gets the source map, reading from disk and parsing if necessary. Returns null if the sourcemap
 * cannot be resolved or is malformed.
 */
@Nullable
public synchronized SourceMapConsumerV3 getSourceMap(ErrorManager errorManager) {
    if (!cached) {
        // Avoid re-reading or reparsing files.
        cached = true;
        String sourceMapPath = sourceFile.getOriginalPath();
        try {
            String sourceMapContents = sourceFile.getCode();
            SourceMapConsumerV3 consumer = new SourceMapConsumerV3();
            consumer.parse(sourceMapContents);
            parsedSourceMap = consumer;
        } catch (IOException e) {
            JSError error = JSError.make(SourceMapInput.SOURCEMAP_RESOLVE_FAILED, sourceMapPath, e.getMessage());
            errorManager.report(error.getDefaultLevel(), error);
        } catch (SourceMapParseException e) {
            JSError error = JSError.make(SourceMapInput.SOURCEMAP_PARSE_FAILED, sourceMapPath, e.getMessage());
            errorManager.report(error.getDefaultLevel(), error);
        }
    }
    return parsedSourceMap;
}
Also used : SourceMapParseException(com.google.debugging.sourcemap.SourceMapParseException) SourceMapConsumerV3(com.google.debugging.sourcemap.SourceMapConsumerV3) IOException(java.io.IOException) Nullable(javax.annotation.Nullable)

Example 2 with SourceMapParseException

use of com.google.debugging.sourcemap.SourceMapParseException 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)2 IOException (java.io.IOException)2 SourceMapConsumerV3 (com.google.debugging.sourcemap.SourceMapConsumerV3)1 SourceMapping (com.google.debugging.sourcemap.SourceMapping)1 URL (java.net.URL)1 Nullable (javax.annotation.Nullable)1 STJSRuntimeException (org.stjs.generator.STJSRuntimeException)1