aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/syntax/MethodLibrary.java30
-rw-r--r--src/main/java/com/google/devtools/build/lib/syntax/SkylarkList.java5
2 files changed, 34 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.",
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/SkylarkList.java b/src/main/java/com/google/devtools/build/lib/syntax/SkylarkList.java
index 547fd3e5b7..74031d3dfe 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/SkylarkList.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/SkylarkList.java
@@ -318,6 +318,11 @@ public abstract class SkylarkList implements Iterable<Object>, SkylarkValue {
add(element);
}
+ public void remove(int index, Location loc, Environment env) throws EvalException {
+ checkMutable(loc, env);
+ contents.remove(index);
+ }
+
/**
* Adds all the elements at the end of the MutableList.
* @param elements the elements to add