/** * @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; }
/** * @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; }
/** * Assigns sequential ids to used mappings, and returns the last line mapped. */ private int prepMappings() throws IOException { // Mark any unused mappings. (new MappingTraversal()).traverse(new UsedMappingCheck()); // Renumber used mappings and keep track of the last line. int id = 0; int maxLine = 0; for (Mapping m : mappings) { if (m.used) { m.id = id++; int endPositionLine = m.endPosition.getLine(); maxLine = Math.max(maxLine, endPositionLine); } } // Adjust for the prefix. return maxLine + prefixPosition.getLine(); }
/** * @return The column adjusted for the prefix position. */ private int getAdjustedCol(FilePosition p) { int rawLine = p.getLine(); int rawCol = p.getColumn(); // Only the first line needs the character position adjusted. return (rawLine != 0) ? rawCol : rawCol + prefixPosition.getColumn(); }
/** * Assigns sequential ids to used mappings, and returns the last line mapped. */ private int prepMappings() throws IOException { // Mark any unused mappings. (new MappingTraversal()).traverse(new UsedMappingCheck()); // Renumber used mappings and keep track of the last line. int id = 0; int maxLine = 0; for (Mapping m : mappings) { if (m.used) { m.id = id++; int endPositionLine = m.endPosition.getLine(); maxLine = Math.max(maxLine, endPositionLine); } } // Adjust for the prefix. return maxLine + prefixPosition.getLine(); }
/** * @return The column adjusted for the prefix position. */ private int getAdjustedCol(FilePosition p) { int rawLine = p.getLine(); int rawCol = p.getColumn(); // Only the first line needs the character position adjusted. return (rawLine != 0) ? rawCol : rawCol + prefixPosition.getColumn(); }
@Override public void visit(String sourceName, String symbolName, FilePosition sourceStartPosition, FilePosition startPosition, FilePosition endPosition) { if(startPosition.getLine() >= lineToAdd) { startPosition = new FilePosition(startPosition.getLine() + 1, startPosition.getColumn()); endPosition = new FilePosition(endPosition.getLine() + 1, endPosition.getColumn()); } generator.addMapping(sourceName, symbolName, sourceStartPosition, startPosition, endPosition); index++; if(index == counter.count) { //add an extra mapping because there seems to be a bug in //SourceMapGeneratorV3's appendTo() that omits the last //entry, for some reason appendExtraMappingToGenerator(generator, sourceName, symbolName, sourceStartPosition, startPosition, endPosition); } } });
/** * Adjusts the line numbers saved in the source map when a line should be * removed during post processing. * * @param lineIndex */ protected void removeLineFromMappings(int lineIndex) { for (SourceMapMapping mapping : sourceMapMappings) { FilePosition destStartPosition = mapping.destStartPosition; int startLine = destStartPosition.getLine(); if(startLine > lineIndex) { mapping.destStartPosition = new FilePosition(startLine - 1, destStartPosition.getColumn()); FilePosition destEndPosition = mapping.destEndPosition; mapping.destEndPosition = new FilePosition(destEndPosition.getLine() - 1, destEndPosition.getColumn()); } } }
/** * Adjusts the line numbers saved in the source map when a line should be * removed during post processing. * * @param lineIndex */ protected void removeLineFromMappings(int lineIndex) { for (SourceMapMapping mapping : sourceMapMappings) { FilePosition destStartPosition = mapping.destStartPosition; int startLine = destStartPosition.getLine(); if(startLine > lineIndex) { mapping.destStartPosition = new FilePosition(startLine - 1, destStartPosition.getColumn()); FilePosition destEndPosition = mapping.destEndPosition; mapping.destEndPosition = new FilePosition(destEndPosition.getLine() - 1, destEndPosition.getColumn()); } } }
/** * Adjusts the line numbers saved in the source map when a line should be * added during post processing. * * @param lineIndex */ protected void addLineToMappings(int lineIndex) { for (SourceMapMapping mapping : sourceMapMappings) { FilePosition destStartPosition = mapping.destStartPosition; int startLine = destStartPosition.getLine(); if(startLine > lineIndex) { mapping.destStartPosition = new FilePosition(startLine + 1, destStartPosition.getColumn()); FilePosition destEndPosition = mapping.destEndPosition; mapping.destEndPosition = new FilePosition(destEndPosition.getLine() + 1, destEndPosition.getColumn()); } } }
/** * Adjusts the line numbers saved in the source map when a line should be * added during post processing. * * @param lineIndex */ protected void addLineToMappings(int lineIndex) { for (SourceMapMapping mapping : sourceMapMappings) { FilePosition destStartPosition = mapping.destStartPosition; int startLine = destStartPosition.getLine(); if(startLine > lineIndex) { mapping.destStartPosition = new FilePosition(startLine + 1, destStartPosition.getColumn()); FilePosition destEndPosition = mapping.destEndPosition; mapping.destEndPosition = new FilePosition(destEndPosition.getLine() + 1, destEndPosition.getColumn()); } } }
/** * Adjusts the line numbers saved in the source map when a line should be * added during post processing. * * @param lineIndex */ protected void addLineToMappings(int lineIndex) { for (SourceMapMapping mapping : sourceMapMappings) { FilePosition destStartPosition = mapping.destStartPosition; int startLine = destStartPosition.getLine(); if(startLine > lineIndex) { mapping.destStartPosition = new FilePosition(startLine + 1, destStartPosition.getColumn()); FilePosition destEndPosition = mapping.destEndPosition; mapping.destEndPosition = new FilePosition(destEndPosition.getLine() + 1, destEndPosition.getColumn()); } } }
/** * Adjusts the line numbers saved in the source map when a line should be * added during post processing. * * @param lineIndex */ protected void addLineToMappings(int lineIndex) { for (SourceMapMapping mapping : sourceMapMappings) { FilePosition destStartPosition = mapping.destStartPosition; int startLine = destStartPosition.getLine(); if(startLine > lineIndex) { mapping.destStartPosition = new FilePosition(startLine + 1, destStartPosition.getColumn()); FilePosition destEndPosition = mapping.destEndPosition; mapping.destEndPosition = new FilePosition(destEndPosition.getLine() + 1, destEndPosition.getColumn()); } } }
/** * Adjusts the line numbers saved in the source map when a line should be * removed during post processing. * * @param lineIndex */ protected void removeLineFromMappings(int lineIndex) { for (SourceMapMapping mapping : sourceMapMappings) { FilePosition destStartPosition = mapping.destStartPosition; int startLine = destStartPosition.getLine(); if(startLine > lineIndex) { mapping.destStartPosition = new FilePosition(startLine - 1, destStartPosition.getColumn()); FilePosition destEndPosition = mapping.destEndPosition; mapping.destEndPosition = new FilePosition(destEndPosition.getLine() - 1, destEndPosition.getColumn()); } } }
/** * Adjusts the line numbers saved in the source map when a line should be * removed during post processing. * * @param lineIndex */ protected void removeLineFromMappings(int lineIndex) { for (SourceMapMapping mapping : sourceMapMappings) { FilePosition destStartPosition = mapping.destStartPosition; int startLine = destStartPosition.getLine(); if(startLine > lineIndex) { mapping.destStartPosition = new FilePosition(startLine - 1, destStartPosition.getColumn()); FilePosition destEndPosition = mapping.destEndPosition; mapping.destEndPosition = new FilePosition(destEndPosition.getLine() - 1, destEndPosition.getColumn()); } } }
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); }
/** * Writes an entry for the given column (of the generated text) and * associated mapping. * The values are stored as relative to the last seen values for each * field and encoded as Base64VLQs. */ void writeEntry(Mapping m, int column) throws IOException { // The relative generated column number Base64VLQ.encode(out, column - previousColumn); previousColumn = column; if (m != null) { // The relative source file id int sourceId = getSourceId(m.sourceFile); Base64VLQ.encode(out, sourceId - previousSourceFileId); previousSourceFileId = sourceId; // The relative source file line and column int srcline = m.originalPosition.getLine(); int srcColumn = m.originalPosition.getColumn(); Base64VLQ.encode(out, srcline - previousSourceLine); previousSourceLine = srcline; Base64VLQ.encode(out, srcColumn - previousSourceColumn); previousSourceColumn = srcColumn; if (m.originalName != null) { // The relative id for the associated symbol name int nameId = getNameId(m.originalName); Base64VLQ.encode(out, (nameId - previousNameId)); previousNameId = nameId; } } }