Refactor SkylarkProvider constructors and add tests
A new constructor is exposed for building an already-exported SkylarkProvider. The existing constructor no longer takes a name argument (since it was almost entirely ignored). The contract around the name arg for BaseFunction has been refined: it is null if the subclass provides its own naming mechanism.
RELNOTES: None
PiperOrigin-RevId: 179804491
diff --git a/src/main/java/com/google/devtools/build/lib/packages/Provider.java b/src/main/java/com/google/devtools/build/lib/packages/Provider.java
index b497b76..2616a20 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/Provider.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/Provider.java
@@ -31,7 +31,9 @@
* {@link SkylarkProvider}.
*
* <p>{@link Provider} serves both as "type identifier" for declared provider instances and as a
- * function that can be called to construct a provider.
+ * function that can be called to construct a provider. To the Skylark user, there are "providers"
+ * and "provider instances"; the former is a Java instance of this class, and the latter is a Java
+ * instance of {@link Info}.
*
* <p>Prefer to use {@link Key} as a serializable identifier of {@link Provider}. In particular,
* {@link Key} should be used in all data structures exposed to Skyframe.
@@ -62,8 +64,19 @@
@Immutable
public abstract class Provider extends BaseFunction {
+ /**
+ * Constructs a provider.
+ *
+ * @param name provider name; should be null iff the subclass overrides {@link #getName}
+ * @param signature the signature for calling this provider as a Skylark function (to construct an
+ * instance of the provider)
+ * @param location the location of this provider's Skylark definition. Use {@link
+ * Location#BUILTIN} if it is a native provider.
+ */
protected Provider(
- String name, FunctionSignature.WithValues<Object, SkylarkType> signature, Location location) {
+ @Nullable String name,
+ FunctionSignature.WithValues<Object, SkylarkType> signature,
+ Location location) {
super(name, signature, location);
}