diff options
author | vladmos <vladmos@google.com> | 2017-07-11 16:31:32 +0200 |
---|---|---|
committer | László Csomor <laszlocsomor@google.com> | 2017-07-11 18:26:04 +0200 |
commit | f07773b31450b1863dd6f9390b9bb8b3040e2d6d (patch) | |
tree | 86cf32dee846e7351573b40584ff3bda27127b14 /src/main/java/com/google/devtools/build/lib/cmdline | |
parent | 2a32a66878ca6f3de6dcb35c8c2043b02ca8f89d (diff) |
Make some objects SkylarkValues
Skylark's Printer.BasePrinter doesn't guarantee it will call `.toString` on
objects of unknown types, and in the future that won't be the case anymore.
In order to keep their current string representations objects should implement
the SkylarkValue interface by providing an explicit implementation of `repr`.
PiperOrigin-RevId: 161526182
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/cmdline')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/cmdline/PackageIdentifier.java | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/cmdline/PackageIdentifier.java b/src/main/java/com/google/devtools/build/lib/cmdline/PackageIdentifier.java index 8640f261de..e276793023 100644 --- a/src/main/java/com/google/devtools/build/lib/cmdline/PackageIdentifier.java +++ b/src/main/java/com/google/devtools/build/lib/cmdline/PackageIdentifier.java @@ -17,6 +17,8 @@ package com.google.devtools.build.lib.cmdline; import com.google.common.collect.ComparisonChain; import com.google.common.collect.Interner; import com.google.devtools.build.lib.concurrent.BlazeInterners; +import com.google.devtools.build.lib.skylarkinterface.SkylarkPrinter; +import com.google.devtools.build.lib.skylarkinterface.SkylarkValue; import com.google.devtools.build.lib.util.Preconditions; import com.google.devtools.build.lib.vfs.Canonicalizer; import com.google.devtools.build.lib.vfs.PathFragment; @@ -27,12 +29,13 @@ import javax.annotation.concurrent.Immutable; /** * Uniquely identifies a package, given a repository name and a package's path fragment. * - * <p>The repository the build is happening in is the <i>default workspace</i>, and is identified - * by the workspace name "". Other repositories can be named in the WORKSPACE file. These - * workspaces are prefixed by {@literal @}.</p> + * <p>The repository the build is happening in is the <i>default workspace</i>, and is identified by + * the workspace name "". Other repositories can be named in the WORKSPACE file. These workspaces + * are prefixed by {@literal @}. */ @Immutable -public final class PackageIdentifier implements Comparable<PackageIdentifier>, Serializable { +public final class PackageIdentifier + implements Comparable<PackageIdentifier>, Serializable, SkylarkValue { private static final Interner<PackageIdentifier> INTERNER = BlazeInterners.newWeakInterner(); @@ -216,4 +219,9 @@ public final class PackageIdentifier implements Comparable<PackageIdentifier>, S .compare(pkgName, that.pkgName) .result(); } + + @Override + public void repr(SkylarkPrinter printer) { + printer.repr(toString()); + } } |