Remove TargetAndConfiguration.getConfiguredTargetKey.

This method is lossy: if the original CTK set the ToolchainContextKey, it is lost when this method is called.

Callers that are operating on top-level targets that cannot possibly have a ToolchainContextKey now have their own versions.

In general, TargetAndConfiguration is terrible and we should remove it.

PiperOrigin-RevId: 397056801
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/BuildView.java b/src/main/java/com/google/devtools/build/lib/analysis/BuildView.java
index f835927..77ef4d4 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/BuildView.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/BuildView.java
@@ -271,7 +271,7 @@
 
     List<ConfiguredTargetKey> topLevelCtKeys =
         topLevelTargetsWithConfigs.stream()
-            .map(TargetAndConfiguration::getConfiguredTargetKey)
+            .map(BuildView::getConfiguredTargetKey)
             .collect(Collectors.toList());
 
     ImmutableList.Builder<AspectClass> aspectClassesBuilder = ImmutableList.builder();
@@ -439,6 +439,14 @@
     return result;
   }
 
+  private static ConfiguredTargetKey getConfiguredTargetKey(
+      TargetAndConfiguration targetAndConfiguration) {
+    return ConfiguredTargetKey.builder()
+        .setLabel(targetAndConfiguration.getLabel())
+        .setConfiguration(targetAndConfiguration.getConfiguration())
+        .build();
+  }
+
   private AnalysisResult createResult(
       ExtendedEventHandler eventHandler,
       EventBus eventBus,