private void generateTypeScriptSourceMapFile(SourceFile sourceFile) throws IOException { if (sourceFile.getSourceMap() == null) { return; } SourceMapGenerator generator = SourceMapGeneratorFactory.getInstance(SourceMapFormat.V3); String javaSourceFilePath = sourceFile.getTsFile().getAbsoluteFile().getCanonicalFile().getParentFile().toPath() .relativize(sourceFile.getJavaFile().getAbsoluteFile().getCanonicalFile().toPath()).toString(); for (Entry entry : sourceFile.getSourceMap().getSortedEntries(new Comparator<SourceMap.Entry>() { @Override public int compare(Entry e1, Entry e2) { return e1.getOutputPosition().compareTo(e2.getOutputPosition()); } })) { generator.addMapping(javaSourceFilePath, null, new FilePosition(entry.getInputPosition().getLine(), entry.getInputPosition().getColumn()), new FilePosition(entry.getOutputPosition().getLine(), entry.getOutputPosition().getColumn()), new FilePosition(entry.getOutputPosition().getLine(), entry.getOutputPosition().getColumn() + 1)); } File outputFile = new File(sourceFile.getTsFile().getPath() + ".map"); try (FileWriter writer = new FileWriter(outputFile, false)) { generator.appendTo(writer, sourceFile.getTsFile().getName()); } catch (Exception ex) { ex.printStackTrace(); } }
.getInstance(SourceMapFormat.V3); Path javaSourcePath = sourceFile.javaSourceDir.getCanonicalFile().toPath(); String sourceRoot = getSourceRoot() != null ? getSourceRoot().toString() : sourceFile.getJsFile().getParentFile().getCanonicalFile().toPath() .relativize(javaSourcePath) + "/"; generator.setSourceRoot(sourceRoot); SourceMapping mapping = SourceMapConsumerFactory.parse(contents); OriginalMapping originalMapping = mapping.getMappingForLine(line, columnIndex + 1); if (originalMapping != null) { sourceFile.tsFile, null, new Position(originalMapping.getLineNumber(), originalMapping.getColumnPosition())), files); if (originPosition != null) { generator.addMapping( javaSourcePath .relativize( originPosition.getFile().getCanonicalFile().toPath()) .toString(), null, new FilePosition(originPosition.getStartLine() - 1, 0), new FilePosition(line - 1, 0), new FilePosition(line - 1, lineContent.length() - 1)); generator.appendTo(writer, outputFile.getName()); } catch (Exception ex) { ex.printStackTrace();
void appendLineMappings() throws IOException { // Start the first line. openLine(true); (new MappingTraversal()).traverse(this); // And close the final line. closeLine(true); }
private void appendExtraMappingToGenerator(SourceMapGeneratorV3 generator, String sourceName, String symbolName, FilePosition sourceStartPosition, FilePosition startPosition, FilePosition endPosition) { //add an extra mapping because there seems to be a bug in //SourceMapGeneratorV3's appendTo() that omits the last //entry, for some reason FilePosition newEndPosition = new FilePosition(endPosition.getLine(), endPosition.getColumn() + 1); generator.addMapping(sourceName, null, sourceStartPosition, endPosition, newEndPosition); }
/** * @return Whether m1 ends before m2 starts. */ private boolean isOverlapped(Mapping m1, Mapping m2) { // No need to use adjusted values here, relative positions are sufficient. int l1 = m1.endPosition.getLine(); int l2 = m2.startPosition.getLine(); int c1 = m1.endPosition.getColumn(); int c2 = m2.startPosition.getColumn(); return (l1 == l2 && c1 >= c2) || l1 > l2; }
/** * Sets the prefix to be added to the beginning of each source path passed to * {@link #addMapping} as debuggers expect (prefix + sourceName) to be a URL * for loading the source code. * * @param path The URL prefix to save in the sourcemap file */ @Override public void setSourceRoot(String path){ ((SourceMapGeneratorV3) generator).setSourceRoot(path); }
/** * Writes the source name map to 'out'. */ private void addSourceNameMap(Appendable out) throws IOException { addNameMap(out, sourceFileMap); }
/** * @param contents The string representing the source map file contents. * @return The parsed source map. * @throws SourceMapParseException */ public static SourceMapping parse(String contents) throws SourceMapParseException { return parse(contents, null); }
/** * Escapes the given string to a double quoted (") JavaScript/JSON string */ static String escapeString(String s) { return escapeString(s, '"', "\\\"", "\'", "\\\\"); }
/** * @return Whether m1 ends before m2 starts. */ private boolean isOverlapped(Mapping m1, Mapping m2) { // No need to use adjusted values here, relative positions are sufficient. int l1 = m1.endPosition.getLine(); int l2 = m2.startPosition.getLine(); int c1 = m1.endPosition.getColumn(); int c2 = m2.startPosition.getColumn(); return (l1 == l2 && c1 >= c2) || l1 > l2; }
void appendLineMappings() throws IOException { // Start the first line. openLine(true); (new MappingTraversal()).traverse(this); // And close the final line. closeLine(true); }
/** * Writes the source name map to 'out'. */ private void addSymbolNameMap(Appendable out) throws IOException { addNameMap(out, originalNameMap); }
/** * Escapes the given string for JSON. */ private static String escapeString(String value) { return Util.escapeString(value); }
/** * Writes the source name map to 'out'. */ private void addSymbolNameMap(Appendable out) throws IOException { addNameMap(out, originalNameMap); }
/** * Writes the source name map to 'out'. */ private void addSourceNameMap(Appendable out) throws IOException { addNameMap(out, sourceFileMap); }