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;
}
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);
}
}
Aggregations