Remove Path from Location, ParserInputSource and bunch of other low-level classes.
This makes the code cleaner because a lot of places never read the file and thus never needed a Path in the first place. I got to this change in a bit convoluted way:
- I wanted the default tools in Android rules to point to //external:
- I wanted to make sure that that doesn't cause an error is no Android rules are built, thus I had to add some binding for them in the default WORKSPACE file
- I wanted the Android rules not to depend on Bazel core with an eye towards eventually moving them to a separate jar / Skylark code
- The default WORKSPACE file is currently composed from files extracted by the Bazel launcher which would make the Android rules depend on a very core mechanism
- I couldn't simply pass in jdk.WORKSPACE as a String because Location, ParserInputSource and a bunch of other things needed a Path, which a simple string doesn't have.
Thus, this change.
--
MOS_MIGRATED_REVID=95828839
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/LineNumberTable.java b/src/main/java/com/google/devtools/build/lib/syntax/LineNumberTable.java
index c006bf9..653abee 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/LineNumberTable.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/LineNumberTable.java
@@ -20,7 +20,7 @@
import com.google.devtools.build.lib.events.Location.LineAndColumn;
import com.google.devtools.build.lib.util.Pair;
import com.google.devtools.build.lib.util.StringUtilities;
-import com.google.devtools.build.lib.vfs.Path;
+import com.google.devtools.build.lib.vfs.PathFragment;
import java.io.Serializable;
import java.util.ArrayList;
@@ -50,9 +50,9 @@
/**
* Returns the path corresponding to the given offset.
*/
- abstract Path getPath(int offset);
+ abstract PathFragment getPath(int offset);
- static LineNumberTable create(char[] buffer, Path path) {
+ static LineNumberTable create(char[] buffer, PathFragment path) {
// If #line appears within a BUILD file, we assume it has been preprocessed
// by gconfig2blaze. We ignore all actual newlines and compute the logical
// LNT based only on the presence of #line markers.
@@ -72,10 +72,10 @@
* A mapping from line number (line >= 1) to character offset into the file.
*/
private final int[] linestart;
- private final Path path;
+ private final PathFragment path;
private final int bufferLength;
- private Regular(char[] buffer, Path path) {
+ private Regular(char[] buffer, PathFragment path) {
// Compute the size.
int size = 2;
for (int i = 0; i < buffer.length; i++) {
@@ -132,7 +132,7 @@
}
@Override
- Path getPath(int offset) {
+ PathFragment getPath(int offset) {
return path;
}
@@ -161,9 +161,9 @@
private static class SingleHashLine implements Serializable {
private final int offset;
private final int line;
- private final Path path;
+ private final PathFragment path;
- SingleHashLine(int offset, int line, Path path) {
+ SingleHashLine(int offset, int line, PathFragment path) {
this.offset = offset;
this.line = line;
this.path = path;
@@ -181,10 +181,10 @@
private static final Pattern pattern = Pattern.compile("\n#line ([0-9]+) \"([^\"\\n]+)\"");
private final List<SingleHashLine> table;
- private final Path defaultPath;
+ private final PathFragment defaultPath;
private final int bufferLength;
- private HashLine(char[] buffer, Path defaultPath) {
+ private HashLine(char[] buffer, PathFragment defaultPath) {
// Not especially efficient, but that's fine: we just exec'd Python.
String bufString = new String(buffer);
Matcher m = pattern.matcher(bufString);
@@ -223,7 +223,7 @@
}
@Override
- Path getPath(int offset) {
+ PathFragment getPath(int offset) {
SingleHashLine hashLine = getHashLine(offset);
return hashLine == null ? defaultPath : hashLine.path;
}