bazel syntax: rename UserDefinedFunction to StarlarkFunction
This CL is a pure renaming.
PiperOrigin-RevId: 265911662
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkAttr.java b/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkAttr.java
index fa254bc..92aee2c 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkAttr.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkAttr.java
@@ -49,10 +49,10 @@
import com.google.devtools.build.lib.syntax.SkylarkList;
import com.google.devtools.build.lib.syntax.SkylarkType;
import com.google.devtools.build.lib.syntax.SkylarkUtils;
+import com.google.devtools.build.lib.syntax.StarlarkFunction;
import com.google.devtools.build.lib.syntax.Type;
import com.google.devtools.build.lib.syntax.Type.ConversionException;
import com.google.devtools.build.lib.syntax.Type.LabelClass;
-import com.google.devtools.build.lib.syntax.UserDefinedFunction;
import com.google.devtools.build.lib.util.FileType;
import com.google.devtools.build.lib.util.FileTypeSet;
import java.util.List;
@@ -130,11 +130,11 @@
Object defaultValue = arguments.get(DEFAULT_ARG);
if (!EvalUtils.isNullOrNone(defaultValue)) {
- if (defaultValue instanceof UserDefinedFunction) {
+ if (defaultValue instanceof StarlarkFunction) {
// Computed attribute. Non label type attributes already caused a type check error.
SkylarkCallbackFunction callback =
new SkylarkCallbackFunction(
- (UserDefinedFunction) defaultValue, ast, env.getSemantics(), context);
+ (StarlarkFunction) defaultValue, ast, env.getSemantics(), context);
// SkylarkComputedDefaultTemplate needs to know the names of all attributes that it depends
// on. However, this method does not know anything about other attributes.
// We solve this problem by asking the SkylarkCallbackFunction for the parameter names used
diff --git a/src/main/java/com/google/devtools/build/lib/packages/RuleFactory.java b/src/main/java/com/google/devtools/build/lib/packages/RuleFactory.java
index 35517ed..29aace6 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/RuleFactory.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/RuleFactory.java
@@ -27,7 +27,7 @@
import com.google.devtools.build.lib.syntax.BaseFunction;
import com.google.devtools.build.lib.syntax.Environment;
import com.google.devtools.build.lib.syntax.FuncallExpression;
-import com.google.devtools.build.lib.syntax.UserDefinedFunction;
+import com.google.devtools.build.lib.syntax.StarlarkFunction;
import com.google.devtools.build.lib.util.Pair;
import java.util.Map;
import java.util.Set;
@@ -342,7 +342,7 @@
return new AttributesAndLocation(args, location);
}
Pair<FuncallExpression, BaseFunction> topCall = env.getTopCall();
- if (topCall == null || !(topCall.second instanceof UserDefinedFunction)) {
+ if (topCall == null || !(topCall.second instanceof StarlarkFunction)) {
return new AttributesAndLocation(args, location);
}
diff --git a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/SkylarkAttrApi.java b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/SkylarkAttrApi.java
index ee8997d..a1f8e18 100644
--- a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/SkylarkAttrApi.java
+++ b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/SkylarkAttrApi.java
@@ -27,8 +27,8 @@
import com.google.devtools.build.lib.syntax.FuncallExpression;
import com.google.devtools.build.lib.syntax.SkylarkDict;
import com.google.devtools.build.lib.syntax.SkylarkList;
+import com.google.devtools.build.lib.syntax.StarlarkFunction;
import com.google.devtools.build.lib.syntax.StarlarkSemantics.FlagIdentifier;
-import com.google.devtools.build.lib.syntax.UserDefinedFunction;
/**
* The "attr" module of the Build API.
@@ -152,7 +152,7 @@
name = DEFAULT_ARG,
allowedTypes = {
@ParamType(type = Integer.class),
- @ParamType(type = UserDefinedFunction.class)
+ @ParamType(type = StarlarkFunction.class)
},
defaultValue = "0",
doc = DEFAULT_DOC,
@@ -264,7 +264,7 @@
@ParamType(type = Label.class),
@ParamType(type = String.class),
@ParamType(type = LateBoundDefaultApi.class),
- @ParamType(type = UserDefinedFunction.class)
+ @ParamType(type = StarlarkFunction.class)
},
callbackEnabled = true,
noneable = true,
@@ -410,7 +410,7 @@
name = DEFAULT_ARG,
allowedTypes = {
@ParamType(type = SkylarkList.class, generic1 = String.class),
- @ParamType(type = UserDefinedFunction.class)
+ @ParamType(type = StarlarkFunction.class)
},
defaultValue = "[]",
doc = DEFAULT_DOC,
@@ -464,7 +464,7 @@
name = DEFAULT_ARG,
allowedTypes = {
@ParamType(type = SkylarkList.class, generic1 = Integer.class),
- @ParamType(type = UserDefinedFunction.class)
+ @ParamType(type = StarlarkFunction.class)
},
defaultValue = "[]",
doc = DEFAULT_DOC,
@@ -508,7 +508,7 @@
name = DEFAULT_ARG,
allowedTypes = {
@ParamType(type = SkylarkList.class, generic1 = Label.class),
- @ParamType(type = UserDefinedFunction.class)
+ @ParamType(type = StarlarkFunction.class)
},
callbackEnabled = true,
defaultValue = "[]",
@@ -625,7 +625,7 @@
name = DEFAULT_ARG,
allowedTypes = {
@ParamType(type = SkylarkDict.class),
- @ParamType(type = UserDefinedFunction.class)
+ @ParamType(type = StarlarkFunction.class)
},
callbackEnabled = true,
defaultValue = "{}",
@@ -734,7 +734,7 @@
name = DEFAULT_ARG,
allowedTypes = {
@ParamType(type = Boolean.class),
- @ParamType(type = UserDefinedFunction.class)
+ @ParamType(type = StarlarkFunction.class)
},
defaultValue = "False",
named = true,
@@ -775,7 +775,7 @@
name = DEFAULT_ARG,
allowedTypes = {
@ParamType(type = Label.class),
- @ParamType(type = UserDefinedFunction.class)
+ @ParamType(type = StarlarkFunction.class)
},
noneable = true,
defaultValue = "None",
@@ -825,7 +825,7 @@
name = DEFAULT_ARG,
allowedTypes = {
@ParamType(type = SkylarkList.class, generic1 = Label.class),
- @ParamType(type = UserDefinedFunction.class)
+ @ParamType(type = StarlarkFunction.class)
},
noneable = true,
defaultValue = "None",
@@ -886,7 +886,7 @@
name = DEFAULT_ARG,
allowedTypes = {
@ParamType(type = SkylarkDict.class),
- @ParamType(type = UserDefinedFunction.class)
+ @ParamType(type = StarlarkFunction.class)
},
named = true,
positional = false,
@@ -944,7 +944,7 @@
name = DEFAULT_ARG,
allowedTypes = {
@ParamType(type = SkylarkDict.class),
- @ParamType(type = UserDefinedFunction.class)
+ @ParamType(type = StarlarkFunction.class)
},
defaultValue = "{}",
named = true,
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/Environment.java b/src/main/java/com/google/devtools/build/lib/syntax/Environment.java
index a01dd72..eb30dee 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/Environment.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/Environment.java
@@ -126,10 +126,10 @@
*
* <p>Any non-frozen {@link Frame} must have the same {@link Mutability} as the current {@link
* Environment}, to avoid interference from other evaluation contexts. For example, a {@link
- * UserDefinedFunction} will close over the global frame of the {@link Environment} in which it
- * was defined. When the function is called from other {@link Environment}s (possibly
- * simultaneously), that global frame must already be frozen; a new local {@link Frame} is created
- * to represent the lexical scope of the function.
+ * StarlarkFunction} will close over the global frame of the {@link Environment} in which it was
+ * defined. When the function is called from other {@link Environment}s (possibly simultaneously),
+ * that global frame must already be frozen; a new local {@link Frame} is created to represent the
+ * lexical scope of the function.
*
* <p>A {@link Frame} can have an associated "parent" {@link Frame}, which is used in {@link #get}
* and {@link #getTransitiveBindings()}
@@ -885,7 +885,7 @@
* Returns if calling the supplied function would be a recursive call, or in other words if the
* supplied function is already on the stack.
*/
- boolean isRecursiveCall(UserDefinedFunction function) {
+ boolean isRecursiveCall(StarlarkFunction function) {
for (Continuation k = continuation; k != null; k = k.continuation) {
// TODO(adonovan): compare code, not closure values, otherwise
// one can defeat this check by writing the Y combinator.
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/Eval.java b/src/main/java/com/google/devtools/build/lib/syntax/Eval.java
index ee77b4d..cf81e59 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/Eval.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/Eval.java
@@ -121,7 +121,7 @@
env.updateAndExport(
node.getIdentifier().getName(),
- new UserDefinedFunction(
+ new StarlarkFunction(
node.getIdentifier().getName(),
node.getIdentifier().getLocation(),
FunctionSignature.WithValues.create(sig, defaultValues, /*types=*/ null),
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/FunctionSignature.java b/src/main/java/com/google/devtools/build/lib/syntax/FunctionSignature.java
index b30a2cc..f3a5609 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/FunctionSignature.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/FunctionSignature.java
@@ -193,7 +193,7 @@
*
* <p>The lists can be null, which is an optimized path for specifying all null values.
*
- * <p>Note that if some values can be null (for BuiltinFunction, not for UserDefinedFunction), you
+ * <p>Note that if some values can be null (for BuiltinFunction, not for StarlarkFunction), you
* should use an ArrayList; otherwise, we recommend an ImmutableList.
*
* <p>V is the class of defaultValues and T is the class of types. When parsing a function
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/Mutability.java b/src/main/java/com/google/devtools/build/lib/syntax/Mutability.java
index b608119..d994d1f 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/Mutability.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/Mutability.java
@@ -355,7 +355,7 @@
throw new MutabilityException("trying to mutate a frozen object");
}
- // Consider an {@link Environment} e1, in which is created {@link UserDefinedFunction} f1, that
+ // Consider an {@link Environment} e1, in which is created {@link StarlarkFunction} f1, that
// closes over some variable v1 bound to list l1. If somehow, via the magic of callbacks, f1 or
// l1 is passed as an argument to some function f2 evaluated in {@link Environment} e2 while e1
// is still mutable, then e2, being a different {@link Environment}, should not be allowed to
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/UserDefinedFunction.java b/src/main/java/com/google/devtools/build/lib/syntax/StarlarkFunction.java
similarity index 93%
rename from src/main/java/com/google/devtools/build/lib/syntax/UserDefinedFunction.java
rename to src/main/java/com/google/devtools/build/lib/syntax/StarlarkFunction.java
index f0591f1..5292e68 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/UserDefinedFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/StarlarkFunction.java
@@ -22,16 +22,15 @@
import com.google.devtools.build.lib.skylarkinterface.SkylarkPrinter;
import com.google.devtools.build.lib.syntax.Environment.LexicalFrame;
-/** A UserDefinedFunction is the function value created by a Starlark {@code def} statement. */
-// TODO(adonovan): rename to StarlarkFunction.
-public class UserDefinedFunction extends BaseFunction {
+/** A StarlarkFunction is the function value created by a Starlark {@code def} statement. */
+public class StarlarkFunction extends BaseFunction {
private final ImmutableList<Statement> statements;
// we close over the globals at the time of definition
private final Environment.GlobalFrame definitionGlobals;
- public UserDefinedFunction(
+ public StarlarkFunction(
String name,
Location location,
FunctionSignature.WithValues<Object, SkylarkType> signature,
diff --git a/src/main/java/com/google/devtools/build/skydoc/SkydocMain.java b/src/main/java/com/google/devtools/build/skydoc/SkydocMain.java
index b0df9d3..8467aac 100644
--- a/src/main/java/com/google/devtools/build/skydoc/SkydocMain.java
+++ b/src/main/java/com/google/devtools/build/skydoc/SkydocMain.java
@@ -66,10 +66,10 @@
import com.google.devtools.build.lib.syntax.ParserInputSource;
import com.google.devtools.build.lib.syntax.Runtime;
import com.google.devtools.build.lib.syntax.SkylarkImport;
+import com.google.devtools.build.lib.syntax.StarlarkFunction;
import com.google.devtools.build.lib.syntax.StarlarkSemantics;
import com.google.devtools.build.lib.syntax.Statement;
import com.google.devtools.build.lib.syntax.StringLiteral;
-import com.google.devtools.build.lib.syntax.UserDefinedFunction;
import com.google.devtools.build.skydoc.fakebuildapi.FakeActionsInfoProvider;
import com.google.devtools.build.skydoc.fakebuildapi.FakeBuildApiGlobals;
import com.google.devtools.build.skydoc.fakebuildapi.FakeConfigApi;
@@ -210,7 +210,7 @@
ImmutableMap.Builder<String, RuleInfo> ruleInfoMap = ImmutableMap.builder();
ImmutableMap.Builder<String, ProviderInfo> providerInfoMap = ImmutableMap.builder();
- ImmutableMap.Builder<String, UserDefinedFunction> userDefinedFunctions = ImmutableMap.builder();
+ ImmutableMap.Builder<String, StarlarkFunction> userDefinedFunctions = ImmutableMap.builder();
ImmutableMap.Builder<String, AspectInfo> aspectInfoMap = ImmutableMap.builder();
ImmutableMap.Builder<Label, String> moduleDocMap = ImmutableMap.builder();
@@ -237,7 +237,7 @@
providerInfoMap.build().entrySet().stream()
.filter(entry -> validSymbolName(symbolNames, entry.getKey()))
.collect(ImmutableMap.toImmutableMap(Entry::getKey, Entry::getValue));
- Map<String, UserDefinedFunction> filteredUserDefinedFunctions =
+ Map<String, StarlarkFunction> filteredStarlarkFunctions =
userDefinedFunctions.build().entrySet().stream()
.filter(entry -> validSymbolName(symbolNames, entry.getKey()))
.collect(ImmutableMap.toImmutableMap(Entry::getKey, Entry::getValue));
@@ -250,7 +250,7 @@
new ProtoRenderer()
.appendRuleInfos(filteredRuleInfos.values())
.appendProviderInfos(filteredProviderInfos.values())
- .appendUserDefinedFunctionInfos(filteredUserDefinedFunctions)
+ .appendStarlarkFunctionInfos(filteredStarlarkFunctions)
.appendAspectInfos(filteredAspectInfos.values())
.setModuleDocstring(moduleDocMap.build().get(targetFileLabel))
.writeModuleInfo(out);
@@ -284,8 +284,8 @@
* ProviderInfo} descriptions. For example, 'my_provider = provider(...)' has key
* 'my_provider'
* @param userDefinedFunctionMap a map builder to be populated with user-defined functions. Keys
- * are exported names of functions, and values are the {@link UserDefinedFunction} objects.
- * For example, 'def my_function(foo):' is a function with key 'my_function'.
+ * are exported names of functions, and values are the {@link StarlarkFunction} objects. For
+ * example, 'def my_function(foo):' is a function with key 'my_function'.
* @param aspectInfoMap a map builder to be populated with aspect definition information for named
* aspects. Keys are exported names of aspects, and values are the {@link AspectInfo} asepct
* descriptions. For example, 'my_aspect = aspect(...)' has key 'my_aspect'
@@ -299,7 +299,7 @@
Label label,
ImmutableMap.Builder<String, RuleInfo> ruleInfoMap,
ImmutableMap.Builder<String, ProviderInfo> providerInfoMap,
- ImmutableMap.Builder<String, UserDefinedFunction> userDefinedFunctionMap,
+ ImmutableMap.Builder<String, StarlarkFunction> userDefinedFunctionMap,
ImmutableMap.Builder<String, AspectInfo> aspectInfoMap,
ImmutableMap.Builder<Label, String> moduleDocMap)
throws InterruptedException, IOException, LabelSyntaxException, EvalException,
@@ -344,8 +344,8 @@
ProviderInfo providerInfo = providerInfoBuild.setProviderName(envEntry.getKey()).build();
providerInfoMap.put(envEntry.getKey(), providerInfo);
}
- if (envEntry.getValue() instanceof UserDefinedFunction) {
- UserDefinedFunction userDefinedFunction = (UserDefinedFunction) envEntry.getValue();
+ if (envEntry.getValue() instanceof StarlarkFunction) {
+ StarlarkFunction userDefinedFunction = (StarlarkFunction) envEntry.getValue();
userDefinedFunctionMap.put(envEntry.getKey(), userDefinedFunction);
}
if (envEntry.getValue() instanceof FakeStructApi) {
@@ -375,12 +375,12 @@
private static void putStructFields(
String namespaceName,
FakeStructApi namespace,
- ImmutableMap.Builder<String, UserDefinedFunction> userDefinedFunctionMap)
+ ImmutableMap.Builder<String, StarlarkFunction> userDefinedFunctionMap)
throws EvalException {
for (String field : namespace.getFieldNames()) {
String qualifiedFieldName = namespaceName + "." + field;
- if (namespace.getValue(field) instanceof UserDefinedFunction) {
- UserDefinedFunction userDefinedFunction = (UserDefinedFunction) namespace.getValue(field);
+ if (namespace.getValue(field) instanceof StarlarkFunction) {
+ StarlarkFunction userDefinedFunction = (StarlarkFunction) namespace.getValue(field);
userDefinedFunctionMap.put(qualifiedFieldName, userDefinedFunction);
} else if (namespace.getValue(field) instanceof FakeStructApi) {
FakeStructApi innerNamespace = (FakeStructApi) namespace.getValue(field);
diff --git a/src/main/java/com/google/devtools/build/skydoc/renderer/RendererMain.java b/src/main/java/com/google/devtools/build/skydoc/renderer/RendererMain.java
index 568520f..038bea7 100644
--- a/src/main/java/com/google/devtools/build/skydoc/renderer/RendererMain.java
+++ b/src/main/java/com/google/devtools/build/skydoc/renderer/RendererMain.java
@@ -19,7 +19,7 @@
import com.google.devtools.build.skydoc.rendering.proto.StardocOutputProtos.ModuleInfo;
import com.google.devtools.build.skydoc.rendering.proto.StardocOutputProtos.ProviderInfo;
import com.google.devtools.build.skydoc.rendering.proto.StardocOutputProtos.RuleInfo;
-import com.google.devtools.build.skydoc.rendering.proto.StardocOutputProtos.UserDefinedFunctionInfo;
+import com.google.devtools.build.skydoc.rendering.proto.StardocOutputProtos.StarlarkFunctionInfo;
import com.google.devtools.common.options.OptionsParser;
import com.google.protobuf.InvalidProtocolBufferException;
import java.io.FileInputStream;
@@ -77,7 +77,7 @@
printWriter.println(renderer.renderMarkdownHeader(moduleInfo));
printRuleInfos(printWriter, renderer, moduleInfo.getRuleInfoList());
printProviderInfos(printWriter, renderer, moduleInfo.getProviderInfoList());
- printUserDefinedFunctions(printWriter, renderer, moduleInfo.getFuncInfoList());
+ printStarlarkFunctions(printWriter, renderer, moduleInfo.getFuncInfoList());
printAspectInfos(printWriter, renderer, moduleInfo.getAspectInfoList());
} catch (InvalidProtocolBufferException e) {
throw new IllegalArgumentException("Input file is not a valid ModuleInfo proto.", e);
@@ -102,12 +102,12 @@
}
}
- private static void printUserDefinedFunctions(
+ private static void printStarlarkFunctions(
PrintWriter printWriter,
MarkdownRenderer renderer,
- List<UserDefinedFunctionInfo> userDefinedFunctions)
+ List<StarlarkFunctionInfo> userDefinedFunctions)
throws IOException {
- for (UserDefinedFunctionInfo funcProto : userDefinedFunctions) {
+ for (StarlarkFunctionInfo funcProto : userDefinedFunctions) {
printWriter.println(renderer.render(funcProto));
printWriter.println();
}
diff --git a/src/main/java/com/google/devtools/build/skydoc/rendering/DocstringParseException.java b/src/main/java/com/google/devtools/build/skydoc/rendering/DocstringParseException.java
index a7825d1..5889ba7 100644
--- a/src/main/java/com/google/devtools/build/skydoc/rendering/DocstringParseException.java
+++ b/src/main/java/com/google/devtools/build/skydoc/rendering/DocstringParseException.java
@@ -15,12 +15,12 @@
package com.google.devtools.build.skydoc.rendering;
import com.google.devtools.build.lib.events.Location;
-import com.google.devtools.build.skydoc.rendering.proto.StardocOutputProtos.UserDefinedFunctionInfo;
+import com.google.devtools.build.skydoc.rendering.proto.StardocOutputProtos.StarlarkFunctionInfo;
import com.google.devtools.skylark.common.DocstringUtils.DocstringParseError;
import java.util.List;
/**
- * An exception that may be thrown during construction of {@link UserDefinedFunctionInfo} if the
+ * An exception that may be thrown during construction of {@link StarlarkFunctionInfo} if the
* function's docstring is malformed.
*/
public class DocstringParseException extends Exception {
diff --git a/src/main/java/com/google/devtools/build/skydoc/rendering/FunctionUtil.java b/src/main/java/com/google/devtools/build/skydoc/rendering/FunctionUtil.java
index 9ff337b..265922d 100644
--- a/src/main/java/com/google/devtools/build/skydoc/rendering/FunctionUtil.java
+++ b/src/main/java/com/google/devtools/build/skydoc/rendering/FunctionUtil.java
@@ -21,10 +21,10 @@
import com.google.devtools.build.lib.syntax.Printer;
import com.google.devtools.build.lib.syntax.Printer.BasePrinter;
import com.google.devtools.build.lib.syntax.SkylarkType;
+import com.google.devtools.build.lib.syntax.StarlarkFunction;
import com.google.devtools.build.lib.syntax.StringLiteral;
-import com.google.devtools.build.lib.syntax.UserDefinedFunction;
import com.google.devtools.build.skydoc.rendering.proto.StardocOutputProtos.FunctionParamInfo;
-import com.google.devtools.build.skydoc.rendering.proto.StardocOutputProtos.UserDefinedFunctionInfo;
+import com.google.devtools.build.skydoc.rendering.proto.StardocOutputProtos.StarlarkFunctionInfo;
import com.google.devtools.skylark.common.DocstringUtils;
import com.google.devtools.skylark.common.DocstringUtils.DocstringInfo;
import com.google.devtools.skylark.common.DocstringUtils.DocstringParseError;
@@ -36,8 +36,8 @@
/** Contains a number of utility methods for functions and parameters. */
public final class FunctionUtil {
/**
- * Create and return a {@link UserDefinedFunctionInfo} object encapsulating information obtained
- * from the given function and from its parsed docstring.
+ * Create and return a {@link StarlarkFunctionInfo} object encapsulating information obtained from
+ * the given function and from its parsed docstring.
*
* @param functionName the name of the function in the target scope. (Note this is not necessarily
* the original exported function name; the function may have been renamed in the target
@@ -46,8 +46,8 @@
* @throws com.google.devtools.build.skydoc.rendering.DocstringParseException if the function's
* docstring is malformed
*/
- public static UserDefinedFunctionInfo fromNameAndFunction(
- String functionName, UserDefinedFunction userDefinedFunction) throws DocstringParseException {
+ public static StarlarkFunctionInfo fromNameAndFunction(
+ String functionName, StarlarkFunction userDefinedFunction) throws DocstringParseException {
String functionDescription = "";
Map<String, String> paramNameToDocMap = Maps.newLinkedHashMap();
@@ -71,7 +71,7 @@
}
}
List<FunctionParamInfo> paramsInfo = parameterInfos(userDefinedFunction, paramNameToDocMap);
- return UserDefinedFunctionInfo.newBuilder()
+ return StarlarkFunctionInfo.newBuilder()
.setFunctionName(functionName)
.setDocString(functionDescription)
.addAllParameter(paramsInfo)
@@ -108,7 +108,7 @@
}
private static List<FunctionParamInfo> parameterInfos(
- UserDefinedFunction userDefinedFunction, Map<String, String> paramNameToDocMap) {
+ StarlarkFunction userDefinedFunction, Map<String, String> paramNameToDocMap) {
FunctionSignature.WithValues<Object, SkylarkType> signature =
userDefinedFunction.getSignature();
ImmutableList.Builder<FunctionParamInfo> parameterInfos = ImmutableList.builder();
diff --git a/src/main/java/com/google/devtools/build/skydoc/rendering/MarkdownRenderer.java b/src/main/java/com/google/devtools/build/skydoc/rendering/MarkdownRenderer.java
index 94543c2..5ae595f 100644
--- a/src/main/java/com/google/devtools/build/skydoc/rendering/MarkdownRenderer.java
+++ b/src/main/java/com/google/devtools/build/skydoc/rendering/MarkdownRenderer.java
@@ -20,7 +20,7 @@
import com.google.devtools.build.skydoc.rendering.proto.StardocOutputProtos.ModuleInfo;
import com.google.devtools.build.skydoc.rendering.proto.StardocOutputProtos.ProviderInfo;
import com.google.devtools.build.skydoc.rendering.proto.StardocOutputProtos.RuleInfo;
-import com.google.devtools.build.skydoc.rendering.proto.StardocOutputProtos.UserDefinedFunctionInfo;
+import com.google.devtools.build.skydoc.rendering.proto.StardocOutputProtos.StarlarkFunctionInfo;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
@@ -136,7 +136,7 @@
* Returns a markdown rendering of a user-defined function's documentation for the function info
* object.
*/
- public String render(UserDefinedFunctionInfo functionInfo) throws IOException {
+ public String render(StarlarkFunctionInfo functionInfo) throws IOException {
VelocityContext context = new VelocityContext();
context.put("util", new MarkdownUtil());
context.put("funcInfo", functionInfo);
diff --git a/src/main/java/com/google/devtools/build/skydoc/rendering/MarkdownUtil.java b/src/main/java/com/google/devtools/build/skydoc/rendering/MarkdownUtil.java
index 3392e70..8328586 100644
--- a/src/main/java/com/google/devtools/build/skydoc/rendering/MarkdownUtil.java
+++ b/src/main/java/com/google/devtools/build/skydoc/rendering/MarkdownUtil.java
@@ -22,7 +22,7 @@
import com.google.devtools.build.skydoc.rendering.proto.StardocOutputProtos.ProviderInfo;
import com.google.devtools.build.skydoc.rendering.proto.StardocOutputProtos.ProviderNameGroup;
import com.google.devtools.build.skydoc.rendering.proto.StardocOutputProtos.RuleInfo;
-import com.google.devtools.build.skydoc.rendering.proto.StardocOutputProtos.UserDefinedFunctionInfo;
+import com.google.devtools.build.skydoc.rendering.proto.StardocOutputProtos.StarlarkFunctionInfo;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@@ -87,11 +87,10 @@
/**
* Return a string representing the summary for the given user-defined function.
*
- * For example: 'my_func(foo, bar)'.
- * The summary will contain hyperlinks for each parameter.
+ * <p>For example: 'my_func(foo, bar)'. The summary will contain hyperlinks for each parameter.
*/
@SuppressWarnings("unused") // Used by markdown template.
- public String funcSummary(UserDefinedFunctionInfo funcInfo) {
+ public String funcSummary(StarlarkFunctionInfo funcInfo) {
List<String> paramNames =
funcInfo.getParameterList().stream()
.map(param -> param.getName())
diff --git a/src/main/java/com/google/devtools/build/skydoc/rendering/ProtoRenderer.java b/src/main/java/com/google/devtools/build/skydoc/rendering/ProtoRenderer.java
index 629f2cd..728cf187 100644
--- a/src/main/java/com/google/devtools/build/skydoc/rendering/ProtoRenderer.java
+++ b/src/main/java/com/google/devtools/build/skydoc/rendering/ProtoRenderer.java
@@ -14,12 +14,12 @@
package com.google.devtools.build.skydoc.rendering;
-import com.google.devtools.build.lib.syntax.UserDefinedFunction;
+import com.google.devtools.build.lib.syntax.StarlarkFunction;
import com.google.devtools.build.skydoc.rendering.proto.StardocOutputProtos.AspectInfo;
import com.google.devtools.build.skydoc.rendering.proto.StardocOutputProtos.ModuleInfo;
import com.google.devtools.build.skydoc.rendering.proto.StardocOutputProtos.ProviderInfo;
import com.google.devtools.build.skydoc.rendering.proto.StardocOutputProtos.RuleInfo;
-import com.google.devtools.build.skydoc.rendering.proto.StardocOutputProtos.UserDefinedFunctionInfo;
+import com.google.devtools.build.skydoc.rendering.proto.StardocOutputProtos.StarlarkFunctionInfo;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.util.Collection;
@@ -50,11 +50,11 @@
return this;
}
- /** Appends {@link UserDefinedFunctionInfo} protos to a {@link ModuleInfo.Builder}. */
- public ProtoRenderer appendUserDefinedFunctionInfos(Map<String, UserDefinedFunction> funcInfosMap)
+ /** Appends {@link StarlarkFunctionInfo} protos to a {@link ModuleInfo.Builder}. */
+ public ProtoRenderer appendStarlarkFunctionInfos(Map<String, StarlarkFunction> funcInfosMap)
throws DocstringParseException {
- for (Map.Entry<String, UserDefinedFunction> entry : funcInfosMap.entrySet()) {
- UserDefinedFunctionInfo funcInfo =
+ for (Map.Entry<String, StarlarkFunction> entry : funcInfosMap.entrySet()) {
+ StarlarkFunctionInfo funcInfo =
FunctionUtil.fromNameAndFunction(entry.getKey(), entry.getValue());
moduleInfo.addFuncInfo(funcInfo);
}
diff --git a/src/main/java/com/google/devtools/build/skydoc/rendering/proto/stardoc_output.proto b/src/main/java/com/google/devtools/build/skydoc/rendering/proto/stardoc_output.proto
index 2a3674e..5cf36ef 100644
--- a/src/main/java/com/google/devtools/build/skydoc/rendering/proto/stardoc_output.proto
+++ b/src/main/java/com/google/devtools/build/skydoc/rendering/proto/stardoc_output.proto
@@ -31,7 +31,7 @@
repeated ProviderInfo provider_info = 2;
- repeated UserDefinedFunctionInfo func_info = 3;
+ repeated StarlarkFunctionInfo func_info = 3;
repeated AspectInfo aspect_info = 4;
@@ -110,7 +110,7 @@
}
// Representation of Starlark function definition.
-message UserDefinedFunctionInfo {
+message StarlarkFunctionInfo {
// The name of the function.
string function_name = 1;
diff --git a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleClassFunctionsTest.java b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleClassFunctionsTest.java
index fc9c05f..41235cd 100644
--- a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleClassFunctionsTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleClassFunctionsTest.java
@@ -136,7 +136,7 @@
return ((SkylarkRuleFunction) lookup(name)).getRuleClass();
}
- private void registerDummyUserDefinedFunction() throws Exception {
+ private void registerDummyStarlarkFunction() throws Exception {
eval("def impl():", " pass");
}
@@ -776,7 +776,7 @@
@Test
public void testRuleUnknownKeyword() throws Exception {
- registerDummyUserDefinedFunction();
+ registerDummyStarlarkFunction();
checkErrorContains(
"unexpected keyword 'bad_keyword', for call to function rule(",
"rule(impl, bad_keyword = 'some text')");
@@ -791,7 +791,7 @@
@Test
public void testRuleBadTypeForAdd() throws Exception {
- registerDummyUserDefinedFunction();
+ registerDummyStarlarkFunction();
checkErrorContains(
"expected value of type 'dict or NoneType' for parameter 'attrs', "
+ "for call to function rule(",
@@ -800,7 +800,7 @@
@Test
public void testRuleBadTypeInAdd() throws Exception {
- registerDummyUserDefinedFunction();
+ registerDummyStarlarkFunction();
checkErrorContains(
"expected <String, Descriptor> type for 'attrs' but got <string, string> instead",
"rule(impl, attrs = {'a1': 'some text'})");
@@ -808,7 +808,7 @@
@Test
public void testRuleBadTypeForDoc() throws Exception {
- registerDummyUserDefinedFunction();
+ registerDummyStarlarkFunction();
checkErrorContains(
"expected value of type 'string' for parameter 'doc', for call to function rule(",
"rule(impl, doc = 1)");
@@ -1575,7 +1575,7 @@
@Test
public void aspectBadTypeForDoc() throws Exception {
- registerDummyUserDefinedFunction();
+ registerDummyStarlarkFunction();
checkErrorContains(
"expected value of type 'string' for parameter 'doc', for call to function aspect(",
"aspect(impl, doc = 1)");
@@ -1737,7 +1737,7 @@
@Test
public void testRuleAddExecutionConstraints() throws Exception {
- registerDummyUserDefinedFunction();
+ registerDummyStarlarkFunction();
scratch.file("test/BUILD", "toolchain_type(name = 'my_toolchain_type')");
evalAndExport(
"r1 = rule(",
@@ -1759,7 +1759,7 @@
ev = createEvaluationTestCase(semantics);
ev.initialize();
- registerDummyUserDefinedFunction();
+ registerDummyStarlarkFunction();
scratch.file("test/BUILD", "toolchain_type(name = 'my_toolchain_type')");
evalAndExport(
"r1 = rule(impl, ",
@@ -1780,7 +1780,7 @@
ev = createEvaluationTestCase(semantics);
ev.initialize();
- registerDummyUserDefinedFunction();
+ registerDummyStarlarkFunction();
scratch.file("test/BUILD", "toolchain_type(name = 'my_toolchain_type')");
evalAndExport(
"r1 = rule(impl, ",
@@ -1802,7 +1802,7 @@
ev.setFailFast(false);
ev.initialize();
- registerDummyUserDefinedFunction();
+ registerDummyStarlarkFunction();
scratch.file("test/BUILD", "toolchain_type(name = 'my_toolchain_type')");
evalAndExport(
"r1 = rule(impl, ",
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/FunctionTest.java b/src/test/java/com/google/devtools/build/lib/syntax/FunctionTest.java
index 9ead6c1..a017ac0 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/FunctionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/FunctionTest.java
@@ -34,7 +34,7 @@
eval("def func(a,b,c):",
" a = 1",
" b = a\n");
- UserDefinedFunction stmt = (UserDefinedFunction) lookup("func");
+ StarlarkFunction stmt = (StarlarkFunction) lookup("func");
assertThat(stmt).isNotNull();
assertThat(stmt.getName()).isEqualTo("func");
assertThat(stmt.getSignature().getSignature().getShape().getMandatoryPositionals())
diff --git a/src/test/java/com/google/devtools/build/skydoc/MarkdownRendererTest.java b/src/test/java/com/google/devtools/build/skydoc/MarkdownRendererTest.java
index aafdc89..4596291 100644
--- a/src/test/java/com/google/devtools/build/skydoc/MarkdownRendererTest.java
+++ b/src/test/java/com/google/devtools/build/skydoc/MarkdownRendererTest.java
@@ -25,7 +25,7 @@
import com.google.devtools.build.skydoc.rendering.proto.StardocOutputProtos.ProviderFieldInfo;
import com.google.devtools.build.skydoc.rendering.proto.StardocOutputProtos.ProviderInfo;
import com.google.devtools.build.skydoc.rendering.proto.StardocOutputProtos.RuleInfo;
-import com.google.devtools.build.skydoc.rendering.proto.StardocOutputProtos.UserDefinedFunctionInfo;
+import com.google.devtools.build.skydoc.rendering.proto.StardocOutputProtos.StarlarkFunctionInfo;
import java.io.IOException;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -131,8 +131,8 @@
.setDocString("the first parameter")
.setDefaultValue("32")
.build();
- UserDefinedFunctionInfo funcInfo =
- UserDefinedFunctionInfo.newBuilder()
+ StarlarkFunctionInfo funcInfo =
+ StarlarkFunctionInfo.newBuilder()
.setFunctionName("my_function")
.setDocString("This function does something.")
.addParameter(paramInfo)
diff --git a/src/test/java/com/google/devtools/build/skydoc/SkydocTest.java b/src/test/java/com/google/devtools/build/skydoc/SkydocTest.java
index 1f04f8b..fba1bdc 100644
--- a/src/test/java/com/google/devtools/build/skydoc/SkydocTest.java
+++ b/src/test/java/com/google/devtools/build/skydoc/SkydocTest.java
@@ -23,8 +23,8 @@
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.skylark.util.SkylarkTestCase;
import com.google.devtools.build.lib.syntax.ParserInputSource;
+import com.google.devtools.build.lib.syntax.StarlarkFunction;
import com.google.devtools.build.lib.syntax.StarlarkSemantics;
-import com.google.devtools.build.lib.syntax.UserDefinedFunction;
import com.google.devtools.build.lib.vfs.FileSystemUtils;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.skydoc.SkydocMain.StarlarkEvaluationException;
@@ -36,7 +36,7 @@
import com.google.devtools.build.skydoc.rendering.proto.StardocOutputProtos.ModuleInfo;
import com.google.devtools.build.skydoc.rendering.proto.StardocOutputProtos.ProviderInfo;
import com.google.devtools.build.skydoc.rendering.proto.StardocOutputProtos.RuleInfo;
-import com.google.devtools.build.skydoc.rendering.proto.StardocOutputProtos.UserDefinedFunctionInfo;
+import com.google.devtools.build.skydoc.rendering.proto.StardocOutputProtos.StarlarkFunctionInfo;
import java.io.IOException;
import java.util.Map;
import java.util.stream.Collectors;
@@ -395,7 +395,7 @@
" \"\"\"",
" pass");
- ImmutableMap.Builder<String, UserDefinedFunction> functionInfoBuilder = ImmutableMap.builder();
+ ImmutableMap.Builder<String, StarlarkFunction> functionInfoBuilder = ImmutableMap.builder();
skydocMain.eval(
StarlarkSemantics.DEFAULT_SEMANTICS,
@@ -406,7 +406,7 @@
ImmutableMap.builder(),
ImmutableMap.builder());
- UserDefinedFunction checkSourcesFn = functionInfoBuilder.build().get("check_sources");
+ StarlarkFunction checkSourcesFn = functionInfoBuilder.build().get("check_sources");
DocstringParseException expected =
assertThrows(
DocstringParseException.class,
@@ -439,7 +439,7 @@
"\"\"\"",
"pass");
- ImmutableMap.Builder<String, UserDefinedFunction> funcInfoMap = ImmutableMap.builder();
+ ImmutableMap.Builder<String, StarlarkFunction> funcInfoMap = ImmutableMap.builder();
skydocMain.eval(
StarlarkSemantics.DEFAULT_SEMANTICS,
@@ -450,17 +450,17 @@
ImmutableMap.builder(),
ImmutableMap.builder());
- Map<String, UserDefinedFunction> functions = funcInfoMap.build();
+ Map<String, StarlarkFunction> functions = funcInfoMap.build();
assertThat(functions).hasSize(1);
ModuleInfo moduleInfo =
- new ProtoRenderer().appendUserDefinedFunctionInfos(functions).getModuleInfo().build();
- UserDefinedFunctionInfo funcInfo = moduleInfo.getFuncInfo(0);
+ new ProtoRenderer().appendStarlarkFunctionInfos(functions).getModuleInfo().build();
+ StarlarkFunctionInfo funcInfo = moduleInfo.getFuncInfo(0);
assertThat(funcInfo.getFunctionName()).isEqualTo("check_function");
assertThat(getParamNames(funcInfo)).containsExactly("foo", "bar", "baz").inOrder();
}
- private static Iterable<String> getParamNames(UserDefinedFunctionInfo funcInfo) {
+ private static Iterable<String> getParamNames(StarlarkFunctionInfo funcInfo) {
return funcInfo.getParameterList().stream()
.map(param -> param.getName())
.collect(Collectors.toList());