Make all WithLegacySkylarkName providers declared providers.

RELNOTES: None.
PiperOrigin-RevId: 163343931
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java b/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java
index 986a93b..80b2c4e 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java
@@ -902,6 +902,17 @@
   }
 
   /**
+   * Returns all the providers of the specified type that are listed under the specified attribute
+   * of this target in the BUILD file, and that contain the specified provider.
+   */
+  public <C extends SkylarkClassObject>
+  Iterable<? extends TransitiveInfoCollection> getPrerequisitesIf(
+      String attributeName, Mode mode, final NativeClassObjectConstructor<C> classType) {
+    return AnalysisUtils.filterByProvider(getPrerequisites(attributeName, mode), classType);
+  }
+
+
+  /**
    * Returns the prerequisite referred to by the specified attribute. Also checks whether
    * the attribute is marked as executable and that the target referred to can actually be
    * executed.
@@ -2094,7 +2105,7 @@
         String missingProviders = getMissingMandatoryProviders(prerequisite, attribute);
         if (missingProviders != null) {
           unfulfilledRequirements.add(
-              "'" + prerequisite.getLabel() + "' does not have mandatory provider "
+              "'" + prerequisite.getLabel() + "' does not have mandatory providers: "
                   + missingProviders);
           hadAllMandatoryProviders = false;
         }