Add the source location of the import string to the LoadStatement AST node, for use in tools.
--
MOS_MIGRATED_REVID=111142252
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/LoadStatement.java b/src/main/java/com/google/devtools/build/lib/syntax/LoadStatement.java
index d373c46..2bc348a 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/LoadStatement.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/LoadStatement.java
@@ -17,6 +17,7 @@
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
+import com.google.devtools.build.lib.events.Location;
import com.google.devtools.build.lib.syntax.compiler.DebugInfo;
import com.google.devtools.build.lib.syntax.compiler.LoopLabels;
import com.google.devtools.build.lib.syntax.compiler.VariableScope;
@@ -33,6 +34,7 @@
private final ImmutableMap<Identifier, String> symbols;
private final ImmutableList<Identifier> cachedSymbols; // to save time
private final SkylarkImport imp;
+ private final Location importLocation;
/**
* Constructs an import statement.
@@ -41,12 +43,17 @@
* the bzl file that should be loaded. If aliasing is used, the value differs from its key's
* {@code symbol.getName()}. Otherwise, both values are identical.
*/
- LoadStatement(SkylarkImport imp, Map<Identifier, String> symbols) {
+ LoadStatement(SkylarkImport imp, Location importLocation, Map<Identifier, String> symbols) {
this.imp = imp;
+ this.importLocation = importLocation;
this.symbols = ImmutableMap.copyOf(symbols);
this.cachedSymbols = ImmutableList.copyOf(symbols.keySet());
}
+ public Location getImportLocation() {
+ return importLocation;
+ }
+
public ImmutableList<Identifier> getSymbols() {
return cachedSymbols;
}
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/Parser.java b/src/main/java/com/google/devtools/build/lib/syntax/Parser.java
index 023a85b..aa37796 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/Parser.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/Parser.java
@@ -1052,7 +1052,7 @@
return;
}
- StringLiteral path = parseStringLiteral();
+ StringLiteral importString = parseStringLiteral();
expect(TokenKind.COMMA);
Map<Identifier, String> symbols = new HashMap<>();
@@ -1070,13 +1070,13 @@
SkylarkImport imp;
try {
- imp = SkylarkImports.create(path.getValue());
- LoadStatement stmt = new LoadStatement(imp, symbols);
+ imp = SkylarkImports.create(importString.getValue());
+ LoadStatement stmt = new LoadStatement(imp, importString.getLocation(), symbols);
list.add(setLocation(stmt, start, token.left));
} catch (SkylarkImportSyntaxException e) {
- String msg = "Load statement parameter '" + path + "' is invalid. "
+ String msg = "Load statement parameter '" + importString + "' is invalid. "
+ e.getMessage();
- reportError(path.getLocation(), msg);
+ reportError(importString.getLocation(), msg);
}
}