When --experimental_extra_action_top_level_only, Bazel to report extra-actions for actions registered by Aspects injected by a top-level rule.

Because we can't know whether an aspect was injected by a top-level target or one of its children, we approximate it by only reporting extra-actions from Aspects that the top-level target could have injected.

RELNOTES: When --experimental_extra_action_top_level_only, Bazel reports extra-actions for actions registered by Aspects injected by a top-level rule (approximately).

--
MOS_MIGRATED_REVID=138570606
diff --git a/src/main/java/com/google/devtools/build/lib/packages/Attribute.java b/src/main/java/com/google/devtools/build/lib/packages/Attribute.java
index 2a867ad..db9d87f 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/Attribute.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/Attribute.java
@@ -88,6 +88,10 @@
     }
 
     public abstract Aspect getAspect(Rule rule);
+
+    public C getAspectClass() {
+      return aspectClass;
+    }
   }
 
   private static class NativeRuleAspect extends RuleAspect<NativeAspectClass> {
@@ -1995,6 +1999,14 @@
     return builder.build();
   }
 
+  public ImmutableList<AspectClass> getAspectClasses() {
+    ImmutableList.Builder<AspectClass> result = ImmutableList.builder();
+    for (RuleAspect<?> aspect : aspects) {
+      result.add(aspect.getAspectClass());
+    }
+    return result.build();
+  }
+
   /**
    * Returns the default value of this attribute in the context of the
    * specified Rule.  For attributes with a computed default, i.e. {@code