Skylark: implemented all() and any()
--
MOS_MIGRATED_REVID=110348607
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 e63b850..205075c 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
@@ -378,18 +378,16 @@
public static final StackManipulation toCollection =
ByteCodeUtils.invoke(EvalUtils.class, "toCollection", Object.class, Location.class);
- @SuppressWarnings("unchecked")
public static Collection<?> toCollection(Object o, Location loc) throws EvalException {
if (o instanceof Collection) {
- return (Collection<Object>) o;
+ return (Collection<?>) o;
} else if (o instanceof SkylarkList) {
return ((SkylarkList) o).getList();
- } else if (o instanceof Map<?, ?>) {
- Map<Comparable<?>, Object> dict = (Map<Comparable<?>, Object>) o;
+ } else if (o instanceof Map) {
// For dictionaries we iterate through the keys only
// For determinism, we sort the keys.
try {
- return SKYLARK_COMPARATOR.sortedCopy(dict.keySet());
+ return SKYLARK_COMPARATOR.sortedCopy(((Map<?, ?>) o).keySet());
} catch (ComparisonException e) {
throw new EvalException(loc, e);
}
@@ -404,17 +402,14 @@
public static final StackManipulation toIterable =
ByteCodeUtils.invoke(EvalUtils.class, "toIterable", Object.class, Location.class);
- @SuppressWarnings("unchecked")
public static Iterable<?> toIterable(Object o, Location loc) throws EvalException {
if (o instanceof String) {
// This is not as efficient as special casing String in for and dict and list comprehension
// statements. However this is a more unified way.
- // The regex matches every character in the string until the end of the string,
- // so "abc" will be split into ["a", "b", "c"].
- return ImmutableList.<Object>copyOf(((String) o).split("(?!^)"));
+ return split((String) o);
} else if (o instanceof Iterable) {
- return (Iterable<Object>) o;
- } else if (o instanceof Map<?, ?>) {
+ return (Iterable<?>) o;
+ } else if (o instanceof Map) {
return toCollection(o, loc);
} else {
throw new EvalException(loc,
@@ -422,6 +417,14 @@
}
}
+ private static ImmutableList<String> split(String value) {
+ ImmutableList.Builder<String> builder = new ImmutableList.Builder<>();
+ for (char c : value.toCharArray()) {
+ builder.add(String.valueOf(c));
+ }
+ return builder.build();
+ }
+
/**
* @return the size of the Skylark object or -1 in case the object doesn't have a size.
*/