/** * Adds a mapping for the given node. Mappings must be added in order. * * @param startPosition The position on the starting line * @param endPosition The position on the ending line. */ @Override public void addMapping( String sourceName, @Nullable String symbolName, FilePosition sourceStartPosition, FilePosition startPosition, FilePosition endPosition) { // Don't bother if there is not sufficient information to be useful. if (sourceName == null || sourceStartPosition.getLine() < 0) { return; } FilePosition adjustedStart = startPosition; FilePosition adjustedEnd = endPosition; if (offsetPosition.getLine() != 0 || offsetPosition.getColumn() != 0) { // If the mapping is found on the first line, we need to offset // its character position by the number of characters found on // the *last* line of the source file to which the code is // being generated. int offsetLine = offsetPosition.getLine(); int startOffsetPosition = offsetPosition.getColumn(); int endOffsetPosition = offsetPosition.getColumn(); if (startPosition.getLine() > 0) { startOffsetPosition = 0; } if (endPosition.getLine() > 0) { endOffsetPosition = 0; } adjustedStart = new FilePosition( startPosition.getLine() + offsetLine, startPosition.getColumn() + startOffsetPosition); adjustedEnd = new FilePosition( endPosition.getLine() + offsetLine, endPosition.getColumn() + endOffsetPosition); } // Create the new mapping. Mapping mapping = new Mapping(); mapping.sourceFile = sourceName; mapping.originalPosition = sourceStartPosition; mapping.originalName = symbolName; mapping.startPosition = adjustedStart; mapping.endPosition = adjustedEnd; // Validate the mappings are in a proper order. if (lastMapping != null) { int lastLine = lastMapping.startPosition.getLine(); int lastColumn = lastMapping.startPosition.getColumn(); int nextLine = mapping.startPosition.getLine(); int nextColumn = mapping.startPosition.getColumn(); Preconditions.checkState( nextLine > lastLine || (nextLine == lastLine && nextColumn >= lastColumn), "Incorrect source mappings order, previous : (%s,%s)\n" + "new : (%s,%s)", lastLine, lastColumn, nextLine, nextColumn); } lastMapping = mapping; mappings.add(mapping); }