Deprecated getFile() and getSourceKind(). Added getFile2() instead.

R=brianwilkerson@google.com

Change-Id: Ia52967472077abd73cdf4df1320dd71b5dee98b7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/196060
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
diff --git a/pkg/analysis_server/lib/src/edit/edit_dartfix.dart b/pkg/analysis_server/lib/src/edit/edit_dartfix.dart
index 78b2d09..6289553 100644
--- a/pkg/analysis_server/lib/src/edit/edit_dartfix.dart
+++ b/pkg/analysis_server/lib/src/edit/edit_dartfix.dart
@@ -15,7 +15,6 @@
 import 'package:analyzer/dart/analysis/session.dart';
 import 'package:analyzer/file_system/file_system.dart';
 import 'package:analyzer/src/generated/engine.dart' show AnalysisOptionsImpl;
-import 'package:analyzer/src/generated/source.dart' show SourceKind;
 import 'package:collection/collection.dart';
 
 class EditDartFix
@@ -215,23 +214,16 @@
       if (pathsProcessed.contains(path)) continue;
       var driver = server.getAnalysisDriver(path);
       if (driver != null) {
-        switch (await driver.getSourceKind(path)) {
-          case SourceKind.PART:
-            // Parts will either be found in a library, below, or if the library
-            // isn't [isIncluded], will be picked up in the final loop.
-            continue;
-          case SourceKind.LIBRARY:
-            var result = await driver.getResolvedLibrary2(path);
-            if (result is ResolvedLibraryResult) {
-              for (var unit in result.units!) {
-                if (pathsToProcess.contains(unit.path) &&
-                    !pathsProcessed.contains(unit.path)) {
-                  await process(unit);
-                  pathsProcessed.add(unit.path!);
-                }
-              }
-              break;
+        var result = await driver.getResolvedLibrary2(path);
+        if (result is ResolvedLibraryResult) {
+          for (var unit in result.units!) {
+            if (pathsToProcess.contains(unit.path) &&
+                !pathsProcessed.contains(unit.path)) {
+              await process(unit);
+              pathsProcessed.add(unit.path!);
             }
+          }
+          break;
         }
       }
     }
diff --git a/pkg/analysis_server/lib/src/lsp/lsp_analysis_server.dart b/pkg/analysis_server/lib/src/lsp/lsp_analysis_server.dart
index 1447e55..0dca37a 100644
--- a/pkg/analysis_server/lib/src/lsp/lsp_analysis_server.dart
+++ b/pkg/analysis_server/lib/src/lsp/lsp_analysis_server.dart
@@ -36,6 +36,7 @@
     show CompletionPerformance;
 import 'package:analysis_server/src/services/refactoring/refactoring.dart';
 import 'package:analyzer/dart/analysis/context_locator.dart';
+import 'package:analyzer/dart/analysis/results.dart';
 import 'package:analyzer/error/error.dart';
 import 'package:analyzer/exception/exception.dart';
 import 'package:analyzer/file_system/file_system.dart';
@@ -244,7 +245,8 @@
   /// analyzed in one of the analysis drivers to which the file was added,
   /// otherwise in the first driver, otherwise `null` is returned.
   LineInfo? getLineInfo(String path) {
-    return getAnalysisDriver(path)?.getFileSync(path).lineInfo;
+    var result = getAnalysisDriver(path)?.getFileSync2(path);
+    return result is FileResult ? result.lineInfo : null;
   }
 
   /// Gets the version of a document known to the server, returning a
diff --git a/pkg/analysis_server/lib/src/services/correction/bulk_fix_processor.dart b/pkg/analysis_server/lib/src/services/correction/bulk_fix_processor.dart
index bf43bf5..b221c46 100644
--- a/pkg/analysis_server/lib/src/services/correction/bulk_fix_processor.dart
+++ b/pkg/analysis_server/lib/src/services/correction/bulk_fix_processor.dart
@@ -22,7 +22,6 @@
 import 'package:analyzer/instrumentation/service.dart';
 import 'package:analyzer/source/error_processor.dart';
 import 'package:analyzer/src/error/codes.dart';
-import 'package:analyzer/src/generated/source.dart';
 import 'package:analyzer/src/generated/utilities_general.dart';
 import 'package:analyzer/src/util/file_paths.dart' as file_paths;
 import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart';
@@ -172,10 +171,6 @@
         if (!file_paths.isDart(pathContext, path)) {
           continue;
         }
-        var kind = await context.currentSession.getSourceKind(path);
-        if (kind != SourceKind.LIBRARY) {
-          continue;
-        }
         var library = await context.currentSession.getResolvedLibrary2(path);
         if (library is ResolvedLibraryResult) {
           await _fixErrorsInLibrary(library);
diff --git a/pkg/analyzer/CHANGELOG.md b/pkg/analyzer/CHANGELOG.md
index 13fe6b3..9691934 100644
--- a/pkg/analyzer/CHANGELOG.md
+++ b/pkg/analyzer/CHANGELOG.md
@@ -17,6 +17,10 @@
   Use `AnalysisSession.getParsedLibraryByElement2()` instead.
 * Deprecated `AnalysisSession.getParsedUnit()`.
   Use `AnalysisSession.getParsedUnit2()` instead.
+* Deprecated `AnalysisSession.getFile()` and `getSourceKind()`.
+  Use `AnalysisSession.getFile2()` instead.
+* Deprecated `AnalysisSession.getUnitElementSignature()`.
+  This method is not used by any known client, and will be removed.
 
 ## 1.4.0
 * Deprecated `TypeProvider.nonSubtypableClasses`.
diff --git a/pkg/analyzer/lib/dart/analysis/results.dart b/pkg/analyzer/lib/dart/analysis/results.dart
index a79c4af..287c470 100644
--- a/pkg/analyzer/lib/dart/analysis/results.dart
+++ b/pkg/analyzer/lib/dart/analysis/results.dart
@@ -82,7 +82,7 @@
 /// parsed file is not required, so [ParsedUnitResult] is not necessary.
 ///
 /// Clients may not extend, implement or mix-in this class.
-abstract class FileResult implements AnalysisResult {
+abstract class FileResult implements SomeFileResult, AnalysisResult {
   /// Whether the file is a part.
   /// If [state] is not [ResultState.VALID], throws [StateError].
   bool get isPart;
@@ -100,6 +100,7 @@
     implements
         InvalidResult,
         SomeErrorsResult,
+        SomeFileResult,
         SomeParsedLibraryResult,
         SomeParsedUnitResult,
         SomeResolvedLibraryResult,
@@ -284,6 +285,15 @@
 /// [ErrorsResult] represents a valid result.
 abstract class SomeErrorsResult {}
 
+/// The result of computing some cheap information for a single file, when full
+/// parsed file is not required, so [ParsedUnitResult] is not necessary.
+///
+/// Clients may not extend, implement or mix-in this class.
+///
+/// There are existing implementations of this class.
+/// [FileResult] represents a valid result.
+abstract class SomeFileResult {}
+
 /// The result of building the element model for a library.
 ///
 /// Clients may not extend, implement or mix-in this class.
@@ -351,6 +361,7 @@
   /// exported by the library. If the signature of a file has not changed, then
   /// there have been no changes that would cause any files that depend on it
   /// to need to be re-analyzed.
+  @Deprecated('This field is not used by clients and will be removed')
   String get signature;
 }
 
diff --git a/pkg/analyzer/lib/dart/analysis/session.dart b/pkg/analyzer/lib/dart/analysis/session.dart
index 8b8db65..2f6aa40 100644
--- a/pkg/analyzer/lib/dart/analysis/session.dart
+++ b/pkg/analyzer/lib/dart/analysis/session.dart
@@ -48,8 +48,13 @@
 
   /// Return information about the file at the given absolute, normalized
   /// [path].
+  @Deprecated('Use getFile2() instead')
   FileResult getFile(String path);
 
+  /// Return information about the file at the given absolute, normalized
+  /// [path].
+  SomeFileResult getFile2(String path);
+
   /// Return a future that will complete with the library element representing
   /// the library with the given [uri].
   @Deprecated('Use getLibraryByUri2() instead')
@@ -135,6 +140,7 @@
   /// complete with [SourceKind.UNKNOWN].
   ///
   /// TODO(migration): should not be nullable
+  @Deprecated('Use getFile2() instead')
   Future<SourceKind?> getSourceKind(String path);
 
   /// Return a future that will complete with information about the results of
@@ -158,6 +164,7 @@
   /// exported by the library. If the signature of a file has not changed, then
   /// there have been no changes that would cause any files that depend on it to
   /// need to be re-analyzed.
+  @Deprecated('This method is not used and will be removed')
   Future<String> getUnitElementSignature(String path);
 }
 
diff --git a/pkg/analyzer/lib/src/dart/analysis/driver.dart b/pkg/analyzer/lib/src/dart/analysis/driver.dart
index fd284cf..37d2981 100644
--- a/pkg/analyzer/lib/src/dart/analysis/driver.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/driver.dart
@@ -184,11 +184,11 @@
       <String, List<Completer<AnalysisDriverUnitIndex>>>{};
 
   /// The mapping from the files for which the unit element key was requested
-  /// using [getUnitElementSignature] to the [Completer]s to report the result.
+  /// using `getUnitElementSignature` to the [Completer]s to report the result.
   final _unitElementSignatureFiles = <String, List<Completer<String>>>{};
 
   /// The mapping from the files for which the unit element key was requested
-  /// using [getUnitElementSignature], and which were found to be parts without
+  /// using `getUnitElementSignature`, and which were found to be parts without
   /// known libraries, to the [Completer]s to report the result.
   final _unitElementSignatureParts = <String, List<Completer<String>>>{};
 
@@ -613,8 +613,20 @@
   /// Return the [FileResult] for the Dart file with the given [path].
   ///
   /// The [path] must be absolute and normalized.
+  @Deprecated('Use getFileSync2() instead')
   FileResult getFileSync(String path) {
     _throwIfNotAbsolutePath(path);
+    return getFileSync2(path) as FileResult;
+  }
+
+  /// Return the [FileResult] for the Dart file with the given [path].
+  ///
+  /// The [path] must be absolute and normalized.
+  SomeFileResult getFileSync2(String path) {
+    if (!_isAbsolutePath(path)) {
+      return InvalidPathResult();
+    }
+
     FileState file = _fileTracker.getFile(path);
     return FileResultImpl(
         _currentSession, path, file.uri, file.lineInfo, file.isPart);
@@ -1032,6 +1044,7 @@
   /// be analyzed, the [Future] completes with `null`.
   ///
   /// The [path] must be absolute and normalized.
+  @Deprecated('Use getFileSync2() instead')
   Future<SourceKind?> getSourceKind(String path) async {
     _throwIfNotAbsolutePath(path);
     if (file_paths.isDart(resourceProvider.pathContext, path)) {
@@ -1087,6 +1100,7 @@
   /// The signature is based the APIs of the files of the library (including
   /// the file itself) of the requested file and the transitive closure of files
   /// imported and exported by the library.
+  @Deprecated('This method is not used and will be removed')
   Future<String> getUnitElementSignature(String path) {
     _throwIfNotAbsolutePath(path);
     if (!_fsState.hasUri(path)) {
diff --git a/pkg/analyzer/lib/src/dart/analysis/session.dart b/pkg/analyzer/lib/src/dart/analysis/session.dart
index fbc5371..c6cb0f7 100644
--- a/pkg/analyzer/lib/src/dart/analysis/session.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/session.dart
@@ -71,12 +71,19 @@
     return _driver.getErrors2(path);
   }
 
+  @Deprecated('Use getFile2() instead')
   @override
   FileResult getFile(String path) {
     _checkConsistency();
     return _driver.getFileSync(path);
   }
 
+  @override
+  SomeFileResult getFile2(String path) {
+    _checkConsistency();
+    return _driver.getFileSync2(path);
+  }
+
   @Deprecated('Use getLibraryByUri2() instead')
   @override
   Future<LibraryElement> getLibraryByUri(String uri) async {
@@ -190,6 +197,7 @@
     return _driver.getResult2(path);
   }
 
+  @Deprecated('Use getFile2() instead')
   @override
   Future<SourceKind?> getSourceKind(String path) {
     _checkConsistency();
@@ -209,6 +217,7 @@
     return _driver.getUnitElement2(path);
   }
 
+  @Deprecated('This method is not used and will be removed')
   @override
   Future<String> getUnitElementSignature(String path) {
     _checkConsistency();
diff --git a/pkg/analyzer/lib/src/dart/analysis/session_helper.dart b/pkg/analyzer/lib/src/dart/analysis/session_helper.dart
index 2b473c1..020af5d 100644
--- a/pkg/analyzer/lib/src/dart/analysis/session_helper.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/session_helper.dart
@@ -70,11 +70,6 @@
     return null;
   }
 
-  /// Return `true` if the file with the [path] is a part.
-  bool isPart(String path) {
-    return session.getFile(path).isPart;
-  }
-
   /// Return a newly resolved, or cached library with the given [path].
   Future<ResolvedLibraryResult?> _getResolvedLibrary(String path) async {
     var result = _resolvedLibraries[path];
diff --git a/pkg/analyzer/test/src/dart/analysis/driver_test.dart b/pkg/analyzer/test/src/dart/analysis/driver_test.dart
index 87cdde7..1852dbe 100644
--- a/pkg/analyzer/test/src/dart/analysis/driver_test.dart
+++ b/pkg/analyzer/test/src/dart/analysis/driver_test.dart
@@ -1356,6 +1356,67 @@
     expect(files, isNot(contains(c)));
   }
 
+  test_getFileSync2_changedFile() async {
+    var a = convertPath('/test/lib/a.dart');
+    var b = convertPath('/test/lib/b.dart');
+
+    newFile(a, content: '');
+    newFile(b, content: r'''
+import 'a.dart';
+
+void f(A a) {}
+''');
+
+    // Ensure that [a.dart] library cycle is loaded.
+    // So, `a.dart` is in the library context.
+    await driver.getResultValid(a);
+
+    // Update the file, changing its API signature.
+    // Note that we don't call `changeFile`.
+    newFile(a, content: 'class A {}\n');
+
+    // Get the file.
+    // We have not called `changeFile(a)`, so we should not read the file.
+    // Moreover, doing this will create a new library cycle [a.dart].
+    // Library cycles are compared by their identity, so we would try to
+    // reload linked summary for [a.dart], and crash.
+    expect(driver.getFileSyncValid(a).lineInfo.lineCount, 1);
+
+    // We have not read `a.dart`, so `A` is still not declared.
+    expect((await driver.getResultValid(b)).errors, isNotEmpty);
+
+    // Notify the driver that the file was changed.
+    driver.changeFile(a);
+
+    // So, `class A {}` is declared now.
+    expect(driver.getFileSyncValid(a).lineInfo.lineCount, 2);
+    expect((await driver.getResultValid(b)).errors, isEmpty);
+  }
+
+  test_getFileSync2_library() async {
+    var path = convertPath('/test/lib/a.dart');
+    newFile(path);
+    var file = driver.getFileSyncValid(path);
+    expect(file.path, path);
+    expect(file.uri.toString(), 'package:test/a.dart');
+    expect(file.isPart, isFalse);
+  }
+
+  test_getFileSync2_notAbsolutePath() async {
+    var result = driver.getFileSync2('not_absolute.dart');
+    expect(result, isA<InvalidPathResult>());
+  }
+
+  test_getFileSync2_part() async {
+    var path = convertPath('/test/lib/a.dart');
+    newFile(path, content: 'part of lib;');
+    var file = driver.getFileSyncValid(path);
+    expect(file.path, path);
+    expect(file.uri.toString(), 'package:test/a.dart');
+    expect(file.isPart, isTrue);
+  }
+
+  @deprecated
   test_getFileSync_changedFile() async {
     var a = convertPath('/test/lib/a.dart');
     var b = convertPath('/test/lib/b.dart');
@@ -1393,6 +1454,7 @@
     expect((await driver.getResultValid(b)).errors, isEmpty);
   }
 
+  @deprecated
   test_getFileSync_library() async {
     var path = convertPath('/test/lib/a.dart');
     newFile(path);
@@ -1402,12 +1464,14 @@
     expect(file.isPart, isFalse);
   }
 
+  @deprecated
   test_getFileSync_notAbsolutePath() async {
     expect(() {
       driver.getFileSync('not_absolute.dart');
     }, throwsArgumentError);
   }
 
+  @deprecated
   test_getFileSync_part() async {
     var path = convertPath('/test/lib/a.dart');
     newFile(path, content: 'part of lib;');
@@ -2089,6 +2153,7 @@
     expect(result1.unit!, isNotNull);
   }
 
+  @deprecated
   test_getSourceKind_changedFile() async {
     var a = convertPath('/test/lib/a.dart');
     var b = convertPath('/test/lib/b.dart');
@@ -2126,6 +2191,7 @@
     expect((await driver.getResultValid(b)).errors, isEmpty);
   }
 
+  @deprecated
   test_getSourceKind_changeFile() async {
     var path = convertPath('/test/lib/test.dart');
     expect(await driver.getSourceKind(path), SourceKind.LIBRARY);
@@ -2139,29 +2205,34 @@
     expect(await driver.getSourceKind(path), SourceKind.LIBRARY);
   }
 
+  @deprecated
   test_getSourceKind_doesNotExist() async {
     var path = convertPath('/test/lib/test.dart');
     expect(await driver.getSourceKind(path), SourceKind.LIBRARY);
   }
 
+  @deprecated
   test_getSourceKind_library() async {
     var path = convertPath('/test/lib/test.dart');
     newFile(path, content: 'class A {}');
     expect(await driver.getSourceKind(path), SourceKind.LIBRARY);
   }
 
+  @deprecated
   test_getSourceKind_notAbsolutePath() async {
     expect(() async {
       await driver.getSourceKind('not_absolute.dart');
     }, throwsArgumentError);
   }
 
+  @deprecated
   test_getSourceKind_notDartFile() async {
     var path = convertPath('/test/lib/test.txt');
     newFile(path, content: 'class A {}');
     expect(await driver.getSourceKind(path), isNull);
   }
 
+  @deprecated
   test_getSourceKind_part() async {
     var path = convertPath('/test/lib/test.dart');
     newFile(path, content: 'part of lib; class A {}');
@@ -2276,27 +2347,6 @@
     expect(signature2, isNot(signature));
   }
 
-  test_getUnitElementSignature2() async {
-    var a = convertPath('/test/lib/a.dart');
-
-    newFile(a, content: 'foo() {}');
-
-    String signature = await driver.getUnitElementSignature(a);
-    expect(signature, isNotNull);
-
-    var unitResult = await driver.getUnitElement2(a);
-    unitResult as UnitElementResult;
-    expect(unitResult.path, a);
-    expect(unitResult.signature, signature);
-
-    modifyFile(a, 'bar() {}');
-    driver.changeFile(a);
-
-    String signature2 = await driver.getUnitElementSignature(a);
-    expect(signature2, isNotNull);
-    expect(signature2, isNot(signature));
-  }
-
   test_hasFilesToAnalyze() async {
     // No files yet, nothing to analyze.
     expect(driver.hasFilesToAnalyze, isFalse);
@@ -3315,6 +3365,7 @@
     }
   }
 
+  @deprecated
   test_part_getUnitElementSignature() async {
     var a = convertPath('/test/lib/a.dart');
     var b = convertPath('/test/lib/b.dart');
@@ -3966,6 +4017,10 @@
 }
 
 extension on AnalysisDriver {
+  FileResult getFileSyncValid(String path) {
+    return getFileSync2(path) as FileResult;
+  }
+
   Future<ResolvedUnitResult> getResultValid(String path) async {
     return await getResult2(path) as ResolvedUnitResult;
   }
diff --git a/pkg/analyzer/test/src/dart/analysis/session_test.dart b/pkg/analyzer/test/src/dart/analysis/session_test.dart
index 5af5179..9d9e9a9 100644
--- a/pkg/analyzer/test/src/dart/analysis/session_test.dart
+++ b/pkg/analyzer/test/src/dart/analysis/session_test.dart
@@ -270,6 +270,29 @@
     expect(errorsResult, isA<InvalidPathResult>());
   }
 
+  test_getFile2_invalidPath_notAbsolute() async {
+    var errorsResult = session.getFile2('not_absolute.dart');
+    expect(errorsResult, isA<InvalidPathResult>());
+  }
+
+  test_getFileSync2_library() async {
+    var path = convertPath('/home/test/lib/a.dart');
+    newFile(path, content: '');
+    var file = session.getFileValid(path);
+    expect(file.path, path);
+    expect(file.uri.toString(), 'package:test/a.dart');
+    expect(file.isPart, isFalse);
+  }
+
+  test_getFileSync2_part() async {
+    var path = convertPath('/home/test/lib/a.dart');
+    newFile(path, content: 'part of lib;');
+    var file = session.getFileValid(path);
+    expect(file.path, path);
+    expect(file.uri.toString(), 'package:test/a.dart');
+    expect(file.isPart, isTrue);
+  }
+
   @deprecated
   test_getLibraryByUri() async {
     newFile(testPath, content: r'''
@@ -942,6 +965,7 @@
     expect(unitResult.libraryElement, isNotNull);
   }
 
+  @deprecated
   test_getSourceKind() async {
     newFile(testPath, content: 'class C {}');
 
@@ -949,6 +973,7 @@
     expect(kind, SourceKind.LIBRARY);
   }
 
+  @deprecated
   test_getSourceKind_part() async {
     newFile(testPath, content: 'part of "a.dart";');
 
@@ -984,9 +1009,6 @@
     expect(unitResult.path, testPath);
     expect(unitResult.uri, Uri.parse('package:test/test.dart'));
     expect(unitResult.element.types, hasLength(2));
-
-    var signature = await session.getUnitElementSignature(testPath);
-    expect(unitResult.signature, signature);
   }
 
   test_resourceProvider() async {
@@ -1003,6 +1025,10 @@
     return getParsedLibrary2(path) as ParsedLibraryResult;
   }
 
+  FileResult getFileValid(String path) {
+    return getFile2(path) as FileResult;
+  }
+
   ParsedUnitResult getParsedUnitValid(String path) {
     return getParsedUnit2(path) as ParsedUnitResult;
   }
diff --git a/pkg/analyzer/test/src/services/available_declarations_test.dart b/pkg/analyzer/test/src/services/available_declarations_test.dart
index 6ba066f..ec8b732 100644
--- a/pkg/analyzer/test/src/services/available_declarations_test.dart
+++ b/pkg/analyzer/test/src/services/available_declarations_test.dart
@@ -3496,9 +3496,9 @@
     newFile(a, content: 'class A {}');
     newFile(b, content: 'class B {}');
     newFile(c, content: 'class C {}');
-    testAnalysisContext.currentSession.getFile(a);
-    testAnalysisContext.currentSession.getFile(b);
-    testAnalysisContext.currentSession.getFile(c);
+    testAnalysisContext.currentSession.getFile2(a);
+    testAnalysisContext.currentSession.getFile2(b);
+    testAnalysisContext.currentSession.getFile2(c);
 
     var context = tracker.addContext(testAnalysisContext);
     await _doAllTrackerWork();
diff --git a/pkg/analyzer_cli/lib/src/error_formatter.dart b/pkg/analyzer_cli/lib/src/error_formatter.dart
index 2301bf0..19fae89 100644
--- a/pkg/analyzer_cli/lib/src/error_formatter.dart
+++ b/pkg/analyzer_cli/lib/src/error_formatter.dart
@@ -312,10 +312,13 @@
     for (var message in error.contextMessages) {
       var session = result.session.analysisContext;
       if (session is DriverBasedAnalysisContext) {
-        var lineInfo = session.driver.getFileSync(message.filePath)?.lineInfo;
-        var location = lineInfo.getLocation(message.offset);
-        contextMessages.add(ContextMessage(message.filePath, message.message,
-            location.lineNumber, location.columnNumber));
+        var fileResult = session.driver.getFileSync2(message.filePath);
+        if (fileResult is FileResult) {
+          var lineInfo = fileResult?.lineInfo;
+          var location = lineInfo.getLocation(message.offset);
+          contextMessages.add(ContextMessage(message.filePath, message.message,
+              location.lineNumber, location.columnNumber));
+        }
       }
     }
 
diff --git a/pkg/nnbd_migration/lib/migration_cli.dart b/pkg/nnbd_migration/lib/migration_cli.dart
index e90259e..accb1f77 100644
--- a/pkg/nnbd_migration/lib/migration_cli.dart
+++ b/pkg/nnbd_migration/lib/migration_cli.dart
@@ -1050,7 +1050,7 @@
   bool get isPreviewServerRunning => _task?.isPreviewServerRunning ?? false;
 
   LineInfo getLineInfo(String path) =>
-      context.currentSession.getFile(path).lineInfo;
+      (context.currentSession.getFile2(path) as FileResult).lineInfo;
 
   void prepareToRerun() {
     var driver = context.driver;
@@ -1065,25 +1065,16 @@
     var pathsProcessed = <String>{};
     for (var path in pathsToProcess) {
       if (pathsProcessed.contains(path)) continue;
-      switch (await driver.getSourceKind(path)) {
-        case SourceKind.PART:
-          // Parts will either be found in a library, below, or if the library
-          // isn't [isIncluded], will be picked up in the final loop.
-          continue;
-          break;
-        case SourceKind.LIBRARY:
-          var result = await driver.getResolvedLibrary2(path);
-          if (result is ResolvedLibraryResult) {
-            for (var unit in result.units) {
-              if (!pathsProcessed.contains(unit.path)) {
-                await process(unit);
-                pathsProcessed.add(unit.path);
-              }
-            }
+      var result = await driver.getResolvedLibrary2(path);
+      // Parts will either be found in a library, below, or if the library
+      // isn't [isIncluded], will be picked up in the final loop.
+      if (result is ResolvedLibraryResult) {
+        for (var unit in result.units) {
+          if (!pathsProcessed.contains(unit.path)) {
+            await process(unit);
+            pathsProcessed.add(unit.path);
           }
-          break;
-        default:
-          break;
+        }
       }
     }
 
diff --git a/pkg/nnbd_migration/test/abstract_context.dart b/pkg/nnbd_migration/test/abstract_context.dart
index b5d1783..1eafda1c 100644
--- a/pkg/nnbd_migration/test/abstract_context.dart
+++ b/pkg/nnbd_migration/test/abstract_context.dart
@@ -5,6 +5,7 @@
 import 'dart:convert';
 
 import 'package:analyzer/dart/analysis/analysis_context.dart';
+import 'package:analyzer/dart/analysis/results.dart';
 import 'package:analyzer/dart/analysis/session.dart';
 import 'package:analyzer/file_system/file_system.dart';
 import 'package:analyzer/file_system/overlay_file_system.dart';
@@ -118,7 +119,8 @@
     return _getContext(path).driver;
   }
 
-  LineInfo getLineInfo(String path) => session.getFile(path).lineInfo;
+  LineInfo getLineInfo(String path) =>
+      (session.getFile2(path) as FileResult).lineInfo;
 
   void setUp() {
     setupResourceProvider();
diff --git a/pkg/nnbd_migration/tool/trial_migration.dart b/pkg/nnbd_migration/tool/trial_migration.dart
index 4c14791..ae67ecc 100644
--- a/pkg/nnbd_migration/tool/trial_migration.dart
+++ b/pkg/nnbd_migration/tool/trial_migration.dart
@@ -65,7 +65,8 @@
           context.contextRoot.analyzedFiles().where((s) => s.endsWith('.dart'));
       files.addAll(localFiles);
       var session = context.currentSession;
-      LineInfo getLineInfo(String path) => session.getFile(path).lineInfo;
+      LineInfo getLineInfo(String path) =>
+          (session.getFile2(path) as FileResult).lineInfo;
       var migration =
           NullabilityMigration(listener, getLineInfo, permissive: true);
       for (var file in localFiles) {