Version 2.16.0-20.0.dev

Merge commit '48b45db3581d14aafd64e7fe77f13f9241682f87' into 'dev'
diff --git a/pkg/analyzer/lib/src/context/source.dart b/pkg/analyzer/lib/src/context/source.dart
index f30c15c..ff628f6 100644
--- a/pkg/analyzer/lib/src/context/source.dart
+++ b/pkg/analyzer/lib/src/context/source.dart
@@ -64,14 +64,6 @@
   }
 
   @override
-  void clearCache() {
-    _absoluteUriToSourceCache.clear();
-    for (var resolver in resolvers) {
-      resolver.clearCache();
-    }
-  }
-
-  @override
   Source? forUri(String absoluteUri) {
     try {
       Uri uri;
diff --git a/pkg/analyzer/lib/src/dart/analysis/file_state.dart b/pkg/analyzer/lib/src/dart/analysis/file_state.dart
index 97cac92..433d6e3 100644
--- a/pkg/analyzer/lib/src/dart/analysis/file_state.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/file_state.dart
@@ -814,20 +814,8 @@
     if (file == null) {
       File resource = _resourceProvider.getFile(path);
       Source fileSource = resource.createSource();
-      Uri? uri = _sourceFactory.restoreUri(fileSource);
-      // Create a new file.
-      // TODO(scheglov) this is duplicate
-      FileSource uriSource = FileSource(resource, uri!);
-      WorkspacePackage? workspacePackage = _workspace?.findPackageFor(path);
-      FeatureSet featureSet = contextFeatureSet(path, uri, workspacePackage);
-      Version packageLanguageVersion =
-          contextLanguageVersion(path, uri, workspacePackage);
-      file = FileState._(this, path, uri, uriSource, workspacePackage,
-          featureSet, packageLanguageVersion);
-      _pathToFile[path] = file;
-      _uriToFile[uri] = file;
-      _addFileWithPath(path, file);
-      file.refresh();
+      Uri uri = _sourceFactory.restoreUri(fileSource)!;
+      file = _newFile(resource, path, uri);
     }
     return file;
   }
@@ -871,17 +859,7 @@
       }
       uri = rewrittenUri;
 
-      FileSource source = FileSource(resource, uri);
-      WorkspacePackage? workspacePackage = _workspace?.findPackageFor(path);
-      FeatureSet featureSet = contextFeatureSet(path, uri, workspacePackage);
-      Version packageLanguageVersion =
-          contextLanguageVersion(path, uri, workspacePackage);
-      file = FileState._(this, path, uri, source, workspacePackage, featureSet,
-          packageLanguageVersion);
-      _pathToFile[path] = file;
-      _uriToFile[uri] = file;
-      _addFileWithPath(path, file);
-      file.refresh();
+      file = _newFile(resource, path, uri);
     }
     return Either2.t1(file);
   }
@@ -935,12 +913,6 @@
     _clearFiles();
   }
 
-  void _addFileWithPath(String path, FileState file) {
-    knownFilePaths.add(path);
-    knownFiles.add(file);
-    fileStamp++;
-  }
-
   /// Clear all [FileState] data - all maps from path or URI, etc.
   void _clearFiles() {
     _uriToFile.clear();
@@ -952,6 +924,23 @@
     _partToLibraries.clear();
     _subtypedNameToFiles.clear();
   }
+
+  FileState _newFile(File resource, String path, Uri uri) {
+    FileSource uriSource = FileSource(resource, uri);
+    WorkspacePackage? workspacePackage = _workspace?.findPackageFor(path);
+    FeatureSet featureSet = contextFeatureSet(path, uri, workspacePackage);
+    Version packageLanguageVersion =
+        contextLanguageVersion(path, uri, workspacePackage);
+    var file = FileState._(this, path, uri, uriSource, workspacePackage,
+        featureSet, packageLanguageVersion);
+    _pathToFile[path] = file;
+    _uriToFile[uri] = file;
+    knownFilePaths.add(path);
+    knownFiles.add(file);
+    fileStamp++;
+    file.refresh();
+    return file;
+  }
 }
 
 @visibleForTesting
diff --git a/pkg/analyzer/lib/src/generated/source.dart b/pkg/analyzer/lib/src/generated/source.dart
index f134a33..69ac8ca 100644
--- a/pkg/analyzer/lib/src/generated/source.dart
+++ b/pkg/analyzer/lib/src/generated/source.dart
@@ -271,10 +271,6 @@
   /// the package (or [null] if there is no registered package URI resolver).
   Map<String, List<Folder>>? get packageMap;
 
-  /// Clear any cached URI resolution information in the [SourceFactory] itself,
-  /// and also ask each [UriResolver]s to clear its caches.
-  void clearCache();
-
   /// Return a source object representing the given absolute URI, or `null` if
   /// the URI is not a valid URI or if it is not an absolute URI.
   ///
@@ -413,16 +409,7 @@
 /// The abstract class `UriResolver` defines the behavior of objects that are
 /// used to resolve URI's for a source factory. Subclasses of this class are
 /// expected to resolve a single scheme of absolute URI.
-///
-/// NOTICE: in a future breaking change release of the analyzer, a method
-/// `void clearCache()` will be added.  Clients that implement, but do not
-/// extend, this class, can prepare for the breaking change by adding an
-/// implementation of this method that clears any cached URI resolution
-/// information.
 abstract class UriResolver {
-  /// Clear any cached URI resolution information.
-  void clearCache() {}
-
   /// Resolve the given absolute [uri]. Return a [Source] representing the file
   /// to which it was resolved, whether or not the resulting source exists, or
   /// `null` if it could not be resolved because the URI is invalid.
diff --git a/pkg/analyzer/lib/src/workspace/bazel.dart b/pkg/analyzer/lib/src/workspace/bazel.dart
index aa3aec8..d7743a0 100644
--- a/pkg/analyzer/lib/src/workspace/bazel.dart
+++ b/pkg/analyzer/lib/src/workspace/bazel.dart
@@ -53,12 +53,6 @@
         _context = workspace.provider.pathContext;
 
   @override
-  void clearCache() {
-    _sourceCache.clear();
-    _workspace.clearCache();
-  }
-
-  @override
   Source? resolveAbsolute(Uri uri) {
     var source = _sourceCache[uri];
     if (source == null) {
@@ -238,10 +232,6 @@
   @override
   UriResolver get packageUriResolver => BazelPackageUriResolver(this);
 
-  void clearCache() {
-    _directoryToPackage.clear();
-  }
-
   @override
   SourceFactory createSourceFactory(
     DartSdk? sdk,
diff --git a/pkg/analyzer/test/src/dart/analysis/base.dart b/pkg/analyzer/test/src/dart/analysis/base.dart
index 7f3d1cb..a015fec 100644
--- a/pkg/analyzer/test/src/dart/analysis/base.dart
+++ b/pkg/analyzer/test/src/dart/analysis/base.dart
@@ -159,9 +159,6 @@
   Uri? Function(Source)? restoreAbsoluteFunction;
 
   @override
-  void clearCache() {}
-
-  @override
   noSuchMethod(Invocation invocation) {
     throw StateError('Unexpected invocation of ${invocation.memberName}');
   }
diff --git a/tools/VERSION b/tools/VERSION
index b08b806..8e1e43b 100644
--- a/tools/VERSION
+++ b/tools/VERSION
@@ -27,5 +27,5 @@
 MAJOR 2
 MINOR 16
 PATCH 0
-PRERELEASE 19
+PRERELEASE 20
 PRERELEASE_PATCH 0
\ No newline at end of file