Split ConfigurationTransitionDependency into a new class

 and break relation to the existing Dependency.

Part of work on toolchain transitions, #10523.

Closes #11398.

PiperOrigin-RevId: 312256302
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/Dependency.java b/src/main/java/com/google/devtools/build/lib/analysis/Dependency.java
index 0b7e227..c34be2a 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/Dependency.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/Dependency.java
@@ -27,17 +27,10 @@
 /**
  * A dependency of a configured target through a label.
  *
- * <p>The dep's configuration can be specified in one of two ways:
- *
- * <p>Explicit configurations: includes the target and the configuration of the dependency
- * configured target and any aspects that may be required, as well as the configurations for these
- * aspects and transition keys. {@link Dependency#getTransitionKeys} provides some more context on
- * transition keys.
- *
- * <p>Configuration transitions: includes the target and the desired configuration transitions that
- * should be applied to produce the dependency's configuration. It's the caller's responsibility to
- * construct an actual configuration out of that. A set of aspects is also included; the caller must
- * also construct configurations for each of these.
+ * <p>All instances have an explicit configuration, which includes the target and the configuration
+ * of the dependency configured target and any aspects that may be required, as well as the
+ * configurations for these aspects and transition keys. {@link Dependency#getTransitionKeys}
+ * provides some more context on transition keys.
  *
  * <p>Note that the presence of an aspect here does not necessarily mean that it will be created.
  * They will be filtered based on the {@link TransitiveInfoProvider} instances their associated
@@ -144,14 +137,6 @@
         ImmutableList.of());
   }
 
-  /**
-   * Creates a new {@link Dependency} with the given transition and aspects.
-   */
-  public static Dependency withTransitionAndAspects(
-      Label label, ConfigurationTransition transition, AspectCollection aspects) {
-    return new ConfigurationTransitionDependency(label, transition, aspects);
-  }
-
   protected final Label label;
 
   /**
@@ -168,27 +153,12 @@
   }
 
   /**
-   * Returns true if this dependency specifies an explicit configuration, false if it specifies
-   * a configuration transition.
-   */
-  public abstract boolean hasExplicitConfiguration();
-
-  /**
    * Returns the explicit configuration intended for this dependency.
-   *
-   * @throws IllegalStateException if {@link #hasExplicitConfiguration} returns false.
    */
   @Nullable
   public abstract BuildConfiguration getConfiguration();
 
   /**
-   * Returns the configuration transition to apply to reach the target this dependency points to.
-   *
-   * @throws IllegalStateException if {@link #hasExplicitConfiguration} returns true.
-   */
-  public abstract ConfigurationTransition getTransition();
-
-  /**
    * Returns the set of aspects which should be evaluated and combined with the configured target
    * pointed to by this dependency.
    *
@@ -198,8 +168,6 @@
 
   /**
    * Returns the configuration an aspect should be evaluated with
-   **
-   * @throws IllegalStateException if {@link #hasExplicitConfiguration()} returns false.
    */
   public abstract BuildConfiguration getAspectConfiguration(AspectDescriptor aspect);
 
@@ -211,8 +179,6 @@
    * multiple entries if the dependency has a null configuration, yet the outgoing edge has a split
    * transition. In such cases all transition keys returned by the transition are tagged to the
    * dependency.
-   *
-   * @throws IllegalStateException if {@link #hasExplicitConfiguration()} returns false.
    */
   public abstract ImmutableList<String> getTransitionKeys();
 
@@ -228,11 +194,6 @@
       this.transitionKeys = Preconditions.checkNotNull(transitionKeys);
     }
 
-    @Override
-    public boolean hasExplicitConfiguration() {
-      return true;
-    }
-
     @Nullable
     @Override
     public BuildConfiguration getConfiguration() {
@@ -240,12 +201,6 @@
     }
 
     @Override
-    public ConfigurationTransition getTransition() {
-      throw new IllegalStateException(
-          "This dependency has an explicit configuration, not a transition.");
-    }
-
-    @Override
     public AspectCollection getAspects() {
       return AspectCollection.EMPTY;
     }
@@ -303,22 +258,11 @@
     }
 
     @Override
-    public boolean hasExplicitConfiguration() {
-      return true;
-    }
-
-    @Override
     public BuildConfiguration getConfiguration() {
       return configuration;
     }
 
     @Override
-    public ConfigurationTransition getTransition() {
-      throw new IllegalStateException(
-          "This dependency has an explicit configuration, not a transition.");
-    }
-
-    @Override
     public AspectCollection getAspects() {
       return aspects;
     }
@@ -358,74 +302,4 @@
     }
   }
 
-  /**
-   * Implementation of a dependency with a given configuration transition.
-   */
-  private static final class ConfigurationTransitionDependency extends Dependency {
-    private final ConfigurationTransition transition;
-    private final AspectCollection aspects;
-
-    public ConfigurationTransitionDependency(
-        Label label, ConfigurationTransition transition, AspectCollection aspects) {
-      super(label);
-      this.transition = Preconditions.checkNotNull(transition);
-      this.aspects = Preconditions.checkNotNull(aspects);
-    }
-
-    @Override
-    public boolean hasExplicitConfiguration() {
-      return false;
-    }
-
-    @Override
-    public BuildConfiguration getConfiguration() {
-      throw new IllegalStateException(
-          "This dependency has a transition, not an explicit configuration.");
-    }
-
-    @Override
-    public ConfigurationTransition getTransition() {
-      return transition;
-    }
-
-    @Override
-    public AspectCollection getAspects() {
-      return aspects;
-    }
-
-    @Override
-    public BuildConfiguration getAspectConfiguration(AspectDescriptor aspect) {
-      throw new IllegalStateException(
-          "This dependency has a transition, not an explicit aspect configuration.");
-    }
-
-    @Override
-    public ImmutableList<String> getTransitionKeys() {
-      throw new IllegalStateException(
-          "This dependency has a transition, not an explicit configuration.");
-    }
-
-    @Override
-    public int hashCode() {
-      return Objects.hash(label, transition, aspects);
-    }
-
-    @Override
-    public boolean equals(Object other) {
-      if (!(other instanceof ConfigurationTransitionDependency)) {
-        return false;
-      }
-      ConfigurationTransitionDependency otherDep = (ConfigurationTransitionDependency) other;
-      return label.equals(otherDep.label)
-          && transition.equals(otherDep.transition)
-          && aspects.equals(otherDep.aspects);
-    }
-
-    @Override
-    public String toString() {
-      return String.format(
-          "%s{label=%s, transition=%s, aspects=%s}",
-          getClass().getSimpleName(), label, transition, aspects);
-    }
-  }
 }