aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/syntax/FuncallExpression.java
diff options
context:
space:
mode:
authorGravatar cparsons <cparsons@google.com>2018-04-04 13:59:27 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-04-04 14:01:20 -0700
commit7520dcce42217c8076b06ed88c0e4e04ed99a0f4 (patch)
treef3c8156e096114dabddba39e8ae7ea21d00e2560 /src/main/java/com/google/devtools/build/lib/syntax/FuncallExpression.java
parent16e188b99a5b0d07a0976ba5eb6013b3de8befb9 (diff)
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
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/syntax/FuncallExpression.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/syntax/FuncallExpression.java15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/FuncallExpression.java b/src/main/java/com/google/devtools/build/lib/syntax/FuncallExpression.java
index 7a807f5e20..597508f04d 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/FuncallExpression.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/FuncallExpression.java
@@ -318,6 +318,21 @@ public final class FuncallExpression extends Expression {
}
/**
+ * Returns a {@link BuiltinCallable} representing a {@link SkylarkCallable}-annotated instance
+ * method of a given object with the given method name.
+ */
+ public static BuiltinCallable getBuiltinCallable(Object obj, String methodName) {
+ Class<?> objClass = obj.getClass();
+ List<MethodDescriptor> methodDescriptors = getMethods(objClass, methodName);
+ if (methodDescriptors.size() != 1) {
+ throw new IllegalStateException(String.format(
+ "Expected exactly 1 method named '%s' in %s, but found %s",
+ methodName, objClass, methodDescriptors.size()));
+ }
+ return new BuiltinCallable(methodName, obj, methodDescriptors.get(0));
+ }
+
+ /**
* Invokes the given structField=true method and returns the result.
*
* @param methodDescriptor the descriptor of the method to invoke