Merge StarlarkIndexable and StarlarkQueryable classes
RELNOTES: None.
PiperOrigin-RevId: 318801861
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/BUILD b/src/main/java/com/google/devtools/build/lib/syntax/BUILD
index 0088f6b..f5bec11 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/BUILD
+++ b/src/main/java/com/google/devtools/build/lib/syntax/BUILD
@@ -115,7 +115,6 @@
"StarlarkIndexable.java",
"StarlarkIterable.java",
"StarlarkList.java",
- "StarlarkQueryable.java",
"StarlarkSemantics.java",
"StarlarkThread.java",
"StarlarkValue.java",
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 d493f27..5889f40 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
@@ -477,8 +477,8 @@
return compare(x, y) >= 0;
case IN:
- if (y instanceof StarlarkQueryable) {
- return ((StarlarkQueryable) y).containsKey(semantics, x);
+ if (y instanceof StarlarkIndexable) {
+ return ((StarlarkIndexable) y).containsKey(semantics, x);
} else if (y instanceof String) {
if (!(x instanceof String)) {
throw Starlark.errorf(
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/StarlarkIndexable.java b/src/main/java/com/google/devtools/build/lib/syntax/StarlarkIndexable.java
index b54007d..07717cd 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/StarlarkIndexable.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/StarlarkIndexable.java
@@ -14,9 +14,20 @@
package com.google.devtools.build.lib.syntax;
-/** A Starlark value that support indexed access, {@code object[key]}. */
-public interface StarlarkIndexable extends StarlarkQueryable {
+/**
+ * A Starlark value that support indexed access ({@code object[key]}) and membership tests ({@code
+ * key in object}).
+ */
+public interface StarlarkIndexable extends StarlarkValue {
/** Returns the value associated with the given key. */
Object getIndex(StarlarkSemantics semantics, Object key) throws EvalException;
+
+ /**
+ * Returns whether the key is in the object. New types should try to follow the semantics of dict:
+ * 'x in y' should return True when 'y[x]' is valid; otherwise, it should either be False or a
+ * failure. Note however that the builtin types string, list, and tuple do not follow this
+ * convention.
+ */
+ boolean containsKey(StarlarkSemantics semantics, Object key) throws EvalException;
}
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/StarlarkQueryable.java b/src/main/java/com/google/devtools/build/lib/syntax/StarlarkQueryable.java
deleted file mode 100644
index 1a904ca..0000000
--- a/src/main/java/com/google/devtools/build/lib/syntax/StarlarkQueryable.java
+++ /dev/null
@@ -1,25 +0,0 @@
-// Copyright 2015 The Bazel Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.google.devtools.build.lib.syntax;
-
-/** A Starlark value that supports membership tests, {@code key in object}. */
-// TODO(adonovan): merge with StarlarkIndexable: no type supports 'x in y' without y[x],
-// and 'x in y' can be defined in terms of y[x], at least as a default implementation.
-// (Implementations of 'x in y' may choose to interpret failure of y[x] as false or a failure.)
-public interface StarlarkQueryable extends StarlarkValue {
-
- /** Returns whether the key is in the object. */
- boolean containsKey(StarlarkSemantics semantics, Object key) throws EvalException;
-}