RuleContext: support visibility check for labels

...instead of only for rules. Separating out the check allows
checking visibility against other sources than rule, e.g., the bzl
file a rule is defined in for implicit attributes.

Change-Id: Ib6ac1586eae73e366d51f5ec15d67566ecf6a36a
PiperOrigin-RevId: 277279823
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 96f4ebf..58b946c 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
@@ -1532,17 +1532,17 @@
   }
 
   /**
-   * @return true if {@code rule} is visible from {@code prerequisite}.
+   * Returns true if {@code label} is visible from {@code prerequisite}.
    *
    * <p>This only computes the logic as implemented by the visibility system. The final decision
-   * whether a dependency is allowed is made by
-   * {@link ConfiguredRuleClassProvider.PrerequisiteValidator}.
+   * whether a dependency is allowed is made by {@link
+   * ConfiguredRuleClassProvider.PrerequisiteValidator}.
    */
-  public static boolean isVisible(Rule rule, TransitiveInfoCollection prerequisite) {
+  public static boolean isVisible(Label label, TransitiveInfoCollection prerequisite) {
     // Check visibility attribute
     for (PackageGroupContents specification :
         prerequisite.getProvider(VisibilityProvider.class).getVisibility()) {
-      if (specification.containsPackage(rule.getLabel().getPackageIdentifier())) {
+      if (specification.containsPackage(label.getPackageIdentifier())) {
         return true;
       }
     }
@@ -1551,6 +1551,17 @@
   }
 
   /**
+   * Returns true if {@code rule} is visible from {@code prerequisite}.
+   *
+   * <p>This only computes the logic as implemented by the visibility system. The final decision
+   * whether a dependency is allowed is made by {@link
+   * ConfiguredRuleClassProvider.PrerequisiteValidator}.
+   */
+  public static boolean isVisible(Rule rule, TransitiveInfoCollection prerequisite) {
+    return isVisible(rule.getLabel(), prerequisite);
+  }
+
+  /**
    * @return the set of features applicable for the current rule's package.
    */
   public ImmutableSet<String> getFeatures() {