/** * Merges current mapping with {@code mapSectionContents} considering the offset {@code (line, * column)}. Any extension in the map section will be ignored. * * @param line The line offset * @param column The column offset * @param mapSectionContents The map section to be appended * @throws SourceMapParseException */ public void mergeMapSection(int line, int column, String mapSectionContents) throws SourceMapParseException { setStartingPosition(line, column); SourceMapConsumerV3 section = new SourceMapConsumerV3(); section.parse(mapSectionContents); section.visitMappings(new ConsumerEntryVisitor()); }
/** * Works like {@link #mergeMapSection(int, int, String)}, except that extensions from the @{code * mapSectionContents} are merged to the top level source map. For conflicts a {@code mergeAction} * is performed. * * @param line The line offset * @param column The column offset * @param mapSectionContents The map section to be appended * @param mergeAction The merge action for conflicting extensions * @throws SourceMapParseException */ public void mergeMapSection( int line, int column, String mapSectionContents, ExtensionMergeAction mergeAction) throws SourceMapParseException { setStartingPosition(line, column); SourceMapConsumerV3 section = new SourceMapConsumerV3(); section.parse(mapSectionContents); section.visitMappings(new ConsumerEntryVisitor()); for (Entry<String, Object> entry : section.getExtensions().entrySet()) { String extensionKey = entry.getKey(); if (extensions.containsKey(extensionKey)) { extensions.put( extensionKey, mergeAction.merge(extensionKey, extensions.get(extensionKey), entry.getValue())); } else { extensions.put(extensionKey, entry.getValue()); } } }