From 2cb04a29f0823d137cbe9d0d83d07b5cade5b160 Mon Sep 17 00:00:00 2001 From: Marwan Tammam Date: Fri, 12 Jul 2019 21:52:56 +0200 Subject: [PATCH 1/6] Add key and reverse parameters to builtin sorted function --- .../devtools/build/lib/syntax/EvalUtils.java | 14 +++++ .../build/lib/syntax/MethodLibrary.java | 55 +++++++++++++++++-- .../build/lib/syntax/MethodLibraryTest.java | 5 +- src/test/starlark/testdata/sorted.sky | 37 +++++++++++++ 4 files changed, 106 insertions(+), 5 deletions(-) create mode 100644 src/test/starlark/testdata/sorted.sky 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 cfec3cdc543a99..af3f0031c27cc4 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 @@ -49,6 +49,16 @@ public ComparisonException(String msg) { } } + public static class SortPair { + public Object key; + public Object value; + + public SortPair(Object key, Object value){ + this.key = key; + this.value = value; + } + } + /** * Compare two Skylark objects. * @@ -77,6 +87,10 @@ public int compare(Object o1, Object o2) { o1 = SkylarkType.convertToSkylark(o1, (Environment) null); o2 = SkylarkType.convertToSkylark(o2, (Environment) null); + if (o1 instanceof SortPair && o2 instanceof SortPair) { + o1 = ((SortPair) o1).key; + o2 = ((SortPair) o2).key; + } if (o1 instanceof SkylarkList && o2 instanceof SkylarkList && ((SkylarkList) o1).isTuple() == ((SkylarkList) o2).isTuple()) { 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 c32b810c292f3e..7772ef4fb79411 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 @@ -42,6 +42,9 @@ import java.util.NoSuchElementException; import java.util.Set; import java.util.TreeSet; +import java.util.HashMap; +import java.util.Arrays; +import java.util.Collections; import javax.annotation.Nullable; /** A helper class containing built in functions for the Skylark language. */ @@ -102,6 +105,19 @@ private static Object findExtreme( } } + private static Object evalKey(Object obj, Object key, Location loc, Environment env) throws EvalException, InterruptedException { + if (key == Runtime.NONE) { + return obj; + } else if (key instanceof BuiltinCallable) { + return ((BuiltinCallable) key).call(new ArrayList<>(Arrays.asList(obj)), + new HashMap<>(), new FuncallExpression(Identifier.of(""), ImmutableList.of()), env); + } else if (key instanceof BaseFunction) { + return ((BaseFunction) key).call(new ArrayList<>(Arrays.asList(obj)), null, null, env); + } + + throw new EvalException(loc, Printer.format("%r object is not callable", EvalUtils.getDataTypeName(key))); + } + @SkylarkCallable( name = "all", doc = @@ -170,14 +186,45 @@ private static boolean hasElementWithBooleanValue( type = Object.class, doc = "This collection.", // TODO(cparsons): This parameter should be positional-only. - legacyNamed = true) + legacyNamed = true), + @Param( + name = "key", + doc = "The key to sort with.", + named = true, + defaultValue = "None", + positional = false, + noneable = true), + @Param( + name = "reverse", + type = Boolean.class, + doc = "Whether to sort asc or desc.", + named = true, + defaultValue = "False", + positional = false, + noneable = true) }, useLocation = true, useEnvironment = true) - public MutableList sorted(Object self, Location loc, Environment env) throws EvalException { + public MutableList sorted(Object self, Object key, Boolean reverse, + Location loc, Environment env) throws EvalException, InterruptedException { + Iterator iterator = EvalUtils.toCollection(self, loc, env).iterator(); + List list = new ArrayList<>(); + + while (iterator.hasNext()) { + Object val = iterator.next(); + list.add(new EvalUtils.SortPair(evalKey(val, key, loc, env), val)); + } + try { - return MutableList.copyOf( - env, EvalUtils.SKYLARK_COMPARATOR.sortedCopy(EvalUtils.toCollection(self, loc, env))); + list = EvalUtils.SKYLARK_COMPARATOR.sortedCopy(list); + for (int i = 0; i < list.size(); i++) { + if (reverse && i < list.size() / 2) { + Collections.swap(list, i, list.size() - i - 1); + } + list.set(i, ((EvalUtils.SortPair) list.get(i)).value); + + } + return MutableList.copyOf(env, list); } catch (EvalUtils.ComparisonException e) { throw new EvalException(loc, e); } diff --git a/src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java b/src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java index aabd29710fe339..c5c3706be9abed 100644 --- a/src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java +++ b/src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java @@ -249,6 +249,9 @@ public void testListSort() throws Exception { .testEval("sorted([True, False, True])", "[False, True, True]") .testEval("sorted(['a','x','b','z'])", "[\"a\", \"b\", \"x\", \"z\"]") .testEval("sorted({1: True, 5: True, 4: False})", "[1, 4, 5]") + .testEval("sorted([3, 2, 1, 0], reverse=True)", "[3, 2, 1, 0]") + .testEval("sorted([[1], [], [1, 2]], key=len, reverse=True)", "[[1, 2], [1], []]") + .testEval("sorted([[0, 5], [4, 1], [1, 7]], key=max)", "[[4, 1], [0, 5], [1, 7]]") .testIfExactError("Cannot compare function with function", "sorted([sorted, sorted])"); } @@ -712,7 +715,7 @@ public void testLegacyNamed() throws Exception { // Parameters which may be specified by keyword but are not explicitly 'named'. .testStatement("all(elements=[True, True])", Boolean.TRUE) .testStatement("any(elements=[True, False])", Boolean.TRUE) - .testEval("sorted(self=[3, 0, 2])", "[0, 2, 3]") + .testEval("sorted(self=[3, 0, 2], key=None, reverse=False)", "[0, 2, 3]") .testEval("reversed(sequence=[3, 2, 0])", "[0, 2, 3]") .testEval("tuple(x=[1, 2])", "(1, 2)") .testEval("list(x=(1, 2))", "[1, 2]") diff --git a/src/test/starlark/testdata/sorted.sky b/src/test/starlark/testdata/sorted.sky new file mode 100644 index 00000000000000..d7fa3ab2d6c4a9 --- /dev/null +++ b/src/test/starlark/testdata/sorted.sky @@ -0,0 +1,37 @@ +assert_eq(sorted([42, 123, 3]), [3, 42, 123]) +assert_eq(sorted(["wiz", "foo", "bar"]), ["bar", "foo", "wiz"]) +assert_eq(sorted([42, 123, 3], reverse=True), [123, 42, 3]) +assert_eq(sorted(["wiz", "foo", "bar"], reverse=True), ["wiz", "foo", "bar"]) +assert_eq(sorted(list({"a": 1, "b": 2})), ['a', 'b']) +--- + +def f(x): + return x[0] +pairs = [(4, 0), (3, 1), (4, 2), (2, 3), (3, 4), (1, 5), (2, 6), (3, 7)] + +assert_eq(sorted(pairs, key=f), + [(1, 5), + (2, 3), (2, 6), + (3, 1), (3, 4), (3, 7), + (4, 0), (4, 2)]) + +--- +assert_eq(sorted(["two", "three", "four"], key=len), + ["two", "four", "three"]) +assert_eq(sorted(["two", "three", "four"], key=len, reverse=True), + ["three", "four", "two"]) +assert_eq(sorted([[1, 5], [0, 10], [4]], key=max), + [[4], [1, 5], [0, 10]]) +assert_eq(sorted([[1, 5], [0, 10], [4]], key=min, reverse=True), + [[4], [1, 5], [0, 10]]) +assert_eq(sorted([[2, 6, 1], [5, 2, 1], [1, 4, 2]], key=sorted), + [[1, 4, 2], [5, 2, 1], [2, 6, 1]]) + +--- +sorted(1) ### type 'int' is not a collection +--- +sorted([1, 2, None, 3]) ### Cannot compare NoneType with int +--- +sorted([1, "one"]) ### Cannot compare string with int +--- +sorted([1, 2, 3], key=1) ### "int" object is not callable From 5904d5eef75f662a6be18d3ae8b55efe9c463438 Mon Sep 17 00:00:00 2001 From: Marwan Tammam Date: Sat, 13 Jul 2019 23:07:58 +0200 Subject: [PATCH 2/6] Revision#1 --- .../devtools/build/lib/syntax/EvalUtils.java | 14 ---- .../build/lib/syntax/MethodLibrary.java | 81 +++++++++++++------ 2 files changed, 56 insertions(+), 39 deletions(-) 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 af3f0031c27cc4..cfec3cdc543a99 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 @@ -49,16 +49,6 @@ public ComparisonException(String msg) { } } - public static class SortPair { - public Object key; - public Object value; - - public SortPair(Object key, Object value){ - this.key = key; - this.value = value; - } - } - /** * Compare two Skylark objects. * @@ -87,10 +77,6 @@ public int compare(Object o1, Object o2) { o1 = SkylarkType.convertToSkylark(o1, (Environment) null); o2 = SkylarkType.convertToSkylark(o2, (Environment) null); - if (o1 instanceof SortPair && o2 instanceof SortPair) { - o1 = ((SortPair) o1).key; - o2 = ((SortPair) o2).key; - } if (o1 instanceof SkylarkList && o2 instanceof SkylarkList && ((SkylarkList) o1).isTuple() == ((SkylarkList) o2).isTuple()) { 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 7772ef4fb79411..7e4f95b7cb9b0f 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 @@ -42,9 +42,9 @@ import java.util.NoSuchElementException; import java.util.Set; import java.util.TreeSet; -import java.util.HashMap; import java.util.Arrays; import java.util.Collections; +import java.util.Comparator; import javax.annotation.Nullable; /** A helper class containing built in functions for the Skylark language. */ @@ -105,19 +105,51 @@ private static Object findExtreme( } } - private static Object evalKey(Object obj, Object key, Location loc, Environment env) throws EvalException, InterruptedException { + private static Object evalKey( + Object obj, Object key, Location loc, Environment env, FuncallExpression ast) + throws EvalException, InterruptedException { if (key == Runtime.NONE) { return obj; } else if (key instanceof BuiltinCallable) { - return ((BuiltinCallable) key).call(new ArrayList<>(Arrays.asList(obj)), - new HashMap<>(), new FuncallExpression(Identifier.of(""), ImmutableList.of()), env); + return ((BuiltinCallable) key).call(Arrays.asList(obj), Collections.emptyMap(), ast, env); } else if (key instanceof BaseFunction) { - return ((BaseFunction) key).call(new ArrayList<>(Arrays.asList(obj)), null, null, env); + return ((BaseFunction) key).call(Arrays.asList(obj), null, null, env); } throw new EvalException(loc, Printer.format("%r object is not callable", EvalUtils.getDataTypeName(key))); } + private static class KeyComparator implements Comparator { + private final Object key; + private final Location loc; + private final Environment env; + private FuncallExpression ast; + private Exception e; + + + public KeyComparator(Object key, Location loc, Environment env) { + this.key = key; + this.loc = loc; + this.env = env; + this.ast = new FuncallExpression(Identifier.of(""), ImmutableList.of()); + } + + public Exception getException() { + return this.e; + } + + @Override + public int compare(Object o1, Object o2) { + try { + return EvalUtils.SKYLARK_COMPARATOR.compare( + evalKey(o1, key, loc, env, ast), evalKey(o2, key, loc, env, ast)); + } catch (Exception e) { + this.e = this.e == null ? e : this.e; + } + return 0; + } + } + @SkylarkCallable( name = "all", doc = @@ -189,7 +221,7 @@ private static boolean hasElementWithBooleanValue( legacyNamed = true), @Param( name = "key", - doc = "The key to sort with.", + doc = "An optional function applied to each element before comparison.", named = true, defaultValue = "None", positional = false, @@ -197,7 +229,7 @@ private static boolean hasElementWithBooleanValue( @Param( name = "reverse", type = Boolean.class, - doc = "Whether to sort asc or desc.", + doc = "Return results in descending order.", named = true, defaultValue = "False", positional = false, @@ -206,28 +238,27 @@ private static boolean hasElementWithBooleanValue( useLocation = true, useEnvironment = true) public MutableList sorted(Object self, Object key, Boolean reverse, - Location loc, Environment env) throws EvalException, InterruptedException { - Iterator iterator = EvalUtils.toCollection(self, loc, env).iterator(); - List list = new ArrayList<>(); + Location loc, Environment env) + throws EvalException, InterruptedException { - while (iterator.hasNext()) { - Object val = iterator.next(); - list.add(new EvalUtils.SortPair(evalKey(val, key, loc, env), val)); - } - - try { - list = EvalUtils.SKYLARK_COMPARATOR.sortedCopy(list); - for (int i = 0; i < list.size(); i++) { - if (reverse && i < list.size() / 2) { - Collections.swap(list, i, list.size() - i - 1); - } - list.set(i, ((EvalUtils.SortPair) list.get(i)).value); + List list = new ArrayList(EvalUtils.toCollection(self, loc, env)); + KeyComparator comparator = new KeyComparator(key, loc, env); + Collections.sort(list, comparator); + Exception e = comparator.getException(); + if (e != null) { + if (e instanceof InterruptedException) { + throw (InterruptedException) e; + } else if (e instanceof EvalUtils.ComparisonException) { + throw new EvalException(loc, e); } - return MutableList.copyOf(env, list); - } catch (EvalUtils.ComparisonException e) { - throw new EvalException(loc, e); + throw (EvalException) e; + } + + if (reverse) { + Collections.reverse(list); } + return MutableList.copyOf(env, list); } @SkylarkCallable( From 04b38c71e21464ad27e9f0cac673e14a038f8ab6 Mon Sep 17 00:00:00 2001 From: Marwan Tammam Date: Sun, 14 Jul 2019 11:30:38 +0200 Subject: [PATCH 3/6] Revision#2 --- .../build/lib/syntax/MethodLibrary.java | 103 ++++++++++-------- 1 file changed, 55 insertions(+), 48 deletions(-) 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 7e4f95b7cb9b0f..cb465eeeb2f3f7 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 @@ -105,51 +105,24 @@ private static Object findExtreme( } } - private static Object evalKey( + private static Object evalKeyFunc( Object obj, Object key, Location loc, Environment env, FuncallExpression ast) throws EvalException, InterruptedException { - if (key == Runtime.NONE) { - return obj; - } else if (key instanceof BuiltinCallable) { - return ((BuiltinCallable) key).call(Arrays.asList(obj), Collections.emptyMap(), ast, env); - } else if (key instanceof BaseFunction) { - return ((BaseFunction) key).call(Arrays.asList(obj), null, null, env); + checkValidKeyFunc(key, loc); + if (key instanceof BuiltinCallable) { + return ((BuiltinCallable) key).call(Collections.singletonList(obj), Collections.emptyMap(), ast, env); } - - throw new EvalException(loc, Printer.format("%r object is not callable", EvalUtils.getDataTypeName(key))); + return ((BaseFunction) key).call(Collections.singletonList(obj), null, null, env); } - private static class KeyComparator implements Comparator { - private final Object key; - private final Location loc; - private final Environment env; - private FuncallExpression ast; - private Exception e; - - - public KeyComparator(Object key, Location loc, Environment env) { - this.key = key; - this.loc = loc; - this.env = env; - this.ast = new FuncallExpression(Identifier.of(""), ImmutableList.of()); - } - - public Exception getException() { - return this.e; - } - - @Override - public int compare(Object o1, Object o2) { - try { - return EvalUtils.SKYLARK_COMPARATOR.compare( - evalKey(o1, key, loc, env, ast), evalKey(o2, key, loc, env, ast)); - } catch (Exception e) { - this.e = this.e == null ? e : this.e; - } - return 0; + private static void checkValidKeyFunc(Object key, Location loc) throws EvalException { + if (key instanceof BuiltinCallable || key instanceof BaseFunction) { + return; } + throw new EvalException(loc, Printer.format("%r object is not callable", EvalUtils.getDataTypeName(key))); } + @SkylarkCallable( name = "all", doc = @@ -241,24 +214,58 @@ public MutableList sorted(Object self, Object key, Boolean reverse, Location loc, Environment env) throws EvalException, InterruptedException { - List list = new ArrayList(EvalUtils.toCollection(self, loc, env)); - KeyComparator comparator = new KeyComparator(key, loc, env); - Collections.sort(list, comparator); - - Exception e = comparator.getException(); - if (e != null) { - if (e instanceof InterruptedException) { - throw (InterruptedException) e; - } else if (e instanceof EvalUtils.ComparisonException) { + ArrayList list = new ArrayList(EvalUtils.toCollection(self, loc, env)); + if (key == Runtime.NONE) { + try { + Collections.sort(list, EvalUtils.SKYLARK_COMPARATOR); + } catch (EvalUtils.ComparisonException e) { throw new EvalException(loc, e); } - throw (EvalException) e; + } else { + checkValidKeyFunc(key, loc); + + final Object KEY = key; + final Location LOC = loc; + final Environment ENV = env; + final FuncallExpression AST = new FuncallExpression(Identifier.of(""), ImmutableList.of()); + + class KeyComparator implements Comparator { + private Exception e; + + public Exception getException() { + return this.e; + } + + @Override + public int compare(Object o1, Object o2) { + try { + return EvalUtils.SKYLARK_COMPARATOR.compare( + evalKeyFunc(o1, KEY, LOC, ENV, AST), evalKeyFunc(o2, KEY, LOC, ENV, AST)); + } catch (Exception e) { + this.e = this.e == null ? e : this.e; + } + return 0; + } + } + + KeyComparator comparator = new KeyComparator(); + Collections.sort(list, comparator); + + Exception e = comparator.getException(); + if (e != null) { + if (e instanceof InterruptedException) { + throw (InterruptedException) e; + } else if (e instanceof EvalUtils.ComparisonException) { + throw new EvalException(loc, e); + } + throw (EvalException) e; + } } if (reverse) { Collections.reverse(list); } - return MutableList.copyOf(env, list); + return MutableList.wrapUnsafe(env, list); } @SkylarkCallable( From 14b98d6bec1ce8b21d3c2f678399dadb147480dc Mon Sep 17 00:00:00 2001 From: Marwan Tammam Date: Sun, 14 Jul 2019 16:50:38 +0200 Subject: [PATCH 4/6] Revision#3 --- .../google/devtools/build/lib/syntax/MethodLibrary.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) 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 cb465eeeb2f3f7..69e5f48880c375 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,14 +109,11 @@ private static Object evalKeyFunc( Object obj, Object key, Location loc, Environment env, FuncallExpression ast) throws EvalException, InterruptedException { checkValidKeyFunc(key, loc); - if (key instanceof BuiltinCallable) { - return ((BuiltinCallable) key).call(Collections.singletonList(obj), Collections.emptyMap(), ast, env); - } - return ((BaseFunction) key).call(Collections.singletonList(obj), null, null, env); + return ((StarlarkFunction) key).call(Collections.singletonList(obj), Collections.emptyMap(), ast, env); } private static void checkValidKeyFunc(Object key, Location loc) throws EvalException { - if (key instanceof BuiltinCallable || key instanceof BaseFunction) { + if (key instanceof StarlarkFunction) { return; } throw new EvalException(loc, Printer.format("%r object is not callable", EvalUtils.getDataTypeName(key))); From 9e916b6b328bea385ad91c05e4473f82bd611d92 Mon Sep 17 00:00:00 2001 From: Marwan Tammam Date: Mon, 15 Jul 2019 11:29:58 +0200 Subject: [PATCH 5/6] Revision#4 --- .../build/lib/syntax/MethodLibrary.java | 45 +++++++++---------- 1 file changed, 21 insertions(+), 24 deletions(-) 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 69e5f48880c375..d9fe8f40f74855 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 @@ -207,8 +207,8 @@ private static boolean hasElementWithBooleanValue( }, useLocation = true, useEnvironment = true) - public MutableList sorted(Object self, Object key, Boolean reverse, - Location loc, Environment env) + public MutableList sorted(Object self, final Object key, Boolean reverse, + final Location loc, final Environment env) throws EvalException, InterruptedException { ArrayList list = new ArrayList(EvalUtils.toCollection(self, loc, env)); @@ -221,41 +221,38 @@ public MutableList sorted(Object self, Object key, Boolean reverse, } else { checkValidKeyFunc(key, loc); - final Object KEY = key; - final Location LOC = loc; - final Environment ENV = env; - final FuncallExpression AST = new FuncallExpression(Identifier.of(""), ImmutableList.of()); + final FuncallExpression ast = new FuncallExpression(Identifier.of(""), ImmutableList.of()); class KeyComparator implements Comparator { - private Exception e; - - public Exception getException() { - return this.e; - } + public Exception e; @Override public int compare(Object o1, Object o2) { try { return EvalUtils.SKYLARK_COMPARATOR.compare( - evalKeyFunc(o1, KEY, LOC, ENV, AST), evalKeyFunc(o2, KEY, LOC, ENV, AST)); - } catch (Exception e) { - this.e = this.e == null ? e : this.e; + evalKeyFunc(o1, key, loc, env, ast), + evalKeyFunc(o2, key, loc, env, ast)); + } catch (InterruptedException | EvalException e) { + if (this.e == null) { + this.e = (Exception) e; + } + return 0; } - return 0; } } - KeyComparator comparator = new KeyComparator(); - Collections.sort(list, comparator); + KeyComparator comp= new KeyComparator(); + try { + Collections.sort(list, comp); + } catch (EvalUtils.ComparisonException e) { + throw new EvalException(loc, e); + } - Exception e = comparator.getException(); - if (e != null) { - if (e instanceof InterruptedException) { - throw (InterruptedException) e; - } else if (e instanceof EvalUtils.ComparisonException) { - throw new EvalException(loc, e); + if (comp.e != null) { + if (comp.e instanceof InterruptedException) { + throw (InterruptedException) comp.e; } - throw (EvalException) e; + throw (EvalException) comp.e; } } From 9666b121c2297a479d6c9b1d131ca802327a931d Mon Sep 17 00:00:00 2001 From: Marwan Tammam Date: Mon, 15 Jul 2019 14:15:53 +0200 Subject: [PATCH 6/6] Revision#5 --- .../devtools/build/lib/syntax/MethodLibrary.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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 d9fe8f40f74855..8c1fd7f12a3e25 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 @@ -224,24 +224,24 @@ public MutableList sorted(Object self, final Object key, Boolean reverse, final FuncallExpression ast = new FuncallExpression(Identifier.of(""), ImmutableList.of()); class KeyComparator implements Comparator { - public Exception e; + Exception e; @Override - public int compare(Object o1, Object o2) { + public int compare(Object x, Object y) { try { return EvalUtils.SKYLARK_COMPARATOR.compare( - evalKeyFunc(o1, key, loc, env, ast), - evalKeyFunc(o2, key, loc, env, ast)); + evalKeyFunc(x, key, loc, env, ast), + evalKeyFunc(y, key, loc, env, ast)); } catch (InterruptedException | EvalException e) { if (this.e == null) { - this.e = (Exception) e; + this.e = e; } return 0; } } } - KeyComparator comp= new KeyComparator(); + KeyComparator comp = new KeyComparator(); try { Collections.sort(list, comp); } catch (EvalUtils.ComparisonException e) {