Use selfCall MethodDescriptor instead of BuiltinCallable in ApiExporter.
BuiltinCallable is going to undergo an imminent overhaul and not superfluously use FunctionSignature, so this is in preparation for that change.
RELNOTES: None.
@@ -28,7 +28,11 @@ import com.google.devtools.build.lib.skylarkinterface.SkylarkInterfaceUtils;
import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
import com.google.devtools.build.lib.syntax.BaseFunction;
import com.google.devtools.build.lib.syntax.FuncallExpression;
+import com.google.devtools.build.lib.syntax.FunctionSignature;
+import com.google.devtools.build.lib.syntax.MethodDescriptor;
import com.google.devtools.build.lib.syntax.SkylarkSemantics;
+import com.google.devtools.build.lib.syntax.SkylarkSignatureProcessor;
+import com.google.devtools.build.lib.syntax.SkylarkType;
import com.google.devtools.common.options.OptionsParser;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
@@ -110,8 +114,14 @@ public class ApiExporter {
if (typeModule != null) {
if (FuncallExpression.hasSelfCallMethod(
SkylarkSemantics.DEFAULT_SEMANTICS, obj.getClass())) {
+ MethodDescriptor descriptor =
+ FuncallExpression.getSelfCallMethodDescriptor(
+ SkylarkSemantics.DEFAULT_SEMANTICS, obj);
+
value = collectFunctionInfo(
- FuncallExpression.getSelfCallMethod(SkylarkSemantics.DEFAULT_SEMANTICS, obj));
+ descriptor.getName(),
+ SkylarkSignatureProcessor.getSignatureForCallable(
+ descriptor.getName(), descriptor, null, null));
} else {
value.setName(entry.getKey());
value.setType(entry.getKey());
@@ -136,14 +146,19 @@ public class ApiExporter {
}
private static Value.Builder collectFunctionInfo(BaseFunction func) {
+ return collectFunctionInfo(func.getName(), func.getSignature());
+ }
+
+ private static Value.Builder collectFunctionInfo(
+ String funcName, FunctionSignature.WithValues<Object, SkylarkType> funcSignature) {
Value.Builder value = Value.newBuilder();
- value.setName(func.getName());
+ value.setName(funcName);
Callable.Builder callable = Callable.newBuilder();
- ImmutableList<String> paramNames = func.getSignature().getSignature().getNames();
- List<Object> defaultValues = func.getSignature().getDefaultValues();
- int positionals = func.getSignature().getSignature().getShape().getMandatoryPositionals();
- int optionals = func.getSignature().getSignature().getShape().getOptionals();
+ ImmutableList<String> paramNames = funcSignature.getSignature().getNames();
+ List<Object> defaultValues = funcSignature.getDefaultValues();
+ int positionals = funcSignature.getSignature().getShape().getMandatoryPositionals();
+ int optionals = funcSignature.getSignature().getShape().getOptionals();
int nameIndex = 0;
for (int i = 0; i < positionals; i++) {
@@ -163,7 +178,7 @@ public class ApiExporter {
nameIndex++;
}
- if (func.getSignature().getSignature().getShape().hasStarArg()) {
+ if (funcSignature.getSignature().getShape().hasStarArg()) {
Param.Builder param = Param.newBuilder();
param.setName("*" + paramNames.get(nameIndex));
param.setIsMandatory(false);
@@ -171,7 +186,7 @@ public class ApiExporter {
nameIndex++;
callable.addParam(param);
}
- if (func.getSignature().getSignature().getShape().hasKwArg()) {
+ if (funcSignature.getSignature().getShape().hasKwArg()) {
Param.Builder param = Param.newBuilder();
param.setIsMandatory(false);
param.setIsStarStarArg(true);
