@GwtIncompatible(value="com.google.gson") public final class SourceMapGeneratorV3 extends java.lang.Object implements SourceMapGenerator
Modifier and Type | Class and Description |
---|---|
(package private) class |
SourceMapGeneratorV3.ConsumerEntryVisitor |
static interface |
SourceMapGeneratorV3.ExtensionMergeAction
This interface provides the merging strategy when an extension conflict
appears because of merging two source maps on method
mergeMapSection(int, int, java.lang.String) . |
private class |
SourceMapGeneratorV3.LineMapper |
(package private) static class |
SourceMapGeneratorV3.Mapping
A mapping from a given position in an input source file to a given position
in the generated code.
|
private class |
SourceMapGeneratorV3.MappingTraversal
Walk the mappings and visit each segment of the mappings, unmapped
segments are visited with a null mapping, unused mapping are not visited.
|
private static interface |
SourceMapGeneratorV3.MappingVisitor |
private class |
SourceMapGeneratorV3.UsedMappingCheck
Mark any visited mapping as "used".
|
Modifier and Type | Field and Description |
---|---|
private java.util.LinkedHashMap<java.lang.String,java.lang.Object> |
extensions
A list of extensions to be added to sourcemap.
|
private SourceMapGeneratorV3.Mapping |
lastMapping
For validation store the last mapping added.
|
private java.lang.String |
lastSourceFile
Cache of the last mappings source name.
|
private int |
lastSourceFileIndex
Cache of the last mappings source name index.
|
private java.util.List<SourceMapGeneratorV3.Mapping> |
mappings
A pre-order traversal ordered list of mappings stored in this map.
|
private FilePosition |
offsetPosition
The position that the current source map is offset in the
buffer being used to generated the compiled source file.
|
private java.util.LinkedHashMap<java.lang.String,java.lang.Integer> |
originalNameMap
A map of source names to source name index
|
private FilePosition |
prefixPosition
The position that the current source map is offset in the
generated the compiled source file by the addition of a
an output wrapper prefix.
|
private java.util.LinkedHashMap<java.lang.String,java.lang.Integer> |
sourceFileMap
A map of source names to source name index
|
private java.lang.String |
sourceRootPath
The source root path for relocating source fails or avoid duplicate values
on the source entry.
|
private static int |
UNMAPPED |
Constructor and Description |
---|
SourceMapGeneratorV3() |
Modifier and Type | Method and Description |
---|---|
void |
addExtension(java.lang.String name,
java.lang.Object object)
Adds field extensions to the json source map.
|
void |
addMapping(java.lang.String sourceName,
java.lang.String symbolName,
FilePosition sourceStartPosition,
FilePosition startPosition,
FilePosition endPosition)
Adds a mapping for the given node.
|
private static void |
addNameMap(java.lang.Appendable out,
java.util.Map<java.lang.String,java.lang.Integer> map) |
private void |
addSourceNameMap(java.lang.Appendable out)
Writes the source name map to 'out'.
|
private void |
addSymbolNameMap(java.lang.Appendable out)
Writes the source name map to 'out'.
|
private static void |
appendField(java.lang.Appendable out,
java.lang.String name,
java.lang.CharSequence value) |
private static void |
appendFieldEnd(java.lang.Appendable out) |
private static void |
appendFieldStart(java.lang.Appendable out,
java.lang.String name) |
private static void |
appendFirstField(java.lang.Appendable out,
java.lang.String name,
java.lang.CharSequence value) |
void |
appendIndexMapTo(java.lang.Appendable out,
java.lang.String name,
java.util.List<SourceMapSection> sections)
Appends the index source map to the given buffer.
|
void |
appendTo(java.lang.Appendable out,
java.lang.String name)
Writes out the source map in the following format (line numbers are for
reference only and are not part of the format):
1.
|
private static java.lang.String |
escapeString(java.lang.String value)
Escapes the given string for JSON.
|
java.lang.Object |
getExtension(java.lang.String name)
Returns the value mapped by the specified extension
or
null if this extension does not exist. |
private int |
getNameId(java.lang.String symbolName) |
private int |
getSourceId(java.lang.String sourceName) |
boolean |
hasExtension(java.lang.String name)
Check whether or not the sourcemap has an extension.
|
void |
mergeMapSection(int line,
int column,
java.lang.String mapSectionContents)
Merges current mapping with
mapSectionContents considering the
offset (line, column) . |
void |
mergeMapSection(int line,
int column,
java.lang.String mapSectionContents,
SourceMapGeneratorV3.ExtensionMergeAction mergeAction)
Works like
mergeMapSection(int, int, String) , except that
extensions from the @{code mapSectionContents} are merged to the top level
source map. |
private static java.lang.CharSequence |
offsetValue(int line,
int column) |
private int |
prepMappings()
Assigns sequential ids to used mappings, and returns the last line mapped.
|
void |
removeExtension(java.lang.String name)
Removes an extension by name if present.
|
void |
reset()
Resets the source map for reuse.
|
void |
setSourceRoot(java.lang.String path)
A prefix to be added to the beginning of each sourceName passed to
addMapping(java.lang.String, java.lang.String, com.google.debugging.sourcemap.FilePosition, com.google.debugging.sourcemap.FilePosition, com.google.debugging.sourcemap.FilePosition) . |
void |
setStartingPosition(int offsetLine,
int offsetIndex)
Sets the source code that exists in the buffer for which the
generated code is being generated.
|
void |
setWrapperPrefix(java.lang.String prefix)
Sets the prefix used for wrapping the generated source file before
it is written.
|
void |
validate(boolean validate)
Whether to perform additional validation on the source map.
|
private static final int UNMAPPED
private java.util.List<SourceMapGeneratorV3.Mapping> mappings
private java.util.LinkedHashMap<java.lang.String,java.lang.Integer> sourceFileMap
private java.util.LinkedHashMap<java.lang.String,java.lang.Integer> originalNameMap
private java.lang.String lastSourceFile
private int lastSourceFileIndex
private SourceMapGeneratorV3.Mapping lastMapping
private FilePosition offsetPosition
private FilePosition prefixPosition
private java.util.LinkedHashMap<java.lang.String,java.lang.Object> extensions
private java.lang.String sourceRootPath
public void reset()
reset
in interface SourceMapGenerator
public void validate(boolean validate)
SourceMapGenerator
validate
in interface SourceMapGenerator
validate
- Whether to perform (potentially costly) validation on the
generated source map.public void setWrapperPrefix(java.lang.String prefix)
setWrapperPrefix
in interface SourceMapGenerator
prefix
- The prefix that is added before the generated source code.public void setStartingPosition(int offsetLine, int offsetIndex)
setStartingPosition
in interface SourceMapGenerator
offsetLine
- The index of the current line being printed.offsetIndex
- The column index of the current character being printed.public void addMapping(java.lang.String sourceName, @Nullable java.lang.String symbolName, FilePosition sourceStartPosition, FilePosition startPosition, FilePosition endPosition)
addMapping
in interface SourceMapGenerator
startPosition
- The position on the starting lineendPosition
- The position on the ending line.sourceName
- The file name to use in the generate source map
to represent this source.symbolName
- The symbol name associated with this position in the
source map.sourceStartPosition
- The starting position in the original source for
represented range outputStartPosition to outputEndPosition in the
generated file.public void mergeMapSection(int line, int column, java.lang.String mapSectionContents) throws SourceMapParseException
mapSectionContents
considering the
offset (line, column)
. Any extension in the map section will be
ignored.line
- The line offsetcolumn
- The column offsetmapSectionContents
- The map section to be appendedSourceMapParseException
public void mergeMapSection(int line, int column, java.lang.String mapSectionContents, SourceMapGeneratorV3.ExtensionMergeAction mergeAction) throws SourceMapParseException
mergeMapSection(int, int, String)
, except that
extensions from the @{code mapSectionContents} are merged to the top level
source map. For conflicts a mergeAction
is performed.line
- The line offsetcolumn
- The column offsetmapSectionContents
- The map section to be appendedmergeAction
- The merge action for conflicting extensionsSourceMapParseException
public void appendTo(java.lang.Appendable out, java.lang.String name) throws java.io.IOException
appendTo
in interface SourceMapGenerator
out
- The stream to which the map will be appended.name
- The name of the generated source file that this source map
represents.java.io.IOException
public void setSourceRoot(java.lang.String path)
addMapping(java.lang.String, java.lang.String, com.google.debugging.sourcemap.FilePosition, com.google.debugging.sourcemap.FilePosition, com.google.debugging.sourcemap.FilePosition)
. Debuggers expect (prefix + sourceName) to be a URL
for loading the source code.path
- The URL prefix to save in the sourcemap file. (Not validated.)public void addExtension(java.lang.String name, java.lang.Object object) throws SourceMapParseException
SourceMapParseExtension
will be thrown.name
- The name of the extension with format organization_fieldobject
- The value of the extension as a valid json valueSourceMapParseException
- if extension name is malformedpublic void removeExtension(java.lang.String name)
name
- The name of the extension with format organization_fieldpublic boolean hasExtension(java.lang.String name)
name
- The name of the extension with format organization_fieldpublic java.lang.Object getExtension(java.lang.String name)
null
if this extension does not exist.name
- null
private void addSourceNameMap(java.lang.Appendable out) throws java.io.IOException
java.io.IOException
private void addSymbolNameMap(java.lang.Appendable out) throws java.io.IOException
java.io.IOException
private static void addNameMap(java.lang.Appendable out, java.util.Map<java.lang.String,java.lang.Integer> map) throws java.io.IOException
java.io.IOException
private static java.lang.String escapeString(java.lang.String value)
private static void appendFirstField(java.lang.Appendable out, java.lang.String name, java.lang.CharSequence value) throws java.io.IOException
java.io.IOException
private static void appendField(java.lang.Appendable out, java.lang.String name, java.lang.CharSequence value) throws java.io.IOException
java.io.IOException
private static void appendFieldStart(java.lang.Appendable out, java.lang.String name) throws java.io.IOException
java.io.IOException
private static void appendFieldEnd(java.lang.Appendable out) throws java.io.IOException
java.io.IOException
private int prepMappings() throws java.io.IOException
java.io.IOException
public void appendIndexMapTo(java.lang.Appendable out, java.lang.String name, java.util.List<SourceMapSection> sections) throws java.io.IOException
appendIndexMapTo
in interface SourceMapGenerator
out
- The stream to which the map will be appended.name
- The name of the generated source file that this source map
represents.sections
- An ordered list of map sections to include in the index.java.io.IOException
private static java.lang.CharSequence offsetValue(int line, int column) throws java.io.IOException
java.io.IOException
private int getSourceId(java.lang.String sourceName)
private int getNameId(java.lang.String symbolName)