Skip to content

Commit

Permalink
starlark annot: delete Param.type and Param.noneable
Browse files Browse the repository at this point in the history
They are redundant wrt allowedTypes, and create inconsistency/confusion.

BUG=168743413
PiperOrigin-RevId: 337936296
  • Loading branch information
adonovan authored and copybara-github committed Oct 19, 2020
1 parent ffd088f commit 6cb560f
Show file tree
Hide file tree
Showing 111 changed files with 1,309 additions and 2,097 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,38 +27,29 @@ public StarlarkParamDoc(StarlarkMethodDoc method, Param param) {
}

/**
* Returns the string representing the type of this parameter with the link to the
* documentation for the type if available.
* Returns the string representing the type of this parameter with the link to the documentation
* for the type if available.
*
* <p>If the parameter type is Object, then returns the empty string. If the parameter
* type is not a generic, then this method returns a string representing the type name
* with a link to the documentation for the type if available. If the parameter type
* is a generic, then this method returns a string "CONTAINER of TYPE".
* <p>If the parameter type is Object, then returns the empty string. If the parameter type is not
* a generic, then this method returns a string representing the type name with a link to the
* documentation for the type if available. If the parameter type is a generic, then this method
* returns a string "CONTAINER of TYPE" (with HTML link markup).
*/
public String getType() {
if (param.type().equals(Object.class)) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < param.allowedTypes().length; i++) {
ParamType paramType = param.allowedTypes()[i];
// Use the paramType's generic class if provided, otherwise the param's generic class
Class<?> generic =
paramType.generic1() == Object.class ? param.generic1() : paramType.generic1();
if (generic.equals(Object.class)) {
sb.append(getTypeAnchor(paramType.type()));
} else {
sb.append(getTypeAnchor(paramType.type(), generic));
}
if (i < param.allowedTypes().length - 1) {
sb.append("; or ");
}
StringBuilder sb = new StringBuilder();
for (int i = 0; i < param.allowedTypes().length; i++) {
ParamType paramType = param.allowedTypes()[i];
// TODO(adonovan): make generic1 an array.
if (paramType.generic1() == Object.class) {
sb.append(getTypeAnchor(paramType.type()));
} else {
sb.append(getTypeAnchor(paramType.type(), paramType.generic1()));
}
if (i < param.allowedTypes().length - 1) {
sb.append("; or ");
}
return sb.toString();
}
if (param.generic1().equals(Object.class)) {
return getTypeAnchor(param.type());
} else {
return getTypeAnchor(param.type(), param.generic1());
}
return sb.toString();
}

public StarlarkMethodDoc getMethod() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -531,10 +531,7 @@ public Label getLocalTargetLabel(String targetName) throws LabelSyntaxException
+ "Label(\"@remapped//wiz:quux\")\n"
+ "</pre>",
parameters = {
@Param(
name = "relName",
type = String.class,
doc = "The label that will be resolved relative to this one.")
@Param(name = "relName", doc = "The label that will be resolved relative to this one.")
},
useStarlarkThread = true)
public Label getRelative(String relName, StarlarkThread thread) throws LabelSyntaxException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.List;
import java.util.Set;
import net.starlark.java.annot.Param;
import net.starlark.java.annot.ParamType;
import net.starlark.java.annot.StarlarkMethod;
import net.starlark.java.eval.Dict;
import net.starlark.java.eval.EvalException;
Expand Down Expand Up @@ -100,11 +101,9 @@ private static class CommonLibrary {
parameters = {
@Param(
name = "x",
type = Object.class,
defaultValue = "None",
positional = true,
named = false,
noneable = true,
doc =
"A positional parameter distinct from other parameters for legacy support. "
+ "\n" //
Expand All @@ -118,32 +117,29 @@ private static class CommonLibrary {
// TODO(cparsons): Make 'order' keyword-only.
@Param(
name = "order",
type = String.class,
defaultValue = "\"default\"",
doc =
"The traversal strategy for the new depset. See "
+ "<a href=\"depset.html\">here</a> for the possible values.",
named = true),
@Param(
name = "direct",
type = Object.class,
defaultValue = "None",
positional = false,
named = true,
noneable = true,
doc = "A list of <i>direct</i> elements of a depset. "),
@Param(
name = "transitive",
named = true,
positional = false,
type = Sequence.class,
generic1 = Depset.class,
noneable = true,
allowedTypes = {
@ParamType(type = Sequence.class, generic1 = Depset.class),
@ParamType(type = NoneType.class),
},
doc = "A list of depsets whose elements will become indirect elements of the depset.",
defaultValue = "None"),
@Param(
name = "items",
type = Object.class,
defaultValue = "[]",
positional = false,
doc =
Expand Down Expand Up @@ -177,14 +173,12 @@ public Depset depset(
parameters = {
@Param(
name = "x",
type = Dict.class,
positional = true,
doc =
"A dict that maps configuration conditions to values. Each key is a label string"
+ " that identifies a config_setting instance."),
@Param(
name = "no_match_error",
type = String.class,
defaultValue = "''",
doc = "Optional custom error to report if no condition matches.",
named = true),
Expand Down Expand Up @@ -216,24 +210,21 @@ private static class BuildLibrary {
"Defines a set of related environments that can be tagged onto rules to prevent"
+ "incompatible rules from depending on each other.",
parameters = {
@Param(
name = "name",
type = String.class,
positional = false,
named = true,
doc = "The name of the rule."),
@Param(name = "name", positional = false, named = true, doc = "The name of the rule."),
// Both parameter below are lists of label designators
@Param(
name = "environments",
type = Sequence.class,
generic1 = Object.class,
allowedTypes = {
@ParamType(type = Sequence.class, generic1 = Label.class),
},
positional = false,
named = true,
doc = "A list of Labels for the environments to be grouped, from the same package."),
@Param(
name = "defaults",
type = Sequence.class,
generic1 = Object.class,
allowedTypes = {
@ParamType(type = Sequence.class, generic1 = Label.class),
},
positional = false,
named = true,
doc = "A list of Labels.")
Expand Down Expand Up @@ -279,8 +270,7 @@ public NoneType environmentGroup(
parameters = {
@Param(
name = "license_strings",
type = Sequence.class,
generic1 = String.class,
allowedTypes = {@ParamType(type = Sequence.class, generic1 = String.class)},
doc = "A list of strings, the names of the licenses used.")
},
// Not documented by docgen, as this is only available in BUILD files.
Expand All @@ -306,9 +296,7 @@ public NoneType licenses(
@StarlarkMethod(
name = "distribs",
doc = "Declare the distribution(s) for the code in the current package.",
parameters = {
@Param(name = "distribution_strings", type = Object.class, doc = "The distributions.")
},
parameters = {@Param(name = "distribution_strings", doc = "The distributions.")},
// Not documented by docgen, as this is only available in BUILD files.
// TODO(cparsons): Devise a solution to document BUILD functions.
documented = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private static final class Constructor extends NativeProvider<ConfigFeatureFlagP
@StarlarkMethod(
name = "FeatureFlagInfo",
documented = false,
parameters = {@Param(name = "value", named = true, type = String.class)},
parameters = {@Param(name = "value", named = true)},
selfCall = true)
public ConfigFeatureFlagProvider selfcall(String value) {
return create(value, Predicates.alwaysTrue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@
import com.google.devtools.build.lib.starlarkbuildapi.core.ProviderApi;
import javax.annotation.Nullable;
import net.starlark.java.annot.Param;
import net.starlark.java.annot.ParamType;
import net.starlark.java.annot.StarlarkBuiltin;
import net.starlark.java.annot.StarlarkMethod;
import net.starlark.java.eval.EvalException;
import net.starlark.java.eval.NoneType;
import net.starlark.java.eval.Sequence;
import net.starlark.java.eval.Starlark;
import net.starlark.java.eval.StarlarkThread;
Expand Down Expand Up @@ -57,24 +59,16 @@ private Provider() {
doc = "The <code>BootClassPathInfo</code> constructor.",
documented = false,
parameters = {
@Param(
name = "bootclasspath",
positional = false,
named = true,
type = Sequence.class,
defaultValue = "[]"),
@Param(
name = "auxiliary",
positional = false,
named = true,
type = Sequence.class,
defaultValue = "[]"),
@Param(name = "bootclasspath", positional = false, named = true, defaultValue = "[]"),
@Param(name = "auxiliary", positional = false, named = true, defaultValue = "[]"),
@Param(
name = "system",
positional = false,
named = true,
type = FileApi.class,
noneable = true,
allowedTypes = {
@ParamType(type = FileApi.class),
@ParamType(type = NoneType.class),
},
defaultValue = "None"),
},
selfCall = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private Provider() {
doc = "The <code>MessageBundleInfo</code> constructor.",
documented = false,
parameters = {
@Param(name = "messages", positional = false, named = true, type = Sequence.class),
@Param(name = "messages", positional = false, named = true),
},
selfCall = true,
useStarlarkThread = true)
Expand Down
Loading

0 comments on commit 6cb560f

Please sign in to comment.