aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/cmdline
diff options
context:
space:
mode:
authorGravatar vladmos <vladmos@google.com>2017-06-30 14:01:45 +0200
committerGravatar Marcel Hlopko <hlopko@google.com>2017-07-03 09:04:59 +0200
commit469079377a9561a7c2cc7a46492c44e012b9fb33 (patch)
tree7b9baaf83c2a9ee2c9a57862d833ae72d5ae9305 /src/main/java/com/google/devtools/build/lib/cmdline
parent86c9d942452d82a479d499ffe61695a983f16bba (diff)
Refactor Printer
It's now easier to customize Printer if in different situations objects should be printed differently. Also its API is cleaner now. Names of methods of SkylarkValue objects now reflect names of Skylark functions: SkylarkValue#repr and SkylarkPrintableValue#str. PiperOrigin-RevId: 160635154
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/cmdline')
-rw-r--r--src/main/java/com/google/devtools/build/lib/cmdline/Label.java32
1 files changed, 5 insertions, 27 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/cmdline/Label.java b/src/main/java/com/google/devtools/build/lib/cmdline/Label.java
index b689f6daa7..9c229018b0 100644
--- a/src/main/java/com/google/devtools/build/lib/cmdline/Label.java
+++ b/src/main/java/com/google/devtools/build/lib/cmdline/Label.java
@@ -24,13 +24,13 @@ import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable;
import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory;
import com.google.devtools.build.lib.skylarkinterface.SkylarkPrintableValue;
+import com.google.devtools.build.lib.skylarkinterface.SkylarkPrinter;
import com.google.devtools.build.lib.util.Preconditions;
import com.google.devtools.build.lib.util.StringCanonicalizer;
import com.google.devtools.build.lib.util.StringUtilities;
import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.devtools.build.skyframe.SkyFunctionName;
import com.google.devtools.build.skyframe.SkyKey;
-import java.io.IOException;
import java.io.InvalidObjectException;
import java.io.ObjectInputStream;
import java.io.Serializable;
@@ -562,34 +562,12 @@ public final class Label implements Comparable<Label>, Serializable, SkylarkPrin
}
@Override
- public void write(Appendable buffer, char quotationMark) {
- // We don't use the Skylark Printer class here to avoid creating a circular dependency.
- //
- // TODO(bazel-team): make the representation readable Label(//foo),
- // and isolate the legacy functions that want the unreadable variant.
- try {
- // There is no need to escape the contents of the Label since characters that might otherwise
- // require escaping are disallowed.
- buffer.append(quotationMark);
- buffer.append(toString());
- buffer.append(quotationMark);
- } catch (IOException e) {
- // This function will only be used with in-memory Appendables, hence we should never get here.
- throw new AssertionError(e);
- }
+ public void repr(SkylarkPrinter printer) {
+ printer.repr(getCanonicalForm());
}
@Override
- public void print(Appendable buffer, char quotationMark) {
- // We don't use the Skylark Printer class here to avoid creating a circular dependency.
- //
- // TODO(bazel-team): make the representation readable Label(//foo),
- // and isolate the legacy functions that want the unreadable variant.
- try {
- buffer.append(toString());
- } catch (IOException e) {
- // This function will only be used with in-memory Appendables, hence we should never get here.
- throw new AssertionError(e);
- }
+ public void str(SkylarkPrinter printer) {
+ printer.append(getCanonicalForm());
}
}