Code cleanup

RELNOTES: None.
PiperOrigin-RevId: 218735707
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/Environment.java b/src/main/java/com/google/devtools/build/lib/syntax/Environment.java
index f0957a3..d96f613 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/Environment.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/Environment.java
@@ -18,6 +18,7 @@
 import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Maps;
 import com.google.common.collect.Sets;
 import com.google.devtools.build.lib.cmdline.Label;
 import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
@@ -199,7 +200,7 @@
 
     private MutableLexicalFrame(Mutability mutability, int initialCapacity) {
       this.mutability = mutability;
-      this.bindings = new LinkedHashMap<>(initialCapacity);
+      this.bindings = Maps.newLinkedHashMapWithExpectedSize(initialCapacity);
     }
 
     private MutableLexicalFrame(Mutability mutability) {
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/EvalExceptionWithStackTrace.java b/src/main/java/com/google/devtools/build/lib/syntax/EvalExceptionWithStackTrace.java
index eda7b53..f1ac2a6 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/EvalExceptionWithStackTrace.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/EvalExceptionWithStackTrace.java
@@ -211,8 +211,7 @@
 
     @Override
     public String toString() {
-      return String.format(
-          "%s @ %s -> %s", label, location, (cause == null) ? "null" : cause.toString());
+      return String.format("%s @ %s -> %s", label, location, String.valueOf(cause));
     }
   }
 
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/FuncallExpression.java b/src/main/java/com/google/devtools/build/lib/syntax/FuncallExpression.java
index dcf038f..1625abd 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/FuncallExpression.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/FuncallExpression.java
@@ -608,8 +608,7 @@
         if (!type.contains(value)) {
           return ArgumentListConversionResult.fromError(
               String.format(
-                  "expected value of type '%s' for parameter '%s'",
-                  type.toString(), param.getName()));
+                  "expected value of type '%s' for parameter '%s'", type, param.getName()));
         }
         if (param.isNamed() && keys.contains(param.getName())) {
           return ArgumentListConversionResult.fromError(
@@ -623,8 +622,7 @@
           if (!type.contains(value)) {
             return ArgumentListConversionResult.fromError(
                 String.format(
-                    "expected value of type '%s' for parameter '%s'",
-                    type.toString(), param.getName()));
+                    "expected value of type '%s' for parameter '%s'", type, param.getName()));
           }
         } else { // Param not specified by user. Use default value.
           if (param.getDefaultValue().isEmpty()) {
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/ListLiteral.java b/src/main/java/com/google/devtools/build/lib/syntax/ListLiteral.java
index e18d419..ba27246 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/ListLiteral.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/ListLiteral.java
@@ -13,11 +13,11 @@
 // limitations under the License.
 package com.google.devtools.build.lib.syntax;
 
+import com.google.common.collect.ImmutableList;
 import com.google.devtools.build.lib.syntax.SkylarkList.MutableList;
 import com.google.devtools.build.lib.syntax.SkylarkList.Tuple;
 import java.io.IOException;
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.List;
 
 /**
@@ -53,7 +53,7 @@
 
   /** A new literal for an empty list, onto which a new location can be specified */
   public static ListLiteral emptyList() {
-    return makeList(Collections.emptyList());
+    return makeList(ImmutableList.of());
   }
 
   public Kind getKind() {
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/LoadStatement.java b/src/main/java/com/google/devtools/build/lib/syntax/LoadStatement.java
index 087333c..9134075 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/LoadStatement.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/LoadStatement.java
@@ -41,7 +41,7 @@
   }
 
   public ImmutableList<Identifier> getSymbols() {
-    return ImmutableList.copyOf(symbolMap.keySet());
+    return symbolMap.keySet().asList();
   }
 
   public StringLiteral getImport() {
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 731ff6f..fffa0bb 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
@@ -16,6 +16,7 @@
 
 import static java.util.stream.Collectors.joining;
 
+import com.google.common.base.Ascii;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Lists;
@@ -491,7 +492,7 @@
 
         @Nullable
         private String getIntegerPrefix(String value) {
-          value = value.toLowerCase();
+          value = Ascii.toLowerCase(value);
           for (String prefix : intPrefixes.keySet()) {
             if (value.startsWith(prefix)) {
               return prefix;
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/ParamDescriptor.java b/src/main/java/com/google/devtools/build/lib/syntax/ParamDescriptor.java
index dd2bb9c..3af7629 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/ParamDescriptor.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/ParamDescriptor.java
@@ -22,7 +22,7 @@
 /** A value class for storing {@link Param} metadata to avoid using Java proxies. */
 public final class ParamDescriptor {
 
-  private String name;
+  private final String name;
   private final String defaultValue;
   private final Class<?> type;
   private final ImmutableList<ParamTypeDescriptor> allowedTypes;
@@ -36,12 +36,10 @@
 
   private ParamDescriptor(
       String name,
-      String doc,
       String defaultValue,
       Class<?> type,
       ImmutableList<ParamTypeDescriptor> allowedTypes,
       Class<?> generic1,
-      boolean callbackEnabled,
       boolean noneable,
       boolean named,
       boolean legacyNamed,
@@ -68,12 +66,10 @@
     boolean noneable = param.noneable();
     return new ParamDescriptor(
         param.name(),
-        param.doc(),
         param.defaultValue(),
         type,
         allowedTypes,
         generic,
-        param.callbackEnabled(),
         noneable,
         param.named(),
         param.legacyNamed(),
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/Parser.java b/src/main/java/com/google/devtools/build/lib/syntax/Parser.java
index 9370cfb..3e9ebd5 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/Parser.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/Parser.java
@@ -29,7 +29,6 @@
 import com.google.devtools.build.lib.syntax.DictionaryLiteral.DictionaryEntryLiteral;
 import com.google.devtools.build.lib.syntax.IfStatement.ConditionalStatements;
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.EnumSet;
 import java.util.HashMap;
 import java.util.List;
@@ -639,7 +638,7 @@
           nextToken();
           // check for the empty tuple literal
           if (token.kind == TokenKind.RPAREN) {
-            ListLiteral literal = ListLiteral.makeTuple(Collections.emptyList());
+            ListLiteral literal = ListLiteral.makeTuple(ImmutableList.of());
             setLocation(literal, start, token.right);
             nextToken();
             return literal;
@@ -811,7 +810,7 @@
     switch (token.kind) {
       case RBRACKET: // singleton List
         {
-          ListLiteral literal = ListLiteral.makeList(Collections.singletonList(expression));
+          ListLiteral literal = ListLiteral.makeList(ImmutableList.of(expression));
           setLocation(literal, start, token.right);
           nextToken();
           return literal;
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/SkylarkSemantics.java b/src/main/java/com/google/devtools/build/lib/syntax/SkylarkSemantics.java
index 462279c..f09875c 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/SkylarkSemantics.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/SkylarkSemantics.java
@@ -15,6 +15,7 @@
 package com.google.devtools.build.lib.syntax;
 
 import com.google.auto.value.AutoValue;
+import com.google.common.base.Ascii;
 import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
 import java.util.List;
@@ -63,7 +64,7 @@
      * would return 'experimental_foo'.
      */
     public String getFlagName() {
-      return this.name().toLowerCase();
+      return Ascii.toLowerCase(this.name());
     }
   }
 
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 0706621..865801f 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
@@ -317,9 +317,12 @@
         SkylarkSignature annotation = field.getAnnotation(SkylarkSignature.class);
         Object value = null;
         try {
-          value = Preconditions.checkNotNull(field.get(null),
-              String.format(
-                  "Error while trying to configure %s.%s: its value is null", type, field));
+          value =
+              Preconditions.checkNotNull(
+                  field.get(null),
+                  "Error while trying to configure %s.%s: its value is null",
+                  type,
+                  field);
           builtins.registerBuiltin(type, field.getName(), value);
           if (BaseFunction.class.isAssignableFrom(field.getType())) {
             BaseFunction function = (BaseFunction) value;
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 482ab6d..38838ab 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
@@ -14,6 +14,7 @@
 
 package com.google.devtools.build.lib.syntax;
 
+import com.google.common.base.Ascii;
 import com.google.common.base.CharMatcher;
 import com.google.common.base.Joiner;
 import com.google.common.collect.ImmutableList;
@@ -110,7 +111,7 @@
       doc = "Returns the lower case version of this string.",
       parameters = {@Param(name = "self", type = String.class)})
   public String lower(String self) {
-    return self.toLowerCase();
+    return Ascii.toLowerCase(self);
   }
 
   @SkylarkCallable(
@@ -118,7 +119,7 @@
       doc = "Returns the upper case version of this string.",
       parameters = {@Param(name = "self", type = String.class)})
   public String upper(String self) {
-    return self.toUpperCase();
+    return Ascii.toUpperCase(self);
   }
 
   /**
@@ -489,7 +490,7 @@
     if (self.isEmpty()) {
       return self;
     }
-    return Character.toUpperCase(self.charAt(0)) + self.substring(1).toLowerCase();
+    return Character.toUpperCase(self.charAt(0)) + Ascii.toLowerCase(self.substring(1));
   }
 
   @SkylarkCallable(
@@ -909,8 +910,7 @@
             defaultValue = "None",
             doc = "optional position at which to stop comparing.")
       })
-  public Boolean endsWith(String self, Object sub, Integer start, Object end)
-      throws ConversionException, EvalException {
+  public Boolean endsWith(String self, Object sub, Integer start, Object end) throws EvalException {
     String str = pythonSubstring(self, start, end, "'end' operand of 'endswith'");
     if (sub instanceof String) {
       return str.endsWith((String) sub);
@@ -1001,7 +1001,7 @@
             doc = "Stop comparing at this position.")
       })
   public Boolean startsWith(String self, Object sub, Integer start, Object end)
-      throws ConversionException, EvalException {
+      throws EvalException {
     String str = pythonSubstring(self, start, end, "'end' operand of 'startswith'");
     if (sub instanceof String) {
       return str.startsWith((String) sub);
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/Type.java b/src/main/java/com/google/devtools/build/lib/syntax/Type.java
index da3a85d..5196a00 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/Type.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/Type.java
@@ -452,8 +452,12 @@
               || valueLabelClass == LabelClass.NONE
               || keyLabelClass == valueLabelClass,
           "A DictType's keys and values must be the same class of label if both contain labels, "
-          + "but the key type " + keyType + " contains " + keyLabelClass + " labels, while "
-          + "the value type " + valueType + " contains " + valueLabelClass + " labels.");
+              + "but the key type %s contains %s labels, while "
+              + "the value type %s contains %s labels.",
+          keyType,
+          keyLabelClass,
+          valueType,
+          valueLabelClass);
       LabelClass labelClass = (keyLabelClass != LabelClass.NONE) ? keyLabelClass : valueLabelClass;
 
       return new DictType<>(keyType, valueType, labelClass);