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(); } }
public void reset() { generator.reset(); sourceLocationFixupCache.clear(); }
public void setStartingPosition(int offsetLine, int offsetIndex) { generator.setStartingPosition(offsetLine, offsetIndex); }
/** * Appends the generated source map to {@code out}. * * @param out an {@link Appendable} object to append the output on * @param name filename to be written inside the source map (not the filename where writes to) * * @see SourceMapGeneratorV3#appendTo */ @Override public void appendOutputTo(Appendable out, String name) throws IOException { generateSourceMap(); generator.appendTo(out, name); }
/** * Generates the source map by passing all mappings to {@link #generator}. */ private void generateSourceMap() { List<CompleteMapping> completeMappings = new ArrayList<>(allMappings.size()); for (Mapping mapping : allMappings) { // If the node does not have an associated source file or source location // is unknown, then the node does not have sufficient info for source map. if (mapping.node.getSourceCodeLocation().isUnknown()) { continue; } CompleteMapping completeMapping = new CompleteMapping(mapping); if (completeMapping.sourceFile == null) { continue; } completeMappings.add(completeMapping); } Collections.sort(completeMappings); for (CompleteMapping completeMapping : completeMappings) { // TODO: could pass in an optional symbol name generator.addMapping( completeMapping.sourceFile, null, completeMapping.inputStart, completeMapping.outputStart, completeMapping.outputEnd); } }
public void setWrapperPrefix(String prefix) { generator.setWrapperPrefix(prefix); }
public void validate(boolean validate) { generator.validate(validate); }
public void addSourceFile(String name, String code) { generator.addSourcesContent(fixupSourceLocation(name), code); }
public void appendTo(Appendable out, String name) throws IOException { generator.appendTo(out, fixupSourceLocation(name)); }
public void addMapping( Node node, FilePosition outputStartPosition, FilePosition outputEndPosition) { String sourceFile = node.getSourceFileName(); // If the node does not have an associated source file or // its line number is -1, then the node does not have sufficient // information for a mapping to be useful. if (sourceFile == null || node.getLineno() < 0) { return; } sourceFile = fixupSourceLocation(sourceFile); String originalName = node.getOriginalName(); // Rhino source lines are one based but for v3 source maps, we make // them zero based. int lineBaseOffset = 1; generator.addMapping( sourceFile, originalName, new FilePosition(node.getLineno() - lineBaseOffset, node.getCharno()), outputStartPosition, outputEndPosition); }
public void setWrapperPrefix(String prefix) { generator.setWrapperPrefix(prefix); }
public void validate(boolean validate) { generator.validate(validate); }
public void appendTo(Appendable out, String name) throws IOException { generator.appendTo(out, fixupSourceLocation(name)); }
generator.addMapping( sourceFile, originalName, new FilePosition(lineNo - lineBaseOffset, charNo),
public void reset() { generator.reset(); sourceLocationFixupCache.clear(); }
public void setStartingPosition(int offsetLine, int offsetIndex) { generator.setStartingPosition(offsetLine, offsetIndex); }