Automatic code cleanup.

PiperOrigin-RevId: 220636130
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/ASTNode.java b/src/main/java/com/google/devtools/build/lib/syntax/ASTNode.java
index c2a1076..790d280 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/ASTNode.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/ASTNode.java
@@ -66,16 +66,16 @@
     this.location = location;
   }
 
-  public Location getLocation() {
-    return location;
-  }
-
   /** @return the same node with its location set, in a slightly more fluent style */
-  public static <NODE extends ASTNode> NODE setLocation(Location location, NODE node) {
+  public static <NodeT extends ASTNode> NodeT setLocation(Location location, NodeT node) {
     node.setLocation(location);
     return node;
   }
 
+  public Location getLocation() {
+    return location;
+  }
+
   /** Number of spaces that each indentation level expands to when pretty-printing. */
   public static final int INDENT_WIDTH = 2;
 
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 7a7e472..49678ad 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
@@ -441,6 +441,22 @@
   }
 
   /**
+   * Inner call to a BaseFunction subclasses need to @Override this method.
+   *
+   * @param args an array of argument values sorted as per the signature.
+   * @param ast the source code for the function if user-defined
+   * @param env the lexical environment of the function call
+   * @throws InterruptedException may be thrown in the function implementations.
+   */
+  // Don't make it abstract, so that subclasses may be defined that @Override the outer call() only.
+  protected Object call(Object[] args, @Nullable FuncallExpression ast, Environment env)
+      throws EvalException, InterruptedException {
+    throw new EvalException(
+        (ast == null) ? Location.BUILTIN : ast.getLocation(),
+        String.format("function %s not implemented", getName()));
+  }
+
+  /**
    * The outer calling convention to a BaseFunction. This function expects all arguments to have
    * been resolved into positional ones.
    *
@@ -468,22 +484,6 @@
   }
 
   /**
-   * Inner call to a BaseFunction subclasses need to @Override this method.
-   *
-   * @param args an array of argument values sorted as per the signature.
-   * @param ast the source code for the function if user-defined
-   * @param env the lexical environment of the function call
-   * @throws InterruptedException may be thrown in the function implementations.
-   */
-  // Don't make it abstract, so that subclasses may be defined that @Override the outer call() only.
-  protected Object call(Object[] args, @Nullable FuncallExpression ast, Environment env)
-      throws EvalException, InterruptedException {
-    throw new EvalException(
-        (ast == null) ? Location.BUILTIN : ast.getLocation(),
-        String.format("function %s not implemented", getName()));
-  }
-
-  /**
    * Render this object in the form of an equivalent Python function signature.
    */
   @Override
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/BinaryOperatorExpression.java b/src/main/java/com/google/devtools/build/lib/syntax/BinaryOperatorExpression.java
index 5ac2fb3..4e5be2b 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/BinaryOperatorExpression.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/BinaryOperatorExpression.java
@@ -157,22 +157,6 @@
     return evaluate(operator, lhs, rhs, env, loc, /*isAugmented=*/false);
   }
 
-  /**
-   * Evaluates {@code lhs @= rhs} and returns the result, possibly mutating {@code lhs}.
-   *
-   * <p>Whether or not {@code lhs} is mutated depends on its type. If it is mutated, then it is also
-   * the return value.
-   */
-  public static Object evaluateAugmented(
-      Operator operator,
-      Object lhs,
-      Object rhs,
-      Environment env,
-      Location loc)
-      throws EvalException, InterruptedException {
-    return evaluate(operator, lhs, rhs, env, loc, /*isAugmented=*/true);
-  }
-
   private static Object evaluate(
       Operator operator,
       Object lhs,
@@ -183,8 +167,8 @@
       throws EvalException, InterruptedException {
     try {
       switch (operator) {
-        // AND and OR are included for completeness, but should normally be handled using
-        // evaluateWithShortCircuiting() instead of this method.
+          // AND and OR are included for completeness, but should normally be handled using
+          // evaluateWithShortCircuiting() instead of this method.
 
         case AND:
           return EvalUtils.toBoolean(lhs) ? rhs : lhs;
@@ -252,6 +236,18 @@
     }
   }
 
+  /**
+   * Evaluates {@code lhs @= rhs} and returns the result, possibly mutating {@code lhs}.
+   *
+   * <p>Whether or not {@code lhs} is mutated depends on its type. If it is mutated, then it is also
+   * the return value.
+   */
+  public static Object evaluateAugmented(
+      Operator operator, Object lhs, Object rhs, Environment env, Location loc)
+      throws EvalException, InterruptedException {
+    return evaluate(operator, lhs, rhs, env, loc, /*isAugmented=*/ true);
+  }
+
   @Override
   Object doEval(Environment env) throws EvalException, InterruptedException {
     if (operator == Operator.AND || operator == Operator.OR) {
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/BuildFileAST.java b/src/main/java/com/google/devtools/build/lib/syntax/BuildFileAST.java
index 44303a5..b67e456 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/BuildFileAST.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/BuildFileAST.java
@@ -105,7 +105,7 @@
           imports.add(SkylarkImports.create(str, /* repositoryMapping= */ ImmutableMap.of()));
         } catch (SkylarkImportSyntaxException e) {
           throw new IllegalStateException(
-              "Cannot create SkylarkImport for '" + str + "'. This is an internal error.");
+              "Cannot create SkylarkImport for '" + str + "'. This is an internal error.", e);
         }
       }
     }
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 bfdc795..0d423ed 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
@@ -246,26 +246,6 @@
     super.configure(annotation);
   }
 
-  // finds the method and makes it accessible (which is needed to find it, and later to use it)
-  protected Method findMethod(final String name) {
-    Method found = null;
-    for (Method method : this.getClass().getDeclaredMethods()) {
-      method.setAccessible(true);
-      if (name.equals(method.getName())) {
-        if (found != null) {
-          throw new IllegalArgumentException(String.format(
-              "function %s has more than one method named %s", getName(), name));
-        }
-        found = method;
-      }
-    }
-    if (found == null) {
-      throw new NoSuchElementException(String.format(
-          "function %s doesn't have a method named %s", getName(), name));
-    }
-    return found;
-  }
-
   /** Configure the reflection mechanism */
   @Override
   protected void configure() {
@@ -279,9 +259,7 @@
       throw new IllegalStateException(
           String.format(
               "bad argument count for %s: method has %s arguments, type list has %s",
-              getName(),
-              innerArgumentCount,
-              parameterTypes.length));
+              getName(), innerArgumentCount, parameterTypes.length));
     }
 
     if (enforcedArgumentTypes != null) {
@@ -289,14 +267,18 @@
         SkylarkType enforcedType = enforcedArgumentTypes.get(i);
         if (enforcedType != null) {
           Class<?> parameterType = parameterTypes[i];
-          String msg = String.format(
-              "fun %s(%s), param %s, enforcedType: %s (%s); parameterType: %s",
-              getName(), signature, signature.getSignature().getNames().get(i),
-              enforcedType, enforcedType.getType(), parameterType);
+          String msg =
+              String.format(
+                  "fun %s(%s), param %s, enforcedType: %s (%s); parameterType: %s",
+                  getName(),
+                  signature,
+                  signature.getSignature().getNames().get(i),
+                  enforcedType,
+                  enforcedType.getType(),
+                  parameterType);
           if (enforcedType instanceof SkylarkType.Simple
               || enforcedType instanceof SkylarkFunctionType) {
-            Preconditions.checkArgument(
-                enforcedType.getType() == parameterType, msg);
+            Preconditions.checkArgument(enforcedType.getType() == parameterType, msg);
             // No need to enforce Simple types on the Skylark side, the JVM will do it for us.
             enforcedArgumentTypes.set(i, null);
           } else if (enforcedType instanceof SkylarkType.Combination) {
@@ -314,9 +296,12 @@
     if (returnType != null) {
       Class<?> type = returnType;
       Class<?> methodReturnType = invokeMethod.getReturnType();
-      Preconditions.checkArgument(type == methodReturnType,
+      Preconditions.checkArgument(
+          type == methodReturnType,
           "signature for function %s says it returns %s but its invoke method returns %s",
-          getName(), returnType, methodReturnType);
+          getName(),
+          returnType,
+          methodReturnType);
     }
   }
 
@@ -326,8 +311,8 @@
   public void configure(BuiltinFunction.Factory factory) {
     // this function must not be configured yet, but the factory must be
     Preconditions.checkState(!isConfigured());
-    Preconditions.checkState(factory.isConfigured(),
-        "function factory is not configured for %s", getName());
+    Preconditions.checkState(
+        factory.isConfigured(), "function factory is not configured for %s", getName());
 
     this.paramDoc = factory.getParamDoc();
     this.signature = factory.getSignature();
@@ -336,6 +321,26 @@
     configure();
   }
 
+  // finds the method and makes it accessible (which is needed to find it, and later to use it)
+  protected Method findMethod(final String name) {
+    Method found = null;
+    for (Method method : this.getClass().getDeclaredMethods()) {
+      method.setAccessible(true);
+      if (name.equals(method.getName())) {
+        if (found != null) {
+          throw new IllegalArgumentException(
+              String.format("function %s has more than one method named %s", getName(), name));
+        }
+        found = method;
+      }
+    }
+    if (found == null) {
+      throw new NoSuchElementException(
+          String.format("function %s doesn't have a method named %s", getName(), name));
+    }
+    return found;
+  }
+
   /**
    * A Factory allows for a @SkylarkSignature annotation to be provided and processed in advance
    * for a function that will be defined later as a closure (see e.g. in PackageFactory).
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 f1ac2a6..c36a649 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
@@ -246,16 +246,7 @@
       return Joiner.on(System.lineSeparator()).join(output);
     }
 
-    /**
-     * Returns the location of the given element or Location.BUILTIN if the element is null.
-     */
-    private Location getLocation(StackFrame element) {
-      return (element == null) ? Location.BUILTIN : element.getLocation();
-    }
-
-    /**
-     * Returns the string representation of the given element.
-     */
+    /** Returns the string representation of the given element. */
     protected String print(StackFrame element) {
       // Similar to Python, the first (most-recent) entry in the stack frame is printed only once.
       // Consequently, we skip it here.
@@ -273,6 +264,11 @@
           element.getCause().getLabel());
     }
 
+    /** Returns the location of the given element or Location.BUILTIN if the element is null. */
+    private Location getLocation(StackFrame element) {
+      return (element == null) ? Location.BUILTIN : element.getLocation();
+    }
+
     private String printFunction(String func) {
       if (func.isEmpty()) {
         return "";
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 b07ab3c..53737ec 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
@@ -304,7 +304,7 @@
     } else if (o instanceof SkylarkNestedSet) {
       return !((SkylarkNestedSet) o).isEmpty();
     } else if (o instanceof Iterable<?>) {
-      return !(Iterables.isEmpty((Iterable<?>) o));
+      return !Iterables.isEmpty((Iterable<?>) o);
     } else {
       return true;
     }
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 42155ec..5677075 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
@@ -243,6 +243,10 @@
       return createInternal(signature, convertedDefaultValues, convertedTypes);
     }
 
+    public static <V, T> WithValues<V, T> create(FunctionSignature signature) {
+      return create(signature, null, null);
+    }
+
     @AutoCodec.VisibleForSerialization
     @AutoCodec.Instantiator
     static <V, T> WithValues<V, T> createInternal(
@@ -250,10 +254,6 @@
       return new AutoValue_FunctionSignature_WithValues<>(signature, defaultValues, types);
     }
 
-    public static <V, T> WithValues<V, T> create(FunctionSignature signature) {
-      return create(signature, null, null);
-    }
-
     /**
      * Parse a list of Parameter into a FunctionSignature.
      *
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/LineNumberTable.java b/src/main/java/com/google/devtools/build/lib/syntax/LineNumberTable.java
index e212a21..b35dfb3 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/LineNumberTable.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/LineNumberTable.java
@@ -46,18 +46,18 @@
     this(computeLinestart(buffer), path, buffer.length);
   }
 
-  @AutoCodec.Instantiator
-  static LineNumberTable createForSerialization(
-      int[] linestart, PathFragment path, int bufferLength) {
-    return LINE_NUMBER_TABLE_INTERNER.intern(new LineNumberTable(linestart, path, bufferLength));
-  }
-
   LineNumberTable(int[] linestart, PathFragment path, int bufferLength) {
     this.linestart = linestart;
     this.path = path;
     this.bufferLength = bufferLength;
   }
 
+  @AutoCodec.Instantiator
+  static LineNumberTable createForSerialization(
+      int[] linestart, PathFragment path, int bufferLength) {
+    return LINE_NUMBER_TABLE_INTERNER.intern(new LineNumberTable(linestart, path, bufferLength));
+  }
+
   static LineNumberTable create(char[] buffer, PathFragment path) {
     return new LineNumberTable(buffer, path);
   }
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 fffa0bb..112fefa 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
@@ -109,7 +109,7 @@
       Iterable<?> items = (args.size() == 1) ? EvalUtils.toIterable(args.get(0), loc, env) : args;
       return maxOrdering.max(items);
     } catch (NoSuchElementException ex) {
-      throw new EvalException(loc, "expected at least one item");
+      throw new EvalException(loc, "expected at least one item", ex);
     }
   }
 
@@ -485,8 +485,8 @@
           } catch (NumberFormatException | ArithmeticException e) {
             throw new EvalException(
                 loc,
-                Printer.format(
-                    "invalid literal for int() with base %d: %r", base, stringForErrors));
+                Printer.format("invalid literal for int() with base %d: %r", base, stringForErrors),
+                e);
           }
         }
 
@@ -562,7 +562,7 @@
             return tuple;
           } catch (ConversionException e) {
             throw new EvalException(
-                loc, String.format("cannot convert item #%d to a sequence", pos));
+                loc, String.format("cannot convert item #%d to a sequence", pos), e);
           }
         }
       };