aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/skylarkinterface
diff options
context:
space:
mode:
authorGravatar vladmos <vladmos@google.com>2017-07-05 10:25:01 -0400
committerGravatar John Cater <jcater@google.com>2017-07-05 10:59:40 -0400
commit6ff634d3f3582c74190a5dd5051a4b0253aec604 (patch)
tree0f3756c6b63539c17c409b5d8893c447b015017a /src/main/java/com/google/devtools/build/lib/skylarkinterface
parentfd04ce8e20c62acc357a9473dcde727a413e915e (diff)
Clean up string representations for labels
If --incompatible_descriptive_string_representations is passed, labels are converted to strings using `repr` differently: `Label("//package:name")` instead of `"//package:name"` This CL doesn't affect representations of other object types but provides the necessary infrastructure for it. PiperOrigin-RevId: 160955284
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/skylarkinterface')
-rw-r--r--src/main/java/com/google/devtools/build/lib/skylarkinterface/SkylarkPrintableValue.java26
-rw-r--r--src/main/java/com/google/devtools/build/lib/skylarkinterface/SkylarkValue.java34
2 files changed, 34 insertions, 26 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/skylarkinterface/SkylarkPrintableValue.java b/src/main/java/com/google/devtools/build/lib/skylarkinterface/SkylarkPrintableValue.java
deleted file mode 100644
index 69426ea6c8..0000000000
--- a/src/main/java/com/google/devtools/build/lib/skylarkinterface/SkylarkPrintableValue.java
+++ /dev/null
@@ -1,26 +0,0 @@
-// Copyright 2015 The Bazel Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-package com.google.devtools.build.lib.skylarkinterface;
-
-/**
- * A Skylark value that is represented by {@code str()} differently than by {@code repr()}.
- */
-public interface SkylarkPrintableValue extends SkylarkValue {
- /**
- * Print an informal, human-readable representation of the value.
- *
- * @param printer a printer to be used for formatting nested values.
- */
- void str(SkylarkPrinter printer);
-}
diff --git a/src/main/java/com/google/devtools/build/lib/skylarkinterface/SkylarkValue.java b/src/main/java/com/google/devtools/build/lib/skylarkinterface/SkylarkValue.java
index a7c8c2779b..bf6a5c5586 100644
--- a/src/main/java/com/google/devtools/build/lib/skylarkinterface/SkylarkValue.java
+++ b/src/main/java/com/google/devtools/build/lib/skylarkinterface/SkylarkValue.java
@@ -37,4 +37,38 @@ public interface SkylarkValue {
* @param printer a printer to be used for formatting nested values.
*/
void repr(SkylarkPrinter printer);
+
+ /**
+ * Print a legacy representation of object x.
+ *
+ * <p>By default dispatches to the {@code repr} method. Should be called instead of {@code repr}
+ * if --incompatible_descriptive_string_representations=false is used.
+ *
+ * @param printer an instance of a printer to be used for formatting nested values
+ */
+ default void reprLegacy(SkylarkPrinter printer) {
+ repr(printer);
+ }
+
+ /**
+ * Print an informal, human-readable representation of the value.
+ *
+ * <p>By default dispatches to the {@code repr} method.
+ *
+ * @param printer a printer to be used for formatting nested values.
+ */
+ default void str(SkylarkPrinter printer) {
+ repr(printer);
+ }
+
+ /**
+ * Print a legacy informal, human-readable representation of the value.
+ *
+ * <p>By default dispatches to the {@code reprLegacy} method.
+ *
+ * @param printer a printer to be used for formatting nested values.
+ */
+ default void strLegacy(SkylarkPrinter printer) {
+ reprLegacy(printer);
+ }
}