mirror of
https://github.com/github/codeql.git
synced 2026-01-04 10:10:20 +01:00
Merge pull request #1642 from xiemaisi/json_locations
Approved by asger-semmle
This commit is contained in:
@@ -43,6 +43,7 @@ public class JSONExtractor implements IExtractor {
|
||||
throw recoverableErrors.get(0).asUserError();
|
||||
|
||||
Label fileLabel = locationManager.getFileLabel();
|
||||
locationManager.setHasLocationTable("json_locations");
|
||||
v.accept(
|
||||
new Visitor<Context, Label>() {
|
||||
private Label emit(JSONValue nd, int kind, Context c) {
|
||||
|
||||
@@ -20,6 +20,7 @@ public class LocationManager {
|
||||
private int startColumn;
|
||||
private int startLine;
|
||||
private final Set<String> locationDefaultEmitted = new LinkedHashSet<String>();
|
||||
private String hasLocation = "hasLocation";
|
||||
|
||||
public LocationManager(File sourceFile, TrapWriter trapWriter, Label fileLabel) {
|
||||
this.sourceFile = sourceFile;
|
||||
@@ -58,6 +59,10 @@ public class LocationManager {
|
||||
startColumn = column;
|
||||
}
|
||||
|
||||
public void setHasLocationTable(String hasLocation) {
|
||||
this.hasLocation = hasLocation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Emit location information for an AST node. The node's location is translated from the parser's
|
||||
* 0-based column numbering scheme into our 1-based scheme and then emitted as a snippet location.
|
||||
@@ -91,7 +96,7 @@ public class LocationManager {
|
||||
/** Emit an absolute location in the current file. No line or column adjustment is performed. */
|
||||
public void emitFileLocation(Label lbl, int sl, int sc, int el, int ec) {
|
||||
Label locLabel = emitLocationsDefault(sl, sc, el, ec);
|
||||
trapWriter.addTuple("hasLocation", lbl, locLabel);
|
||||
trapWriter.addTuple(hasLocation, lbl, locLabel);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -37,7 +37,7 @@ public class Main {
|
||||
* A version identifier that should be updated every time the extractor changes in such a way that
|
||||
* it may produce different tuples for the same file under the same {@link ExtractorConfig}.
|
||||
*/
|
||||
public static final String EXTRACTOR_VERSION = "2019-04-17";
|
||||
public static final String EXTRACTOR_VERSION = "2019-07-25";
|
||||
|
||||
public static final Pattern NEWLINE = Pattern.compile("\n");
|
||||
|
||||
|
||||
@@ -99,6 +99,7 @@ public class YAMLExtractor implements IExtractor {
|
||||
trapWriter = textualExtractor.getTrapwriter();
|
||||
|
||||
Label fileLabel = locationManager.getFileLabel();
|
||||
locationManager.setHasLocationTable("yaml_locations");
|
||||
try {
|
||||
parser = new ParserImpl(new StreamReader(textualExtractor.getSource()));
|
||||
resolver = new Resolver();
|
||||
|
||||
Reference in New Issue
Block a user