bazel syntax: move Printer.{repr,str,format,formatWithList} to Starlark

These fundamental API operations belong in class Starlark.

Also, this prepares the way for renaming
skylarkinterface.SkylarkPrinter to syntax.Printer by avoiding conflict
between static methods and future interface methods.

The little-used debugPrint operation was not thus moved.

This is a breaking change for copybara.

PiperOrigin-RevId: 282054622
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/configuredtargets/AbstractConfiguredTarget.java b/src/main/java/com/google/devtools/build/lib/analysis/configuredtargets/AbstractConfiguredTarget.java
index 67d43eb..9e982e1 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/configuredtargets/AbstractConfiguredTarget.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/configuredtargets/AbstractConfiguredTarget.java
@@ -38,7 +38,6 @@
 import com.google.devtools.build.lib.skylarkinterface.SkylarkPrinter;
 import com.google.devtools.build.lib.syntax.EvalException;
 import com.google.devtools.build.lib.syntax.EvalUtils;
-import com.google.devtools.build.lib.syntax.Printer;
 import com.google.devtools.build.lib.syntax.SkylarkClassObject;
 import com.google.devtools.build.lib.syntax.Starlark;
 import com.google.devtools.build.lib.syntax.StarlarkSemantics;
@@ -163,7 +162,7 @@
     }
     throw new EvalException(
         loc,
-        Printer.format(
+        Starlark.format(
             "%r%s doesn't contain declared provider '%s'",
             this,
             getRuleClassString().isEmpty() ? "" : " (rule '" + getRuleClassString() + "')",
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/configuredtargets/RuleConfiguredTarget.java b/src/main/java/com/google/devtools/build/lib/analysis/configuredtargets/RuleConfiguredTarget.java
index 3defd90..06a3f2d 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/configuredtargets/RuleConfiguredTarget.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/configuredtargets/RuleConfiguredTarget.java
@@ -49,7 +49,7 @@
 import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec.VisibleForSerialization;
 import com.google.devtools.build.lib.skylarkbuildapi.ActionApi;
 import com.google.devtools.build.lib.skylarkinterface.SkylarkPrinter;
-import com.google.devtools.build.lib.syntax.Printer;
+import com.google.devtools.build.lib.syntax.Starlark;
 import java.util.function.Consumer;
 import javax.annotation.Nullable;
 
@@ -199,7 +199,7 @@
 
   @Override
   public String getErrorMessageForUnknownField(String name) {
-    return Printer.format(
+    return Starlark.format(
         "%r (rule '%s') doesn't have provider '%s'", this, getRuleClassString(), name);
   }
 
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/platform/ConstraintCollection.java b/src/main/java/com/google/devtools/build/lib/analysis/platform/ConstraintCollection.java
index 9d4bed3..da73061 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/platform/ConstraintCollection.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/platform/ConstraintCollection.java
@@ -36,8 +36,8 @@
 import com.google.devtools.build.lib.skylarkinterface.SkylarkPrinter;
 import com.google.devtools.build.lib.syntax.EvalException;
 import com.google.devtools.build.lib.syntax.EvalUtils;
-import com.google.devtools.build.lib.syntax.Printer;
 import com.google.devtools.build.lib.syntax.Sequence;
+import com.google.devtools.build.lib.syntax.Starlark;
 import com.google.devtools.build.lib.syntax.StarlarkList;
 import com.google.devtools.build.lib.util.Fingerprint;
 import java.util.Collection;
@@ -249,7 +249,7 @@
   // It's easier to use the Starlark repr as a string form, not what AutoValue produces.
   @Override
   public final String toString() {
-    return Printer.str(this);
+    return Starlark.str(this);
   }
 
   @Override
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleContext.java b/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleContext.java
index f5424be..c175365 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleContext.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleContext.java
@@ -82,7 +82,6 @@
 import com.google.devtools.build.lib.syntax.EvalException;
 import com.google.devtools.build.lib.syntax.EvalUtils;
 import com.google.devtools.build.lib.syntax.NoneType;
-import com.google.devtools.build.lib.syntax.Printer;
 import com.google.devtools.build.lib.syntax.Sequence;
 import com.google.devtools.build.lib.syntax.SkylarkIndexable;
 import com.google.devtools.build.lib.syntax.Starlark;
@@ -1120,7 +1119,7 @@
     for (Map.Entry<?, ?> entry : labelDict.entrySet()) {
       Object key = entry.getKey();
       if (!(key instanceof Label)) {
-        throw new EvalException(loc, Printer.format("invalid key %r in 'label_dict'", key));
+        throw new EvalException(loc, Starlark.format("invalid key %r in 'label_dict'", key));
       }
       ImmutableList.Builder<Artifact> files = ImmutableList.builder();
       Object val = entry.getValue();
@@ -1130,13 +1129,13 @@
       } else {
         throw new EvalException(
             loc,
-            Printer.format(
+            Starlark.format(
                 "invalid value %r in 'label_dict': expected iterable, but got '%s'",
                 val, EvalUtils.getDataTypeName(val)));
       }
       for (Object file : valIter) {
         if (!(file instanceof Artifact)) {
-          throw new EvalException(loc, Printer.format("invalid value %r in 'label_dict'", val));
+          throw new EvalException(loc, Starlark.format("invalid value %r in 'label_dict'", val));
         }
         files.add((Artifact) file);
       }
diff --git a/src/main/java/com/google/devtools/build/lib/packages/BuildType.java b/src/main/java/com/google/devtools/build/lib/packages/BuildType.java
index 4d68711..3f3bea7 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/BuildType.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/BuildType.java
@@ -557,7 +557,7 @@
 
     @Override
     public String toString() {
-      return Printer.repr(this);
+      return Starlark.repr(this);
     }
 
     @Override
diff --git a/src/main/java/com/google/devtools/build/lib/packages/StructImpl.java b/src/main/java/com/google/devtools/build/lib/packages/StructImpl.java
index 835d9b6..c08e892 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/StructImpl.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/StructImpl.java
@@ -27,7 +27,6 @@
 import com.google.devtools.build.lib.syntax.Dict;
 import com.google.devtools.build.lib.syntax.EvalException;
 import com.google.devtools.build.lib.syntax.EvalUtils;
-import com.google.devtools.build.lib.syntax.Printer;
 import com.google.devtools.build.lib.syntax.Sequence;
 import com.google.devtools.build.lib.syntax.SkylarkType;
 import com.google.devtools.build.lib.syntax.Starlark;
@@ -359,6 +358,6 @@
 
   @Override
   public String toString() {
-    return Printer.repr(this);
+    return Starlark.repr(this);
   }
 }
diff --git a/src/main/java/com/google/devtools/build/lib/rules/config/ConfigFeatureFlag.java b/src/main/java/com/google/devtools/build/lib/rules/config/ConfigFeatureFlag.java
index b08f496..2a8ce3e 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/config/ConfigFeatureFlag.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/config/ConfigFeatureFlag.java
@@ -38,7 +38,7 @@
 import com.google.devtools.build.lib.packages.Attribute;
 import com.google.devtools.build.lib.packages.Attribute.ComputedDefault;
 import com.google.devtools.build.lib.packages.AttributeMap;
-import com.google.devtools.build.lib.syntax.Printer;
+import com.google.devtools.build.lib.syntax.Starlark;
 import java.util.List;
 import java.util.Optional;
 
@@ -113,7 +113,7 @@
       ruleContext.attributeError(
           "allowed_values",
           "cannot contain duplicates, but contained multiple of "
-              + Printer.repr(duplicates.build()));
+              + Starlark.repr(duplicates.build()));
     }
 
     Optional<String> defaultValue =
@@ -124,9 +124,9 @@
       ruleContext.attributeError(
           "default_value",
           "must be one of "
-              + Printer.repr(values.asList())
+              + Starlark.repr(values.asList())
               + ", but was "
-              + Printer.repr(defaultValue.get()));
+              + Starlark.repr(defaultValue.get()));
     }
 
     if (ruleContext.hasErrors()) {
@@ -144,9 +144,9 @@
       // TODO(b/140635901): When configurationError is available, use that instead.
       ruleContext.ruleError(
           "value must be one of "
-              + Printer.repr(values.asList())
+              + Starlark.repr(values.asList())
               + ", but was "
-              + Printer.repr(configuredValue.get()));
+              + Starlark.repr(configuredValue.get()));
       return null;
     }
 
diff --git a/src/main/java/com/google/devtools/build/lib/skylarkdebug/server/DebuggerSerialization.java b/src/main/java/com/google/devtools/build/lib/skylarkdebug/server/DebuggerSerialization.java
index 7a7bf91..2fc14b6 100644
--- a/src/main/java/com/google/devtools/build/lib/skylarkdebug/server/DebuggerSerialization.java
+++ b/src/main/java/com/google/devtools/build/lib/skylarkdebug/server/DebuggerSerialization.java
@@ -26,7 +26,7 @@
 import com.google.devtools.build.lib.syntax.EvalException;
 import com.google.devtools.build.lib.syntax.EvalUtils;
 import com.google.devtools.build.lib.syntax.MethodDescriptor;
-import com.google.devtools.build.lib.syntax.Printer;
+import com.google.devtools.build.lib.syntax.Starlark;
 import java.lang.reflect.Array;
 import java.util.Map;
 import java.util.Set;
@@ -51,7 +51,7 @@
     if (value instanceof String) {
       return (String) value;
     }
-    return Printer.repr(value);
+    return Starlark.repr(value);
   }
 
   private static boolean hasChildren(Object value) {
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/BaseFunction.java b/src/main/java/com/google/devtools/build/lib/syntax/BaseFunction.java
index ba44c34..aa86f4b 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/BaseFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/BaseFunction.java
@@ -347,7 +347,7 @@
 
   private String printDefaultValue(int i) {
     Object v = defaultValues != null ? defaultValues.get(i) : null;
-    return v != null ? Printer.repr(v) : null;
+    return v != null ? Starlark.repr(v) : null;
   }
 
   @Override
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/Depset.java b/src/main/java/com/google/devtools/build/lib/syntax/Depset.java
index 2fe96a8..30f6251 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/Depset.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/Depset.java
@@ -353,7 +353,7 @@
 
   @Override
   public String toString() {
-    return Printer.repr(this);
+    return Starlark.repr(this);
   }
 
   public Order getOrder() {
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/Dict.java b/src/main/java/com/google/devtools/build/lib/syntax/Dict.java
index bbe71ef..31e3c8e 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/Dict.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/Dict.java
@@ -165,7 +165,7 @@
     if (defaultValue != Starlark.UNBOUND) {
       return defaultValue;
     }
-    throw new EvalException(loc, Printer.format("KeyError: %r", key));
+    throw new EvalException(loc, Starlark.format("KeyError: %r", key));
   }
 
   @SkylarkCallable(
@@ -426,7 +426,7 @@
 
   @Override
   public String toString() {
-    return Printer.repr(this);
+    return Starlark.repr(this);
   }
 
   /**
@@ -454,7 +454,7 @@
         null,
         String.format(
             "%s is not of expected type dict or NoneType",
-            description == null ? Printer.repr(obj) : String.format("'%s'", description)));
+            description == null ? Starlark.repr(obj) : String.format("'%s'", description)));
   }
 
   /**
@@ -480,10 +480,10 @@
   @SuppressWarnings("unchecked")
   public <X, Y> Map<X, Y> getContents(
       Class<X> keyType, Class<Y> valueType, @Nullable String description) throws EvalException {
-    Object keyDescription = description == null
-        ? null : Printer.formattable("'%s' key", description);
-    Object valueDescription = description == null
-        ? null : Printer.formattable("'%s' value", description);
+    Object keyDescription =
+        description == null ? null : Printer.formattable("'%s' key", description);
+    Object valueDescription =
+        description == null ? null : Printer.formattable("'%s' value", description);
     for (Map.Entry<?, ?> e : this.entrySet()) {
       SkylarkType.checkType(e.getKey(), keyType, keyDescription);
       if (e.getValue() != null) {
@@ -496,7 +496,7 @@
   @Override
   public final Object getIndex(Object key, Location loc) throws EvalException {
     if (!this.containsKey(key)) {
-      throw new EvalException(loc, Printer.format("key %r not found in dictionary", key));
+      throw new EvalException(loc, Starlark.format("key %r not found in dictionary", key));
     }
     return this.get(key);
   }
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/Eval.java b/src/main/java/com/google/devtools/build/lib/syntax/Eval.java
index 82f615e..25d450b 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/Eval.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/Eval.java
@@ -450,7 +450,7 @@
             dict.put(k, v, loc);
             if (dict.size() == before) {
               throw new EvalException(
-                  loc, "Duplicated key " + Printer.repr(k) + " when creating dictionary");
+                  loc, "Duplicated key " + Starlark.repr(k) + " when creating dictionary");
             }
           }
           return dict;
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/EvalUtils.java b/src/main/java/com/google/devtools/build/lib/syntax/EvalUtils.java
index bca1cc9..1043d7e3 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/EvalUtils.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/EvalUtils.java
@@ -114,7 +114,7 @@
   static void checkHashable(Object x) throws EvalException {
     if (!isHashable(x)) {
       throw new EvalException(
-          null, Printer.format("unhashable type: '%s'", EvalUtils.getDataTypeName(x)));
+          null, Starlark.format("unhashable type: '%s'", EvalUtils.getDataTypeName(x)));
     }
   }
 
@@ -796,9 +796,9 @@
       String pattern = (String) x;
       try {
         if (y instanceof Tuple) {
-          return Printer.formatWithList(pattern, (Tuple) y);
+          return Starlark.formatWithList(pattern, (Tuple) y);
         }
-        return Printer.format(pattern, y);
+        return Starlark.format(pattern, y);
       } catch (IllegalFormatException e) {
         throw new EvalException(location, e.getMessage());
       }
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/MethodLibrary.java b/src/main/java/com/google/devtools/build/lib/syntax/MethodLibrary.java
index bb746ec..954edc8 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/MethodLibrary.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/MethodLibrary.java
@@ -241,7 +241,7 @@
       }
     } else {
       throw new EvalException(
-          loc, Printer.format("%r object is not callable", EvalUtils.getDataTypeName(key)));
+          loc, Starlark.format("%r object is not callable", EvalUtils.getDataTypeName(key)));
     }
 
     if (reverse) {
@@ -366,7 +366,7 @@
       useLocation = true)
   public String str(Object x, Location loc) throws EvalException {
     try {
-      return Printer.str(x);
+      return Starlark.str(x);
     } catch (NestedSetDepthException exception) {
       throw new EvalException(
           loc,
@@ -393,7 +393,7 @@
             noneable = true)
       })
   public String repr(Object x) {
-    return Printer.repr(x);
+    return Starlark.repr(x);
   }
 
   @SkylarkCallable(
@@ -496,7 +496,7 @@
       } else if (x instanceof Integer) {
         return (Integer) x;
       }
-      throw new EvalException(loc, Printer.format("%r is not of type string or int or bool", x));
+      throw new EvalException(loc, Starlark.format("%r is not of type string or int or bool", x));
     }
   }
 
@@ -505,7 +505,7 @@
 
     boolean isNegative = false;
     if (string.isEmpty()) {
-      throw new EvalException(loc, Printer.format("string argument to int() cannot be empty"));
+      throw new EvalException(loc, Starlark.format("string argument to int() cannot be empty"));
     }
     char c = string.charAt(0);
     if (c == '+') {
@@ -526,7 +526,7 @@
           // to confusion between octal and decimal).
           throw new EvalException(
               loc,
-              Printer.format(
+              Starlark.format(
                   "cannot infer base for int() when value begins with a 0: %r", stringForErrors));
         }
         base = 10;
@@ -541,7 +541,7 @@
       } else if (base != expectedBase) {
         throw new EvalException(
             loc,
-            Printer.format("invalid literal for int() with base %d: %r", base, stringForErrors));
+            Starlark.format("invalid literal for int() with base %d: %r", base, stringForErrors));
       }
     }
 
@@ -556,7 +556,7 @@
     } catch (NumberFormatException | ArithmeticException e) {
       throw new EvalException(
           loc,
-          Printer.format("invalid literal for int() with base %d: %r", base, stringForErrors),
+          Starlark.format("invalid literal for int() with base %d: %r", base, stringForErrors),
           e);
     }
   }
@@ -840,7 +840,7 @@
       },
       useLocation = true)
   public NoneType fail(Object msg, Object attr, Location loc) throws EvalException {
-    String str = Printer.str(msg);
+    String str = Starlark.str(msg);
     if (attr != Starlark.NONE) {
       str = String.format("attribute %s: %s", attr, str);
     }
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/Mutability.java b/src/main/java/com/google/devtools/build/lib/syntax/Mutability.java
index 7d7c015..b6efa89 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/Mutability.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/Mutability.java
@@ -239,7 +239,7 @@
     List<Location> locList = lockedItems.get(object);
     if (!locList.remove(loc)) {
       throw new IllegalArgumentException(
-          Printer.format(
+          Starlark.format(
               "trying to unlock an object for a location at which it was not locked (%r)", loc));
     }
     if (locList.isEmpty()) {
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/Printer.java b/src/main/java/com/google/devtools/build/lib/syntax/Printer.java
index 3d1c297..7e4548b 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/Printer.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/Printer.java
@@ -71,53 +71,12 @@
 
   // These static methods proxy to the similar methods of BasePrinter
 
-  /**
-   * Format an object with Skylark's {@code debugPrint}.
-   */
-  public static String debugPrint(Object x) {
+  /** Format an object with Skylark's {@code debugPrint}. */
+  static String debugPrint(Object x) {
     return getPrinter().debugPrint(x).toString();
   }
 
   /**
-   * Format an object with Skylark's {@code str}.
-   */
-  public static String str(Object x) {
-    return getPrinter().str(x).toString();
-  }
-
-  /**
-   * Format an object with Skylark's {@code repr}.
-   */
-  public static String repr(Object x) {
-    return getPrinter().repr(x).toString();
-  }
-
-
-  /**
-   * Perform Python-style string formatting, as per pattern % tuple Limitations: only %d %s %r %%
-   * are supported.
-   *
-   * @param pattern a format string.
-   * @param arguments an array containing positional arguments.
-   * @return the formatted string.
-   */
-  public static String format(String pattern, Object... arguments) {
-    return getPrinter().format(pattern, arguments).toString();
-  }
-
-  /**
-   * Perform Python-style string formatting, as per pattern % tuple Limitations: only %d %s %r %%
-   * are supported.
-   *
-   * @param pattern a format string.
-   * @param arguments a tuple containing positional arguments.
-   * @return the formatted string.
-   */
-  public static String formatWithList(String pattern, List<?> arguments) {
-    return getPrinter().formatWithList(pattern, arguments).toString();
-  }
-
-  /**
    * Perform Python-style string formatting, lazily.
    *
    * @param pattern a format string.
@@ -129,7 +88,7 @@
     return new Formattable() {
       @Override
       public String toString() {
-        return formatWithList(pattern, args);
+        return Starlark.formatWithList(pattern, args);
       }
 
       @Override
@@ -505,9 +464,9 @@
             if (a >= argLength) {
               throw new MissingFormatWidthException(
                   "not enough arguments for format pattern "
-                      + Printer.repr(pattern)
+                      + Starlark.repr(pattern)
                       + ": "
-                      + Printer.repr(Tuple.copyOf(arguments)));
+                      + Starlark.repr(Tuple.copyOf(arguments)));
             }
             Object argument = arguments.get(a++);
             switch (directive) {
@@ -517,7 +476,7 @@
                   continue;
                 } else {
                   throw new MissingFormatWidthException(
-                      "invalid argument " + Printer.repr(argument) + " for format pattern %d");
+                      "invalid argument " + Starlark.repr(argument) + " for format pattern %d");
                 }
               case 'r':
                 this.repr(argument);
@@ -529,10 +488,11 @@
             // fall through
           default:
             throw new MissingFormatWidthException(
-                // The call to Printer.repr doesn't cause an infinite recursion because it's
+                // The call to Starlark.repr doesn't cause an infinite recursion because it's
                 // only used to format a string properly
-                String.format("unsupported format character \"%s\" at index %s in %s",
-                    String.valueOf(directive), p + 1, Printer.repr(pattern)));
+                String.format(
+                    "unsupported format character \"%s\" at index %s in %s",
+                    String.valueOf(directive), p + 1, Starlark.repr(pattern)));
         }
       }
       if (a < argLength) {
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/SelectorList.java b/src/main/java/com/google/devtools/build/lib/syntax/SelectorList.java
index 2a72bcd..f50d01e 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/SelectorList.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/SelectorList.java
@@ -164,7 +164,7 @@
 
   @Override
   public String toString() {
-    return Printer.repr(this);
+    return Starlark.repr(this);
   }
 
   @Override
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/SelectorValue.java b/src/main/java/com/google/devtools/build/lib/syntax/SelectorValue.java
index 95ef764..c4bd73d 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/SelectorValue.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/SelectorValue.java
@@ -73,7 +73,7 @@
 
   @Override
   public String toString() {
-    return Printer.repr(this);
+    return Starlark.repr(this);
   }
 
   @Override
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/Sequence.java b/src/main/java/com/google/devtools/build/lib/syntax/Sequence.java
index ae23070..9c1ce2b 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/Sequence.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/Sequence.java
@@ -120,9 +120,11 @@
     if (obj instanceof Sequence) {
       return ((Sequence<?>) obj).getContents(type, description);
     }
-    throw new EvalException(null,
-        String.format("Illegal argument: %s is not of expected type list or NoneType",
-            description == null ? Printer.repr(obj) : String.format("'%s'", description)));
+    throw new EvalException(
+        null,
+        String.format(
+            "Illegal argument: %s is not of expected type list or NoneType",
+            description == null ? Starlark.repr(obj) : String.format("'%s'", description)));
   }
 
   /**
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/SkylarkSignatureProcessor.java b/src/main/java/com/google/devtools/build/lib/syntax/SkylarkSignatureProcessor.java
index 2bf7914..e6d7222 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/SkylarkSignatureProcessor.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/SkylarkSignatureProcessor.java
@@ -252,7 +252,7 @@
               + " %s",
           name,
           param.name(),
-          Printer.repr(defaultValue),
+          Starlark.repr(defaultValue),
           enforcedType);
     }
     return officialType;
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/SkylarkType.java b/src/main/java/com/google/devtools/build/lib/syntax/SkylarkType.java
index b6d8f3f..abf654b 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/SkylarkType.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/SkylarkType.java
@@ -692,7 +692,7 @@
     if (!type.isInstance(object)) {
       throw new EvalException(
           null,
-          Printer.format(
+          Starlark.format(
               "expected type '%r' %sbut got type '%s' instead",
               type,
               description == null ? "" : String.format("for %s ", description),
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/Starlark.java b/src/main/java/com/google/devtools/build/lib/syntax/Starlark.java
index 79214b2..338bb6f 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/Starlark.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/Starlark.java
@@ -142,6 +142,26 @@
     }
   }
 
+  /** Returns the string form of a value as if by the Starlark expression {@code str(x)}. */
+  public static String str(Object x) {
+    return Printer.getPrinter().str(x).toString();
+  }
+
+  /** Returns the string form of a value as if by the Starlark expression {@code repr(x)}. */
+  public static String repr(Object x) {
+    return Printer.getPrinter().repr(x).toString();
+  }
+
+  /** Returns a string formatted as if by the Starlark expression {@code pattern % arguments}. */
+  public static String format(String pattern, Object... arguments) {
+    return Printer.getPrinter().format(pattern, arguments).toString();
+  }
+
+  /** Returns a string formatted as if by the Starlark expression {@code pattern % arguments}. */
+  public static String formatWithList(String pattern, List<?> arguments) {
+    return Printer.getPrinter().formatWithList(pattern, arguments).toString();
+  }
+
   /**
    * Adds to the environment {@code env} all {@code StarlarkCallable}-annotated fields and methods
    * of value {@code v}. The class of {@code v} must have or inherit a {@code SkylarkModule} or
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/StarlarkList.java b/src/main/java/com/google/devtools/build/lib/syntax/StarlarkList.java
index 998b302..411de33 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/StarlarkList.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/StarlarkList.java
@@ -194,7 +194,7 @@
   // TODO(adonovan): SkylarkValue has 3 String methods yet still we need this fourth. Why?
   @Override
   public String toString() {
-    return Printer.repr(this);
+    return Starlark.repr(this);
   }
 
   /** Returns a new StarlarkList containing n consecutive repeats of this tuple. */
@@ -334,7 +334,7 @@
         return Starlark.NONE;
       }
     }
-    throw new EvalException(loc, Printer.format("item %r not found in list", x));
+    throw new EvalException(loc, Starlark.format("item %r not found in list", x));
   }
 
   /**
@@ -433,7 +433,7 @@
         return i;
       }
     }
-    throw new EvalException(loc, Printer.format("item %r not found in list", x));
+    throw new EvalException(loc, Starlark.format("item %r not found in list", x));
   }
 
   @SkylarkCallable(
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/StarlarkThread.java b/src/main/java/com/google/devtools/build/lib/syntax/StarlarkThread.java
index 95e82bc..3731194 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/StarlarkThread.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/StarlarkThread.java
@@ -384,7 +384,7 @@
       return obj1.equals(obj2)
           || (obj1 instanceof SkylarkValue
               && obj2 instanceof SkylarkValue
-              && Printer.repr(obj1).equals(Printer.repr(obj2)));
+              && Starlark.repr(obj1).equals(Starlark.repr(obj2)));
     }
 
     /**
@@ -456,10 +456,10 @@
             String.format(
                 "%s: this one has %s (class %s, %s), but given one has %s (class %s, %s)",
                 name,
-                Printer.repr(value),
+                Starlark.repr(value),
                 value.getClass().getName(),
                 value,
-                Printer.repr(otherValue),
+                Starlark.repr(otherValue),
                 otherValue.getClass().getName(),
                 otherValue));
       }
@@ -795,7 +795,7 @@
       // imported from a parent StarlarkThread by updating the current StarlarkThread, which will
       // not trigger a MutabilityException.
       throw new AssertionError(
-          Printer.format("Can't update %s to %r in frozen environment", varname, value), e);
+          Starlark.format("Can't update %s to %r in frozen environment", varname, value), e);
     }
     return this;
   }
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/StringModule.java b/src/main/java/com/google/devtools/build/lib/syntax/StringModule.java
index 0931fbc..d769c70 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/StringModule.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/StringModule.java
@@ -703,7 +703,7 @@
       throws EvalException {
     int res = stringFind(false, self, sub, start, end, "'end' argument to rindex");
     if (res < 0) {
-      throw new EvalException(loc, Printer.format("substring %r not found in %r", sub, self));
+      throw new EvalException(loc, Starlark.format("substring %r not found in %r", sub, self));
     }
     return res;
   }
@@ -743,7 +743,7 @@
       throws EvalException {
     int res = stringFind(true, self, sub, start, end, "'end' argument to index");
     if (res < 0) {
-      throw new EvalException(loc, Printer.format("substring %r not found in %r", sub, self));
+      throw new EvalException(loc, Starlark.format("substring %r not found in %r", sub, self));
     }
     return res;
   }
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/Tuple.java b/src/main/java/com/google/devtools/build/lib/syntax/Tuple.java
index dbee242..b0bad85 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/Tuple.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/Tuple.java
@@ -172,7 +172,7 @@
   // TODO(adonovan): SkylarkValue has 3 String methods yet still we need this fourth. Why?
   @Override
   public String toString() {
-    return Printer.repr(this);
+    return Starlark.repr(this);
   }
 
   @Override
diff --git a/src/main/java/com/google/devtools/starlark/Starlark.java b/src/main/java/com/google/devtools/starlark/Starlark.java
index a42fb0c..9c62c34 100644
--- a/src/main/java/com/google/devtools/starlark/Starlark.java
+++ b/src/main/java/com/google/devtools/starlark/Starlark.java
@@ -21,7 +21,6 @@
 import com.google.devtools.build.lib.syntax.Module;
 import com.google.devtools.build.lib.syntax.Mutability;
 import com.google.devtools.build.lib.syntax.ParserInput;
-import com.google.devtools.build.lib.syntax.Printer;
 import com.google.devtools.build.lib.syntax.StarlarkThread;
 import com.google.devtools.build.lib.syntax.SyntaxError;
 import java.io.BufferedReader;
@@ -103,7 +102,7 @@
       try {
         Object result = EvalUtils.execAndEvalOptionalFinalExpression(input, thread);
         if (result != null) {
-          System.out.println(Printer.repr(result));
+          System.out.println(com.google.devtools.build.lib.syntax.Starlark.repr(result));
         }
       } catch (SyntaxError ex) {
         for (Event ev : ex.errors()) {
diff --git a/src/test/java/com/google/devtools/build/lib/packages/BuildTypeTest.java b/src/test/java/com/google/devtools/build/lib/packages/BuildTypeTest.java
index b8f7cce..b18a701 100644
--- a/src/test/java/com/google/devtools/build/lib/packages/BuildTypeTest.java
+++ b/src/test/java/com/google/devtools/build/lib/packages/BuildTypeTest.java
@@ -29,9 +29,9 @@
 import com.google.devtools.build.lib.packages.Type.ConversionException;
 import com.google.devtools.build.lib.syntax.EvalException;
 import com.google.devtools.build.lib.syntax.EvalUtils;
-import com.google.devtools.build.lib.syntax.Printer;
 import com.google.devtools.build.lib.syntax.SelectorList;
 import com.google.devtools.build.lib.syntax.SelectorValue;
+import com.google.devtools.build.lib.syntax.Starlark;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
@@ -655,7 +655,7 @@
     // with a List<Label> even though this isn't a valid datatype in the
     // interpreter.
     // Fileset isn't part of bazel, even though FilesetEntry is.
-    assertThat(Printer.repr(createTestFilesetEntry()))
+    assertThat(Starlark.repr(createTestFilesetEntry()))
         .isEqualTo(createExpectedFilesetEntryString('"'));
   }
 
@@ -664,7 +664,7 @@
     FilesetEntry entryDereference =
       createTestFilesetEntry(FilesetEntry.SymlinkBehavior.DEREFERENCE);
 
-    assertThat(Printer.repr(entryDereference))
+    assertThat(Starlark.repr(entryDereference))
         .isEqualTo(createExpectedFilesetEntryString(FilesetEntry.SymlinkBehavior.DEREFERENCE, '"'));
   }
 
@@ -684,8 +684,8 @@
     FilesetEntry withoutStripPrefix = createStripPrefixFilesetEntry(".");
     FilesetEntry withStripPrefix = createStripPrefixFilesetEntry("orange");
 
-    String prettyWithout = Printer.repr(withoutStripPrefix);
-    String prettyWith = Printer.repr(withStripPrefix);
+    String prettyWithout = Starlark.repr(withoutStripPrefix);
+    String prettyWith = Starlark.repr(withStripPrefix);
 
     assertThat(prettyWithout).contains("strip_prefix = \".\"");
     assertThat(prettyWith).contains("strip_prefix = \"orange\"");
@@ -694,7 +694,7 @@
   @Test
   public void testPrintFilesetEntry() throws Exception {
     assertThat(
-            Printer.repr(
+            Starlark.repr(
                 new FilesetEntry(
                     /* srcLabel */ Label.parseAbsolute("//foo:BUILD", ImmutableMap.of()),
                     /* files */ ImmutableList.of(
diff --git a/src/test/java/com/google/devtools/build/lib/packages/SkylarkProviderTest.java b/src/test/java/com/google/devtools/build/lib/packages/SkylarkProviderTest.java
index 6eeba19..842625e 100644
--- a/src/test/java/com/google/devtools/build/lib/packages/SkylarkProviderTest.java
+++ b/src/test/java/com/google/devtools/build/lib/packages/SkylarkProviderTest.java
@@ -23,7 +23,7 @@
 import com.google.devtools.build.lib.cmdline.Label;
 import com.google.devtools.build.lib.packages.SkylarkProvider.SkylarkKey;
 import com.google.devtools.build.lib.syntax.Mutability;
-import com.google.devtools.build.lib.syntax.Printer;
+import com.google.devtools.build.lib.syntax.Starlark;
 import com.google.devtools.build.lib.syntax.StarlarkThread;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -42,7 +42,7 @@
     assertThat(provider.getErrorMessageFormatForUnknownField())
         .isEqualTo("Object has no '%s' attribute.");
     assertThat(provider.isImmutable()).isFalse();
-    assertThat(Printer.repr(provider)).isEqualTo("<provider>");
+    assertThat(Starlark.repr(provider)).isEqualTo("<provider>");
     assertThrows(
         IllegalStateException.class,
         () -> provider.getKey());
@@ -59,7 +59,7 @@
     assertThat(provider.getErrorMessageFormatForUnknownField())
         .isEqualTo("'prov' object has no attribute '%s'");
     assertThat(provider.isImmutable()).isTrue();
-    assertThat(Printer.repr(provider)).isEqualTo("<provider>");
+    assertThat(Starlark.repr(provider)).isEqualTo("<provider>");
     assertThat(provider.getKey()).isEqualTo(key);
   }
 
diff --git a/src/test/java/com/google/devtools/build/lib/packages/util/PackageFactoryTestBase.java b/src/test/java/com/google/devtools/build/lib/packages/util/PackageFactoryTestBase.java
index c79eda7..adfd8b7 100644
--- a/src/test/java/com/google/devtools/build/lib/packages/util/PackageFactoryTestBase.java
+++ b/src/test/java/com/google/devtools/build/lib/packages/util/PackageFactoryTestBase.java
@@ -33,7 +33,7 @@
 import com.google.devtools.build.lib.packages.Package;
 import com.google.devtools.build.lib.packages.RawAttributeMapper;
 import com.google.devtools.build.lib.packages.Rule;
-import com.google.devtools.build.lib.syntax.Printer;
+import com.google.devtools.build.lib.syntax.Starlark;
 import com.google.devtools.build.lib.testutil.Scratch;
 import com.google.devtools.build.lib.testutil.TestUtils;
 import com.google.devtools.build.lib.util.Pair;
@@ -206,7 +206,7 @@
             includes,
             excludes,
             excludeDirs,
-            Printer.format("(result == sorted(%r)) or fail('incorrect glob result')", result));
+            Starlark.format("(result == sorted(%r)) or fail('incorrect glob result')", result));
 
     Package pkg = evaluated.first;
     GlobCache globCache = evaluated.second;
@@ -238,7 +238,7 @@
     Path file =
         scratch.file(
             "/globs/BUILD",
-            Printer.format(
+            Starlark.format(
                 "result = glob(%r, exclude=%r, exclude_directories=%r)",
                 includes, excludes, excludeDirs ? 1 : 0),
             resultAssertion);
diff --git a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java
index e6615d0..340745f 100644
--- a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java
@@ -645,7 +645,7 @@
   private void assertMatches(String description, String expectedPattern, String computedValue)
       throws Exception {
     assertWithMessage(
-            Printer.format(
+            Starlark.format(
                 "%s %r did not match pattern '%s'", description, computedValue, expectedPattern))
         .that(Pattern.matches(expectedPattern, computedValue))
         .isTrue();
@@ -2900,7 +2900,7 @@
     setRuleContext(createRuleContext("//foo:foo"));
     exec("args = ruleContext.actions.args()", "args.add_all(['--foo', '--bar'])");
     Args args = (Args) eval("args");
-    assertThat(Printer.debugPrint(args)).isEqualTo("--foo --bar");
+    assertThat(Printer.getPrinter().debugPrint(args).toString()).isEqualTo("--foo --bar");
   }
 
   @Test
diff --git a/src/test/java/com/google/devtools/build/lib/skylarkdebug/server/DebuggerSerializationTest.java b/src/test/java/com/google/devtools/build/lib/skylarkdebug/server/DebuggerSerializationTest.java
index 74707f3..b0bfbed 100644
--- a/src/test/java/com/google/devtools/build/lib/skylarkdebug/server/DebuggerSerializationTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skylarkdebug/server/DebuggerSerializationTest.java
@@ -28,7 +28,7 @@
 import com.google.devtools.build.lib.skylarkinterface.SkylarkValue;
 import com.google.devtools.build.lib.syntax.Depset;
 import com.google.devtools.build.lib.syntax.EvalUtils;
-import com.google.devtools.build.lib.syntax.Printer;
+import com.google.devtools.build.lib.syntax.Starlark;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -263,7 +263,7 @@
 
   private static void assertTypeAndDescription(Object object, Value value) {
     assertThat(value.getType()).isEqualTo(EvalUtils.getDataTypeName(object));
-    assertThat(value.getDescription()).isEqualTo(Printer.repr(object));
+    assertThat(value.getDescription()).isEqualTo(Starlark.repr(object));
   }
 
   /**
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/BaseFunctionTest.java b/src/test/java/com/google/devtools/build/lib/syntax/BaseFunctionTest.java
index c0b00d1..8c69e45 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/BaseFunctionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/BaseFunctionTest.java
@@ -146,18 +146,15 @@
             + "b1 = bar(name='foo', type='jpg', version=42)\n"
             + "b2 = bar()\n");
 
-    assertThat(Printer.repr(lookup("v1")))
-        .isEqualTo("(1, 2, 3, 4, 7, 8, (), {})");
-    assertThat(Printer.repr(lookup("v2")))
+    assertThat(Starlark.repr(lookup("v1"))).isEqualTo("(1, 2, 3, 4, 7, 8, (), {})");
+    assertThat(Starlark.repr(lookup("v2")))
         .isEqualTo("(1, \"x\", \"y\", \"z\", \"t\", 9, (), {\"i\": 0})");
-    assertThat(Printer.repr(lookup("v3")))
-        .isEqualTo("(1, 2, 3, 4, 5, 6, (7, 8), {\"i\": 0})");
+    assertThat(Starlark.repr(lookup("v3"))).isEqualTo("(1, 2, 3, 4, 5, 6, (7, 8), {\"i\": 0})");
 
     // NB: the conversion to a TreeMap below ensures the keys are sorted.
-    assertThat(Printer.repr(
-        new TreeMap<String, Object>((Map<String, Object>) lookup("b1"))))
+    assertThat(Starlark.repr(new TreeMap<String, Object>((Map<String, Object>) lookup("b1"))))
         .isEqualTo("{\"name\": \"foo\", \"type\": \"jpg\", \"version\": 42}");
-    assertThat(Printer.repr(lookup("b2"))).isEqualTo("{}");
+    assertThat(Starlark.repr(lookup("b2"))).isEqualTo("{}");
   }
 
   @Test
@@ -171,9 +168,9 @@
             + "v3 = f(a=1,)\n"
             + "v4 = f(**{\"a\": 1},)\n");
 
-    assertThat(Printer.repr(lookup("v1"))).isEqualTo("None");
-    assertThat(Printer.repr(lookup("v2"))).isEqualTo("None");
-    assertThat(Printer.repr(lookup("v3"))).isEqualTo("None");
-    assertThat(Printer.repr(lookup("v4"))).isEqualTo("None");
+    assertThat(Starlark.repr(lookup("v1"))).isEqualTo("None");
+    assertThat(Starlark.repr(lookup("v2"))).isEqualTo("None");
+    assertThat(Starlark.repr(lookup("v3"))).isEqualTo("None");
+    assertThat(Starlark.repr(lookup("v4"))).isEqualTo("None");
   }
 }
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/PrinterTest.java b/src/test/java/com/google/devtools/build/lib/syntax/PrinterTest.java
index 38e8591..97e9d1a 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/PrinterTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/PrinterTest.java
@@ -41,44 +41,44 @@
   public void testPrinter() throws Exception {
     // Note that prettyPrintValue and printValue only differ on behaviour of
     // labels and strings at toplevel.
-    assertThat(Printer.str(createObjWithStr())).isEqualTo("<str marker>");
-    assertThat(Printer.repr(createObjWithStr())).isEqualTo("<repr marker>");
+    assertThat(Starlark.str(createObjWithStr())).isEqualTo("<str marker>");
+    assertThat(Starlark.repr(createObjWithStr())).isEqualTo("<repr marker>");
 
-    assertThat(Printer.str("foo\nbar")).isEqualTo("foo\nbar");
-    assertThat(Printer.repr("foo\nbar")).isEqualTo("\"foo\\nbar\"");
-    assertThat(Printer.str("'")).isEqualTo("'");
-    assertThat(Printer.repr("'")).isEqualTo("\"'\"");
-    assertThat(Printer.str("\"")).isEqualTo("\"");
-    assertThat(Printer.repr("\"")).isEqualTo("\"\\\"\"");
-    assertThat(Printer.str(3)).isEqualTo("3");
-    assertThat(Printer.repr(3)).isEqualTo("3");
-    assertThat(Printer.repr(Starlark.NONE)).isEqualTo("None");
+    assertThat(Starlark.str("foo\nbar")).isEqualTo("foo\nbar");
+    assertThat(Starlark.repr("foo\nbar")).isEqualTo("\"foo\\nbar\"");
+    assertThat(Starlark.str("'")).isEqualTo("'");
+    assertThat(Starlark.repr("'")).isEqualTo("\"'\"");
+    assertThat(Starlark.str("\"")).isEqualTo("\"");
+    assertThat(Starlark.repr("\"")).isEqualTo("\"\\\"\"");
+    assertThat(Starlark.str(3)).isEqualTo("3");
+    assertThat(Starlark.repr(3)).isEqualTo("3");
+    assertThat(Starlark.repr(Starlark.NONE)).isEqualTo("None");
 
-    assertThat(Printer.str(Label.parseAbsolute("//x", ImmutableMap.of()))).isEqualTo("//x:x");
-    assertThat(Printer.repr(Label.parseAbsolute("//x", ImmutableMap.of())))
+    assertThat(Starlark.str(Label.parseAbsolute("//x", ImmutableMap.of()))).isEqualTo("//x:x");
+    assertThat(Starlark.repr(Label.parseAbsolute("//x", ImmutableMap.of())))
         .isEqualTo("Label(\"//x:x\")");
 
     List<?> list = StarlarkList.of(null, "foo", "bar");
     List<?> tuple = Tuple.of("foo", "bar");
 
-    assertThat(Printer.str(Tuple.of(1, list, 3))).isEqualTo("(1, [\"foo\", \"bar\"], 3)");
-    assertThat(Printer.repr(Tuple.of(1, list, 3))).isEqualTo("(1, [\"foo\", \"bar\"], 3)");
-    assertThat(Printer.str(StarlarkList.of(null, 1, tuple, 3)))
+    assertThat(Starlark.str(Tuple.of(1, list, 3))).isEqualTo("(1, [\"foo\", \"bar\"], 3)");
+    assertThat(Starlark.repr(Tuple.of(1, list, 3))).isEqualTo("(1, [\"foo\", \"bar\"], 3)");
+    assertThat(Starlark.str(StarlarkList.of(null, 1, tuple, 3)))
         .isEqualTo("[1, (\"foo\", \"bar\"), 3]");
-    assertThat(Printer.repr(StarlarkList.of(null, 1, tuple, 3)))
+    assertThat(Starlark.repr(StarlarkList.of(null, 1, tuple, 3)))
         .isEqualTo("[1, (\"foo\", \"bar\"), 3]");
 
     Map<Object, Object> dict =
         ImmutableMap.<Object, Object>of(1, tuple, 2, list, "foo", StarlarkList.of(null));
-    assertThat(Printer.str(dict))
+    assertThat(Starlark.str(dict))
         .isEqualTo("{1: (\"foo\", \"bar\"), 2: [\"foo\", \"bar\"], \"foo\": []}");
-    assertThat(Printer.repr(dict))
+    assertThat(Starlark.repr(dict))
         .isEqualTo("{1: (\"foo\", \"bar\"), 2: [\"foo\", \"bar\"], \"foo\": []}");
   }
 
   private void checkFormatPositionalFails(String errorMessage, String format, Object... arguments) {
     IllegalFormatException e =
-        assertThrows(IllegalFormatException.class, () -> Printer.format(format, arguments));
+        assertThrows(IllegalFormatException.class, () -> Starlark.format(format, arguments));
     assertThat(e).hasMessageThat().isEqualTo(errorMessage);
   }
 
@@ -89,33 +89,33 @@
     map.put(3, 3);
     map.put("foo", 42);
     map.put(7, "bar");
-    assertThat(Printer.str(map)).isEqualTo("{5: 5, 3: 3, \"foo\": 42, 7: \"bar\"}");
+    assertThat(Starlark.str(map)).isEqualTo("{5: 5, 3: 3, \"foo\": 42, 7: \"bar\"}");
   }
 
   @Test
   public void testFormatPositional() throws Exception {
-    assertThat(Printer.formatWithList("%s %d", Tuple.of("foo", 3))).isEqualTo("foo 3");
-    assertThat(Printer.format("%s %d", "foo", 3)).isEqualTo("foo 3");
+    assertThat(Starlark.formatWithList("%s %d", Tuple.of("foo", 3))).isEqualTo("foo 3");
+    assertThat(Starlark.format("%s %d", "foo", 3)).isEqualTo("foo 3");
 
-    assertThat(Printer.format("%s %s %s", 1, null, 3)).isEqualTo("1 null 3");
+    assertThat(Starlark.format("%s %s %s", 1, null, 3)).isEqualTo("1 null 3");
 
     // Note: formatToString doesn't perform scalar x -> (x) conversion;
     // The %-operator is responsible for that.
-    assertThat(Printer.formatWithList("", Tuple.of())).isEmpty();
-    assertThat(Printer.format("%s", "foo")).isEqualTo("foo");
-    assertThat(Printer.format("%s", 3.14159)).isEqualTo("3.14159");
+    assertThat(Starlark.formatWithList("", Tuple.of())).isEmpty();
+    assertThat(Starlark.format("%s", "foo")).isEqualTo("foo");
+    assertThat(Starlark.format("%s", 3.14159)).isEqualTo("3.14159");
     checkFormatPositionalFails("not all arguments converted during string formatting",
         "%s", 1, 2, 3);
-    assertThat(Printer.format("%%%s", "foo")).isEqualTo("%foo");
+    assertThat(Starlark.format("%%%s", "foo")).isEqualTo("%foo");
     checkFormatPositionalFails("not all arguments converted during string formatting",
         "%%s", "foo");
     checkFormatPositionalFails("unsupported format character \" \" at index 1 in \"% %s\"",
         "% %s", "foo");
-    assertThat(Printer.format("%s", StarlarkList.of(null, 1, 2, 3))).isEqualTo("[1, 2, 3]");
-    assertThat(Printer.format("%s", Tuple.of(1, 2, 3))).isEqualTo("(1, 2, 3)");
-    assertThat(Printer.format("%s", StarlarkList.of(null))).isEqualTo("[]");
-    assertThat(Printer.format("%s", Tuple.of())).isEqualTo("()");
-    assertThat(Printer.format("%% %d %r %s", 1, "2", "3")).isEqualTo("% 1 \"2\" 3");
+    assertThat(Starlark.format("%s", StarlarkList.of(null, 1, 2, 3))).isEqualTo("[1, 2, 3]");
+    assertThat(Starlark.format("%s", Tuple.of(1, 2, 3))).isEqualTo("(1, 2, 3)");
+    assertThat(Starlark.format("%s", StarlarkList.of(null))).isEqualTo("[]");
+    assertThat(Starlark.format("%s", Tuple.of())).isEqualTo("()");
+    assertThat(Starlark.format("%% %d %r %s", 1, "2", "3")).isEqualTo("% 1 \"2\" 3");
 
     checkFormatPositionalFails(
         "invalid argument \"1\" for format pattern %d",