예제 #1
0
 /** Creates an "OriginalMapping" object for the given entry object. */
 private OriginalMapping getOriginalMappingForEntry(Entry entry) {
   if (entry.getSourceFileId() == UNMAPPED) {
     return null;
   } else {
     // Adjust the line/column here to be start at 1.
     Builder x =
         OriginalMapping.newBuilder()
             .setOriginalFile(sources[entry.getSourceFileId()])
             .setLineNumber(entry.getSourceLine() + 1)
             .setColumnPosition(entry.getSourceColumn() + 1);
     if (entry.getNameId() != UNMAPPED) {
       x.setIdentifier(names[entry.getNameId()]);
     }
     return x.build();
   }
 }
예제 #2
0
  /**
   * Reverse the source map; the created mapping will allow us to quickly go from a source file and
   * line number to a collection of target OriginalMappings.
   */
  private void createReverseMapping() {
    reverseSourceMapping = new HashMap<String, Map<Integer, Collection<OriginalMapping>>>();

    for (int targetLine = 0; targetLine < lines.size(); targetLine++) {
      ArrayList<Entry> entries = lines.get(targetLine);

      if (entries != null) {
        for (Entry entry : entries) {
          if (entry.getSourceFileId() != UNMAPPED && entry.getSourceLine() != UNMAPPED) {
            String originalFile = sources[entry.getSourceFileId()];

            if (!reverseSourceMapping.containsKey(originalFile)) {
              reverseSourceMapping.put(
                  originalFile, new HashMap<Integer, Collection<OriginalMapping>>());
            }

            Map<Integer, Collection<OriginalMapping>> lineToCollectionMap =
                reverseSourceMapping.get(originalFile);

            int sourceLine = entry.getSourceLine();

            if (!lineToCollectionMap.containsKey(sourceLine)) {
              lineToCollectionMap.put(sourceLine, new ArrayList<OriginalMapping>(1));
            }

            Collection<OriginalMapping> mappings = lineToCollectionMap.get(sourceLine);

            Builder builder =
                OriginalMapping.newBuilder()
                    .setLineNumber(targetLine)
                    .setColumnPosition(entry.getGeneratedColumn());

            mappings.add(builder.build());
          }
        }
      }
    }
  }