aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/syntax/BuiltinFunction.java
diff options
context:
space:
mode:
authorGravatar Francois-Rene Rideau <tunes@google.com>2015-04-20 18:35:05 +0000
committerGravatar Laszlo Csomor <laszlocsomor@google.com>2015-04-21 10:57:39 +0000
commita3ac202ec114c092221b296a2695d0aadd50031f (patch)
treef06351880eb87347d3ca5e247ab4e050831c903d /src/main/java/com/google/devtools/build/lib/syntax/BuiltinFunction.java
parent1c72383a145ce29174fee15525d3caf44ae47959 (diff)
Migrate SkylarkBuiltin annotations to SkylarkSignature instead.
-- MOS_MIGRATED_REVID=91603959
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/syntax/BuiltinFunction.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/syntax/BuiltinFunction.java18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/BuiltinFunction.java b/src/main/java/com/google/devtools/build/lib/syntax/BuiltinFunction.java
index fb9e2fdabb..08ea8ee3c1 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/BuiltinFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/BuiltinFunction.java
@@ -16,6 +16,7 @@ package com.google.devtools.build.lib.syntax;
import com.google.common.base.Preconditions;
import com.google.devtools.build.lib.events.Location;
import com.google.devtools.build.lib.packages.Type.ConversionException;
+import com.google.devtools.build.lib.syntax.SkylarkSignatureProcessor.HackHackEitherList;
import com.google.devtools.build.lib.syntax.SkylarkType.SkylarkFunctionType;
import java.lang.reflect.InvocationTargetException;
@@ -59,6 +60,9 @@ public class BuiltinFunction extends BaseFunction {
// to be used as size of argument array by the outer call method.
private int innerArgumentCount;
+ // The returnType of the method.
+ private Class<?> returnType;
+
/** Create unconfigured function from its name */
public BuiltinFunction(String name) {
@@ -202,6 +206,7 @@ public class BuiltinFunction extends BaseFunction {
enforcedArgumentTypes = new ArrayList<>();
this.extraArgs = SkylarkSignatureProcessor.getExtraArgs(annotation);
super.configure(annotation);
+ this.returnType = annotation.returnType();
}
// finds the method and makes it accessible (which is needed to find it, and later to use it)
@@ -236,8 +241,6 @@ public class BuiltinFunction extends BaseFunction {
"bad argument count for %s: method has %s arguments, type list has %s",
getName(), innerArgumentCount, parameterTypes.length);
- // TODO(bazel-team): also grab the returnType from the annotations,
- // and check it against method return type
if (enforcedArgumentTypes != null) {
for (int i = 0; i < arguments; i++) {
SkylarkType enforcedType = enforcedArgumentTypes.get(i);
@@ -254,8 +257,7 @@ public class BuiltinFunction extends BaseFunction {
// No need to enforce Simple types on the Skylark side, the JVM will do it for us.
enforcedArgumentTypes.set(i, null);
} else if (enforcedType instanceof SkylarkType.Combination) {
- Preconditions.checkArgument(
- enforcedType.getType() == parameterType, msg);
+ Preconditions.checkArgument(enforcedType.getType() == parameterType, msg);
} else {
Preconditions.checkArgument(
parameterType == Object.class || parameterType == null, msg);
@@ -265,6 +267,14 @@ public class BuiltinFunction extends BaseFunction {
}
// No need for the enforcedArgumentTypes List if all the types were Simple
enforcedArgumentTypes = FunctionSignature.<SkylarkType>valueListOrNull(enforcedArgumentTypes);
+
+ if (returnType != null) {
+ Class<?> type = returnType;
+ if (type == HackHackEitherList.class) {
+ type = Object.class;
+ }
+ Preconditions.checkArgument(type == invokeMethod.getReturnType());
+ }
}
/** Configure by copying another function's configuration */