Migrate SkylarkNativeModule methods to use @SkylarkCallable instead of @SkylarkSignature
Most notably, this involves introduction of a new function abstraction, BuiltinMethod, which can wrap a {objc, SkylarkCallable} pair into a BaseFunction for later calling. (This is required due to the current layer of indirection on the end "native" module)
RELNOTES: None.
PiperOrigin-RevId: 191642467
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java b/src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java
index ed8fb91..ee6fc42 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java
@@ -163,6 +163,7 @@
return ImmutableMap.of("a", ImmutableList.of("b", "c"));
}
+
@SkylarkCallable(
name = "with_params",
documented = false,
@@ -352,6 +353,18 @@
+ ")";
}
+ @SkylarkCallable(name = "proxy_methods_object",
+ doc = "Returns a struct containing all callable method objects of this mock",
+ allowReturnNones = true)
+ public ClassObject proxyMethodsObject() {
+ ImmutableMap.Builder<String, Object> builder = new ImmutableMap.Builder<>();
+ for (String nativeFunction : FuncallExpression.getMethodNames(Mock.class)) {
+ builder.put(nativeFunction,
+ FuncallExpression.getBuiltinCallable(this, nativeFunction));
+ }
+ return NativeProvider.STRUCT.create(builder.build(), "no native callable '%s'");
+ }
+
@Override
public String toString() {
return "<mock>";
@@ -921,6 +934,16 @@
}
@Test
+ public void testProxyMethodsObject() throws Exception {
+ new SkylarkTest()
+ .update("mock", new Mock())
+ .setUp(
+ "m = mock.proxy_methods_object()",
+ "b = m.with_params(1, True, named=True)")
+ .testLookup("b", "with_params(1, true, false, true, false, a)");
+ }
+
+ @Test
public void testJavaCallWithPositionalAndKwargs() throws Exception {
new SkylarkTest()
.update("mock", new Mock())
@@ -1527,6 +1550,7 @@
"is_empty",
"nullfunc_failing",
"nullfunc_working",
+ "proxy_methods_object",
"return_bad",
"string",
"string_list",