Revert "Add AnalysisDriver.contextRoot, deprecate configure()."

This reverts commit 3b111d5e0dfe7ed3a8b92faac6db155744bc2c0f.

Reason for revert: Wrong design, will rework.

Original change's description:
> Add AnalysisDriver.contextRoot, deprecate configure().
>
> In the future AnalysisDriver.analysisContext will be removed, and
> AnalysisDriver will implement AnalysisContext. At the same time we
> will remove DriverBasedAnalysisContext.
>
> Google3 looks green.
> https://fusion2.corp.google.com/presubmit/tap/453818030
>
> Change-Id: Iaa6bf85e27c3be5d0ecb40126d6b857fe6f2aa64
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/247626
> Reviewed-by: Samuel Rawlins <srawlins@google.com>
> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>

TBR=scheglov@google.com,brianwilkerson@google.com,srawlins@google.com

Change-Id: I2eb567c6343636d3affd48bb4bfb0b4b1aa788b6
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/247861
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
diff --git a/pkg/analysis_server/lib/src/plugin/plugin_watcher.dart b/pkg/analysis_server/lib/src/plugin/plugin_watcher.dart
index e388f07..9aad161 100644
--- a/pkg/analysis_server/lib/src/plugin/plugin_watcher.dart
+++ b/pkg/analysis_server/lib/src/plugin/plugin_watcher.dart
@@ -38,7 +38,7 @@
   /// analysis.
   @override
   void addedDriver(AnalysisDriver driver) {
-    var contextRoot = driver.contextRoot!;
+    var contextRoot = driver.analysisContext!.contextRoot;
     _driverInfo[driver] = _DriverInfo(
         contextRoot, <String>[contextRoot.root.path, _getSdkPath(driver)]);
     var enabledPlugins = driver.analysisOptions.enabledPluginNames;
@@ -65,7 +65,8 @@
           // TODO(brianwilkerson) Do we need to wait for the plugin to be added?
           // If we don't, then tests don't have any way to know when to expect
           // that the list of plugins has been updated.
-          manager.addPluginToContextRoot(driver.contextRoot!, pluginPath);
+          manager.addPluginToContextRoot(
+              driver.analysisContext!.contextRoot, pluginPath);
         }
       }
     }
@@ -78,7 +79,7 @@
     if (info == null) {
       throw StateError('Cannot remove a driver that was not added');
     }
-    manager.removedContextRoot(driver.contextRoot!);
+    manager.removedContextRoot(driver.analysisContext!.contextRoot);
     _driverInfo.remove(driver);
   }
 
diff --git a/pkg/analyzer/lib/src/dart/analysis/context_builder.dart b/pkg/analyzer/lib/src/dart/analysis/context_builder.dart
index 9e24ae5..c1185f2 100644
--- a/pkg/analyzer/lib/src/dart/analysis/context_builder.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/context_builder.dart
@@ -14,7 +14,6 @@
 import 'package:analyzer/src/context/packages.dart';
 import 'package:analyzer/src/dart/analysis/byte_store.dart'
     show ByteStore, MemoryByteStore;
-import 'package:analyzer/src/dart/analysis/context_root.dart';
 import 'package:analyzer/src/dart/analysis/driver.dart'
     show AnalysisDriver, AnalysisDriverScheduler;
 import 'package:analyzer/src/dart/analysis/driver_based_analysis_context.dart';
@@ -117,16 +116,19 @@
       packages: _createPackageMap(
         contextRoot: contextRoot,
       ),
-      contextRoot: contextRoot as ContextRootImpl,
       enableIndex: enableIndex,
       externalSummaries: summaryData,
       retainDataForTesting: retainDataForTesting,
       fileContentCache: fileContentCache,
       macroKernelBuilder: macroKernelBuilder,
       macroExecutor: macroExecutor,
-      declaredVariables: declaredVariables,
     );
 
+    if (declaredVariables != null) {
+      driver.declaredVariables = declaredVariables;
+      driver.configure();
+    }
+
     // AnalysisDriver reports results into streams.
     // We need to drain these streams to avoid memory leak.
     if (drainStreams) {
@@ -134,7 +136,11 @@
       driver.exceptions.drain<void>();
     }
 
-    return DriverBasedAnalysisContext(resourceProvider, contextRoot, driver);
+    DriverBasedAnalysisContext context =
+        DriverBasedAnalysisContext(resourceProvider, contextRoot, driver);
+    driver.configure(analysisContext: context);
+
+    return context;
   }
 
   /// Return [Packages] to analyze the [contextRoot].
diff --git a/pkg/analyzer/lib/src/dart/analysis/driver.dart b/pkg/analyzer/lib/src/dart/analysis/driver.dart
index 1e9c672..3b355eb 100644
--- a/pkg/analyzer/lib/src/dart/analysis/driver.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/driver.dart
@@ -17,7 +17,6 @@
 import 'package:analyzer/file_system/file_system.dart';
 import 'package:analyzer/src/context/packages.dart';
 import 'package:analyzer/src/dart/analysis/byte_store.dart';
-import 'package:analyzer/src/dart/analysis/context_root.dart';
 import 'package:analyzer/src/dart/analysis/feature_set_provider.dart';
 import 'package:analyzer/src/dart/analysis/file_content_cache.dart';
 import 'package:analyzer/src/dart/analysis/file_state.dart';
@@ -117,9 +116,6 @@
   /// the content from the file.
   final FileContentCache _fileContentCache;
 
-  /// The context root from which this context was created.
-  ContextRootImpl? contextRoot;
-
   /// The analysis options to analyze with.
   AnalysisOptionsImpl _analysisOptions;
 
@@ -136,7 +132,7 @@
   final macro.MultiMacroExecutor? macroExecutor;
 
   /// The declared environment variables.
-  final DeclaredVariables declaredVariables;
+  DeclaredVariables declaredVariables = DeclaredVariables();
 
   /// The analysis context that created this driver / session.
   api.AnalysisContext? analysisContext;
@@ -260,11 +256,9 @@
     required Packages packages,
     this.macroKernelBuilder,
     this.macroExecutor,
-    this.contextRoot,
     FileContentCache? fileContentCache,
     this.enableIndex = false,
     SummaryDataStore? externalSummaries,
-    DeclaredVariables? declaredVariables,
     bool retainDataForTesting = false,
   })  : _scheduler = scheduler,
         _resourceProvider = resourceProvider,
@@ -276,13 +270,11 @@
         _packages = packages,
         _sourceFactory = sourceFactory,
         _externalSummaries = externalSummaries,
-        declaredVariables = declaredVariables ?? DeclaredVariables(),
         testingData = retainDataForTesting ? TestingData() : null {
     _onResults = _resultController.stream.asBroadcastStream();
     _testView = AnalysisDriverTestView(this);
     _createFileTracker();
     _scheduler.add(this);
-    _scheduler.driverWatcher?.addedDriver(this);
     _search = Search(this);
   }
 
@@ -336,7 +328,7 @@
   }
 
   /// Return the path of the folder at the root of the context.
-  String get name => contextRoot?.root.path ?? '';
+  String get name => analysisContext?.contextRoot.root.path ?? '';
 
   /// Return the number of files scheduled for analysis.
   int get numberOfFilesToAnalyze => _fileTracker.numberOfPendingFiles;
@@ -577,7 +569,6 @@
   ///
   /// At least one of the optional parameters should be provided, but only those
   /// that represent state that has actually changed need be provided.
-  @Deprecated('Provide all necessary values to the constructor')
   void configure({
     api.AnalysisContext? analysisContext,
     AnalysisOptionsImpl? analysisOptions,
@@ -586,7 +577,6 @@
   }) {
     if (analysisContext != null) {
       this.analysisContext = analysisContext;
-      contextRoot = analysisContext.contextRoot as ContextRootImpl;
       _scheduler.driverWatcher?.addedDriver(this);
     }
     if (analysisOptions != null) {
@@ -1506,7 +1496,7 @@
       _resourceProvider,
       name,
       sourceFactory,
-      contextRoot?.workspace,
+      analysisContext?.contextRoot.workspace,
       analysisOptions,
       declaredVariables,
       _saltForUnlinked,
@@ -1584,7 +1574,7 @@
     buffer.addUint32List(_analysisOptions.signature);
     _addDeclaredVariablesToSignature(buffer);
 
-    var workspace = contextRoot?.workspace;
+    var workspace = analysisContext?.contextRoot.workspace;
     workspace?.contributeToResolutionSalt(buffer);
 
     _saltForResolution = buffer.toUint32List();
@@ -2000,6 +1990,9 @@
   void add(AnalysisDriverGeneric driver) {
     _drivers.add(driver);
     _hasWork.notify();
+    if (driver is AnalysisDriver && driver.analysisContext != null) {
+      driverWatcher?.addedDriver(driver);
+    }
   }
 
   /// Notify that there is a change to the [driver], it it might need to