diff options
author | 2018-02-20 13:20:30 -0800 | |
---|---|---|
committer | 2018-02-20 13:22:33 -0800 | |
commit | 80a0633bbeef3f84ab6eb6513a5d36936cd1bdbb (patch) | |
tree | a4ce5b4d8422a6103d0c93fb6ed8db3ccd1f1c22 /src/main/java/com/google/devtools/build/lib/vfs | |
parent | dd090a6e8825093e7e5364ed49f16ba68f0fe54c (diff) |
Adds ObjectCodecRegistry to {Des|S}erializationContext.
* AutoCodec now delegates to the registry.
* Adds getSuperclass logic for resolving a codec.
* Small cleanups for classes that break the registry.
TODO after this change:
* Explicit CODEC definitions are no longer needed and existing ones should be cleaned up.
* POLYMORPHIC is no longer be needed and should be cleaned up.
PiperOrigin-RevId: 186351845
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/vfs')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/vfs/Root.java | 34 |
1 files changed, 17 insertions, 17 deletions
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 6f090e41a7..c23dbeb7d0 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 @@ -33,37 +33,37 @@ import javax.annotation.Nullable; * <p>A typical root could be the exec path, a package root, or an output root specific to some * configuration. We also support absolute roots for non-hermetic paths outside the user workspace. */ -public interface Root extends Comparable<Root>, Serializable { +public abstract class Root implements Comparable<Root>, Serializable { - ObjectCodec<Root> CODEC = new RootCodec(); + public static final ObjectCodec<Root> CODEC = new RootCodec(); /** Constructs a root from a path. */ - static Root fromPath(Path path) { + public static Root fromPath(Path path) { return new PathRoot(path); } /** Returns an absolute root. Can only be used with absolute path fragments. */ - static Root absoluteRoot(FileSystem fileSystem) { + public static Root absoluteRoot(FileSystem fileSystem) { return fileSystem.getAbsoluteRoot(); } /** Returns a path by concatenating the root and the root-relative path. */ - Path getRelative(PathFragment rootRelativePath); + public abstract Path getRelative(PathFragment rootRelativePath); /** Returns a path by concatenating the root and the root-relative path. */ - Path getRelative(String rootRelativePath); + public abstract Path getRelative(String rootRelativePath); /** Returns the relative path between the root and the given path. */ - PathFragment relativize(Path path); + public abstract PathFragment relativize(Path path); /** Returns the relative path between the root and the given absolute path fragment. */ - PathFragment relativize(PathFragment absolutePathFragment); + public abstract PathFragment relativize(PathFragment absolutePathFragment); /** Returns whether the given path is under this root. */ - boolean contains(Path path); + public abstract boolean contains(Path path); /** Returns whether the given absolute path fragment is under this root. */ - boolean contains(PathFragment absolutePathFragment); + public abstract boolean contains(PathFragment absolutePathFragment); /** * Returns the underlying path. Please avoid using this method. @@ -71,12 +71,12 @@ public interface Root extends Comparable<Root>, Serializable { * <p>Not all roots are backed by paths, so this may return null. */ @Nullable - Path asPath(); + public abstract Path asPath(); - boolean isAbsolute(); + public abstract boolean isAbsolute(); /** Implementation of Root that is backed by a {@link Path}. */ - final class PathRoot implements Root { + public static final class PathRoot extends Root { private final Path path; PathRoot(Path path) { @@ -160,7 +160,7 @@ public interface Root extends Comparable<Root>, Serializable { } /** An absolute root of a file system. Can only resolve absolute path fragments. */ - final class AbsoluteRoot implements Root { + public static final class AbsoluteRoot extends Root { private FileSystem fileSystem; // Non-final for serialization AbsoluteRoot(FileSystem fileSystem) { @@ -258,7 +258,7 @@ public interface Root extends Comparable<Root>, Serializable { } /** Codec to serialize {@link Root}s. */ - class RootCodec implements ObjectCodec<Root> { + private static class RootCodec implements ObjectCodec<Root> { @Override public Class<Root> getEncodedClass() { return Root.class; @@ -272,7 +272,7 @@ public interface Root extends Comparable<Root>, Serializable { throws SerializationException, IOException { if (obj instanceof PathRoot) { codedOut.writeBoolNoTag(false); - Path.CODEC.serialize(context, ((PathRoot) obj).path, codedOut); + context.serialize(((PathRoot) obj).path, codedOut); } else if (obj instanceof AbsoluteRoot) { Preconditions.checkArgument( ((AbsoluteRoot) obj).fileSystem == context.getDependency(FileSystem.class)); @@ -289,7 +289,7 @@ public interface Root extends Comparable<Root>, Serializable { if (isAbsolute) { return context.getDependency(FileSystem.class).getAbsoluteRoot(); } else { - Path path = Path.CODEC.deserialize(context, codedIn); + Path path = context.deserialize(codedIn); return new PathRoot(path); } } |