Misc cleanups of syntax dir

RELNOTES: None
PiperOrigin-RevId: 161560683
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 05ff85c..871f528 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
@@ -158,7 +158,7 @@
    * @param signature the signature, without default values or types
    */
   public BaseFunction(String name, FunctionSignature signature) {
-    this(name, FunctionSignature.WithValues.<Object, SkylarkType>create(signature), null);
+    this(name, FunctionSignature.WithValues.create(signature), null);
   }
 
   /**
@@ -285,8 +285,7 @@
       arguments[kwParamIndex] = SkylarkDict.copyOf(env, kwargs);
     } else {
       // Hard general case (2c): some keyword arguments may correspond to named parameters
-      SkylarkDict<String, Object> kwArg = hasKwParam
-          ? SkylarkDict.<String, Object>of(env) : SkylarkDict.<String, Object>empty();
+      SkylarkDict<String, Object> kwArg = hasKwParam ? SkylarkDict.of(env) : SkylarkDict.empty();
 
       // For nicer stabler error messages, start by checking against
       // an argument being provided both as positional argument and as keyword argument.
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/BazelLibrary.java b/src/main/java/com/google/devtools/build/lib/syntax/BazelLibrary.java
index c01cc4e..1896e67 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/BazelLibrary.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/BazelLibrary.java
@@ -223,8 +223,7 @@
       };
 
   private static Environment.Frame createGlobals() {
-    List<BaseFunction> bazelGlobalFunctions =
-        ImmutableList.<BaseFunction>of(select, depset, set, type);
+    List<BaseFunction> bazelGlobalFunctions = ImmutableList.of(select, depset, set, type);
 
     try (Mutability mutability = Mutability.create("BUILD")) {
       Environment env = Environment.builder(mutability).build();
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/BuiltinFunction.java b/src/main/java/com/google/devtools/build/lib/syntax/BuiltinFunction.java
index 5852386..cce162e 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/BuiltinFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/BuiltinFunction.java
@@ -34,7 +34,7 @@
 public class BuiltinFunction extends BaseFunction {
 
   /** ExtraArgKind so you can tweek your function's own calling convention */
-  public static enum ExtraArgKind {
+  public enum ExtraArgKind {
     LOCATION,
     SYNTAX_TREE,
     ENVIRONMENT;
@@ -305,7 +305,7 @@
       }
     }
     // No need for the enforcedArgumentTypes List if all the types were Simple
-    enforcedArgumentTypes = FunctionSignature.<SkylarkType>valueListOrNull(enforcedArgumentTypes);
+    enforcedArgumentTypes = FunctionSignature.valueListOrNull(enforcedArgumentTypes);
 
     if (returnType != null) {
       Class<?> type = returnType;
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 1a8d2b3..9b17cea 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
@@ -262,22 +262,22 @@
    */
   private static final class Continuation {
     /** The {@link BaseFunction} being evaluated that will return into this Continuation. */
-    BaseFunction function;
+    final BaseFunction function;
 
     /** The {@link FuncallExpression} to which this Continuation will return. */
-    FuncallExpression caller;
+    final FuncallExpression caller;
 
     /** The next Continuation after this Continuation. */
-    @Nullable Continuation continuation;
+    @Nullable final Continuation continuation;
 
     /** The lexical Frame of the caller. */
-    Frame lexicalFrame;
+    final Frame lexicalFrame;
 
     /** The global Frame of the caller. */
-    Frame globalFrame;
+    final Frame globalFrame;
 
     /** The set of known global variables of the caller. */
-    @Nullable Set<String> knownGlobalVariables;
+    @Nullable final Set<String> knownGlobalVariables;
 
     Continuation(
         Continuation continuation,
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 6cc14f2..7ef2eb3 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
@@ -583,6 +583,6 @@
         b.put(key, value);
       }
     }
-    return SkylarkDict.<K, V>copyOf(env, b.build());
+    return SkylarkDict.copyOf(env, b.build());
   }
 }
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/FunctionSignature.java b/src/main/java/com/google/devtools/build/lib/syntax/FunctionSignature.java
index 37e6f06..df1489a 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/FunctionSignature.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/FunctionSignature.java
@@ -167,7 +167,7 @@
 
   /** Intern a list of names */
   public static ImmutableList<String> names(String... names) {
-    return names(ImmutableList.<String>copyOf(names));
+    return names(ImmutableList.copyOf(names));
   }
 
   // Interner
@@ -363,15 +363,15 @@
         params.add(starStar);
         types.add(starStarType);
       }
-      return WithValues.<V, T>create(
+      return WithValues.create(
           FunctionSignature.create(
               Shape.create(
                   mandatoryPositionals, optionalPositionals,
                   mandatoryNamedOnly, optionalNamedOnly,
                   star != null, starStar != null),
-              ImmutableList.<String>copyOf(params)),
-          FunctionSignature.<V>valueListOrNull(defaults),
-          FunctionSignature.<T>valueListOrNull(types));
+              ImmutableList.copyOf(params)),
+          FunctionSignature.valueListOrNull(defaults),
+          FunctionSignature.valueListOrNull(types));
     }
 
     public StringBuilder toStringBuilder(final StringBuilder sb) {
@@ -384,8 +384,7 @@
      * @param sb Output StringBuffer
      * @param showDefaults Determines whether the default values of arguments should be printed (if
      *     present)
-     * @param skipMissingTypeNames Determines whether missing type names should be omitted (true) or
-     *     replaced with "object" (false).
+     * @param showTypes Determines whether parameter type information should be shown
      * @param skipFirstMandatory Determines whether the first mandatory parameter should be omitted.
      */
     public StringBuilder toStringBuilder(
@@ -528,7 +527,7 @@
         names.length - (kwArg ? 1 : 0) - (starArg ? 1 : 0)
             - numMandatoryPositionals - numOptionalPositionals - numMandatoryNamedOnly,
         starArg, kwArg),
-        ImmutableList.<String>copyOf(names));
+        ImmutableList.copyOf(names));
   }
 
   /**
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/GlobCriteria.java b/src/main/java/com/google/devtools/build/lib/syntax/GlobCriteria.java
index 91979fb..f0f5f03 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/GlobCriteria.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/GlobCriteria.java
@@ -64,7 +64,7 @@
       int excludeIndex = text.indexOf("], exclude=[");
       if (excludeIndex == -1) {
         String listText = text.substring(6, text.length() - 2);
-        return new GlobCriteria(parseList(listText), ImmutableList.<String>of(), true);
+        return new GlobCriteria(parseList(listText), ImmutableList.of(), true);
       } else {
         String listText = text.substring(6, excludeIndex);
         String excludeText = text.substring(excludeIndex + 12, text.length() - 2);
@@ -72,7 +72,7 @@
       }
     } else if (text.startsWith("[") && text.endsWith("]")) {
       String listText = text.substring(1, text.length() - 1);
-      return new GlobCriteria(parseList(listText), ImmutableList.<String>of(), false);
+      return new GlobCriteria(parseList(listText), ImmutableList.of(), false);
     } else {
       throw new IllegalArgumentException(
           "unrecognized format (not from toExpression?): " + text);
@@ -101,7 +101,7 @@
    */
   public static GlobCriteria fromList(Iterable<?> list) {
     Iterable<String> strings = Iterables.transform(list, Functions.toStringFunction());
-    return new GlobCriteria(ImmutableList.copyOf(strings), ImmutableList.<String>of(), false);
+    return new GlobCriteria(ImmutableList.copyOf(strings), ImmutableList.of(), false);
   }
 
   /**
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/GlobList.java b/src/main/java/com/google/devtools/build/lib/syntax/GlobList.java
index a21b523..fbe5315 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/GlobList.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/GlobList.java
@@ -81,7 +81,7 @@
   public static <T> GlobList<T> concat(
       List<? extends T> list1, List<? extends T> list2) {
     // we add the list to both includes and matches, preserving order
-    Builder<GlobCriteria> criteriaBuilder = ImmutableList.<GlobCriteria>builder();
+    Builder<GlobCriteria> criteriaBuilder = ImmutableList.builder();
     if (list1 instanceof GlobList<?>) {
       criteriaBuilder.addAll(((GlobList<?>) list1).criteria);
     } else {
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/Lexer.java b/src/main/java/com/google/devtools/build/lib/syntax/Lexer.java
index 61fdb60..ecb6bab 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/Lexer.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/Lexer.java
@@ -174,8 +174,7 @@
 
     @Override
     public PathFragment getPath() {
-      PathFragment path = lineNumberTable.getPath(getStartOffset());
-      return path;
+      return lineNumberTable.getPath(getStartOffset());
     }
 
     @Override
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 e549699..d3f739a 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
@@ -395,7 +395,7 @@
       result.addFirst(input.substring(0, remainingLength));
     }
 
-    return new MutableList(result, env);
+    return new MutableList<>(result, env);
   }
 
   @SkylarkSignature(name = "partition", objectType = StringModule.class,
@@ -1114,10 +1114,10 @@
   )
   private static final BuiltinFunction sorted =
       new BuiltinFunction("sorted") {
-        public <E> MutableList<E> invoke(Object self, Location loc, Environment env)
+        public MutableList<?> invoke(Object self, Location loc, Environment env)
             throws EvalException {
           try {
-            return new MutableList(
+            return new MutableList<>(
                 EvalUtils.SKYLARK_COMPARATOR.sortedCopy(EvalUtils.toCollection(self, loc, env)),
                 env);
           } catch (EvalUtils.ComparisonException e) {
@@ -1157,7 +1157,7 @@
           for (Object element : EvalUtils.toIterable(sequence, loc, env)) {
             tmpList.addFirst(element);
           }
-          return new MutableList(tmpList, env);
+          return new MutableList<>(tmpList, env);
         }
       };
 
@@ -1377,7 +1377,7 @@
           Object key = self.firstKey();
           Object value = self.get(key);
           self.remove(key, loc, env);
-          return Tuple.<Object>of(key, value);
+          return Tuple.of(key, value);
         }
       };
 
@@ -1481,7 +1481,7 @@
   private static final BuiltinFunction values =
       new BuiltinFunction("values") {
         public MutableList<?> invoke(SkylarkDict<?, ?> self, Environment env) throws EvalException {
-          return new MutableList(self.values(), env);
+          return new MutableList<>(self.values(), env);
         }
       };
 
@@ -1504,7 +1504,7 @@
           for (Map.Entry<?, ?> entries : self.entrySet()) {
             list.add(Tuple.of(entries.getKey(), entries.getValue()));
           }
-          return new MutableList(list, env);
+          return new MutableList<>(list, env);
         }
       };
 
@@ -1582,7 +1582,7 @@
   private static final BuiltinFunction list =
       new BuiltinFunction("list") {
         public MutableList<?> invoke(Object x, Location loc, Environment env) throws EvalException {
-          return new MutableList(EvalUtils.toCollection(x, loc, env), env);
+          return new MutableList<>(EvalUtils.toCollection(x, loc, env), env);
         }
       };
 
@@ -1770,12 +1770,12 @@
   )
   private static final BuiltinFunction dict =
       new BuiltinFunction("dict") {
-        public SkylarkDict invoke(
+        public SkylarkDict<?, ?> invoke(
             Object args, SkylarkDict<String, Object> kwargs, Location loc, Environment env)
             throws EvalException {
-          SkylarkDict<Object, Object> argsDict =
+          SkylarkDict<?, ?> argsDict =
               (args instanceof SkylarkDict)
-                  ? (SkylarkDict<Object, Object>) args
+                  ? (SkylarkDict<?, ?>) args
                   : getDictFromArgs(args, loc, env);
           return SkylarkDict.plus(argsDict, kwargs, env);
         }
@@ -1831,7 +1831,7 @@
             result.add(Tuple.of(count, obj));
             count++;
           }
-          return new MutableList(result, env);
+          return new MutableList<>(result, env);
         }
       };
 
@@ -1925,7 +1925,7 @@
               start += step;
             }
           }
-          return new MutableList(result, env);
+          return new MutableList<>(result, env);
         }
       };
 
@@ -2037,7 +2037,7 @@
           }
           fields.addAll(Runtime.getFunctionNames(object.getClass()));
           fields.addAll(FuncallExpression.getMethodNames(object.getClass()));
-          return new MutableList(fields, env);
+          return new MutableList<>(fields, env);
         }
       };
 
@@ -2163,7 +2163,7 @@
               result.add(Tuple.copyOf(elem));
             }
           } while (allHasNext);
-          return new MutableList(result, env);
+          return new MutableList<>(result, env);
         }
       };
 
@@ -2227,7 +2227,7 @@
   public static final class BoolModule {}
 
   static final List<BaseFunction> defaultGlobalFunctions =
-      ImmutableList.<BaseFunction>of(
+      ImmutableList.of(
           all, any, bool, dict, dir, fail, getattr, hasattr, hash, enumerate, int_, len, list, max,
           min, print, range, repr, reversed, sorted, str, tuple, zip);
 
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 1b00915..e1e77c1 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
@@ -148,9 +148,9 @@
   }
 
   /**
-   * Remove the lock for a given {@link Freezable} that is associated with the given
-   * @{link Location}. It is an error if {@code object} does not belong to this mutability,
-   * or has no lock corresponding to {@code loc}.
+   * Remove the lock for a given {@link Freezable} that is associated with the given {@link
+   * Location}. It is an error if {@code object} does not belong to this mutability, or has no lock
+   * corresponding to {@code loc}.
    */
   public void unlock(Freezable object, Location loc) {
     if (!object.mutability().equals(this)) {
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/Runtime.java b/src/main/java/com/google/devtools/build/lib/syntax/Runtime.java
index e3e2e87..4c2b10d 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/Runtime.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/Runtime.java
@@ -216,7 +216,7 @@
    */
   public static Set<String> getFunctionNames(Class<?> nameSpace) {
     Map<String, BaseFunction> nameSpaceFunctions = getNamespaceFunctions(nameSpace);
-    return nameSpaceFunctions != null ? nameSpaceFunctions.keySet() : ImmutableSet.<String>of();
+    return nameSpaceFunctions != null ? nameSpaceFunctions.keySet() : ImmutableSet.of();
   }
 
   static void setupMethodEnvironment(
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 57a2dc4..098e7d9 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
@@ -74,7 +74,7 @@
    * Creates a "wrapper" list that consists of a single select.
    */
   public static SelectorList of(SelectorValue selector) {
-    return new SelectorList(selector.getType(), ImmutableList.<Object>of(selector));
+    return new SelectorList(selector.getType(), ImmutableList.of(selector));
   }
 
   /**
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/SkylarkCallbackFunction.java b/src/main/java/com/google/devtools/build/lib/syntax/SkylarkCallbackFunction.java
index 4d04ebd..d675db5 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/SkylarkCallbackFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/SkylarkCallbackFunction.java
@@ -55,7 +55,7 @@
    * required from the specified context.
    */
   private ImmutableList<Object> buildArgumentList(ClassObject ctx, Object... arguments) {
-    Builder<Object> builder = ImmutableList.<Object>builder();
+    Builder<Object> builder = ImmutableList.builder();
     ImmutableList<String> names = getParameterNames();
     int requiredParameters = names.size() - arguments.length;
     for (int pos = 0; pos < requiredParameters; ++pos) {
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/SkylarkDict.java b/src/main/java/com/google/devtools/build/lib/syntax/SkylarkDict.java
index bdcf336..0831822 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/SkylarkDict.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/SkylarkDict.java
@@ -87,7 +87,7 @@
     return this;
   }
 
-  private <KK extends K, VV extends V> SkylarkDict putAllUnsafe(Map<KK, VV> m) {
+  private <KK extends K, VV extends V> SkylarkDict<K, V> putAllUnsafe(Map<KK, VV> m) {
     for (Map.Entry<KK, VV> e : m.entrySet()) {
       contents.put(e.getKey(), e.getValue());
     }
@@ -235,7 +235,7 @@
       SkylarkDict<? extends K, ? extends V> left,
       SkylarkDict<? extends K, ? extends V> right,
       @Nullable Environment env) {
-    SkylarkDict<K, V> result = SkylarkDict.<K, V>of(env);
+    SkylarkDict<K, V> result = SkylarkDict.of(env);
     result.putAllUnsafe(left);
     result.putAllUnsafe(right);
     return result;
@@ -243,6 +243,8 @@
 
   private static final SkylarkDict<?, ?> EMPTY = of(null);
 
+  // Safe because the empty singleton is immutable.
+  @SuppressWarnings("unchecked")
   public static <K, V> SkylarkDict<K, V> empty() {
     return (SkylarkDict<K, V>) EMPTY;
   }
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/SkylarkList.java b/src/main/java/com/google/devtools/build/lib/syntax/SkylarkList.java
index c9e3eec..3b70903 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/SkylarkList.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/SkylarkList.java
@@ -176,7 +176,7 @@
    */
   public void set(Object key, E value, Location loc, Environment env) throws EvalException {
     checkMutable(loc, env);
-    List list = getContentsUnsafe();
+    List<E> list = getContentsUnsafe();
     int index = EvalUtils.getSequenceIndex(key, list.size(), loc);
     list.set(index, value);
   }
@@ -255,7 +255,7 @@
    * Creates immutable SkylarkList with given elements.
    */
   public static <E> SkylarkList<E> createImmutable(Iterable<? extends E> contents) {
-    return new MutableList<E>(contents, Mutability.IMMUTABLE);
+    return new MutableList<>(contents, Mutability.IMMUTABLE);
   }
 
   /** A class for mutable lists. */
@@ -293,7 +293,6 @@
      * Creates a MutableList from contents and a Mutability.
      * @param contents the contents of the list
      * @param mutability a Mutability context
-     * @return a MutableList containing the elements
      */
     @SuppressWarnings("unchecked")
     private MutableList(Iterable<? extends E> contents, Mutability mutability) {
@@ -321,7 +320,6 @@
      * Creates a MutableList from contents and an Environment.
      * @param contents the contents of the list
      * @param env an Environment from which to inherit Mutability, or null for immutable
-     * @return a MutableList containing the elements
      */
     public MutableList(Iterable<? extends E> contents, @Nullable Environment env) {
       this(contents, env == null ? Mutability.IMMUTABLE : env.mutability());
@@ -341,7 +339,7 @@
      * @return a Skylark list containing the specified arguments as elements.
      */
     public static <E> MutableList<E> of(@Nullable Environment env, E... contents) {
-      return new MutableList(ImmutableList.copyOf(contents), env);
+      return new MutableList<>(ImmutableList.copyOf(contents), env);
     }
 
     /**
@@ -404,8 +402,11 @@
       if (left.getGlobList() == null && right.getGlobList() == null) {
         return new MutableList<>(left, right, env);
       }
-      return new MutableList(GlobList.concat(
-          left.getGlobListOrContentsUnsafe(), right.getGlobListOrContentsUnsafe()), env);
+      return new MutableList<>(
+          GlobList.concat(
+              left.getGlobListOrContentsUnsafe(),
+              right.getGlobListOrContentsUnsafe()),
+          env);
     }
 
     /**
@@ -419,7 +420,7 @@
     public static <E> MutableList<E> duplicate(
         final MutableList<? extends E> list, final int times, final Environment env) {
       if (times <= 0) {
-        return new MutableList<E>(ImmutableList.<E>of(), env);
+        return new MutableList<>(ImmutableList.of(), env);
       }
 
       if (list.getGlobList() == null) {
@@ -427,7 +428,7 @@
         for (int i = 1; i < times; i++) {
           iterable = Iterables.concat(iterable, list);
         }
-        return new MutableList<E>(iterable, env);
+        return new MutableList<>(iterable, env);
       }
 
       List<? extends E> globs = list.getGlobListOrContentsUnsafe();
@@ -435,7 +436,7 @@
       for (int i = 1; i < times; i++) {
         globs = GlobList.concat(globs, original);
       }
-      return new MutableList<E>(globs, env);
+      return new MutableList<>(globs, env);
     }
 
     /**
@@ -496,7 +497,7 @@
     /**
      * An empty IMMUTABLE MutableList.
      */
-    public static final MutableList EMPTY = new MutableList(Tuple.EMPTY, Mutability.IMMUTABLE);
+    public static final MutableList<?> EMPTY = new MutableList<>(Tuple.EMPTY, Mutability.IMMUTABLE);
   }
 
   /** An immutable tuple, e.g. in (1, 2, 3) */
@@ -538,7 +539,7 @@
     private static final Tuple<?> EMPTY = new Tuple<>(ImmutableList.of());
 
     @SuppressWarnings("unchecked")
-    public static final <E> Tuple<E> empty() {
+    public static <E> Tuple<E> empty() {
       return (Tuple<E>) EMPTY;
     }
 
@@ -549,7 +550,7 @@
       if (contents.isEmpty()) {
         return empty();
       }
-      return new Tuple(contents);
+      return new Tuple<>(contents);
     }
 
     /**
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/SkylarkMutable.java b/src/main/java/com/google/devtools/build/lib/syntax/SkylarkMutable.java
index 941b7f3..a1da805 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/SkylarkMutable.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/SkylarkMutable.java
@@ -86,7 +86,7 @@
     @Override
     public Iterator<E> iterator() {
       return getContentsUnsafe().iterator();
-    };
+    }
 
     @Override
     public int size() {
@@ -99,7 +99,7 @@
     }
 
     @Override
-    public final <Object> Object[] toArray(Object[] other) {
+    public final <T> T[] toArray(T[] other) {
       return getContentsUnsafe().toArray(other);
     }
 
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/SkylarkNestedSet.java b/src/main/java/com/google/devtools/build/lib/syntax/SkylarkNestedSet.java
index 3d8daea..12a0132 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/SkylarkNestedSet.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/SkylarkNestedSet.java
@@ -281,8 +281,7 @@
    * Returns the contents of the set as a {@link Collection}.
    */
   public Collection<Object> toCollection() {
-    // Do not remove <Object>: workaround for Java 7 type inference.
-    return ImmutableList.<Object>copyOf(set.toCollection());
+    return ImmutableList.copyOf(set.toCollection());
   }
 
   /**
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 6e76520..08100da 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
@@ -50,8 +50,8 @@
     Preconditions.checkArgument(name.equals(annotation.name()),
         "%s != %s", name, annotation.name());
     ArrayList<Parameter<Object, SkylarkType>> paramList = new ArrayList<>();
-    HashMap<String, SkylarkType> enforcedTypes = enforcedTypesList == null
-        ? null : new HashMap<String, SkylarkType>();
+    HashMap<String, SkylarkType> enforcedTypes =
+        enforcedTypesList == null ? null : new HashMap<>();
 
     HashMap<String, String> doc = new HashMap<>();
     boolean documented = annotation.documented();
@@ -89,7 +89,7 @@
                 /*mandatory=*/false, /*star=*/false, /*starStar=*/true, /*defaultValue=*/null));
       }
       FunctionSignature.WithValues<Object, SkylarkType> signature =
-          FunctionSignature.WithValues.<Object, SkylarkType>of(paramList);
+          FunctionSignature.WithValues.of(paramList);
       for (String paramName : signature.getSignature().getNames()) {
         if (enforcedTypesList != null) {
           enforcedTypesList.add(enforcedTypes.get(paramName));
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 638c8e1..c176f3c 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
@@ -139,7 +139,7 @@
     return TOP;
   }
 
-  private static final class Empty {}; // Empty type, used as basis for Bottom
+  private static final class Empty {} // Empty type, used as basis for Bottom
 
   // Notable types
 
@@ -333,7 +333,7 @@
         if (generic == BOTTOM) {
           return BOTTOM;
         }
-        SkylarkType arg = intersection(argType, ((Combination) other).getArgType());
+        SkylarkType arg = intersection(argType, other.getArgType());
         if (arg == BOTTOM) {
           return BOTTOM;
         }
@@ -379,7 +379,7 @@
     }
 
     private static final Interner<Combination> combinationInterner =
-        BlazeInterners.<Combination>newWeakInterner();
+        BlazeInterners.newWeakInterner();
 
     public static SkylarkType of(SkylarkType generic, SkylarkType argument) {
       // assume all combinations with TOP are the same as the simple type, and canonicalize.
@@ -441,7 +441,7 @@
       return list;
     }
     @Override public SkylarkType intersectWith(SkylarkType other) {
-      List<SkylarkType> otherTypes = addElements(new ArrayList<SkylarkType>(), other);
+      List<SkylarkType> otherTypes = addElements(new ArrayList<>(), other);
       List<SkylarkType> results = new ArrayList<>();
       for (SkylarkType element : types) {
         for (SkylarkType otherElement : otherTypes) {
@@ -487,14 +487,14 @@
       } else if (canonical.size() == 1) {
         return canonical.get(0);
       } else {
-        return new Union(ImmutableList.<SkylarkType>copyOf(canonical));
+        return new Union(ImmutableList.copyOf(canonical));
       }
     }
     public static SkylarkType of(SkylarkType... types) {
       return of(Arrays.asList(types));
     }
     public static SkylarkType of(SkylarkType t1, SkylarkType t2) {
-      return of(ImmutableList.<SkylarkType>of(t1, t2));
+      return of(ImmutableList.of(t1, t2));
     }
     public static SkylarkType of(Class<?> t1, Class<?> t2) {
       return of(Simple.forClass(t1), Simple.forClass(t2));
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 aac5420..731d0cc 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
@@ -77,7 +77,7 @@
   // this over selectableConvert.
 
   /**
-   * Equivalent to {@link #convert(Object, String, Object)} where the label is {@code null}.
+   * Equivalent to {@link #convert(Object, Object, Object)} where the label is {@code null}.
    * Useful for converting values to types that do not involve the type {@code LABEL}
    * and hence do not require the label of the current package.
    */
@@ -86,7 +86,7 @@
   }
 
   /**
-   * Like {@link #convert(Object, String, Object)}, but converts skylark {@code None}
+   * Like {@link #convert(Object, Object, Object)}, but converts skylark {@code None}
    * to given {@code defaultValue}.
    */
   @Nullable public final T convertOptional(Object x,
@@ -99,7 +99,7 @@
   }
 
   /**
-   * Like {@link #convert(Object, String, Object)}, but converts skylark {@code None}
+   * Like {@link #convert(Object, Object, Object)}, but converts skylark {@code None}
    * to java {@code null}.
    */
   @Nullable public final T convertOptional(Object x, String what, @Nullable Object context)
@@ -108,7 +108,7 @@
   }
 
   /**
-   * Like {@link #convert(Object, String)}, but converts skylark {@code NONE} to java {@code null}.
+   * Like {@link #convert(Object, Object)}, but converts skylark {@code NONE} to java {@code null}.
    */
   @Nullable public final T convertOptional(Object x, String what) throws ConversionException {
     return convertOptional(x, what, null);
@@ -129,7 +129,7 @@
    * Function accepting a (potentially null) {@link Label} and an arbitrary context object. Used by
    * {@link #visitLabels}.
    */
-  public static interface LabelVisitor<C> {
+  public interface LabelVisitor<C> {
     void visit(@Nullable Label label, @Nullable C context) throws InterruptedException;
   }
 
@@ -691,8 +691,7 @@
       } else if (x instanceof List) {
         return (List<Object>) x;
       } else if (x instanceof Iterable) {
-        // Do not remove <Object>: workaround for Java 7 type inference.
-        return ImmutableList.<Object>copyOf((Iterable<?>) x);
+        return ImmutableList.copyOf((Iterable<?>) x);
       } else {
         throw new ConversionException(this, x, what);
       }
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/ValidationEnvironment.java b/src/main/java/com/google/devtools/build/lib/syntax/ValidationEnvironment.java
index 46b4761..0f28640 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/ValidationEnvironment.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/ValidationEnvironment.java
@@ -18,10 +18,8 @@
 import com.google.devtools.build.lib.events.EventHandler;
 import com.google.devtools.build.lib.events.Location;
 import com.google.devtools.build.lib.util.Preconditions;
-import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
-import java.util.Map;
 import java.util.Set;
 import java.util.Stack;
 
@@ -37,8 +35,6 @@
 
   private final Set<String> variables = new HashSet<>();
 
-  private final Map<String, Location> variableLocations = new HashMap<>();
-
   private final Set<String> readOnlyVariables = new HashSet<>();
 
   private final SkylarkSemanticsOptions semantics;
@@ -84,7 +80,6 @@
       }
     }
     variables.add(varname);
-    variableLocations.put(varname, location);
   }
 
   private void checkReadonly(String varname, Location location) throws EvalException {