aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/syntax/MethodLibrary.java
diff options
context:
space:
mode:
authorGravatar Laurent Le Brun <laurentlb@google.com>2015-12-16 15:02:03 +0000
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2015-12-16 15:31:41 +0000
commit8853df9a19dabc72c3b723b84e6cb69b6fb2884e (patch)
tree4b7b7efb3b8092333c0a96eadbce6da65979f195 /src/main/java/com/google/devtools/build/lib/syntax/MethodLibrary.java
parentf8f855c6ee75a30558a3ce3dcb0759a1dcc59504 (diff)
Implement list.remove function
-- MOS_MIGRATED_REVID=110356439
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/syntax/MethodLibrary.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/syntax/MethodLibrary.java30
1 files changed, 29 insertions, 1 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 dc3f50b72e..2a64a0e02b 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
@@ -1183,7 +1183,7 @@ public class MethodLibrary {
"Returns the index in the list of the first item whose value is x. "
+ "It is an error if there is no such item.",
mandatoryPositionals = {
- @Param(name = "self", type = MutableList.class, doc = "This string, a separator."),
+ @Param(name = "self", type = MutableList.class, doc = "This list."),
@Param(name = "x", type = Object.class, doc = "The object to search.")
},
useLocation = true
@@ -1202,6 +1202,34 @@ public class MethodLibrary {
}
};
+ @SkylarkSignature(
+ name = "remove",
+ objectType = MutableList.class,
+ returnType = Runtime.NoneType.class,
+ doc =
+ "Removes the first item from the list whose value is x. "
+ + "It is an error if there is no such item.",
+ mandatoryPositionals = {
+ @Param(name = "self", type = MutableList.class, doc = "This list."),
+ @Param(name = "x", type = Object.class, doc = "The object to remove.")
+ },
+ useLocation = true,
+ useEnvironment = true
+ )
+ private static BuiltinFunction listRemove =
+ new BuiltinFunction("remove") {
+ public Runtime.NoneType invoke(MutableList self, Object x, Location loc, Environment env)
+ throws EvalException {
+ for (int i = 0; i < self.size(); i++) {
+ if (self.get(i).equals(x)) {
+ self.remove(i, loc, env);
+ return Runtime.NONE;
+ }
+ }
+ throw new EvalException(loc, Printer.format("Item %r not found in list", x));
+ }
+ };
+
// dictionary access operator
@SkylarkSignature(name = "$index", documented = false, objectType = Map.class,
doc = "Looks up a value in a dictionary.",