Search in sources :

Example 1 with Builder

use of com.google.debugging.sourcemap.proto.Mapping.OriginalMapping.Builder in project closure-compiler by google.

the class SourceMapConsumerV3 method createReverseMapping.

/**
 * 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<>();
    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());
                }
            }
        }
    }
}
Also used : OriginalMapping(com.google.debugging.sourcemap.proto.Mapping.OriginalMapping) Builder(com.google.debugging.sourcemap.proto.Mapping.OriginalMapping.Builder) Collection(java.util.Collection)

Aggregations

OriginalMapping (com.google.debugging.sourcemap.proto.Mapping.OriginalMapping)1 Builder (com.google.debugging.sourcemap.proto.Mapping.OriginalMapping.Builder)1 Collection (java.util.Collection)1