aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/syntax
diff options
context:
space:
mode:
authorGravatar jcater <jcater@google.com>2017-10-26 21:58:37 +0200
committerGravatar Dmitry Lomov <dslomov@google.com>2017-10-27 16:29:32 +0200
commit9f1f941e973b5d64cdc24f347e48a7bc5fa8715f (patch)
tree78909beff114fc7fd89f0a2ea25c9d0e37e9ea80 /src/main/java/com/google/devtools/build/lib/syntax
parent19c5039ad76476951095f603aad380051086a832 (diff)
Fix SelectorList.isListType to properly consider all classes that can be assigned to java.util.List, not just ArrayList.
PiperOrigin-RevId: 173577936
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/syntax')
-rw-r--r--src/main/java/com/google/devtools/build/lib/syntax/SelectorList.java24
1 files changed, 15 insertions, 9 deletions
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 7ec367cb89..3180483777 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
@@ -20,8 +20,6 @@ import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
import com.google.devtools.build.lib.skylarkinterface.SkylarkPrinter;
import com.google.devtools.build.lib.skylarkinterface.SkylarkValue;
import com.google.devtools.build.lib.util.Preconditions;
-import java.util.ArrayList;
-import java.util.Arrays;
import java.util.List;
/**
@@ -86,12 +84,22 @@ public final class SelectorList implements SkylarkValue {
*/
public static SelectorList concat(Location location, Object value1, Object value2)
throws EvalException {
- return of(location, Arrays.asList(value1, value2));
+ return of(location, value1, value2);
}
/**
- * Creates a list from the given sequence of values, which must be non-empty. Each value may be
- * a native type, a select over that type, or a selector list over that type.
+ * Creates a list from the given sequence of values, which must be non-empty. Each value may be a
+ * native type, a select over that type, or a selector list over that type.
+ *
+ * @throws EvalException if all values don't have the same underlying type
+ */
+ public static SelectorList of(Location location, Object... values) throws EvalException {
+ return SelectorList.of(location, ImmutableList.copyOf(values));
+ }
+
+ /**
+ * Creates a list from the given sequence of values, which must be non-empty. Each value may be a
+ * native type, a select over that type, or a selector list over that type.
*
* @throws EvalException if all values don't have the same underlying type
*/
@@ -122,9 +130,7 @@ public final class SelectorList implements SkylarkValue {
return new SelectorList(getNativeType(firstValue), elements.build());
}
- // TODO(bazel-team): match on the List interface, not the actual implementation. For now,
- // we verify this is the right class through test coverage.
- private static final Class<?> NATIVE_LIST_TYPE = ArrayList.class;
+ private static final Class<?> NATIVE_LIST_TYPE = List.class;
private static Class<?> getNativeType(Object value) {
if (value instanceof SelectorList) {
@@ -137,7 +143,7 @@ public final class SelectorList implements SkylarkValue {
}
private static boolean isListType(Class<?> type) {
- return type == NATIVE_LIST_TYPE
+ return NATIVE_LIST_TYPE.isAssignableFrom(type)
|| type.getSuperclass() == SkylarkList.class
|| type == GlobList.class;
}