Rename relativePath -> rootRelativePath in Root and friends. This makes it clearer that the path fragments in question are relative *to the root*. Confusingly, when the root is absolute, the root relative fragment is also absolute. This makes it a tiny bit clearer that the path fragment may be absolute. PiperOrigin-RevId: 182544893
diff --git a/src/main/java/com/google/devtools/build/lib/rules/repository/LocalRepositoryFunction.java b/src/main/java/com/google/devtools/build/lib/rules/repository/LocalRepositoryFunction.java index 5b8f088..a335d9d 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/repository/LocalRepositoryFunction.java +++ b/src/main/java/com/google/devtools/build/lib/rules/repository/LocalRepositoryFunction.java
@@ -96,7 +96,9 @@ RootedPath workspaceRootedFile = RootedPath.toRootedPath( directory.getRoot(), - directory.getRelativePath().getRelative(BuildFileName.WORKSPACE.getFilenameFragment())); + directory + .getRootRelativePath() + .getRelative(BuildFileName.WORKSPACE.getFilenameFragment())); SkyKey workspaceFileKey = FileValue.key(workspaceRootedFile); FileValue value;
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/FileFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/FileFunction.java index 9cae797..dc04d4b 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/FileFunction.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/FileFunction.java
@@ -55,7 +55,7 @@ RootedPath rootedPath = (RootedPath) skyKey.argument(); RootedPath realRootedPath = null; FileStateValue realFileStateValue = null; - PathFragment relativePath = rootedPath.getRelativePath(); + PathFragment relativePath = rootedPath.getRootRelativePath(); // Resolve ancestor symlinks, but only if the current file is not the filesystem root (has no // parent) or a package path root (treated opaquely and handled by skyframe's DiffAwareness @@ -117,7 +117,7 @@ private static Pair<RootedPath, FileStateValue> resolveFromAncestors( RootedPath rootedPath, Environment env) throws FileFunctionException, InterruptedException { - PathFragment relativePath = rootedPath.getRelativePath(); + PathFragment relativePath = rootedPath.getRootRelativePath(); RootedPath realRootedPath = rootedPath; FileValue parentFileValue = null; PathFragment parentDirectory = relativePath.getParentDirectory(); @@ -130,8 +130,10 @@ } PathFragment baseName = PathFragment.create(relativePath.getBaseName()); RootedPath parentRealRootedPath = parentFileValue.realRootedPath(); - realRootedPath = RootedPath.toRootedPath(parentRealRootedPath.getRoot(), - parentRealRootedPath.getRelativePath().getRelative(baseName)); + realRootedPath = + RootedPath.toRootedPath( + parentRealRootedPath.getRoot(), + parentRealRootedPath.getRootRelativePath().getRelative(baseName)); if (!parentFileValue.exists()) { return Pair.<RootedPath, FileStateValue>of(
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/GraphBackedRecursivePackageProvider.java b/src/main/java/com/google/devtools/build/lib/skyframe/GraphBackedRecursivePackageProvider.java index ad8fc99..53325ae 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/GraphBackedRecursivePackageProvider.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/GraphBackedRecursivePackageProvider.java
@@ -258,7 +258,7 @@ (CollectPackagesUnderDirectoryValue) val; if (collectPackagesValue != null) { if (collectPackagesValue.isDirectoryPackage()) { - builder.add(info.rootedDir.getRelativePath()); + builder.add(info.rootedDir.getRootRelativePath()); } if (collectPackagesValue.getErrorMessage() != null) { @@ -269,7 +269,7 @@ collectPackagesValue.getSubdirectoryTransitivelyContainsPackagesOrErrors(); for (RootedPath subdirectory : subdirectoryTransitivelyContainsPackages.keySet()) { if (subdirectoryTransitivelyContainsPackages.get(subdirectory)) { - PathFragment subdirectoryRelativePath = subdirectory.getRelativePath(); + PathFragment subdirectoryRelativePath = subdirectory.getRootRelativePath(); ImmutableSet<PathFragment> blacklistedSubdirectoriesBeneathThisSubdirectory = info.blacklistedSubdirectories .stream()
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/LocalRepositoryLookupFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/LocalRepositoryLookupFunction.java index 66d4afa..6d6d2eb 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/LocalRepositoryLookupFunction.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/LocalRepositoryLookupFunction.java
@@ -60,7 +60,7 @@ // Is this the root directory? If so, we're in the MAIN repository. This assumes that the main // repository has a WORKSPACE in the root directory, but Bazel will have failed with an error // before this can be called if that is incorrect. - if (directory.getRelativePath().equals(PathFragment.EMPTY_FRAGMENT)) { + if (directory.getRootRelativePath().equals(PathFragment.EMPTY_FRAGMENT)) { return LocalRepositoryLookupValue.mainRepository(); } @@ -84,7 +84,7 @@ // If we haven't found a repository yet, check the parent directory. RootedPath parentDirectory = RootedPath.toRootedPath( - directory.getRoot(), directory.getRelativePath().getParentDirectory()); + directory.getRoot(), directory.getRootRelativePath().getParentDirectory()); return env.getValue(LocalRepositoryLookupValue.key(parentDirectory)); } @@ -95,7 +95,7 @@ RootedPath.toRootedPath( directory.getRoot(), directory - .getRelativePath() + .getRootRelativePath() .getRelative(BuildFileName.WORKSPACE.getFilenameFragment())); FileValue workspaceFileValue = (FileValue) env.getValueOrThrow(FileValue.key(workspaceRootedFile), IOException.class);
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/PrepareDepsOfTargetsUnderDirectoryFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/PrepareDepsOfTargetsUnderDirectoryFunction.java index 780254b..05ef591 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/PrepareDepsOfTargetsUnderDirectoryFunction.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/PrepareDepsOfTargetsUnderDirectoryFunction.java
@@ -81,7 +81,7 @@ CollectTargetsInPackageValue.key( PackageIdentifier.create( recursivePkgKey.getRepository(), - recursivePkgKey.getRootedPath().getRelativePath()), + recursivePkgKey.getRootedPath().getRootRelativePath()), filteringPolicy)), keysToRequest); }
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ProcessPackageDirectory.java b/src/main/java/com/google/devtools/build/lib/skyframe/ProcessPackageDirectory.java index ce995c9..6d1cf5a 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/ProcessPackageDirectory.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/ProcessPackageDirectory.java
@@ -75,7 +75,7 @@ SkyFunction.Environment env, Set<PathFragment> excludedPaths) throws InterruptedException { - PathFragment rootRelativePath = rootedPath.getRelativePath(); + PathFragment rootRelativePath = rootedPath.getRootRelativePath(); SkyKey fileKey = FileValue.key(rootedPath); FileValue fileValue; @@ -170,7 +170,7 @@ RepositoryName repositoryName, Set<PathFragment> excludedPaths) { Root root = rootedPath.getRoot(); - PathFragment rootRelativePath = rootedPath.getRelativePath(); + PathFragment rootRelativePath = rootedPath.getRootRelativePath(); boolean followSymlinks = shouldFollowSymlinksWhenTraversing(dirListingValue.getDirents()); List<SkyKey> childDeps = new ArrayList<>(); for (Dirent dirent : dirListingValue.getDirents()) {
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/RecursiveDirectoryTraversalFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/RecursiveDirectoryTraversalFunction.java index f72e436..a885bef 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/RecursiveDirectoryTraversalFunction.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/RecursiveDirectoryTraversalFunction.java
@@ -137,7 +137,7 @@ Map<SkyKey, SkyValue> subdirectorySkyValues; if (packageExistenceAndSubdirDeps.packageExists()) { - PathFragment rootRelativePath = rootedPath.getRelativePath(); + PathFragment rootRelativePath = rootedPath.getRootRelativePath(); SkyKey packageKey = PackageValue.key( PackageIdentifier.create(recursivePkgKey.getRepository(), rootRelativePath));
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunction.java index d8e569e..bc02d56 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunction.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunction.java
@@ -54,10 +54,12 @@ public static final class GeneratedPathConflictException extends RecursiveFilesystemTraversalException { GeneratedPathConflictException(TraversalRequest traversal) { - super(String.format( - "Generated directory %s conflicts with package under the same path. Additional info: %s", - traversal.path.getRelativePath().getPathString(), - traversal.errorInfo != null ? traversal.errorInfo : traversal.toString())); + super( + String.format( + "Generated directory %s conflicts with package under the same path. " + + "Additional info: %s", + traversal.path.getRootRelativePath().getPathString(), + traversal.errorInfo != null ? traversal.errorInfo : traversal.toString())); } } @@ -132,8 +134,10 @@ if (rootInfo.type.isFile()) { if (traversal.pattern == null - || traversal.pattern.matcher( - rootInfo.realPath.getRelativePath().getPathString()).matches()) { + || traversal + .pattern + .matcher(rootInfo.realPath.getRootRelativePath().getPathString()) + .matches()) { // The root is a file or a symlink to one. return resultForFileRoot(traversal.path, rootInfo); } else { @@ -152,8 +156,10 @@ new GeneratedPathConflictException(traversal)); } else if (pkgLookupResult.isPackage() && !traversal.skipTestingForSubpackage) { // The traversal was requested for a directory that defines a package. - String msg = traversal.errorInfo + " crosses package boundary into package rooted at " - + traversal.path.getRelativePath().getPathString(); + String msg = + traversal.errorInfo + + " crosses package boundary into package rooted at " + + traversal.path.getRootRelativePath().getPathString(); switch (traversal.crossPkgBoundaries) { case CROSS: // We are free to traverse the subpackage but we need to display a warning. @@ -298,8 +304,9 @@ throws MissingDepException, IOException, InterruptedException { Preconditions.checkArgument(rootInfo.type.exists() && !rootInfo.type.isFile(), "{%s} {%s}", traversal, rootInfo); - PackageLookupValue pkgLookup = (PackageLookupValue) getDependentSkyValue(env, - PackageLookupValue.key(traversal.path.getRelativePath())); + PackageLookupValue pkgLookup = + (PackageLookupValue) + getDependentSkyValue(env, PackageLookupValue.key(traversal.path.getRootRelativePath())); if (pkgLookup.packageExists()) { if (traversal.isGenerated) { @@ -340,8 +347,10 @@ List<SkyKey> result = new ArrayList<>(); for (Dirent dirent : dirListing.getDirents()) { - RootedPath childPath = RootedPath.toRootedPath(traversal.path.getRoot(), - traversal.path.getRelativePath().getRelative(dirent.getName())); + RootedPath childPath = + RootedPath.toRootedPath( + traversal.path.getRoot(), + traversal.path.getRootRelativePath().getRelative(dirent.getName())); TraversalRequest childTraversal = traversal.forChildEntry(childPath); result.add(RecursiveFilesystemTraversalValue.key(childTraversal)); }
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalValue.java index d3bbc16..e791b5c 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalValue.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalValue.java
@@ -168,8 +168,8 @@ * originally assumed. */ TraversalRequest forChangedRootPath(Root newRoot) { - return duplicate(RootedPath.toRootedPath(newRoot, path.getRelativePath()), - skipTestingForSubpackage); + return duplicate( + RootedPath.toRootedPath(newRoot, path.getRootRelativePath()), skipTestingForSubpackage); } @Override @@ -214,7 +214,7 @@ } PathFragment getNameInSymlinkTree() { - return linkName.getRelativePath(); + return linkName.getRootRelativePath(); } @Override @@ -301,7 +301,7 @@ @Override public PathFragment getNameInSymlinkTree() { - return path.getRelativePath(); + return path.getRootRelativePath(); } @Override @@ -360,7 +360,7 @@ @Override public PathFragment getNameInSymlinkTree() { - return path.getRelativePath(); + return path.getRootRelativePath(); } @Override
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/RecursivePkgValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/RecursivePkgValue.java index 20919a0..74f94bf 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/RecursivePkgValue.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/RecursivePkgValue.java
@@ -83,8 +83,7 @@ public RecursivePkgKey(RepositoryName repositoryName, RootedPath rootedPath, ImmutableSet<PathFragment> excludedPaths) { - PathFragment.checkAllPathsAreUnder(excludedPaths, - rootedPath.getRelativePath()); + PathFragment.checkAllPathsAreUnder(excludedPaths, rootedPath.getRootRelativePath()); Preconditions.checkState(!repositoryName.isDefault()); this.repositoryName = repositoryName; this.rootedPath = Preconditions.checkNotNull(rootedPath);
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java index 9e0a419..c182d69 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java
@@ -984,7 +984,7 @@ DirectoryListingStateValue oldDirListingStateValue = (DirectoryListingStateValue) valuesMap.get(dirListingStateKey); if (oldDirListingStateValue != null) { - String baseName = rootedPath.getRelativePath().getBaseName(); + String baseName = rootedPath.getRootRelativePath().getBaseName(); Dirent oldDirent = oldDirListingStateValue.getDirents().maybeGetDirent(baseName); changedType = (oldDirent == null) || !compatibleFileTypes(oldDirent.getType(), newValue.getType()); @@ -1005,8 +1005,9 @@ } private static SkyKey parentDirectoryListingStateKey(RootedPath rootedPath) { - RootedPath parentDirRootedPath = RootedPath.toRootedPath( - rootedPath.getRoot(), rootedPath.getRelativePath().getParentDirectory()); + RootedPath parentDirRootedPath = + RootedPath.toRootedPath( + rootedPath.getRoot(), rootedPath.getRootRelativePath().getParentDirectory()); return DirectoryListingStateValue.key(parentDirRootedPath); }
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeIncrementalBuildMonitor.java b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeIncrementalBuildMonitor.java index bb27716..462e51f 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeIncrementalBuildMonitor.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeIncrementalBuildMonitor.java
@@ -20,7 +20,6 @@ import com.google.devtools.build.lib.vfs.PathFragment; import com.google.devtools.build.lib.vfs.RootedPath; import com.google.devtools.build.skyframe.SkyKey; - import java.util.HashSet; import java.util.Set; @@ -40,7 +39,7 @@ for (SkyKey skyKey : invalidatedValues) { if (skyKey.functionName().equals(SkyFunctions.FILE_STATE)) { RootedPath file = (RootedPath) skyKey.argument(); - maybeAddFile(file.getRelativePath()); + maybeAddFile(file.getRootRelativePath()); } } }
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/WorkspaceASTFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/WorkspaceASTFunction.java index 4c56ade..a36fd32 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/WorkspaceASTFunction.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/WorkspaceASTFunction.java
@@ -53,7 +53,7 @@ return null; } - Path repoWorkspace = workspaceRoot.getRoot().getRelative(workspaceRoot.getRelativePath()); + Path repoWorkspace = workspaceRoot.getRoot().getRelative(workspaceRoot.getRootRelativePath()); try { BuildFileAST ast = BuildFileAST.parseBuildFile( ParserInputSource.create(ruleClassProvider.getDefaultWorkspacePrefix(),
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/WorkspaceFileFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/WorkspaceFileFunction.java index 3f0f3f8..945ecfe 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/WorkspaceFileFunction.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/WorkspaceFileFunction.java
@@ -72,7 +72,7 @@ return null; } - Path repoWorkspace = workspaceRoot.getRoot().getRelative(workspaceRoot.getRelativePath()); + Path repoWorkspace = workspaceRoot.getRoot().getRelative(workspaceRoot.getRootRelativePath()); Package.Builder builder = packageFactory.newExternalPackageBuilder( repoWorkspace, ruleClassProvider.getRunfilesPrefix());
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/serialization/testutils/FsUtils.java b/src/main/java/com/google/devtools/build/lib/skyframe/serialization/testutils/FsUtils.java index 53962ba..29cb354 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/serialization/testutils/FsUtils.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/serialization/testutils/FsUtils.java
@@ -37,6 +37,6 @@ /** Returns path relative to {@link #TEST_ROOT}. */ public static PathFragment rootPathRelative(String path) { - return TEST_ROOT.getRelativePath().getRelative(path); + return TEST_ROOT.getRootRelativePath().getRelative(path); } }
diff --git a/src/main/java/com/google/devtools/build/lib/vfs/Root.java b/src/main/java/com/google/devtools/build/lib/vfs/Root.java index 6446fb1..bc47e42 100644 --- a/src/main/java/com/google/devtools/build/lib/vfs/Root.java +++ b/src/main/java/com/google/devtools/build/lib/vfs/Root.java
@@ -48,22 +48,22 @@ } /** Returns a path by concatenating the root and the root-relative path. */ - Path getRelative(PathFragment relativePath); + Path getRelative(PathFragment rootRelativePath); /** Returns a path by concatenating the root and the root-relative path. */ - Path getRelative(String relativePath); + Path getRelative(String rootRelativePath); /** Returns the relative path between the root and the given path. */ PathFragment relativize(Path path); /** Returns the relative path between the root and the given absolute path fragment. */ - PathFragment relativize(PathFragment pathFragment); + PathFragment relativize(PathFragment absolutePathFragment); /** Returns whether the given path is under this root. */ boolean contains(Path path); /** Returns whether the given absolute path fragment is under this root. */ - boolean contains(PathFragment pathFragment); + boolean contains(PathFragment absolutePathFragment); /** * Returns the underlying path. Please avoid using this method. @@ -84,13 +84,13 @@ } @Override - public Path getRelative(PathFragment relativePath) { - return path.getRelative(relativePath); + public Path getRelative(PathFragment rootRelativePath) { + return path.getRelative(rootRelativePath); } @Override - public Path getRelative(String relativePath) { - return path.getRelative(relativePath); + public Path getRelative(String rootRelativePath) { + return path.getRelative(rootRelativePath); } @Override @@ -99,9 +99,9 @@ } @Override - public PathFragment relativize(PathFragment relativePath) { - Preconditions.checkArgument(relativePath.isAbsolute()); - return relativePath.relativeTo(path.asFragment()); + public PathFragment relativize(PathFragment absolutePathFragment) { + Preconditions.checkArgument(absolutePathFragment.isAbsolute()); + return absolutePathFragment.relativeTo(path.asFragment()); } @Override @@ -110,8 +110,9 @@ } @Override - public boolean contains(PathFragment relativePath) { - return relativePath.isAbsolute() && relativePath.startsWith(path.asFragment()); + public boolean contains(PathFragment absolutePathFragment) { + return absolutePathFragment.isAbsolute() + && absolutePathFragment.startsWith(path.asFragment()); } @Override @@ -167,14 +168,14 @@ } @Override - public Path getRelative(PathFragment relativePath) { - Preconditions.checkArgument(relativePath.isAbsolute()); - return fileSystem.getPath(relativePath); + public Path getRelative(PathFragment rootRelativePath) { + Preconditions.checkArgument(rootRelativePath.isAbsolute()); + return fileSystem.getPath(rootRelativePath); } @Override - public Path getRelative(String relativePath) { - return getRelative(PathFragment.create(relativePath)); + public Path getRelative(String rootRelativePath) { + return getRelative(PathFragment.create(rootRelativePath)); } @Override @@ -183,9 +184,9 @@ } @Override - public PathFragment relativize(PathFragment pathFragment) { - Preconditions.checkArgument(pathFragment.isAbsolute()); - return pathFragment; + public PathFragment relativize(PathFragment absolutePathFragment) { + Preconditions.checkArgument(absolutePathFragment.isAbsolute()); + return absolutePathFragment; } @Override @@ -194,8 +195,8 @@ } @Override - public boolean contains(PathFragment pathFragment) { - return pathFragment.isAbsolute(); + public boolean contains(PathFragment absolutePathFragment) { + return absolutePathFragment.isAbsolute(); } @Override
diff --git a/src/main/java/com/google/devtools/build/lib/vfs/RootedPath.java b/src/main/java/com/google/devtools/build/lib/vfs/RootedPath.java index 8deca0a..50dedfe 100644 --- a/src/main/java/com/google/devtools/build/lib/vfs/RootedPath.java +++ b/src/main/java/com/google/devtools/build/lib/vfs/RootedPath.java
@@ -36,36 +36,36 @@ public class RootedPath implements Serializable { private final Root root; - private final PathFragment relativePath; + private final PathFragment rootRelativePath; private final Path path; /** Constructs a {@link RootedPath} from a {@link Root} and path fragment relative to the root. */ - private RootedPath(Root root, PathFragment relativePath) { + private RootedPath(Root root, PathFragment rootRelativePath) { Preconditions.checkState( - relativePath.isAbsolute() == root.isAbsolute(), - "relativePath: %s root: %s", - relativePath, + rootRelativePath.isAbsolute() == root.isAbsolute(), + "rootRelativePath: %s root: %s", + rootRelativePath, root); this.root = root; - this.relativePath = relativePath.normalize(); - this.path = root.getRelative(this.relativePath); + this.rootRelativePath = rootRelativePath.normalize(); + this.path = root.getRelative(this.rootRelativePath); } - /** Returns a rooted path representing {@code relativePath} relative to {@code root}. */ - public static RootedPath toRootedPath(Root root, PathFragment relativePath) { - if (relativePath.isAbsolute()) { + /** Returns a rooted path representing {@code rootRelativePath} relative to {@code root}. */ + public static RootedPath toRootedPath(Root root, PathFragment rootRelativePath) { + if (rootRelativePath.isAbsolute()) { if (root.isAbsolute()) { - return new RootedPath(root, relativePath); + return new RootedPath(root, rootRelativePath); } else { Preconditions.checkArgument( - root.contains(relativePath), - "relativePath '%s' is absolute, but it's not under root '%s'", - relativePath, + root.contains(rootRelativePath), + "rootRelativePath '%s' is absolute, but it's not under root '%s'", + rootRelativePath, root); - return new RootedPath(root, root.relativize(relativePath)); + return new RootedPath(root, root.relativize(rootRelativePath)); } } else { - return new RootedPath(root, relativePath); + return new RootedPath(root, rootRelativePath); } } @@ -100,11 +100,9 @@ return root; } - /** - * Returns the (normalized) path relative to {@code #getRoot}. - */ - public PathFragment getRelativePath() { - return relativePath; + /** Returns the path fragment relative to {@code #getRoot}. */ + public PathFragment getRootRelativePath() { + return rootRelativePath; } @Override @@ -116,17 +114,18 @@ return false; } RootedPath other = (RootedPath) obj; - return Objects.equals(root, other.root) && Objects.equals(relativePath, other.relativePath); + return Objects.equals(root, other.root) + && Objects.equals(rootRelativePath, other.rootRelativePath); } @Override public int hashCode() { - return Objects.hash(root, relativePath); + return Objects.hash(root, rootRelativePath); } @Override public String toString() { - return "[" + root + "]/[" + relativePath + "]"; + return "[" + root + "]/[" + rootRelativePath + "]"; } /** Custom serialization for {@link RootedPath}s. */ @@ -148,15 +147,15 @@ public void serialize(RootedPath rootedPath, CodedOutputStream codedOut) throws IOException, SerializationException { rootCodec.serialize(rootedPath.getRoot(), codedOut); - PathFragment.CODEC.serialize(rootedPath.getRelativePath(), codedOut); + PathFragment.CODEC.serialize(rootedPath.getRootRelativePath(), codedOut); } @Override public RootedPath deserialize(CodedInputStream codedIn) throws IOException, SerializationException { Root root = rootCodec.deserialize(codedIn); - PathFragment relativePath = PathFragment.CODEC.deserialize(codedIn); - return toRootedPath(root, relativePath); + PathFragment rootRelativePath = PathFragment.CODEC.deserialize(codedIn); + return toRootedPath(root, rootRelativePath); } } }