Version 2.14.0-17.0.dev

Merge commit '543d653ca827a2ff1856d7d3a76bded9ae233477' into 'dev'
diff --git a/.packages b/.packages
index 7646deb..af07227 100644
--- a/.packages
+++ b/.packages
@@ -66,7 +66,6 @@
 mime:third_party/pkg/mime/lib
 mockito:third_party/pkg/mockito/lib
 modular_test:pkg/modular_test/lib
-mustache:third_party/pkg/mustache/lib
 native_stack_traces:pkg/native_stack_traces/lib
 nnbd_migration:pkg/nnbd_migration/lib
 oauth2:third_party/pkg/oauth2/lib
diff --git a/pkg/analysis_server/lib/src/analysis_server_abstract.dart b/pkg/analysis_server/lib/src/analysis_server_abstract.dart
index 1cb9178..5fab9db 100644
--- a/pkg/analysis_server/lib/src/analysis_server_abstract.dart
+++ b/pkg/analysis_server/lib/src/analysis_server_abstract.dart
@@ -340,7 +340,9 @@
       return null;
     }
 
-    return getAnalysisDriver(path)?.currentSession.getParsedUnit(path);
+    var session = getAnalysisDriver(path)?.currentSession;
+    var result = session?.getParsedUnit2(path);
+    return result is ParsedUnitResult ? result : null;
   }
 
   /// Return the resolved unit for the file with the given [path]. The file is
diff --git a/pkg/analysis_server/lib/src/lsp/handlers/commands/sort_members.dart b/pkg/analysis_server/lib/src/lsp/handlers/commands/sort_members.dart
index dd7b2d0..5eec574 100644
--- a/pkg/analysis_server/lib/src/lsp/handlers/commands/sort_members.dart
+++ b/pkg/analysis_server/lib/src/lsp/handlers/commands/sort_members.dart
@@ -12,6 +12,7 @@
 import 'package:analysis_server/src/lsp/lsp_analysis_server.dart';
 import 'package:analysis_server/src/lsp/progress.dart';
 import 'package:analysis_server/src/services/correction/sort_members.dart';
+import 'package:analyzer/dart/analysis/results.dart';
 
 class SortMembersCommandHandler extends SimpleEditCommandHandler {
   SortMembersCommandHandler(LspAnalysisServer server) : super(server);
@@ -37,18 +38,20 @@
     final docIdentifier = server.getVersionedDocumentIdentifier(path);
 
     var driver = server.getAnalysisDriver(path);
-    final result = await driver?.parseFile(path);
+    final result0 = await driver?.parseFile2(path);
 
     if (cancellationToken.isCancellationRequested) {
       return error(ErrorCodes.RequestCancelled, 'Request was cancelled');
     }
 
-    if (result == null) {
+    if (result0 is! ParsedUnitResult) {
       return ErrorOr.error(ResponseError(
         code: ServerErrorCodes.FileNotAnalyzed,
         message: '$commandName is only available for analyzed files',
       ));
     }
+    // TODO(scheglov) inline after migration
+    var result = result0 as ParsedUnitResult;
     final code = result.content;
     final unit = result.unit;
 
diff --git a/pkg/analysis_server/lib/src/services/refactoring/rename_import.dart b/pkg/analysis_server/lib/src/services/refactoring/rename_import.dart
index 5de4b4b..db58a6d 100644
--- a/pkg/analysis_server/lib/src/services/refactoring/rename_import.dart
+++ b/pkg/analysis_server/lib/src/services/refactoring/rename_import.dart
@@ -8,6 +8,7 @@
 import 'package:analysis_server/src/services/refactoring/refactoring.dart';
 import 'package:analysis_server/src/services/refactoring/refactoring_internal.dart';
 import 'package:analysis_server/src/services/refactoring/rename.dart';
+import 'package:analyzer/dart/analysis/results.dart';
 import 'package:analyzer/dart/analysis/session.dart';
 import 'package:analyzer/dart/ast/ast.dart';
 import 'package:analyzer/dart/element/element.dart';
@@ -49,7 +50,7 @@
     // update declaration
     {
       var prefix = element.prefix;
-      SourceEdit edit;
+      SourceEdit? edit;
       if (newName.isEmpty) {
         // We should not get `prefix == null` because we check in
         // `checkNewName` that the new name is different.
@@ -57,22 +58,28 @@
           return;
         }
         var node = _findNode();
-        var uriEnd = node.uri.end;
-        var prefixEnd = element.prefixOffset + prefix.nameLength;
-        edit = newSourceEdit_range(
-            range.startOffsetEndOffset(uriEnd, prefixEnd), '');
+        if (node != null) {
+          var uriEnd = node.uri.end;
+          var prefixEnd = element.prefixOffset + prefix.nameLength;
+          edit = newSourceEdit_range(
+              range.startOffsetEndOffset(uriEnd, prefixEnd), '');
+        }
       } else {
         if (prefix == null) {
           var node = _findNode();
-          var uriEnd = node.uri.end;
-          edit = newSourceEdit_range(SourceRange(uriEnd, 0), ' as $newName');
+          if (node != null) {
+            var uriEnd = node.uri.end;
+            edit = newSourceEdit_range(SourceRange(uriEnd, 0), ' as $newName');
+          }
         } else {
           var offset = element.prefixOffset;
           var length = prefix.nameLength;
           edit = newSourceEdit_range(SourceRange(offset, length), newName);
         }
       }
-      doSourceChange_addElementEdit(change, element, edit);
+      if (edit != null) {
+        doSourceChange_addElementEdit(change, element, edit);
+      }
     }
     // update references
     var matches = await searchEngine.searchReferences(element);
@@ -98,10 +105,14 @@
   }
 
   /// Return the [ImportDirective] node that corresponds to the [element].
-  ImportDirective _findNode() {
+  ImportDirective? _findNode() {
     var library = element.library;
     var path = library.source.fullName;
-    var unit = session.getParsedUnit(path).unit;
+    var unitResult = session.getParsedUnit2(path);
+    if (unitResult is! ParsedUnitResult) {
+      return null;
+    }
+    var unit = unitResult.unit;
     var index = library.imports.indexOf(element);
     return unit.directives.whereType<ImportDirective>().elementAt(index);
   }
@@ -111,7 +122,11 @@
   /// it. Otherwise return `null`.
   SimpleIdentifier? _getInterpolationIdentifier(SourceReference reference) {
     var source = reference.element.source!;
-    var unit = session.getParsedUnit(source.fullName).unit;
+    var unitResult = session.getParsedUnit2(source.fullName);
+    if (unitResult is! ParsedUnitResult) {
+      return null;
+    }
+    var unit = unitResult.unit;
     var nodeLocator = NodeLocator(reference.range.offset);
     var node = nodeLocator.searchWithin(unit);
     if (node is SimpleIdentifier) {
diff --git a/pkg/analysis_server/test/analysis/get_navigation_test.dart b/pkg/analysis_server/test/analysis/get_navigation_test.dart
index 99943b9..38def2f 100644
--- a/pkg/analysis_server/test/analysis/get_navigation_test.dart
+++ b/pkg/analysis_server/test/analysis/get_navigation_test.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.9
-
 import 'package:analysis_server/protocol/protocol.dart';
 import 'package:analysis_server/protocol/protocol_generated.dart';
 import 'package:analysis_server/src/domain_analysis.dart';
@@ -94,9 +92,10 @@
     var request = _createGetNavigationRequest(file, 0, 100);
     var response = await serverChannel.sendRequest(request);
     expect(response.error, isNull);
-    expect(response.result['files'], isEmpty);
-    expect(response.result['targets'], isEmpty);
-    expect(response.result['regions'], isEmpty);
+    var result = response.result!;
+    expect(result['files'], isEmpty);
+    expect(result['targets'], isEmpty);
+    expect(result['regions'], isEmpty);
   }
 
   Future<void> test_fileOutsideOfRoot() async {
diff --git a/pkg/analysis_server/test/analysis/test_all.dart b/pkg/analysis_server/test/analysis/test_all.dart
index 8954813..1187065 100644
--- a/pkg/analysis_server/test/analysis/test_all.dart
+++ b/pkg/analysis_server/test/analysis/test_all.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.9
-
 import 'package:test_reflective_loader/test_reflective_loader.dart';
 
 import 'get_errors_test.dart' as get_errors;
diff --git a/pkg/analysis_server/test/client/completion_driver_test.dart b/pkg/analysis_server/test/client/completion_driver_test.dart
index 4d6ee60..86d1fbb 100644
--- a/pkg/analysis_server/test/client/completion_driver_test.dart
+++ b/pkg/analysis_server/test/client/completion_driver_test.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.9
-
 import 'package:analysis_server/src/analysis_server.dart';
 import 'package:analysis_server/src/services/completion/dart/utilities.dart';
 import 'package:analyzer/src/test_utilities/resource_provider_mixin.dart';
@@ -23,9 +21,9 @@
 }
 
 abstract class AbstractCompletionDriverTest with ResourceProviderMixin {
-  CompletionDriver driver;
-  Map<String, String> packageRoots;
-  List<CompletionSuggestion> suggestions;
+  late CompletionDriver driver;
+  Map<String, String> packageRoots = {};
+  late List<CompletionSuggestion> suggestions;
 
   String get projectName => 'project';
 
@@ -47,7 +45,7 @@
   }
 
   Future<List<CompletionSuggestion>> addTestFile(String content,
-      {int offset}) async {
+      {int? offset}) async {
     driver.addTestFile(content, offset: offset);
     await getSuggestions();
     // For sanity, ensure that there are no errors recorded for project files
@@ -57,10 +55,10 @@
   }
 
   void assertNoSuggestion({
-    @required String completion,
-    ElementKind element,
-    CompletionSuggestionKind kind,
-    String file,
+    required String completion,
+    ElementKind? element,
+    CompletionSuggestionKind? kind,
+    String? file,
   }) {
     expect(
         suggestionsWith(
@@ -73,10 +71,10 @@
   }
 
   void assertSuggestion({
-    @required String completion,
-    ElementKind element,
-    CompletionSuggestionKind kind,
-    String file,
+    required String completion,
+    ElementKind? element,
+    CompletionSuggestionKind? kind,
+    String? file,
   }) {
     expect(
         suggestionWith(
@@ -89,10 +87,10 @@
   }
 
   void assertSuggestions({
-    @required String completion,
-    ElementKind element,
-    CompletionSuggestionKind kind,
-    String file,
+    required String completion,
+    ElementKind? element,
+    CompletionSuggestionKind? kind,
+    String? file,
   }) {
     expect(
         suggestionWith(
@@ -129,7 +127,7 @@
     suggestions.sort(completionComparator);
     for (var s in suggestions) {
       print(
-          '[${s.relevance}] ${s.completion} • ${s.element?.kind?.name ?? ""} ${s.kind.name} ${s.element?.location?.file ?? ""}');
+          '[${s.relevance}] ${s.completion} • ${s.element?.kind.name ?? ""} ${s.kind.name} ${s.element?.location?.file ?? ""}');
     }
   }
 
@@ -152,10 +150,10 @@
   }
 
   SuggestionMatcher suggestionHas({
-    @required String completion,
-    ElementKind element,
-    CompletionSuggestionKind kind,
-    String file,
+    required String completion,
+    ElementKind? element,
+    CompletionSuggestionKind? kind,
+    String? file,
   }) =>
       (CompletionSuggestion s) {
         if (s.completion != completion) {
@@ -175,19 +173,19 @@
       };
 
   Iterable<CompletionSuggestion> suggestionsWith({
-    @required String completion,
-    ElementKind element,
-    CompletionSuggestionKind kind,
-    String file,
+    required String completion,
+    ElementKind? element,
+    CompletionSuggestionKind? kind,
+    String? file,
   }) =>
       suggestions.where(suggestionHas(
           completion: completion, element: element, kind: kind, file: file));
 
   CompletionSuggestion suggestionWith({
-    @required String completion,
-    ElementKind element,
-    CompletionSuggestionKind kind,
-    String file,
+    required String completion,
+    ElementKind? element,
+    CompletionSuggestionKind? kind,
+    String? file,
   }) {
     final matches = suggestionsWith(
         completion: completion, element: element, kind: kind, file: file);
diff --git a/pkg/analysis_server/test/client/impl/completion_driver.dart b/pkg/analysis_server/test/client/impl/completion_driver.dart
index a4569aa..48a7ef0 100644
--- a/pkg/analysis_server/test/client/impl/completion_driver.dart
+++ b/pkg/analysis_server/test/client/impl/completion_driver.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.9
-
 import 'dart:async';
 import 'dart:math' as math;
 
@@ -73,18 +71,18 @@
 
   final Map<String, List<AnalysisError>> filesErrors = {};
 
-  String completionId;
-  int completionOffset;
-  int replacementOffset;
-  int replacementLength;
+  late String completionId;
+  late int completionOffset;
+  late int replacementOffset;
+  late int replacementLength;
 
   CompletionDriver({
-    @required this.supportsAvailableSuggestions,
-    AnalysisServerOptions serverOptions,
-    @required MemoryResourceProvider resourceProvider,
-    @required String projectPath,
-    @required String testFilePath,
-  })  : _resourceProvider = resourceProvider,
+    required this.supportsAvailableSuggestions,
+    AnalysisServerOptions? serverOptions,
+    required MemoryResourceProvider resourceProvider,
+    required String projectPath,
+    required String testFilePath,
+  })   : _resourceProvider = resourceProvider,
         super(
             serverOptions: serverOptions ?? AnalysisServerOptions(),
             projectPath: resourceProvider.convertPath(projectPath),
@@ -95,7 +93,7 @@
   MemoryResourceProvider get resourceProvider => _resourceProvider;
 
   @override
-  String addTestFile(String content, {int offset}) {
+  String addTestFile(String content, {int? offset}) {
     completionOffset = content.indexOf('^');
     if (offset != null) {
       expect(completionOffset, -1, reason: 'cannot supply offset and ^');
@@ -110,7 +108,7 @@
   }
 
   @override
-  void createProject({Map<String, String> packageRoots}) {
+  void createProject({Map<String, String>? packageRoots}) {
     super.createProject(packageRoots: packageRoots);
     if (supportsAvailableSuggestions) {
       var request = CompletionSetSubscriptionsParams(
@@ -133,7 +131,7 @@
   }
 
   @override
-  File newFile(String path, String content, [int stamp]) => resourceProvider
+  File newFile(String path, String content, [int? stamp]) => resourceProvider
       .newFile(resourceProvider.convertPath(path), content, stamp);
 
   @override
@@ -190,12 +188,12 @@
       var importedSets = <IncludedSuggestionSet>[];
       var notImportedSets = <IncludedSuggestionSet>[];
 
-      for (var set in params.includedSuggestionSets) {
+      for (var set in params.includedSuggestionSets!) {
         var id = set.id;
         while (!idToSetMap.containsKey(id)) {
           await Future.delayed(const Duration(milliseconds: 1));
         }
-        var suggestionSet = idToSetMap[id];
+        var suggestionSet = idToSetMap[id]!;
         if (importedLibraryUris.contains(suggestionSet.uri)) {
           importedSets.add(set);
         } else {
@@ -212,7 +210,7 @@
       void addSuggestion(
           AvailableSuggestion suggestion, IncludedSuggestionSet includeSet) {
         var kind = suggestion.element.kind;
-        if (!includedKinds.contains(kind)) {
+        if (!includedKinds!.contains(kind)) {
           return;
         }
         var completionSuggestion =
@@ -229,7 +227,7 @@
           '${s.declaringLibraryUri}:${s.element.kind}:${s.label}';
 
       for (var includeSet in importedSets) {
-        var set = idToSetMap[includeSet.id];
+        var set = idToSetMap[includeSet.id]!;
         for (var suggestion in set.items) {
           if (seenElements.add(suggestionId(suggestion))) {
             addSuggestion(suggestion, includeSet);
@@ -238,7 +236,7 @@
       }
 
       for (var includeSet in notImportedSets) {
-        var set = idToSetMap[includeSet.id];
+        var set = idToSetMap[includeSet.id]!;
         for (var suggestion in set.items) {
           if (!seenElements.contains(suggestionId(suggestion))) {
             addSuggestion(suggestion, includeSet);
@@ -252,11 +250,11 @@
       var params = CompletionAvailableSuggestionsParams.fromNotification(
         notification,
       );
-      for (var set in params.changedLibraries) {
+      for (var set in params.changedLibraries!) {
         idToSetMap[set.id] = set;
         uriToSetMap[set.uri] = set;
       }
-      for (var id in params.removedLibraries) {
+      for (var id in params.removedLibraries!) {
         var set = idToSetMap.remove(id);
         uriToSetMap.remove(set?.uri);
       }
diff --git a/pkg/analysis_server/test/client/test_all.dart b/pkg/analysis_server/test/client/test_all.dart
index 7887a9d..417c4d3 100644
--- a/pkg/analysis_server/test/client/test_all.dart
+++ b/pkg/analysis_server/test/client/test_all.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.9
-
 import 'package:test_reflective_loader/test_reflective_loader.dart';
 
 import 'completion_driver_test.dart' as completion_driver;
diff --git a/pkg/analysis_server/test/completion_test.dart b/pkg/analysis_server/test/completion_test.dart
index 4cefdef..eaf324a 100644
--- a/pkg/analysis_server/test/completion_test.dart
+++ b/pkg/analysis_server/test/completion_test.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.9
-
 import 'dart:collection';
 
 import 'package:test/test.dart';
@@ -2418,7 +2416,7 @@
   /// expected to fail.  This should be used to mark known completion bugs that
   /// have not yet been fixed.
   void buildTests(String baseName, String originalSource, List<String> results,
-      {Map<String, String> extraFiles, String failingTests = ''}) {
+      {Map<String, String>? extraFiles, String failingTests = ''}) {
     var completionTests = LocationSpec.from(originalSource, results);
     completionTests.sort((LocationSpec first, LocationSpec second) {
       return first.id.compareTo(second.id);
diff --git a/pkg/analysis_server/test/completion_test_support.dart b/pkg/analysis_server/test/completion_test_support.dart
index 83a70c8..0e63271 100644
--- a/pkg/analysis_server/test/completion_test_support.dart
+++ b/pkg/analysis_server/test/completion_test_support.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.9
-
 import 'dart:collection';
 
 import 'package:analyzer_plugin/protocol/protocol_common.dart';
@@ -20,7 +18,7 @@
       .toList();
 
   void assertHasCompletion(String completion,
-      {ElementKind elementKind, bool isDeprecated}) {
+      {ElementKind? elementKind, bool? isDeprecated}) {
     var expectedOffset = completion.indexOf(CURSOR_MARKER);
     if (expectedOffset >= 0) {
       if (completion.contains(CURSOR_MARKER, expectedOffset + 1)) {
@@ -31,8 +29,8 @@
     } else {
       expectedOffset = completion.length;
     }
-    CompletionSuggestion matchingSuggestion;
-    suggestions.forEach((CompletionSuggestion suggestion) {
+    CompletionSuggestion? matchingSuggestion;
+    for (var suggestion in suggestions) {
       if (suggestion.completion == completion) {
         if (matchingSuggestion == null) {
           matchingSuggestion = suggestion;
@@ -48,14 +46,14 @@
               "Expected exactly one '$completion' but found multiple:\n  $suggestedCompletions");
         }
       }
-    });
+    }
     if (matchingSuggestion == null) {
       fail("Expected '$completion' but found none:\n  $suggestedCompletions");
     }
     expect(matchingSuggestion.selectionOffset, equals(expectedOffset));
     expect(matchingSuggestion.selectionLength, equals(0));
     if (elementKind != null) {
-      expect(matchingSuggestion.element.kind, elementKind);
+      expect(matchingSuggestion.element!.kind, elementKind);
     }
     if (isDeprecated != null) {
       expect(matchingSuggestion.isDeprecated, isDeprecated);
@@ -74,14 +72,14 @@
   /// "already typed".
   void filterResults(String content) {
     var charsAlreadyTyped =
-        content.substring(replacementOffset, completionOffset).toLowerCase();
+        content.substring(replacementOffset!, completionOffset).toLowerCase();
     suggestions = suggestions
         .where((CompletionSuggestion suggestion) =>
             suggestion.completion.toLowerCase().startsWith(charsAlreadyTyped))
         .toList();
   }
 
-  Future runTest(LocationSpec spec, [Map<String, String> extraFiles]) {
+  Future runTest(LocationSpec spec, [Map<String, String>? extraFiles]) {
     super.setUp();
     return Future(() {
       var content = spec.source;
@@ -113,7 +111,7 @@
   int testLocation = -1;
   List<String> positiveResults = <String>[];
   List<String> negativeResults = <String>[];
-  String source;
+  late String source;
 
   LocationSpec(this.id);
 
diff --git a/pkg/analysis_server/test/domain_analysis_test.dart b/pkg/analysis_server/test/domain_analysis_test.dart
index b05effd..653339c 100644
--- a/pkg/analysis_server/test/domain_analysis_test.dart
+++ b/pkg/analysis_server/test/domain_analysis_test.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.9
-
 import 'dart:async';
 
 import 'package:analysis_server/protocol/protocol.dart';
@@ -20,7 +18,6 @@
 import 'package:analyzer/src/test_utilities/resource_provider_mixin.dart';
 import 'package:analyzer_plugin/protocol/protocol_common.dart';
 import 'package:analyzer_plugin/protocol/protocol_generated.dart' as plugin;
-import 'package:meta/meta.dart';
 import 'package:test/test.dart';
 import 'package:test_reflective_loader/test_reflective_loader.dart';
 
@@ -263,7 +260,7 @@
   Response testSetAnalysisRoots(List<String> included, List<String> excluded) {
     var request =
         AnalysisSetAnalysisRootsParams(included, excluded).toRequest('0');
-    return handler.handleRequest(request);
+    return handler.handleRequest(request)!;
   }
 
   Future<void> xtest_getReachableSources_invalidSource() async {
@@ -276,10 +273,9 @@
 
     var request = AnalysisGetReachableSourcesParams('/does/not/exist.dart')
         .toRequest('0');
-    var response = handler.handleRequest(request);
-    expect(response.error, isNotNull);
-    expect(response.error.code,
-        RequestErrorCode.GET_REACHABLE_SOURCES_INVALID_FILE);
+    var response = handler.handleRequest(request)!;
+    var error = response.error!;
+    expect(error.code, RequestErrorCode.GET_REACHABLE_SOURCES_INVALID_FILE);
   }
 
   Future<void> xtest_getReachableSources_validSources() async {
@@ -293,9 +289,9 @@
     await server.onAnalysisComplete;
 
     var request = AnalysisGetReachableSourcesParams(fileA).toRequest('0');
-    var response = handler.handleRequest(request);
+    var response = handler.handleRequest(request)!;
 
-    Map json = response.toJson()[Response.RESULT];
+    var json = response.toJson()[Response.RESULT] as Map<String, dynamic>;
 
     // Sanity checks.
     expect(json['sources'], hasLength(6));
@@ -1418,9 +1414,9 @@
   }
 
   void _assertAnalyzedFiles({
-    @required List<String> hasErrors,
+    required List<String> hasErrors,
     List<String> noErrors = const [],
-    @required List<String> notAnalyzed,
+    required List<String> notAnalyzed,
   }) {
     for (var path in hasErrors) {
       assertHasErrors(path);
@@ -1454,9 +1450,9 @@
 
 /// A helper to test 'analysis.*' requests.
 class AnalysisTestHelper with ResourceProviderMixin {
-  MockServerChannel serverChannel;
-  AnalysisServer server;
-  AnalysisDomainHandler handler;
+  late MockServerChannel serverChannel;
+  late AnalysisServer server;
+  late AnalysisDomainHandler handler;
 
   Map<AnalysisService, List<String>> analysisSubscriptions = {};
 
@@ -1464,9 +1460,9 @@
   Map<String, List<HighlightRegion>> filesHighlights = {};
   Map<String, List<NavigationRegion>> filesNavigation = {};
 
-  String projectPath;
-  String testFile;
-  String testCode;
+  late String projectPath;
+  late String testFile;
+  late String testCode;
 
   AnalysisTestHelper() {
     projectPath = convertPath('/project');
@@ -1773,8 +1769,7 @@
     addAnalysisSubscription(AnalysisService.HIGHLIGHTS, testFile);
     // wait for analysis
     await waitForTasksFinished();
-    var params = pluginManager.analysisSetSubscriptionsParams;
-    expect(params, isNotNull);
+    var params = pluginManager.analysisSetSubscriptionsParams!;
     var subscriptions = params.subscriptions;
     expect(subscriptions, hasLength(1));
     var files = subscriptions[plugin.AnalysisService.HIGHLIGHTS];
diff --git a/pkg/analysis_server/test/domain_completion_test.dart b/pkg/analysis_server/test/domain_completion_test.dart
index 8da9476..08d3056 100644
--- a/pkg/analysis_server/test/domain_completion_test.dart
+++ b/pkg/analysis_server/test/domain_completion_test.dart
@@ -2,11 +2,10 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.9
-
 import 'package:analysis_server/protocol/protocol_generated.dart';
 import 'package:analysis_server/src/plugin/plugin_manager.dart';
 import 'package:analysis_server/src/provisional/completion/dart/completion_dart.dart';
+import 'package:analyzer/instrumentation/service.dart';
 import 'package:analyzer_plugin/protocol/protocol.dart' as plugin;
 import 'package:analyzer_plugin/protocol/protocol_common.dart';
 import 'package:analyzer_plugin/protocol/protocol_generated.dart' as plugin;
@@ -15,6 +14,7 @@
 
 import 'domain_completion_util.dart';
 import 'mocks.dart';
+import 'src/plugin/plugin_manager_test.dart';
 
 void main() {
   defineReflectiveSuite(() {
@@ -735,7 +735,7 @@
         .toRequest('0');
     var response = await waitResponse(request);
     expect(response.id, '0');
-    expect(response.error.code, RequestErrorCode.INVALID_PARAMETER);
+    expect(response.error!.code, RequestErrorCode.INVALID_PARAMETER);
   }
 
   Future<void> test_overrides() {
@@ -803,7 +803,8 @@
         ^
       }
     ''');
-    PluginInfo info = DiscoveredPluginInfo('a', 'b', 'c', null, null);
+    PluginInfo info = DiscoveredPluginInfo('a', 'b', 'c',
+        TestNotificationManager(), InstrumentationService.NULL_SERVICE);
     var result = plugin.CompletionGetSuggestionsResult(
         testFile.indexOf('^'), 0, <CompletionSuggestion>[
       CompletionSuggestion(CompletionSuggestionKind.IDENTIFIER,
diff --git a/pkg/analysis_server/test/domain_completion_util.dart b/pkg/analysis_server/test/domain_completion_util.dart
index 80786c5..8670a6f 100644
--- a/pkg/analysis_server/test/domain_completion_util.dart
+++ b/pkg/analysis_server/test/domain_completion_util.dart
@@ -17,7 +17,7 @@
 class AbstractCompletionDomainTest extends AbstractAnalysisTest {
   late String completionId;
   late int completionOffset;
-  late int replacementOffset;
+  int? replacementOffset;
   late int replacementLength;
   Map<String, Completer<void>> receivedSuggestionsCompleters = {};
   List<CompletionSuggestion> suggestions = [];
diff --git a/pkg/analysis_server/test/edit/assists_test.dart b/pkg/analysis_server/test/edit/assists_test.dart
index 93a35f0..e2cb0dc 100644
--- a/pkg/analysis_server/test/edit/assists_test.dart
+++ b/pkg/analysis_server/test/edit/assists_test.dart
@@ -2,11 +2,10 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.9
-
 import 'package:analysis_server/protocol/protocol_generated.dart';
 import 'package:analysis_server/src/edit/edit_domain.dart';
 import 'package:analysis_server/src/plugin/plugin_manager.dart';
+import 'package:analyzer/instrumentation/service.dart';
 import 'package:analyzer_plugin/protocol/protocol.dart' as plugin;
 import 'package:analyzer_plugin/protocol/protocol_common.dart';
 import 'package:analyzer_plugin/protocol/protocol_generated.dart' as plugin;
@@ -15,6 +14,7 @@
 
 import '../analysis_abstract.dart';
 import '../mocks.dart';
+import '../src/plugin/plugin_manager_test.dart';
 
 void main() {
   defineReflectiveSuite(() {
@@ -24,7 +24,7 @@
 
 @reflectiveTest
 class AssistsTest extends AbstractAnalysisTest {
-  List<SourceChange> changes;
+  late List<SourceChange> changes;
 
   Future<void> prepareAssists(String search, [int length = 0]) async {
     var offset = findOffset(search);
@@ -46,7 +46,8 @@
   }
 
   Future<void> test_fromPlugins() async {
-    PluginInfo info = DiscoveredPluginInfo('a', 'b', 'c', null, null);
+    PluginInfo info = DiscoveredPluginInfo('a', 'b', 'c',
+        TestNotificationManager(), InstrumentationService.NULL_SERVICE);
     var message = 'From a plugin';
     var change = plugin.PrioritizedSourceChange(
         5,
diff --git a/pkg/analysis_server/test/edit/bulk_fixes_test.dart b/pkg/analysis_server/test/edit/bulk_fixes_test.dart
index 5d88990..d48358f 100644
--- a/pkg/analysis_server/test/edit/bulk_fixes_test.dart
+++ b/pkg/analysis_server/test/edit/bulk_fixes_test.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.9
-
 import 'dart:io';
 
 import 'package:analysis_server/protocol/protocol_generated.dart';
@@ -11,7 +9,6 @@
 import 'package:analysis_server/src/services/linter/lint_names.dart';
 import 'package:analyzer_plugin/protocol/protocol_common.dart';
 import 'package:linter/src/rules.dart';
-import 'package:meta/meta.dart';
 import 'package:test/test.dart';
 import 'package:test_reflective_loader/test_reflective_loader.dart';
 
@@ -26,7 +23,7 @@
 @reflectiveTest
 class BulkFixesTest extends AbstractAnalysisTest {
   void assertContains(List<BulkFix> details,
-      {@required String path, @required String code, @required int count}) {
+      {required String path, required String code, required int count}) {
     for (var detail in details) {
       if (detail.path == path) {
         for (var fix in detail.fixes) {
diff --git a/pkg/analysis_server/test/edit/format_test.dart b/pkg/analysis_server/test/edit/format_test.dart
index bcab9d1..1990b31 100644
--- a/pkg/analysis_server/test/edit/format_test.dart
+++ b/pkg/analysis_server/test/edit/format_test.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.9
-
 import 'package:analysis_server/protocol/protocol_generated.dart';
 import 'package:analysis_server/src/edit/edit_domain.dart';
 import 'package:test/test.dart';
@@ -112,7 +110,7 @@
   }
 
   EditFormatResult _formatAt(int selectionOffset, int selectionLength,
-      {int lineLength}) {
+      {int? lineLength}) {
     var request = EditFormatParams(testFile, selectionOffset, selectionLength,
             lineLength: lineLength)
         .toRequest('0');
diff --git a/pkg/analysis_server/test/edit/organize_directives_test.dart b/pkg/analysis_server/test/edit/organize_directives_test.dart
index e81ca0e..c18850e 100644
--- a/pkg/analysis_server/test/edit/organize_directives_test.dart
+++ b/pkg/analysis_server/test/edit/organize_directives_test.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.9
-
 import 'package:analysis_server/protocol/protocol_generated.dart';
 import 'package:analysis_server/src/edit/edit_domain.dart';
 import 'package:analyzer_plugin/protocol/protocol_common.dart';
@@ -21,7 +19,7 @@
 
 @reflectiveTest
 class OrganizeDirectivesTest extends AbstractAnalysisTest {
-  SourceFileEdit fileEdit;
+  late SourceFileEdit fileEdit;
 
   @override
   void setUp() {
diff --git a/pkg/analysis_server/test/edit/refactoring_test.dart b/pkg/analysis_server/test/edit/refactoring_test.dart
index 9baa5b3..d14a01d 100644
--- a/pkg/analysis_server/test/edit/refactoring_test.dart
+++ b/pkg/analysis_server/test/edit/refactoring_test.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.9
-
 import 'package:analysis_server/protocol/protocol.dart';
 import 'package:analysis_server/protocol/protocol_generated.dart';
 import 'package:analysis_server/src/edit/edit_domain.dart';
@@ -248,7 +246,7 @@
 @reflectiveTest
 class ExtractLocalVariableTest extends _AbstractGetRefactoring_Test {
   Future<Response> sendExtractRequest(
-      int offset, int length, String name, bool extractAll) {
+      int offset, int length, String? name, bool extractAll) {
     var kind = RefactoringKind.EXTRACT_LOCAL_VARIABLE;
     var options =
         name != null ? ExtractLocalVariableOptions(name, extractAll) : null;
@@ -263,7 +261,7 @@
   }
 
   Future<Response> sendStringSuffixRequest(
-      String search, String suffix, String name, bool extractAll) {
+      String search, String suffix, String? name, bool extractAll) {
     var offset = findOffset(search + suffix);
     var length = search.length;
     return sendExtractRequest(offset, length, name, extractAll);
@@ -293,7 +291,7 @@
       return sendStringRequest('1 + 2', 'res', true);
     });
     // We get the refactoring feedback....
-    ExtractLocalVariableFeedback feedback = result.feedback;
+    var feedback = result.feedback as ExtractLocalVariableFeedback;
     expect(feedback.names, contains('myName'));
   }
 
@@ -306,7 +304,7 @@
     return getRefactoringResult(() {
       return sendExtractRequest(testCode.indexOf('222 +'), 0, 'res', true);
     }).then((result) {
-      ExtractLocalVariableFeedback feedback = result.feedback;
+      var feedback = result.feedback as ExtractLocalVariableFeedback;
       expect(feedback.coveringExpressionOffsets, [
         testCode.indexOf('222 +'),
         testCode.indexOf('111 +'),
@@ -390,7 +388,7 @@
     var result = await getRefactoringResult(() {
       return sendStringSuffixRequest('getSelectedItem()', ';', null, true);
     });
-    ExtractLocalVariableFeedback feedback = result.feedback;
+    var feedback = result.feedback as ExtractLocalVariableFeedback;
     expect(
         feedback.names, unorderedEquals(['treeItem', 'item', 'selectedItem']));
     expect(result.change, isNull);
@@ -426,7 +424,7 @@
     return getRefactoringResult(() {
       return sendStringRequest('1 + 2', 'res', true);
     }).then((result) {
-      ExtractLocalVariableFeedback feedback = result.feedback;
+      var feedback = result.feedback as ExtractLocalVariableFeedback;
       expect(feedback.offsets, [findOffset('1 + 2'), findOffset('1 +  2')]);
       expect(feedback.lengths, [5, 6]);
     });
@@ -490,7 +488,7 @@
       var result = await getRefactoringResult(() {
         return sendStringRequest('1 + 2', 'res', true);
       });
-      ExtractLocalVariableFeedback feedback = result.feedback;
+      var feedback = result.feedback as ExtractLocalVariableFeedback;
       expect(feedback.names, contains('myName'));
     }
     var initialResetCount = test_resetCount;
@@ -515,7 +513,7 @@
       var result = await getRefactoringResult(() {
         return sendStringRequest('1 + 2', 'res', true);
       });
-      ExtractLocalVariableFeedback feedback = result.feedback;
+      var feedback = result.feedback as ExtractLocalVariableFeedback;
       expect(feedback.names, contains('myName'));
     }
     var initialResetCount = test_resetCount;
@@ -534,7 +532,7 @@
       var result = await getRefactoringResult(() {
         return sendStringRequest('1 + 2', 'res', true);
       });
-      ExtractLocalVariableFeedback feedback = result.feedback;
+      var feedback = result.feedback as ExtractLocalVariableFeedback;
       // The refactoring was reset, so we don't get stale results.
       expect(feedback.names, contains('otherName'));
     }
@@ -549,8 +547,8 @@
 ''');
     return waitForTasksFinished().then((_) {
       return sendStringRequest('1 + 2', 'res', true).then((response) {
-        expect(response.error, isNotNull);
-        expect(response.error.code, RequestErrorCode.SERVER_ERROR);
+        var error = response.error!;
+        expect(error.code, RequestErrorCode.SERVER_ERROR);
       });
     });
   }
@@ -564,8 +562,8 @@
 ''');
     return waitForTasksFinished().then((_) {
       return sendStringRequest('1 + 2', 'res', true).then((response) {
-        expect(response.error, isNotNull);
-        expect(response.error.code, RequestErrorCode.SERVER_ERROR);
+        var error = response.error!;
+        expect(error.code, RequestErrorCode.SERVER_ERROR);
       });
     });
   }
@@ -579,8 +577,8 @@
 ''');
     return waitForTasksFinished().then((_) {
       return sendStringRequest('1 + 2', 'res', true).then((response) {
-        expect(response.error, isNotNull);
-        expect(response.error.code, RequestErrorCode.SERVER_ERROR);
+        var error = response.error!;
+        expect(error.code, RequestErrorCode.SERVER_ERROR);
       });
     });
   }
@@ -588,10 +586,10 @@
 
 @reflectiveTest
 class ExtractMethodTest extends _AbstractGetRefactoring_Test {
-  int offset;
-  int length;
+  late int offset;
+  late int length;
   String name = 'res';
-  ExtractMethodOptions options;
+  ExtractMethodOptions? options;
 
   Future<void> test_expression() {
     addTestFile('''
@@ -644,13 +642,13 @@
 ''');
     _setOffsetLengthForString('a + b');
     var result = await getRefactoringResult(_computeChange);
-    ExtractMethodFeedback feedback = result.feedback;
+    var feedback = result.feedback as ExtractMethodFeedback;
     var parameters = feedback.parameters;
     parameters[0].name = 'aaa';
     parameters[1].name = 'bbb';
     parameters[1].type = 'num';
     parameters.insert(0, parameters.removeLast());
-    options.parameters = parameters;
+    options!.parameters = parameters;
     return assertSuccessfulRefactoring(_sendExtractRequest, '''
 main() {
   int a = 1;
@@ -775,7 +773,7 @@
     await waitForTasksFinished();
     var response = await _sendExtractRequest();
     var result = EditGetRefactoringResult.fromResponse(response);
-    return result.feedback;
+    return result.feedback as ExtractMethodFeedback;
   }
 
   Future _prepareOptions() {
@@ -785,7 +783,7 @@
     }).then((result) {
       assertResultProblemsOK(result);
       // fill options from result
-      ExtractMethodFeedback feedback = result.feedback;
+      var feedback = result.feedback as ExtractMethodFeedback;
       options = ExtractMethodOptions(
           feedback.returnType, false, name, feedback.parameters, true);
       // done
@@ -811,7 +809,7 @@
 
 @reflectiveTest
 class GetAvailableRefactoringsTest extends AbstractAnalysisTest {
-  List<RefactoringKind> kinds;
+  late List<RefactoringKind> kinds;
 
   void addFlutterPackage() {
     var libFolder = MockPackages.instance.addFlutter(resourceProvider);
@@ -1077,7 +1075,7 @@
       return _sendInlineRequest('res =');
     });
     // We get the refactoring feedback....
-    InlineLocalVariableFeedback feedback = result.feedback;
+    var feedback = result.feedback as InlineLocalVariableFeedback;
     expect(feedback.occurrences, 2);
   }
 
@@ -1092,7 +1090,7 @@
     return getRefactoringResult(() {
       return _sendInlineRequest('test =');
     }).then((result) {
-      InlineLocalVariableFeedback feedback = result.feedback;
+      var feedback = result.feedback as InlineLocalVariableFeedback;
       expect(feedback.name, 'test');
       expect(feedback.occurrences, 2);
     });
@@ -1183,7 +1181,7 @@
     return getRefactoringResult(() {
       return _sendInlineRequest('test(int p)');
     }).then((result) {
-      InlineMethodFeedback feedback = result.feedback;
+      var feedback = result.feedback as InlineMethodFeedback;
       expect(feedback.className, 'A');
       expect(feedback.methodName, 'test');
       expect(feedback.isDeclaration, isTrue);
@@ -1288,7 +1286,7 @@
 
 @reflectiveTest
 class MoveFileTest extends _AbstractGetRefactoring_Test {
-  MoveFileOptions options;
+  late MoveFileOptions options;
 
   @failingTest
   Future<void> test_OK() {
@@ -1322,7 +1320,7 @@
 
 @reflectiveTest
 class RenameTest extends _AbstractGetRefactoring_Test {
-  Future<Response> sendRenameRequest(String search, String newName,
+  Future<Response> sendRenameRequest(String search, String? newName,
       {String id = '0', bool validateOnly = false}) {
     var options = newName != null ? RenameOptions(newName) : null;
     var request = EditGetRefactoringParams(RefactoringKind.RENAME, testFile,
@@ -1409,7 +1407,7 @@
 }
 ''',
       feedbackValidator: (feedback) {
-        RenameFeedback renameFeedback = feedback;
+        var renameFeedback = feedback as RenameFeedback;
         expect(renameFeedback.offset, 18);
         expect(renameFeedback.length, 4);
       },
@@ -1438,7 +1436,7 @@
 }
 ''',
       feedbackValidator: (feedback) {
-        RenameFeedback renameFeedback = feedback;
+        var renameFeedback = feedback as RenameFeedback;
         expect(renameFeedback.offset, 42);
         expect(renameFeedback.length, 4);
       },
@@ -1467,7 +1465,7 @@
 }
 ''',
       feedbackValidator: (feedback) {
-        RenameFeedback renameFeedback = feedback;
+        var renameFeedback = feedback as RenameFeedback;
         expect(renameFeedback.offset, 48);
         expect(renameFeedback.length, 4);
       },
@@ -1496,7 +1494,7 @@
 }
 ''',
       feedbackValidator: (feedback) {
-        RenameFeedback renameFeedback = feedback;
+        var renameFeedback = feedback as RenameFeedback;
         expect(renameFeedback.offset, 42);
         expect(renameFeedback.length, 4);
       },
@@ -1525,7 +1523,7 @@
 }
 ''',
       feedbackValidator: (feedback) {
-        RenameFeedback renameFeedback = feedback;
+        var renameFeedback = feedback as RenameFeedback;
         expect(renameFeedback.offset, 48);
         expect(renameFeedback.length, 4);
       },
@@ -1559,7 +1557,7 @@
     return getRefactoringResult(() {
       return sendRenameRequest('Test {}', 'NewName', validateOnly: true);
     }).then((result) {
-      RenameFeedback feedback = result.feedback;
+      var feedback = result.feedback as RenameFeedback;
       assertResultProblemsOK(result);
       expect(feedback.elementKindName, 'class');
       expect(feedback.oldName, 'Test');
@@ -1735,13 +1733,12 @@
     }).then((result) {
       assertResultProblemsOK(result);
       // prepare potential edit ID
-      var potentialIds = result.potentialEdits;
+      var potentialIds = result.potentialEdits!;
       expect(potentialIds, hasLength(1));
       var potentialId = potentialIds[0];
       // find potential edit
-      var change = result.change;
-      var potentialEdit = _findEditWithId(change, potentialId);
-      expect(potentialEdit, isNotNull);
+      var change = result.change!;
+      var potentialEdit = _findEditWithId(change, potentialId)!;
       expect(potentialEdit.offset, findOffset('test(); // a2'));
       expect(potentialEdit.length, 4);
     });
@@ -1790,7 +1787,7 @@
 }
 ''',
       feedbackValidator: (feedback) {
-        RenameFeedback renameFeedback = feedback;
+        var renameFeedback = feedback as RenameFeedback;
         expect(renameFeedback.offset, 20);
         expect(renameFeedback.length, 4);
       },
@@ -1819,7 +1816,7 @@
 }
 ''',
       feedbackValidator: (feedback) {
-        RenameFeedback renameFeedback = feedback;
+        var renameFeedback = feedback as RenameFeedback;
         expect(renameFeedback.offset, 43);
         expect(renameFeedback.length, 4);
       },
@@ -1836,7 +1833,7 @@
     return getRefactoringResult(() {
       return sendRenameRequest('st v;', 'NewName');
     }).then((result) {
-      RenameFeedback feedback = result.feedback;
+      var feedback = result.feedback as RenameFeedback;
       expect(feedback, isNotNull);
       expect(feedback.offset, findOffset('Test v;'));
       expect(feedback.length, 'Test'.length);
@@ -1930,7 +1927,7 @@
 }
 ''',
         feedbackValidator: (feedback) {
-          RenameFeedback renameFeedback = feedback;
+          var renameFeedback = feedback as RenameFeedback;
           expect(renameFeedback.offset, -1);
           expect(renameFeedback.length, 0);
         });
@@ -1958,7 +1955,7 @@
 }
 ''',
         feedbackValidator: (feedback) {
-          RenameFeedback renameFeedback = feedback;
+          var renameFeedback = feedback as RenameFeedback;
           expect(renameFeedback.offset, 51);
           expect(renameFeedback.length, 4);
         });
@@ -2127,7 +2124,7 @@
   print(otherName);
 }
 ''');
-    server.getAnalysisDriver(testFile).getResult2(testFile);
+    server.getAnalysisDriver(testFile)!.getResult2(testFile);
     // send the second request, with the same kind, file and offset
     await waitForTasksFinished();
     result = await getRefactoringResult(() {
@@ -2143,8 +2140,8 @@
         isResponseFailure('0', RequestErrorCode.REFACTORING_REQUEST_CANCELLED));
   }
 
-  SourceEdit _findEditWithId(SourceChange change, String id) {
-    SourceEdit potentialEdit;
+  SourceEdit? _findEditWithId(SourceChange change, String id) {
+    SourceEdit? potentialEdit;
     change.edits.forEach((fileEdit) {
       fileEdit.edits.forEach((edit) {
         if (edit.id == id) {
@@ -2155,9 +2152,8 @@
     return potentialEdit;
   }
 
-  void _validateFeedback(EditGetRefactoringResult result, {String oldName}) {
-    RenameFeedback feedback = result.feedback;
-    expect(feedback, isNotNull);
+  void _validateFeedback(EditGetRefactoringResult result, {String? oldName}) {
+    var feedback = result.feedback as RenameFeedback;
     if (oldName != null) {
       expect(feedback.oldName, oldName);
     }
@@ -2170,7 +2166,7 @@
 
   /// Asserts that [problems] has a single ERROR problem.
   void assertResultProblemsError(List<RefactoringProblem> problems,
-      [String message]) {
+      [String? message]) {
     var problem = problems[0];
     expect(problem.severity, RefactoringProblemSeverity.ERROR,
         reason: problem.toString());
@@ -2181,7 +2177,7 @@
 
   /// Asserts that [result] has a single FATAL problem.
   void assertResultProblemsFatal(List<RefactoringProblem> problems,
-      [String message]) {
+      [String? message]) {
     var problem = problems[0];
     expect(problems, hasLength(1));
     expect(problem.severity, RefactoringProblemSeverity.FATAL,
@@ -2200,7 +2196,7 @@
 
   /// Asserts that [result] has a single WARNING problem.
   void assertResultProblemsWarning(List<RefactoringProblem> problems,
-      [String message]) {
+      [String? message]) {
     var problem = problems[0];
     expect(problems, hasLength(1));
     expect(problem.severity, RefactoringProblemSeverity.WARNING,
@@ -2212,7 +2208,7 @@
 
   Future assertSuccessfulRefactoring(
       Future<Response> Function() requestSender, String expectedCode,
-      {void Function(RefactoringFeedback) feedbackValidator}) async {
+      {void Function(RefactoringFeedback?)? feedbackValidator}) async {
     var result = await getRefactoringResult(requestSender);
     assertResultProblemsOK(result);
     if (feedbackValidator != null) {
@@ -2225,8 +2221,7 @@
   /// which results in the [expectedCode].
   void assertTestRefactoringResult(
       EditGetRefactoringResult result, String expectedCode) {
-    var change = result.change;
-    expect(change, isNotNull);
+    var change = result.change!;
     for (var fileEdit in change.edits) {
       if (fileEdit.file == testFile) {
         var actualCode = SourceEdit.applySequence(testCode, fileEdit.edits);
@@ -2247,7 +2242,7 @@
   }
 
   Future<Response> sendRequest(
-      RefactoringKind kind, int offset, int length, RefactoringOptions options,
+      RefactoringKind kind, int offset, int length, RefactoringOptions? options,
       [bool validateOnly = false]) {
     var request = EditGetRefactoringParams(
             kind, testFile, offset, length, validateOnly,
diff --git a/pkg/analysis_server/test/edit/sort_members_test.dart b/pkg/analysis_server/test/edit/sort_members_test.dart
index 083b834..52c1932 100644
--- a/pkg/analysis_server/test/edit/sort_members_test.dart
+++ b/pkg/analysis_server/test/edit/sort_members_test.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.9
-
 import 'package:analysis_server/protocol/protocol_generated.dart';
 import 'package:analysis_server/src/edit/edit_domain.dart';
 import 'package:analyzer_plugin/protocol/protocol_common.dart';
@@ -21,7 +19,7 @@
 
 @reflectiveTest
 class SortMembersTest extends AbstractAnalysisTest {
-  SourceFileEdit fileEdit;
+  late SourceFileEdit fileEdit;
 
   @override
   void setUp() {
diff --git a/pkg/analysis_server/test/edit/statement_completion_test.dart b/pkg/analysis_server/test/edit/statement_completion_test.dart
index c442c9c..09e11a7 100644
--- a/pkg/analysis_server/test/edit/statement_completion_test.dart
+++ b/pkg/analysis_server/test/edit/statement_completion_test.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.9
-
 import 'package:analysis_server/protocol/protocol_generated.dart';
 import 'package:analysis_server/src/edit/edit_domain.dart';
 import 'package:analyzer_plugin/protocol/protocol_common.dart';
@@ -21,7 +19,7 @@
 
 @reflectiveTest
 class StatementCompletionTest extends AbstractAnalysisTest {
-  SourceChange change;
+  late SourceChange change;
 
   @override
   void setUp() {
@@ -103,7 +101,7 @@
         (s) => s.indexOf(match) + match.length); // Ensure cursor after '='.
   }
 
-  void _assertHasChange(String message, String expectedCode, [Function cmp]) {
+  void _assertHasChange(String message, String expectedCode, [Function? cmp]) {
     if (change.message == message) {
       if (change.edits.isNotEmpty) {
         var resultCode =
@@ -111,12 +109,12 @@
         expect(resultCode, expectedCode.replaceAll('/*caret*/', ''));
         if (cmp != null) {
           int offset = cmp(resultCode);
-          expect(change.selection.offset, offset);
+          expect(change.selection!.offset, offset);
         }
       } else {
         if (cmp != null) {
           int offset = cmp(testCode);
-          expect(change.selection.offset, offset);
+          expect(change.selection!.offset, offset);
         }
       }
       return;
diff --git a/pkg/analysis_server/test/edit/test_all.dart b/pkg/analysis_server/test/edit/test_all.dart
index e1d5aec..21cf0bc 100644
--- a/pkg/analysis_server/test/edit/test_all.dart
+++ b/pkg/analysis_server/test/edit/test_all.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.9
-
 import 'package:test_reflective_loader/test_reflective_loader.dart';
 
 import 'assists_test.dart' as assists;
diff --git a/pkg/analysis_server/test/lsp/definition_test.dart b/pkg/analysis_server/test/lsp/definition_test.dart
index f78d059..08b013a 100644
--- a/pkg/analysis_server/test/lsp/definition_test.dart
+++ b/pkg/analysis_server/test/lsp/definition_test.dart
@@ -198,9 +198,6 @@
     expect(res, isEmpty);
   }
 
-  /// Failing due to incorrect range because _DartNavigationCollector._getCodeLocation
-  /// does not handle parts.
-  @failingTest
   Future<void> test_part() async {
     final mainContents = '''
     import 'lib.dart';
diff --git a/pkg/analysis_server/test/search/abstract_search_domain.dart b/pkg/analysis_server/test/search/abstract_search_domain.dart
index f6e20ee..cba622f 100644
--- a/pkg/analysis_server/test/search/abstract_search_domain.dart
+++ b/pkg/analysis_server/test/search/abstract_search_domain.dart
@@ -13,7 +13,7 @@
 
 class AbstractSearchDomainTest extends AbstractAnalysisTest {
   final Map<String, _ResultSet> resultSets = {};
-  late String searchId;
+  String? searchId;
   List<SearchResult> results = <SearchResult>[];
   late SearchResult result;
 
diff --git a/pkg/analysis_server/test/search/declarations_test.dart b/pkg/analysis_server/test/search/declarations_test.dart
index 349085d..a1f4900 100644
--- a/pkg/analysis_server/test/search/declarations_test.dart
+++ b/pkg/analysis_server/test/search/declarations_test.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.9
-
 import 'package:analysis_server/protocol/protocol_generated.dart';
 import 'package:analyzer_plugin/protocol/protocol_common.dart';
 import 'package:test/test.dart';
@@ -19,10 +17,10 @@
 
 @reflectiveTest
 class DeclarationsTest extends AbstractSearchDomainTest {
-  SearchGetElementDeclarationsResult declarationsResult;
+  late SearchGetElementDeclarationsResult declarationsResult;
 
   ElementDeclaration assertHas(String name, ElementKind kind,
-      {String className, String mixinName}) {
+      {String? className, String? mixinName}) {
     return declarationsResult.declarations.singleWhere((ElementDeclaration d) =>
         declarationsResult.files[d.fileIndex] == testFile &&
         d.name == name &&
@@ -214,7 +212,7 @@
   }
 
   Future<void> _getDeclarations(
-      {String file, String pattern, int maxResults}) async {
+      {String? file, String? pattern, int? maxResults}) async {
     var request = SearchGetElementDeclarationsParams(
             file: file, pattern: pattern, maxResults: maxResults)
         .toRequest('0');
diff --git a/pkg/analysis_server/test/search/element_references_test.dart b/pkg/analysis_server/test/search/element_references_test.dart
index 1049186..9515144 100644
--- a/pkg/analysis_server/test/search/element_references_test.dart
+++ b/pkg/analysis_server/test/search/element_references_test.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.9
-
 import 'package:analysis_server/protocol/protocol_generated.dart';
 import 'package:analyzer_plugin/protocol/protocol_common.dart';
 import 'package:test/test.dart';
@@ -19,7 +17,7 @@
 
 @reflectiveTest
 class ElementReferencesTest extends AbstractSearchDomainTest {
-  Element searchElement;
+  Element? searchElement;
 
   void assertHasRef(SearchResultKind kind, String search, bool isPotential) {
     assertHasResult(kind, search);
@@ -53,7 +51,7 @@
 }
 ''');
     await findElementReferences('named(p)', false);
-    expect(searchElement.kind, ElementKind.CONSTRUCTOR);
+    expect(searchElement!.kind, ElementKind.CONSTRUCTOR);
     expect(results, hasLength(2));
     assertHasResult(SearchResultKind.REFERENCE, '.named(1)', 6);
     assertHasResult(SearchResultKind.REFERENCE, '.named(2)', 6);
@@ -77,7 +75,7 @@
 }
 ''');
     await findElementReferences('named(p); // A', true);
-    expect(searchElement.kind, ElementKind.CONSTRUCTOR);
+    expect(searchElement!.kind, ElementKind.CONSTRUCTOR);
     expect(results, hasLength(1));
     assertHasResult(SearchResultKind.REFERENCE, '.named(1)', 6);
   }
@@ -93,7 +91,7 @@
 }
 ''');
     await findElementReferences('A(p)', false);
-    expect(searchElement.kind, ElementKind.CONSTRUCTOR);
+    expect(searchElement!.kind, ElementKind.CONSTRUCTOR);
     expect(results, hasLength(2));
     assertHasResult(SearchResultKind.REFERENCE, '(1)', 0);
     assertHasResult(SearchResultKind.REFERENCE, '(2)', 0);
@@ -122,7 +120,7 @@
 }
 ''');
     await findElementReferences('A(p)', true);
-    expect(searchElement.kind, ElementKind.CONSTRUCTOR);
+    expect(searchElement!.kind, ElementKind.CONSTRUCTOR);
     expect(results, hasLength(1));
     assertHasResult(SearchResultKind.REFERENCE, '(1)', 0);
   }
@@ -140,7 +138,7 @@
 }
 ''');
     await findElementReferences('E on int', false);
-    expect(searchElement.kind, ElementKind.EXTENSION);
+    expect(searchElement!.kind, ElementKind.EXTENSION);
     expect(results, hasLength(2));
     assertHasResult(SearchResultKind.REFERENCE, 'E.foo();');
     assertHasResult(SearchResultKind.REFERENCE, 'E(0)');
@@ -167,7 +165,7 @@
 }
 ''');
     await findElementReferences('fff; // declaration', false);
-    expect(searchElement.kind, ElementKind.FIELD);
+    expect(searchElement!.kind, ElementKind.FIELD);
     expect(results, hasLength(10));
     assertHasResult(SearchResultKind.WRITE, 'fff); // in constructor');
     assertHasResult(SearchResultKind.WRITE, 'fff = 1;');
@@ -200,7 +198,7 @@
 ''');
     {
       await findElementReferences('fff =>', false);
-      expect(searchElement.kind, ElementKind.FIELD);
+      expect(searchElement!.kind, ElementKind.FIELD);
       expect(results, hasLength(4));
       assertHasResult(SearchResultKind.READ, 'fff); // in m()');
       assertHasResult(SearchResultKind.WRITE, 'fff = 1;');
@@ -229,7 +227,7 @@
 }
 ''');
     await findElementReferences('fff); // in constructor', false);
-    expect(searchElement.kind, ElementKind.FIELD);
+    expect(searchElement!.kind, ElementKind.FIELD);
     expect(results, hasLength(3));
     assertHasResult(SearchResultKind.WRITE, 'fff); // in constructor');
     assertHasResult(SearchResultKind.WRITE, 'fff = 2;');
@@ -257,7 +255,7 @@
 }
 ''');
     await findElementReferences('fff; // declaration', false);
-    expect(searchElement.kind, ElementKind.FIELD);
+    expect(searchElement!.kind, ElementKind.FIELD);
     expect(results, hasLength(8));
     // m()
     assertHasResult(SearchResultKind.WRITE, 'fff = 2;');
@@ -288,7 +286,7 @@
 ''');
     {
       await findElementReferences('fff =>', false);
-      expect(searchElement.kind, ElementKind.FIELD);
+      expect(searchElement!.kind, ElementKind.FIELD);
       expect(results, hasLength(4));
       assertHasResult(SearchResultKind.READ, 'fff); // in m()');
       assertHasResult(SearchResultKind.WRITE, 'fff = 1;');
@@ -322,7 +320,7 @@
 ''');
     {
       await findElementReferences('fff =>', false);
-      expect(searchElement.kind, ElementKind.FIELD);
+      expect(searchElement!.kind, ElementKind.FIELD);
       expect(results, hasLength(4));
       assertHasResult(SearchResultKind.READ, 'fff); // in m()');
       assertHasResult(SearchResultKind.WRITE, 'fff = 1;');
@@ -348,7 +346,7 @@
 }
 ''');
     await findElementReferences('fff(p) {}', false);
-    expect(searchElement.kind, ElementKind.FUNCTION);
+    expect(searchElement!.kind, ElementKind.FUNCTION);
     expect(results, hasLength(2));
     assertHasResult(SearchResultKind.INVOCATION, 'fff(1)');
     assertHasResult(SearchResultKind.REFERENCE, 'fff);');
@@ -372,7 +370,7 @@
   }
   ''');
     await findElementReferences('fff; // in B', false);
-    expect(searchElement.kind, ElementKind.FIELD);
+    expect(searchElement!.kind, ElementKind.FIELD);
     assertHasResult(SearchResultKind.WRITE, 'fff = 10;');
     assertHasResult(SearchResultKind.WRITE, 'fff = 20;');
     assertHasResult(SearchResultKind.WRITE, 'fff = 30;');
@@ -396,7 +394,7 @@
 }
 ''');
     await findElementReferences('mmm(_) {} // in B', false);
-    expect(searchElement.kind, ElementKind.METHOD);
+    expect(searchElement!.kind, ElementKind.METHOD);
     assertHasResult(SearchResultKind.INVOCATION, 'mmm(10)');
     assertHasResult(SearchResultKind.INVOCATION, 'mmm(20)');
     assertHasResult(SearchResultKind.INVOCATION, 'mmm(30)');
@@ -420,7 +418,7 @@
 }
 ''');
     await findElementReferences('mmm(_) {} // in B', false);
-    expect(searchElement.kind, ElementKind.METHOD);
+    expect(searchElement!.kind, ElementKind.METHOD);
     expect(results, hasLength(1));
     assertHasResult(SearchResultKind.INVOCATION, 'mmm(20)');
   }
@@ -443,7 +441,7 @@
 }
 ''');
     await findElementReferences('p}) {} // in B', false);
-    expect(searchElement.kind, ElementKind.PARAMETER);
+    expect(searchElement!.kind, ElementKind.PARAMETER);
     assertHasResult(SearchResultKind.REFERENCE, 'p: 1');
     assertHasResult(SearchResultKind.REFERENCE, 'p: 2');
     assertHasResult(SearchResultKind.REFERENCE, 'p: 3');
@@ -462,7 +460,7 @@
 }
 ''');
     await findElementReferences('myLabel; // break', false);
-    expect(searchElement.kind, ElementKind.LABEL);
+    expect(searchElement!.kind, ElementKind.LABEL);
     expect(results, hasLength(2));
     assertHasResult(SearchResultKind.REFERENCE, 'myLabel; // continue');
     assertHasResult(SearchResultKind.REFERENCE, 'myLabel; // break');
@@ -479,7 +477,7 @@
 }
 ''');
     await findElementReferences('vvv = 1', false);
-    expect(searchElement.kind, ElementKind.LOCAL_VARIABLE);
+    expect(searchElement!.kind, ElementKind.LOCAL_VARIABLE);
     expect(results, hasLength(4));
     assertHasResult(SearchResultKind.READ, 'vvv);');
     assertHasResult(SearchResultKind.READ_WRITE, 'vvv += 3');
@@ -502,7 +500,7 @@
 }
 ''');
     await findElementReferences('mmm(p) {}', false);
-    expect(searchElement.kind, ElementKind.METHOD);
+    expect(searchElement!.kind, ElementKind.METHOD);
     expect(results, hasLength(4));
     assertHasResult(SearchResultKind.INVOCATION, 'mmm(1);');
     assertHasResult(SearchResultKind.REFERENCE, 'mmm); // in m()');
@@ -524,7 +522,7 @@
 }
 ''');
     await findElementReferences('foo() {}', false);
-    expect(searchElement.kind, ElementKind.METHOD);
+    expect(searchElement!.kind, ElementKind.METHOD);
     expect(results, hasLength(4));
     assertHasResult(SearchResultKind.INVOCATION, 'foo(); // 1');
     assertHasResult(SearchResultKind.REFERENCE, 'foo; // 2');
@@ -544,7 +542,7 @@
 }
 ''');
     await findElementReferences('mmm(p) {}', false);
-    expect(searchElement.kind, ElementKind.METHOD);
+    expect(searchElement!.kind, ElementKind.METHOD);
     expect(results, hasLength(2));
     assertHasResult(SearchResultKind.INVOCATION, 'mmm(10);');
     assertHasResult(SearchResultKind.REFERENCE, 'mmm);');
@@ -556,7 +554,7 @@
 class B extends Object with A {} // B
 ''');
     await findElementReferences('A {}', false);
-    expect(searchElement.kind, ElementKind.MIXIN);
+    expect(searchElement!.kind, ElementKind.MIXIN);
     expect(results, hasLength(1));
     assertHasResult(SearchResultKind.REFERENCE, 'A {} // B');
   }
@@ -594,7 +592,7 @@
 }
 ''');
     await findElementReferences('ppp) {', false);
-    expect(searchElement.kind, ElementKind.PARAMETER);
+    expect(searchElement!.kind, ElementKind.PARAMETER);
     expect(results, hasLength(4));
     assertHasResult(SearchResultKind.READ, 'ppp);');
     assertHasResult(SearchResultKind.READ_WRITE, 'ppp += 3');
@@ -801,9 +799,10 @@
 }
 ''');
     await findElementReferences('ppp;', false);
+    var searchElement = this.searchElement!;
     expect(searchElement.kind, ElementKind.PREFIX);
     expect(searchElement.name, 'ppp');
-    expect(searchElement.location.startLine, 1);
+    expect(searchElement.location!.startLine, 1);
     expect(results, hasLength(2));
     assertHasResult(SearchResultKind.REFERENCE, 'ppp.Future');
     assertHasResult(SearchResultKind.REFERENCE, 'ppp.Stream');
@@ -820,7 +819,7 @@
 }
 ''');
     await findElementReferences('vvv = 1', false);
-    expect(searchElement.kind, ElementKind.TOP_LEVEL_VARIABLE);
+    expect(searchElement!.kind, ElementKind.TOP_LEVEL_VARIABLE);
     expect(results, hasLength(4));
     assertHasResult(SearchResultKind.READ, 'vvv);');
     assertHasResult(SearchResultKind.WRITE, 'vvv += 3');
@@ -839,7 +838,7 @@
 ''');
     {
       await findElementReferences('vvv =>', false);
-      expect(searchElement.kind, ElementKind.TOP_LEVEL_VARIABLE);
+      expect(searchElement!.kind, ElementKind.TOP_LEVEL_VARIABLE);
       expect(results, hasLength(2));
       assertHasResult(SearchResultKind.READ, 'vvv);');
       assertHasResult(SearchResultKind.WRITE, 'vvv = 1;');
@@ -860,7 +859,7 @@
 }
 ''');
     await findElementReferences('int a', false);
-    expect(searchElement.kind, ElementKind.CLASS);
+    expect(searchElement!.kind, ElementKind.CLASS);
     assertHasResult(SearchResultKind.REFERENCE, 'int a');
     assertHasResult(SearchResultKind.REFERENCE, 'int b');
   }
@@ -872,7 +871,7 @@
 }
 ''');
     await findElementReferences('F =', false);
-    expect(searchElement.kind, ElementKind.TYPE_ALIAS);
+    expect(searchElement!.kind, ElementKind.TYPE_ALIAS);
     expect(results, hasLength(1));
     assertHasResult(SearchResultKind.REFERENCE, 'F f');
   }
@@ -885,13 +884,13 @@
 ''');
     // Can find `A`.
     await findElementReferences('A<T> =', false);
-    expect(searchElement.kind, ElementKind.TYPE_ALIAS);
+    expect(searchElement!.kind, ElementKind.TYPE_ALIAS);
     expect(results, hasLength(1));
     assertHasResult(SearchResultKind.REFERENCE, 'A<String>');
 
     // Can find in `A`.
     await findElementReferences('int,', false);
-    expect(searchElement.kind, ElementKind.CLASS);
+    expect(searchElement!.kind, ElementKind.CLASS);
     assertHasResult(SearchResultKind.REFERENCE, 'int,');
   }
 
@@ -902,7 +901,7 @@
 }
 ''');
     await findElementReferences('F()', false);
-    expect(searchElement.kind, ElementKind.TYPE_ALIAS);
+    expect(searchElement!.kind, ElementKind.TYPE_ALIAS);
     expect(results, hasLength(1));
     assertHasResult(SearchResultKind.REFERENCE, 'F f');
   }
@@ -915,7 +914,7 @@
 }
 ''');
     await findElementReferences('T> {', false);
-    expect(searchElement.kind, ElementKind.TYPE_PARAMETER);
+    expect(searchElement!.kind, ElementKind.TYPE_PARAMETER);
     expect(results, hasLength(2));
     assertHasResult(SearchResultKind.REFERENCE, 'T f;');
     assertHasResult(SearchResultKind.REFERENCE, 'T m()');
diff --git a/pkg/analysis_server/test/search/member_declarations_test.dart b/pkg/analysis_server/test/search/member_declarations_test.dart
index 46e9a46..d838f8e 100644
--- a/pkg/analysis_server/test/search/member_declarations_test.dart
+++ b/pkg/analysis_server/test/search/member_declarations_test.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.9
-
 import 'package:analysis_server/protocol/protocol_generated.dart';
 import 'package:analyzer_plugin/protocol/protocol_common.dart';
 import 'package:test/test.dart';
@@ -20,10 +18,11 @@
 @reflectiveTest
 class MemberDeclarationsTest extends AbstractSearchDomainTest {
   void assertHasDeclaration(ElementKind kind, String className) {
-    result = findTopLevelResult(kind, className);
+    var result = findTopLevelResult(kind, className);
     if (result == null) {
       fail('Not found: kind=$kind in="$className"\nin\n' + results.join('\n'));
     }
+    this.result = result;
   }
 
   Future findMemberDeclarations(String name) async {
@@ -35,7 +34,7 @@
     return waitForSearchResults();
   }
 
-  SearchResult findTopLevelResult(ElementKind kind, String enclosingClass) {
+  SearchResult? findTopLevelResult(ElementKind kind, String enclosingClass) {
     for (var result in results) {
       var element = result.path[0];
       var clazz = result.path[1];
diff --git a/pkg/analysis_server/test/search/member_references_test.dart b/pkg/analysis_server/test/search/member_references_test.dart
index ca74c67..a2c7b18 100644
--- a/pkg/analysis_server/test/search/member_references_test.dart
+++ b/pkg/analysis_server/test/search/member_references_test.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.9
-
 import 'package:analysis_server/protocol/protocol_generated.dart';
 import 'package:test/test.dart';
 import 'package:test_reflective_loader/test_reflective_loader.dart';
diff --git a/pkg/analysis_server/test/search/test_all.dart b/pkg/analysis_server/test/search/test_all.dart
index b4e4f8c..403be90 100644
--- a/pkg/analysis_server/test/search/test_all.dart
+++ b/pkg/analysis_server/test/search/test_all.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.9
-
 import 'package:test_reflective_loader/test_reflective_loader.dart';
 
 import 'declarations_test.dart' as declarations_test;
diff --git a/pkg/analysis_server/test/search/top_level_declarations_test.dart b/pkg/analysis_server/test/search/top_level_declarations_test.dart
index 37a7cf8..2242204 100644
--- a/pkg/analysis_server/test/search/top_level_declarations_test.dart
+++ b/pkg/analysis_server/test/search/top_level_declarations_test.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.9
-
 import 'package:analysis_server/protocol/protocol_generated.dart';
 import 'package:analyzer_plugin/protocol/protocol_common.dart';
 import 'package:test/test.dart';
@@ -20,14 +18,15 @@
 @reflectiveTest
 class TopLevelDeclarationsTest extends AbstractSearchDomainTest {
   void assertHasDeclaration(ElementKind kind, String name) {
-    result = findTopLevelResult(kind, name);
+    var result = findTopLevelResult(kind, name);
     if (result == null) {
       fail('Not found: kind=$kind name="$name"\nin\n' + results.join('\n'));
     }
+    this.result = result;
   }
 
   void assertNoDeclaration(ElementKind kind, String name) {
-    result = findTopLevelResult(kind, name);
+    var result = findTopLevelResult(kind, name);
     if (result != null) {
       fail('Unexpected: kind=$kind name="$name"\nin\n' + results.join('\n'));
     }
@@ -44,7 +43,7 @@
     return waitForSearchResults();
   }
 
-  SearchResult findTopLevelResult(ElementKind kind, String name) {
+  SearchResult? findTopLevelResult(ElementKind kind, String name) {
     for (var result in results) {
       var element = result.path[0];
       if (element.kind == kind && element.name == name) {
diff --git a/pkg/analysis_server/test/services/completion/dart/relevance/bool_assignment_test.dart b/pkg/analysis_server/test/services/completion/dart/relevance/bool_assignment_test.dart
index 701f7c5..039c915 100644
--- a/pkg/analysis_server/test/services/completion/dart/relevance/bool_assignment_test.dart
+++ b/pkg/analysis_server/test/services/completion/dart/relevance/bool_assignment_test.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.9
-
 import 'package:analyzer_plugin/protocol/protocol_common.dart';
 import 'package:test_reflective_loader/test_reflective_loader.dart';
 
diff --git a/pkg/analysis_server/test/services/completion/dart/relevance/completion_relevance.dart b/pkg/analysis_server/test/services/completion/dart/relevance/completion_relevance.dart
index 8a2fcd3b..81532df 100644
--- a/pkg/analysis_server/test/services/completion/dart/relevance/completion_relevance.dart
+++ b/pkg/analysis_server/test/services/completion/dart/relevance/completion_relevance.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.9
-
 import 'package:analyzer_plugin/protocol/protocol_common.dart';
 import 'package:test/test.dart';
 
diff --git a/pkg/analysis_server/test/services/completion/dart/relevance/deprecated_member_test.dart b/pkg/analysis_server/test/services/completion/dart/relevance/deprecated_member_test.dart
index fe82af1..44d0f92 100644
--- a/pkg/analysis_server/test/services/completion/dart/relevance/deprecated_member_test.dart
+++ b/pkg/analysis_server/test/services/completion/dart/relevance/deprecated_member_test.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.9
-
 import 'package:analyzer_plugin/protocol/protocol_common.dart';
 import 'package:test_reflective_loader/test_reflective_loader.dart';
 
diff --git a/pkg/analysis_server/test/services/completion/dart/relevance/instance_member_test.dart b/pkg/analysis_server/test/services/completion/dart/relevance/instance_member_test.dart
index 5faa5df..de08d73 100644
--- a/pkg/analysis_server/test/services/completion/dart/relevance/instance_member_test.dart
+++ b/pkg/analysis_server/test/services/completion/dart/relevance/instance_member_test.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.9
-
 import 'package:test_reflective_loader/test_reflective_loader.dart';
 
 import 'completion_relevance.dart';
diff --git a/pkg/analysis_server/test/services/completion/dart/relevance/is_no_such_method_test.dart b/pkg/analysis_server/test/services/completion/dart/relevance/is_no_such_method_test.dart
index 52327e6..388a377 100644
--- a/pkg/analysis_server/test/services/completion/dart/relevance/is_no_such_method_test.dart
+++ b/pkg/analysis_server/test/services/completion/dart/relevance/is_no_such_method_test.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.9
-
 import 'package:analyzer_plugin/protocol/protocol_common.dart';
 import 'package:test_reflective_loader/test_reflective_loader.dart';
 
diff --git a/pkg/analysis_server/test/services/completion/dart/relevance/local_variable_test.dart b/pkg/analysis_server/test/services/completion/dart/relevance/local_variable_test.dart
index 284020f..c1481fb 100644
--- a/pkg/analysis_server/test/services/completion/dart/relevance/local_variable_test.dart
+++ b/pkg/analysis_server/test/services/completion/dart/relevance/local_variable_test.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.9
-
 import 'package:analyzer_plugin/protocol/protocol_common.dart';
 import 'package:test_reflective_loader/test_reflective_loader.dart';
 
diff --git a/pkg/analysis_server/test/services/completion/dart/relevance/named_argument_test.dart b/pkg/analysis_server/test/services/completion/dart/relevance/named_argument_test.dart
index b9c200d..ff02ed2 100644
--- a/pkg/analysis_server/test/services/completion/dart/relevance/named_argument_test.dart
+++ b/pkg/analysis_server/test/services/completion/dart/relevance/named_argument_test.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.9
-
 import 'package:test_reflective_loader/test_reflective_loader.dart';
 
 import '../../../../src/utilities/mock_packages.dart';
diff --git a/pkg/analysis_server/test/services/completion/dart/relevance/non_type_member_test.dart b/pkg/analysis_server/test/services/completion/dart/relevance/non_type_member_test.dart
index 27f3789..084c91c 100644
--- a/pkg/analysis_server/test/services/completion/dart/relevance/non_type_member_test.dart
+++ b/pkg/analysis_server/test/services/completion/dart/relevance/non_type_member_test.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.9
-
 import 'package:analyzer_plugin/protocol/protocol_common.dart';
 import 'package:test_reflective_loader/test_reflective_loader.dart';
 
diff --git a/pkg/analysis_server/test/services/completion/dart/relevance/static_member_test.dart b/pkg/analysis_server/test/services/completion/dart/relevance/static_member_test.dart
index 7042169..314b1e0 100644
--- a/pkg/analysis_server/test/services/completion/dart/relevance/static_member_test.dart
+++ b/pkg/analysis_server/test/services/completion/dart/relevance/static_member_test.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.9
-
 import 'package:test_reflective_loader/test_reflective_loader.dart';
 
 import 'completion_relevance.dart';
diff --git a/pkg/analysis_server/test/services/completion/dart/relevance/test_all.dart b/pkg/analysis_server/test/services/completion/dart/relevance/test_all.dart
index d6bf383..d6679e5 100644
--- a/pkg/analysis_server/test/services/completion/dart/relevance/test_all.dart
+++ b/pkg/analysis_server/test/services/completion/dart/relevance/test_all.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.9
-
 import 'package:test_reflective_loader/test_reflective_loader.dart';
 
 import 'bool_assignment_test.dart' as bool_assignments;
diff --git a/pkg/analysis_server/test/services/completion/dart/test_all.dart b/pkg/analysis_server/test/services/completion/dart/test_all.dart
index 7e3c13c..c8ccce6 100644
--- a/pkg/analysis_server/test/services/completion/dart/test_all.dart
+++ b/pkg/analysis_server/test/services/completion/dart/test_all.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.9
-
 import 'package:test_reflective_loader/test_reflective_loader.dart';
 
 import 'arglist_contributor_test.dart' as arglist_test;
diff --git a/pkg/analysis_server/test/services/completion/test_all.dart b/pkg/analysis_server/test/services/completion/test_all.dart
index 4aaa784..533fb7a 100644
--- a/pkg/analysis_server/test/services/completion/test_all.dart
+++ b/pkg/analysis_server/test/services/completion/test_all.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.9
-
 import 'package:test_reflective_loader/test_reflective_loader.dart';
 
 import 'dart/test_all.dart' as dart_all;
diff --git a/pkg/analysis_server/test/services/correction/sort_members_test.dart b/pkg/analysis_server/test/services/correction/sort_members_test.dart
index 88cc25d..a766800 100644
--- a/pkg/analysis_server/test/services/correction/sort_members_test.dart
+++ b/pkg/analysis_server/test/services/correction/sort_members_test.dart
@@ -3,6 +3,7 @@
 // BSD-style license that can be found in the LICENSE file.
 
 import 'package:analysis_server/src/services/correction/sort_members.dart';
+import 'package:analyzer/dart/analysis/results.dart';
 import 'package:analyzer_plugin/protocol/protocol_common.dart';
 import 'package:test/test.dart';
 import 'package:test_reflective_loader/test_reflective_loader.dart';
@@ -924,7 +925,7 @@
 
   Future<void> _parseTestUnit(String code) async {
     addTestSource(code);
-    var result = session.getParsedUnit(testFile);
+    var result = session.getParsedUnit2(testFile) as ParsedUnitResult;
     testUnit = result.unit;
   }
 }
diff --git a/pkg/analysis_server/test/services/test_all.dart b/pkg/analysis_server/test/services/test_all.dart
index 85f29c1..954023d 100644
--- a/pkg/analysis_server/test/services/test_all.dart
+++ b/pkg/analysis_server/test/services/test_all.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.9
-
 import 'package:test_reflective_loader/test_reflective_loader.dart';
 
 import 'completion/test_all.dart' as completion_all;
diff --git a/pkg/analysis_server/test/src/computer/imported_elements_computer_test.dart b/pkg/analysis_server/test/src/computer/imported_elements_computer_test.dart
index 7057898..2cd24c1 100644
--- a/pkg/analysis_server/test/src/computer/imported_elements_computer_test.dart
+++ b/pkg/analysis_server/test/src/computer/imported_elements_computer_test.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.9
-
 import 'package:analysis_server/protocol/protocol_generated.dart';
 import 'package:analysis_server/src/computer/imported_elements_computer.dart';
 import 'package:analyzer/dart/analysis/results.dart';
@@ -21,9 +19,9 @@
 
 @reflectiveTest
 class ImportedElementsComputerTest extends AbstractContextTest {
-  String sourcePath;
+  late String sourcePath;
 
-  List<ImportedElements> importedElements;
+  late List<ImportedElements> importedElements;
 
   void assertElements(List<ImportedElements> expectedElementsList) {
     expect(importedElements, hasLength(expectedElementsList.length));
@@ -475,7 +473,7 @@
     var result =
         await session.getResolvedUnit2(sourcePath) as ResolvedUnitResult;
     var computer = ImportedElementsComputer(
-        result.unit, content.indexOf(selection), selection.length);
+        result.unit!, content.indexOf(selection), selection.length);
     importedElements = computer.compute();
   }
 }
diff --git a/pkg/analysis_server/test/src/computer/test_all.dart b/pkg/analysis_server/test/src/computer/test_all.dart
index a1243b2..1a04173 100644
--- a/pkg/analysis_server/test/src/computer/test_all.dart
+++ b/pkg/analysis_server/test/src/computer/test_all.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.9
-
 import 'package:test_reflective_loader/test_reflective_loader.dart';
 
 import 'closing_labels_computer_test.dart' as closing_labels_computer;
diff --git a/pkg/analysis_server/test/src/domain_abstract_test.dart b/pkg/analysis_server/test/src/domain_abstract_test.dart
index 73c72eb..36ca0d3 100644
--- a/pkg/analysis_server/test/src/domain_abstract_test.dart
+++ b/pkg/analysis_server/test/src/domain_abstract_test.dart
@@ -2,17 +2,17 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.9
-
 import 'package:analysis_server/src/domain_abstract.dart';
 import 'package:analysis_server/src/plugin/plugin_manager.dart';
 import 'package:analysis_server/src/protocol_server.dart' hide Element;
+import 'package:analyzer/instrumentation/service.dart';
 import 'package:analyzer_plugin/protocol/protocol.dart' as plugin;
 import 'package:analyzer_plugin/protocol/protocol_generated.dart' as plugin;
 import 'package:test/test.dart';
 import 'package:test_reflective_loader/test_reflective_loader.dart';
 
 import '../analysis_abstract.dart';
+import 'plugin/plugin_manager_test.dart';
 
 void main() {
   defineReflectiveSuite(() {
@@ -38,8 +38,8 @@
 
   Future<void> test_waitForResponses_nonEmpty_noTimeout_immediate() async {
     AbstractRequestHandler handler = TestAbstractRequestHandler(server);
-    PluginInfo plugin1 = DiscoveredPluginInfo('p1', '', '', null, null);
-    PluginInfo plugin2 = DiscoveredPluginInfo('p2', '', '', null, null);
+    var plugin1 = _pluginInfo('p1');
+    var plugin2 = _pluginInfo('p2');
     var response1 = plugin.Response('1', 1);
     var response2 = plugin.Response('2', 2);
     var futures = <PluginInfo, Future<plugin.Response>>{
@@ -52,8 +52,8 @@
 
   Future<void> test_waitForResponses_nonEmpty_noTimeout_withError() async {
     AbstractRequestHandler handler = TestAbstractRequestHandler(server);
-    PluginInfo plugin1 = DiscoveredPluginInfo('p1', '', '', null, null);
-    PluginInfo plugin2 = DiscoveredPluginInfo('p2', '', '', null, null);
+    var plugin1 = _pluginInfo('p1');
+    var plugin2 = _pluginInfo('p2');
     var response1 = plugin.Response('1', 1);
     var response2 = plugin.Response('2', 2,
         error: plugin.RequestError(
@@ -68,9 +68,9 @@
 
   Future<void> test_waitForResponses_nonEmpty_timeout_someDelayed() async {
     AbstractRequestHandler handler = TestAbstractRequestHandler(server);
-    PluginInfo plugin1 = DiscoveredPluginInfo('p1', '', '', null, null);
-    PluginInfo plugin2 = DiscoveredPluginInfo('p2', '', '', null, null);
-    PluginInfo plugin3 = DiscoveredPluginInfo('p3', '', '', null, null);
+    var plugin1 = _pluginInfo('p1');
+    var plugin2 = _pluginInfo('p2');
+    var plugin3 = _pluginInfo('p3');
     var response1 = plugin.Response('1', 1);
     var response2 = plugin.Response('2', 2);
     var response3 = plugin.Response('3', 3);
@@ -82,6 +82,11 @@
     var responses = await handler.waitForResponses(futures, timeout: 50);
     expect(responses, unorderedEquals([response2]));
   }
+
+  PluginInfo _pluginInfo(String path) {
+    return DiscoveredPluginInfo(path, '', '', TestNotificationManager(),
+        InstrumentationService.NULL_SERVICE);
+  }
 }
 
 class TestAbstractRequestHandler extends AbstractRequestHandler {
diff --git a/pkg/analysis_server/test/src/domains/completion/available_suggestion_sets_test.dart b/pkg/analysis_server/test/src/domains/completion/available_suggestion_sets_test.dart
index 32f0198..68ef83c 100644
--- a/pkg/analysis_server/test/src/domains/completion/available_suggestion_sets_test.dart
+++ b/pkg/analysis_server/test/src/domains/completion/available_suggestion_sets_test.dart
@@ -2,9 +2,8 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.9
-
 import 'package:analysis_server/src/protocol_server.dart';
+import 'package:collection/collection.dart';
 import 'package:test/test.dart';
 import 'package:test_reflective_loader/test_reflective_loader.dart';
 
@@ -471,16 +470,15 @@
   }
 
   static void assertNoSuggestion(AvailableSuggestionSet set, String label,
-      {ElementKind kind}) {
-    var suggestion = set.items.singleWhere(
-        (s) => s.label == label && (kind == null || s.element.kind == kind),
-        orElse: () => null);
+      {ElementKind? kind}) {
+    var suggestion = set.items.singleWhereOrNull(
+        (s) => s.label == label && (kind == null || s.element.kind == kind));
     expect(suggestion, null);
   }
 
   static AvailableSuggestion _getSuggestion(
       AvailableSuggestionSet set, String label,
-      {ElementKind kind}) {
+      {ElementKind? kind}) {
     return set.items.singleWhere(
         (s) => s.label == label && (kind == null || s.element.kind == kind));
   }
diff --git a/pkg/analysis_server/test/src/domains/completion/available_suggestions_base.dart b/pkg/analysis_server/test/src/domains/completion/available_suggestions_base.dart
index 76e3d5c..d9417a4 100644
--- a/pkg/analysis_server/test/src/domains/completion/available_suggestions_base.dart
+++ b/pkg/analysis_server/test/src/domains/completion/available_suggestions_base.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.9
-
 import 'dart:convert';
 
 import 'package:analysis_server/protocol/protocol_constants.dart';
@@ -45,11 +43,11 @@
       var params = CompletionAvailableSuggestionsParams.fromNotification(
         notification,
       );
-      for (var set in params.changedLibraries) {
+      for (var set in params.changedLibraries!) {
         idToSetMap[set.id] = set;
         uriToSetMap[set.uri] = set;
       }
-      for (var id in params.removedLibraries) {
+      for (var id in params.removedLibraries!) {
         var set = idToSetMap.remove(id);
         uriToSetMap.remove(set?.uri);
       }
@@ -69,9 +67,7 @@
   /// Remove the set with the given [uri].
   /// The set must be already received.
   void removeSet(String uri) {
-    var set = uriToSetMap.remove(uri);
-    expect(set, isNotNull);
-
+    var set = uriToSetMap.remove(uri)!;
     idToSetMap.remove(set.id);
   }
 
diff --git a/pkg/analysis_server/test/src/domains/completion/get_suggestion_details_test.dart b/pkg/analysis_server/test/src/domains/completion/get_suggestion_details_test.dart
index 9b4d38a..9009034 100644
--- a/pkg/analysis_server/test/src/domains/completion/get_suggestion_details_test.dart
+++ b/pkg/analysis_server/test/src/domains/completion/get_suggestion_details_test.dart
@@ -2,10 +2,7 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.9
-
 import 'package:analysis_server/src/protocol_server.dart';
-import 'package:meta/meta.dart';
 import 'package:test/test.dart';
 import 'package:test_reflective_loader/test_reflective_loader.dart';
 
@@ -39,7 +36,7 @@
     );
 
     expect(result.completion, 'MyEnum.aaa');
-    _assertTestFileChange(result.change, r'''
+    _assertTestFileChange(result.change!, r'''
 import 'package:test/a.dart';
 
 main() {} // ref
@@ -63,7 +60,7 @@
     );
 
     expect(result.completion, 'sin');
-    _assertEmptyChange(result.change);
+    _assertEmptyChange(result.change!);
   }
 
   Future<void> test_existingImport_prefixed() async {
@@ -83,7 +80,7 @@
     );
 
     expect(result.completion, 'math.sin');
-    _assertEmptyChange(result.change);
+    _assertEmptyChange(result.change!);
   }
 
   Future<void> test_invalid_library() async {
@@ -92,7 +89,7 @@
     var response = await waitResponse(
       _buildRequest(id: -1, label: 'foo', offset: 0),
     );
-    expect(response.error.code, RequestErrorCode.INVALID_PARAMETER);
+    expect(response.error!.code, RequestErrorCode.INVALID_PARAMETER);
   }
 
   Future<void> test_newImport() async {
@@ -110,7 +107,7 @@
     );
 
     expect(result.completion, 'sin');
-    _assertTestFileChange(result.change, r'''
+    _assertTestFileChange(result.change!, r'''
 import 'dart:math';
 
 main() {} // ref
@@ -139,7 +136,7 @@
     );
 
     expect(result.completion, 'sin');
-    _assertTestFileChange(result.change, r'''
+    _assertTestFileChange(result.change!, r'''
 library foo;
 
 import 'dart:math';
@@ -173,7 +170,7 @@
     );
 
     expect(result.completion, 'sin');
-    _assertTestFileChange(result.change, r'''
+    _assertTestFileChange(result.change!, r'''
 @myAnnotation
 
 import 'dart:math';
@@ -205,7 +202,7 @@
     );
 
     expect(result.completion, 'sin');
-    _assertTestFileChange(result.change, r'''
+    _assertTestFileChange(result.change!, r'''
 import 'dart:async';
 import 'dart:math';
 @myAnnotation
@@ -237,7 +234,7 @@
     );
 
     expect(result.completion, 'sin');
-    _assertTestFileChange(result.change, r'''
+    _assertTestFileChange(result.change!, r'''
 import 'dart:math';
 
 part 'a.dart';
@@ -260,10 +257,10 @@
   }
 
   Request _buildRequest({
-    String file,
-    @required int id,
-    @required String label,
-    @required int offset,
+    String? file,
+    required int id,
+    required String label,
+    required int offset,
   }) {
     return CompletionGetSuggestionDetailsParams(
       file ?? testFile,
diff --git a/pkg/analysis_server/test/src/domains/completion/get_suggestions_available_test.dart b/pkg/analysis_server/test/src/domains/completion/get_suggestions_available_test.dart
index 9ec1326..195678c 100644
--- a/pkg/analysis_server/test/src/domains/completion/get_suggestions_available_test.dart
+++ b/pkg/analysis_server/test/src/domains/completion/get_suggestions_available_test.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.9
-
 import 'package:analysis_server/src/protocol_server.dart';
 import 'package:test/test.dart';
 import 'package:test_reflective_loader/test_reflective_loader.dart';
@@ -36,8 +34,7 @@
   }
 
   void _assertHasImport(String exportingUri, String declaringUri, String name) {
-    var existingImports = fileToExistingImports[testFile];
-    expect(existingImports, isNotNull);
+    var existingImports = fileToExistingImports[testFile]!;
 
     var existingImport = existingImports.imports.singleWhere((import) =>
         existingImports.elements.strings[import.uri] == exportingUri);
@@ -64,7 +61,7 @@
     var results = await _getSuggestions(testFile, 0);
     expect(results.includedElementKinds, isNotEmpty);
 
-    var includedIdSet = results.includedSuggestionSets.map((set) => set.id);
+    var includedIdSet = results.includedSuggestionSets!.map((set) => set.id);
     expect(includedIdSet, contains(mathSet.id));
     expect(includedIdSet, contains(asyncSet.id));
   }
@@ -107,7 +104,7 @@
       unorderedEquals([ElementKind.CONSTRUCTOR]),
     );
 
-    var includedIdSet = results.includedSuggestionSets.map((set) => set.id);
+    var includedIdSet = results.includedSuggestionSets!.map((set) => set.id);
     expect(includedIdSet, contains(mathSet.id));
     expect(includedIdSet, contains(asyncSet.id));
   }
@@ -140,7 +137,7 @@
     var results = await _getSuggestions(testPath, 0);
 
     expect(
-      results.includedSuggestionSets.singleWhere((set) {
+      results.includedSuggestionSets!.singleWhere((set) {
         return set.id == aSet.id;
       }).displayUri,
       '../a.dart',
@@ -156,7 +153,7 @@
 
     var results = await _getSuggestions(testPath, 0);
     expect(
-      results.includedSuggestionSets.singleWhere((set) {
+      results.includedSuggestionSets!.singleWhere((set) {
         return set.id == aSet.id;
       }).displayUri,
       isNull,
@@ -242,7 +239,7 @@
       testCode.indexOf('); // ref'),
     );
 
-    var includedTags = results.includedSuggestionRelevanceTags;
+    var includedTags = results.includedSuggestionRelevanceTags!;
     int findBoost(String tag) {
       for (var includedTag in includedTags) {
         if (includedTag.tag == tag) {
@@ -276,7 +273,7 @@
       testCode.indexOf(' // ref'),
     );
 
-    assertJsonText(results.includedSuggestionRelevanceTags, r'''
+    assertJsonText(results.includedSuggestionRelevanceTags!, r'''
 [
   {
     "tag": "ElementKind.PREFIX",
@@ -340,7 +337,7 @@
       testCode.indexOf('); // ref'),
     );
 
-    assertJsonText(results.includedSuggestionRelevanceTags, r'''
+    assertJsonText(results.includedSuggestionRelevanceTags!, r'''
 [
   {
     "tag": "ElementKind.PREFIX",
@@ -404,7 +401,7 @@
       testCode.indexOf('); // ref'),
     );
 
-    assertJsonText(results.includedSuggestionRelevanceTags, r'''
+    assertJsonText(results.includedSuggestionRelevanceTags!, r'''
 [
   {
     "tag": "ElementKind.MIXIN",
@@ -475,7 +472,7 @@
       testCode.indexOf(' // ref'),
     );
 
-    assertJsonText(results.includedSuggestionRelevanceTags, r'''
+    assertJsonText(results.includedSuggestionRelevanceTags!, r'''
 [
   {
     "tag": "ElementKind.PREFIX",
@@ -535,7 +532,7 @@
       testCode.indexOf(' // ref'),
     );
 
-    assertJsonText(results.includedSuggestionRelevanceTags, r'''
+    assertJsonText(results.includedSuggestionRelevanceTags!, r'''
 [
   {
     "tag": "ElementKind.MIXIN",
@@ -605,7 +602,7 @@
       testCode.indexOf(']; // ref'),
     );
 
-    assertJsonText(results.includedSuggestionRelevanceTags, r'''
+    assertJsonText(results.includedSuggestionRelevanceTags!, r'''
 [
   {
     "tag": "dart:core::int",
diff --git a/pkg/analysis_server/test/src/domains/completion/test_all.dart b/pkg/analysis_server/test/src/domains/completion/test_all.dart
index dc4bd6b..1452e21 100644
--- a/pkg/analysis_server/test/src/domains/completion/test_all.dart
+++ b/pkg/analysis_server/test/src/domains/completion/test_all.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.9
-
 import 'package:test_reflective_loader/test_reflective_loader.dart';
 
 import 'available_suggestion_sets_test.dart' as available_suggestion_sets;
diff --git a/pkg/analysis_server/test/src/domains/flutter/base.dart b/pkg/analysis_server/test/src/domains/flutter/base.dart
index 88d9c9d..2cadf8b 100644
--- a/pkg/analysis_server/test/src/domains/flutter/base.dart
+++ b/pkg/analysis_server/test/src/domains/flutter/base.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.9
-
 import 'package:analysis_server/src/flutter/flutter_domain.dart';
 import 'package:analysis_server/src/protocol_server.dart';
 import 'package:test/test.dart';
diff --git a/pkg/analysis_server/test/src/domains/flutter/get_widget_description_test.dart b/pkg/analysis_server/test/src/domains/flutter/get_widget_description_test.dart
index fe6b73a..39baacd 100644
--- a/pkg/analysis_server/test/src/domains/flutter/get_widget_description_test.dart
+++ b/pkg/analysis_server/test/src/domains/flutter/get_widget_description_test.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.9
-
 import 'package:analysis_server/src/protocol_server.dart';
 import 'package:test/test.dart';
 import 'package:test_reflective_loader/test_reflective_loader.dart';
@@ -34,7 +32,7 @@
     expect(property.expression, "'aaa'");
     expect(property.isRequired, isTrue);
     expect(property.editor, isNotNull);
-    expect(property.value.stringValue, 'aaa');
+    expect(property.value!.stringValue, 'aaa');
   }
 
   Future<void> test_notInstanceCreation() async {
@@ -46,7 +44,7 @@
 
     var response = await getWidgetDescriptionResponse('42');
     expect(
-      response.error.code,
+      response.error!.code,
       RequestErrorCode.FLUTTER_GET_WIDGET_DESCRIPTION_NO_WIDGET,
     );
   }
@@ -60,7 +58,7 @@
 
     var response = await getWidgetDescriptionResponse('new Foo');
     expect(
-      response.error.code,
+      response.error!.code,
       RequestErrorCode.FLUTTER_GET_WIDGET_DESCRIPTION_NO_WIDGET,
     );
   }
diff --git a/pkg/analysis_server/test/src/domains/flutter/set_property_value_test.dart b/pkg/analysis_server/test/src/domains/flutter/set_property_value_test.dart
index 10c2eb9..56a8c90 100644
--- a/pkg/analysis_server/test/src/domains/flutter/set_property_value_test.dart
+++ b/pkg/analysis_server/test/src/domains/flutter/set_property_value_test.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.9
-
 import 'package:analysis_server/src/protocol_server.dart';
 import 'package:test/test.dart';
 import 'package:test_reflective_loader/test_reflective_loader.dart';
@@ -135,7 +133,7 @@
 
   Future<FlutterSetWidgetPropertyValueResult> _setValue(
     FlutterWidgetProperty property,
-    FlutterWidgetPropertyValue value,
+    FlutterWidgetPropertyValue? value,
   ) async {
     var response = await _setValueResponse(property, value);
     expect(response.error, isNull);
@@ -144,7 +142,7 @@
 
   Future<Response> _setValueResponse(
     FlutterWidgetProperty property,
-    FlutterWidgetPropertyValue value,
+    FlutterWidgetPropertyValue? value,
   ) async {
     var request = FlutterSetWidgetPropertyValueParams(
       property.id,
diff --git a/pkg/analysis_server/test/src/domains/flutter/test_all.dart b/pkg/analysis_server/test/src/domains/flutter/test_all.dart
index 97e2c81..2030531 100644
--- a/pkg/analysis_server/test/src/domains/flutter/test_all.dart
+++ b/pkg/analysis_server/test/src/domains/flutter/test_all.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.9
-
 import 'package:test_reflective_loader/test_reflective_loader.dart';
 
 import 'get_widget_description_test.dart' as get_widget_description;
diff --git a/pkg/analysis_server/test/src/domains/test_all.dart b/pkg/analysis_server/test/src/domains/test_all.dart
index dc9a595..dac4cfe 100644
--- a/pkg/analysis_server/test/src/domains/test_all.dart
+++ b/pkg/analysis_server/test/src/domains/test_all.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.9
-
 import 'package:test_reflective_loader/test_reflective_loader.dart';
 
 import 'completion/test_all.dart' as completion;
diff --git a/pkg/analysis_server/test/src/flutter/flutter_outline_notification_test.dart b/pkg/analysis_server/test/src/flutter/flutter_outline_notification_test.dart
index 7096a77..6d57e25 100644
--- a/pkg/analysis_server/test/src/flutter/flutter_outline_notification_test.dart
+++ b/pkg/analysis_server/test/src/flutter/flutter_outline_notification_test.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.9
-
 import 'dart:async';
 
 import 'package:analysis_server/protocol/protocol.dart';
@@ -25,15 +23,16 @@
 
 @reflectiveTest
 class FlutterNotificationOutlineTest extends AbstractAnalysisTest {
-  Folder flutterFolder;
+  late Folder flutterFolder;
 
   final Map<FlutterService, List<String>> flutterSubscriptions = {};
 
   final Completer<void> _outlineReceived = Completer();
-  FlutterOutline outline;
+  late FlutterOutline outline;
 
   FlutterDomainHandler get flutterHandler =>
-      server.handlers.singleWhere((handler) => handler is FlutterDomainHandler);
+      server.handlers.singleWhere((handler) => handler is FlutterDomainHandler)
+          as FlutterDomainHandler;
 
   void addFlutterSubscription(FlutterService service, String file) {
     // add file to subscription
@@ -97,25 +96,25 @@
     await prepareOutline();
     var unitOutline = outline;
 
-    var myWidgetOutline = unitOutline.children[0];
+    var myWidgetOutline = unitOutline.children![0];
     expect(myWidgetOutline.kind, FlutterOutlineKind.DART_ELEMENT);
-    expect(myWidgetOutline.dartElement.name, 'MyWidget');
+    expect(myWidgetOutline.dartElement!.name, 'MyWidget');
 
-    var buildOutline = myWidgetOutline.children[0];
+    var buildOutline = myWidgetOutline.children![0];
     expect(buildOutline.kind, FlutterOutlineKind.DART_ELEMENT);
-    expect(buildOutline.dartElement.name, 'build');
+    expect(buildOutline.dartElement!.name, 'build');
 
-    var columnOutline = buildOutline.children[0];
+    var columnOutline = buildOutline.children![0];
     expect(columnOutline.kind, FlutterOutlineKind.NEW_INSTANCE);
     expect(columnOutline.className, 'Column');
     expect(columnOutline.children, hasLength(2));
 
-    var textOutlineA = columnOutline.children[0];
+    var textOutlineA = columnOutline.children![0];
     expect(textOutlineA.kind, FlutterOutlineKind.NEW_INSTANCE);
     expect(textOutlineA.className, 'Text');
     expect(textOutlineA.offset, code.indexOf("const Text('aaa')"));
 
-    var textOutlineB = columnOutline.children[1];
+    var textOutlineB = columnOutline.children![1];
     expect(textOutlineB.kind, FlutterOutlineKind.NEW_INSTANCE);
     expect(textOutlineB.className, 'Text');
     expect(textOutlineB.offset, code.indexOf("const Text('bbb')"));
diff --git a/pkg/analysis_server/test/src/flutter/test_all.dart b/pkg/analysis_server/test/src/flutter/test_all.dart
index 54e575a..48db007 100644
--- a/pkg/analysis_server/test/src/flutter/test_all.dart
+++ b/pkg/analysis_server/test/src/flutter/test_all.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.9
-
 import 'package:test_reflective_loader/test_reflective_loader.dart';
 
 import 'flutter_outline_computer_test.dart' as outline_computer;
diff --git a/pkg/analysis_server/test/src/services/completion/dart/completion_test.dart b/pkg/analysis_server/test/src/services/completion/dart/completion_test.dart
index c9c355e..004e07b 100644
--- a/pkg/analysis_server/test/src/services/completion/dart/completion_test.dart
+++ b/pkg/analysis_server/test/src/services/completion/dart/completion_test.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.9
-
 import 'package:analysis_server/src/protocol_server.dart';
 import 'package:test_reflective_loader/test_reflective_loader.dart';
 
diff --git a/pkg/analysis_server/test/src/services/completion/dart/test_all.dart b/pkg/analysis_server/test/src/services/completion/dart/test_all.dart
index 06a051a..ab0ad81 100644
--- a/pkg/analysis_server/test/src/services/completion/dart/test_all.dart
+++ b/pkg/analysis_server/test/src/services/completion/dart/test_all.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.9
-
 import 'package:test_reflective_loader/test_reflective_loader.dart';
 
 import 'completion_test.dart' as completion;
diff --git a/pkg/analysis_server/test/src/services/completion/test_all.dart b/pkg/analysis_server/test/src/services/completion/test_all.dart
index 75303aa..19d31b3 100644
--- a/pkg/analysis_server/test/src/services/completion/test_all.dart
+++ b/pkg/analysis_server/test/src/services/completion/test_all.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.9
-
 import 'package:test_reflective_loader/test_reflective_loader.dart';
 
 import 'dart/test_all.dart' as dart;
diff --git a/pkg/analysis_server/test/src/services/correction/fix/data_driven/test_all.dart b/pkg/analysis_server/test/src/services/correction/fix/data_driven/test_all.dart
index f393c9b..a21ba3c 100644
--- a/pkg/analysis_server/test/src/services/correction/fix/data_driven/test_all.dart
+++ b/pkg/analysis_server/test/src/services/correction/fix/data_driven/test_all.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.9
-
 import 'package:test_reflective_loader/test_reflective_loader.dart';
 
 import 'add_type_parameter_test.dart' as add_type_parameter;
diff --git a/pkg/analysis_server/test/src/services/correction/fix/data_driven/transform_set_manager_test.dart b/pkg/analysis_server/test/src/services/correction/fix/data_driven/transform_set_manager_test.dart
index 60665b9..d182ab1 100644
--- a/pkg/analysis_server/test/src/services/correction/fix/data_driven/transform_set_manager_test.dart
+++ b/pkg/analysis_server/test/src/services/correction/fix/data_driven/transform_set_manager_test.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.9
-
 import 'package:analysis_server/src/services/correction/fix/data_driven/transform_set_manager.dart';
 import 'package:analyzer/dart/analysis/results.dart';
 import 'package:analyzer/dart/analysis/session.dart';
@@ -38,7 +36,7 @@
     var testFile = convertPath('/home/test/lib/test.dart');
     addSource(testFile, '');
     var result = await session.getResolvedLibraryValid(testFile);
-    var sets = manager.forLibrary(result.element);
+    var sets = manager.forLibrary(result.element!);
     expect(sets, hasLength(2));
   }
 
@@ -49,7 +47,7 @@
     var testFile = convertPath('/home/test/lib/test.dart');
     addSource(testFile, '');
     var result = await session.getResolvedLibraryValid(testFile);
-    var sets = manager.forLibrary(result.element);
+    var sets = manager.forLibrary(result.element!);
     expect(sets, hasLength(0));
   }
 
diff --git a/pkg/analysis_server/test/src/services/correction/fix/test_all.dart b/pkg/analysis_server/test/src/services/correction/fix/test_all.dart
index 8d78b42..570d7a8 100644
--- a/pkg/analysis_server/test/src/services/correction/fix/test_all.dart
+++ b/pkg/analysis_server/test/src/services/correction/fix/test_all.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.9
-
 import 'package:test_reflective_loader/test_reflective_loader.dart';
 
 import 'add_async_test.dart' as add_async;
diff --git a/pkg/analysis_server/test/src/services/correction/test_all.dart b/pkg/analysis_server/test/src/services/correction/test_all.dart
index 96c3fa6..abc5ddb 100644
--- a/pkg/analysis_server/test/src/services/correction/test_all.dart
+++ b/pkg/analysis_server/test/src/services/correction/test_all.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.9
-
 import 'package:test_reflective_loader/test_reflective_loader.dart';
 
 import 'assist/test_all.dart' as assist_all;
diff --git a/pkg/analysis_server/test/src/services/test_all.dart b/pkg/analysis_server/test/src/services/test_all.dart
index 2c3be26..e5d8aa0 100644
--- a/pkg/analysis_server/test/src/services/test_all.dart
+++ b/pkg/analysis_server/test/src/services/test_all.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.9
-
 import 'package:test_reflective_loader/test_reflective_loader.dart';
 
 import 'completion/test_all.dart' as completion;
diff --git a/pkg/analysis_server/test/src/test_all.dart b/pkg/analysis_server/test/src/test_all.dart
index ce38f77..0cb76aa 100644
--- a/pkg/analysis_server/test/src/test_all.dart
+++ b/pkg/analysis_server/test/src/test_all.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.9
-
 import 'package:test_reflective_loader/test_reflective_loader.dart';
 
 import 'cider/test_all.dart' as cider;
diff --git a/pkg/analysis_server/test/verify_sorted_test.dart b/pkg/analysis_server/test/verify_sorted_test.dart
index dff52dd..9cf62ed 100644
--- a/pkg/analysis_server/test/verify_sorted_test.dart
+++ b/pkg/analysis_server/test/verify_sorted_test.dart
@@ -134,8 +134,8 @@
       }
       var relativePath = pathContext.relative(path, from: testDirPath);
       test(relativePath, () {
-        var result = session.getParsedUnit(path);
-        if (result.state != ResultState.VALID) {
+        var result = session.getParsedUnit2(path);
+        if (result is! ParsedUnitResult) {
           fail('Could not parse $path');
         }
         var code = result.content;
diff --git a/pkg/analysis_server/tool/migration_runner.dart b/pkg/analysis_server/tool/migration_runner.dart
index 355040f..ec9b6a2 100644
--- a/pkg/analysis_server/tool/migration_runner.dart
+++ b/pkg/analysis_server/tool/migration_runner.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.9
-
 /// This executable provides the ability to run the migration tool in process
 /// on a single package.  It should be invoked with two command-line arguments:
 /// a path to a configuration file and the name of a package to migrate.
@@ -54,18 +52,14 @@
   migrationTest.setUp();
   print('Migrating');
   await migrationTest.run(packageRoot, port);
-  if (port == null) {
-    print('Done');
-    io.exit(0);
-  } else {
-    print('Done.  Please point your browser to localhost:$port/\$filePath');
-  }
+  migrationTest.tearDown();
+  print('Done.  Please point your browser to localhost:$port/\$filePath');
 }
 
 class MigrationBase {
   ResourceProvider resourceProvider = PhysicalResourceProvider.INSTANCE;
-  MockServerChannel serverChannel;
-  AnalysisServer server;
+  late MockServerChannel serverChannel;
+  late AnalysisServer server;
 
   AnalysisServer createAnalysisServer() {
     //
@@ -114,8 +108,6 @@
 
   void tearDown() {
     server.done();
-    server = null;
-    serverChannel = null;
   }
 
   /// Returns a [Future] that completes when the server's analysis is complete.
@@ -157,11 +149,11 @@
   Map<String, String> get externalPackages =>
       ((testInfoJson['external_packages'] ?? {}) as Map).cast<String, String>();
 
-  String get outputRoot => testInfoJson['output_root'];
+  String get outputRoot => testInfoJson['output_root'] as String;
 
-  int get port => testInfoJson['port'];
+  int get port => testInfoJson['port'] as int;
 
-  String get sdkRoot => testInfoJson['sdk_root'];
+  String get sdkRoot => testInfoJson['sdk_root'] as String;
 
   String packageRoot(String packageName) {
     if (thirdPartyPackages.contains(packageName)) {
@@ -169,7 +161,7 @@
     } else if (builtInPackages.contains(packageName)) {
       return path.join(sdkRoot, 'pkg', packageName);
     } else if (externalPackages.containsKey(packageName)) {
-      return externalPackages[packageName];
+      return externalPackages[packageName] as String;
     } else {
       throw StateError('Unrecognized package $packageName');
     }
diff --git a/pkg/analysis_server_client/test/verify_sorted_test.dart b/pkg/analysis_server_client/test/verify_sorted_test.dart
index 5a19d51..dfa4c4a 100644
--- a/pkg/analysis_server_client/test/verify_sorted_test.dart
+++ b/pkg/analysis_server_client/test/verify_sorted_test.dart
@@ -55,8 +55,8 @@
       }
       var relativePath = pathContext.relative(path, from: testDirPath);
       test(relativePath, () {
-        var result = session.getParsedUnit(path);
-        if (result.state != ResultState.VALID) {
+        var result = session.getParsedUnit2(path);
+        if (result is! ParsedUnitResult) {
           fail('Could not parse $path');
         }
         var code = result.content;
diff --git a/pkg/analyzer/CHANGELOG.md b/pkg/analyzer/CHANGELOG.md
index 398e956..13fe6b3 100644
--- a/pkg/analyzer/CHANGELOG.md
+++ b/pkg/analyzer/CHANGELOG.md
@@ -11,6 +11,12 @@
   Use `AnalysisSession.getLibraryByUri2()` instead.
 * Deprecated `AnalysisSession.getErrors()`.
   Use `AnalysisSession.getErrors2()` instead.
+* Deprecated `AnalysisSession.getParsedLibrary()`.
+  Use `AnalysisSession.getParsedLibrary2()` instead.
+* Deprecated `AnalysisSession.getParsedLibraryByElement()`.
+  Use `AnalysisSession.getParsedLibraryByElement2()` instead.
+* Deprecated `AnalysisSession.getParsedUnit()`.
+  Use `AnalysisSession.getParsedUnit2()` instead.
 
 ## 1.4.0
 * Deprecated `TypeProvider.nonSubtypableClasses`.
diff --git a/pkg/analyzer/doc/tutorial/ast.md b/pkg/analyzer/doc/tutorial/ast.md
index 2adab31..3e9e3fa 100644
--- a/pkg/analyzer/doc/tutorial/ast.md
+++ b/pkg/analyzer/doc/tutorial/ast.md
@@ -55,8 +55,10 @@
 
 ```dart
 void processFile(AnalysisSession session, String path) {
-  ParsedUnitResult result = session.getParsedUnit(path);
-  CompilationUnit unit = result.unit;
+  var result = session.getParsedUnit2(path);
+  if (result is ParsedUnitResult) {
+    CompilationUnit unit = result.unit;
+  }
 }
 ```
 
diff --git a/pkg/analyzer/lib/dart/analysis/results.dart b/pkg/analyzer/lib/dart/analysis/results.dart
index 762a44f..a79c4af 100644
--- a/pkg/analyzer/lib/dart/analysis/results.dart
+++ b/pkg/analyzer/lib/dart/analysis/results.dart
@@ -49,6 +49,7 @@
     implements
         InvalidResult,
         SomeLibraryElementResult,
+        SomeParsedLibraryResult,
         SomeResolvedLibraryResult {}
 
 /// The declaration of an [Element].
@@ -99,6 +100,8 @@
     implements
         InvalidResult,
         SomeErrorsResult,
+        SomeParsedLibraryResult,
+        SomeParsedUnitResult,
         SomeResolvedLibraryResult,
         SomeResolvedUnitResult,
         SomeUnitElementResult {}
@@ -121,7 +124,10 @@
 ///
 /// Clients may not extend, implement or mix-in this class.
 class NotElementOfThisSessionResult
-    implements InvalidResult, SomeResolvedLibraryResult {}
+    implements
+        InvalidResult,
+        SomeParsedLibraryResult,
+        SomeResolvedLibraryResult {}
 
 /// The type of [InvalidResult] returned when the given file is not a library,
 /// but a part of a library.
@@ -131,6 +137,7 @@
     implements
         InvalidResult,
         SomeLibraryElementResult,
+        SomeParsedLibraryResult,
         SomeResolvedLibraryResult {}
 
 /// The type of [InvalidResult] returned when the given file path does not
@@ -145,6 +152,7 @@
     implements
         InvalidResult,
         SomeErrorsResult,
+        SomeParsedLibraryResult,
         SomeResolvedLibraryResult,
         SomeResolvedUnitResult,
         SomeUnitElementResult {}
@@ -152,7 +160,8 @@
 /// The result of building parsed AST(s) for the whole library.
 ///
 /// Clients may not extend, implement or mix-in this class.
-abstract class ParsedLibraryResult implements AnalysisResult {
+abstract class ParsedLibraryResult
+    implements SomeParsedLibraryResult, AnalysisResult {
   /// The parsed units of the library.
   ///
   /// TODO(migration): should not be null, probably empty list
@@ -168,7 +177,8 @@
 /// those discovered during scanning and parsing.
 ///
 /// Clients may not extend, implement or mix-in this class.
-abstract class ParsedUnitResult implements AnalysisResultWithErrors {
+abstract class ParsedUnitResult
+    implements SomeParsedUnitResult, AnalysisResultWithErrors {
   /// The content of the file that was scanned and parsed.
   String get content;
 
@@ -278,9 +288,27 @@
 ///
 /// Clients may not extend, implement or mix-in this class.
 ///
+/// There are existing implementations of this class.
 /// [LibraryElementResult] represents a valid result.
 abstract class SomeLibraryElementResult {}
 
+/// The result of building parsed AST(s) for the whole library.
+///
+/// Clients may not extend, implement or mix-in this class.
+///
+/// There are existing implementations of this class.
+/// [ParsedLibraryResult] represents a valid result.
+abstract class SomeParsedLibraryResult {}
+
+/// The result of parsing of a single file. The errors returned include only
+/// those discovered during scanning and parsing.
+///
+/// Clients may not extend, implement or mix-in this class.
+///
+/// There are existing implementations of this class.
+/// [ParsedUnitResult] represents a valid result.
+abstract class SomeParsedUnitResult {}
+
 /// The result of building resolved AST(s) for the whole library.
 ///
 /// Clients may not extend, implement or mix-in this class.
@@ -331,11 +359,17 @@
 ///
 /// Clients may not extend, implement or mix-in this class.
 class UnspecifiedInvalidResult
-    implements InvalidResult, SomeLibraryElementResult {}
+    implements
+        InvalidResult,
+        SomeLibraryElementResult,
+        SomeParsedLibraryResult {}
 
 /// The type of [InvalidResult] returned when the given URI corresponds to
 /// a library that is served from an external summary bundle.
 ///
 /// Clients may not extend, implement or mix-in this class.
 class UriOfExternalLibraryResult
-    implements InvalidResult, SomeResolvedLibraryResult {}
+    implements
+        InvalidResult,
+        SomeParsedLibraryResult,
+        SomeResolvedLibraryResult {}
diff --git a/pkg/analyzer/lib/dart/analysis/session.dart b/pkg/analyzer/lib/dart/analysis/session.dart
index 5e4b6fa..8b8db65 100644
--- a/pkg/analyzer/lib/dart/analysis/session.dart
+++ b/pkg/analyzer/lib/dart/analysis/session.dart
@@ -64,18 +64,33 @@
   ///
   /// Throw [ArgumentError] if the given [path] is not the defining compilation
   /// unit for a library (that is, is a part of a library).
+  @Deprecated('Use getParsedLibrary2() instead')
   ParsedLibraryResult getParsedLibrary(String path);
 
   /// Return information about the results of parsing units of the library file
+  /// with the given absolute, normalized [path].
+  SomeParsedLibraryResult getParsedLibrary2(String path);
+
+  /// Return information about the results of parsing units of the library file
   /// with the given library [element].
   ///
   /// Throw [ArgumentError] if the [element] was not produced by this session.
+  @Deprecated('Use getParsedLibraryByElement2() instead')
   ParsedLibraryResult getParsedLibraryByElement(LibraryElement element);
 
+  /// Return information about the results of parsing units of the library file
+  /// with the given library [element].
+  SomeParsedLibraryResult getParsedLibraryByElement2(LibraryElement element);
+
   /// Return information about the results of parsing the file with the given
   /// absolute, normalized [path].
+  @Deprecated('Use getParsedUnit2() instead')
   ParsedUnitResult getParsedUnit(String path);
 
+  /// Return information about the results of parsing the file with the given
+  /// absolute, normalized [path].
+  SomeParsedUnitResult getParsedUnit2(String path);
+
   /// Return a future that will complete with information about the results of
   /// resolving all of the files in the library with the given absolute,
   /// normalized [path].
diff --git a/pkg/analyzer/lib/src/dart/analysis/driver.dart b/pkg/analyzer/lib/src/dart/analysis/driver.dart
index 33182f1..fd284cf 100644
--- a/pkg/analyzer/lib/src/dart/analysis/driver.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/driver.dart
@@ -720,20 +720,40 @@
   ///
   /// The [path] must be absolute and normalized.
   ParsedLibraryResult getParsedLibrary(String path) {
-    FileState file = _fsState.getFileForPath(path);
+    var result = getParsedLibrary2(path);
 
-    if (file.isExternalLibrary) {
-      return ParsedLibraryResultImpl.external(currentSession, file.uri);
+    if (result is NotLibraryButPartResult) {
+      throw ArgumentError('Is a part: $path');
     }
 
+    return result as ParsedLibraryResult;
+  }
+
+  /// Return a [ParsedLibraryResult] for the library with the given [path].
+  ///
+  /// The [path] must be absolute and normalized.
+  SomeParsedLibraryResult getParsedLibrary2(String path) {
+    if (!_isAbsolutePath(path)) {
+      return InvalidPathResult();
+    }
+
+    if (!_fsState.hasUri(path)) {
+      return NotPathOfUriResult();
+    }
+
+    FileState file = _fsState.getFileForPath(path);
+
     if (file.isPart) {
-      throw ArgumentError('Is a part: $path');
+      return NotLibraryButPartResult();
     }
 
     var units = <ParsedUnitResult>[];
     for (var unitFile in file.libraryFiles) {
       var unitPath = unitFile.path;
-      var unitResult = parseFileSync(unitPath);
+      var unitResult = parseFileSync2(unitPath);
+      if (unitResult is! ParsedUnitResult) {
+        return UnspecifiedInvalidResult();
+      }
       units.add(unitResult);
     }
 
@@ -744,6 +764,7 @@
   ///
   /// Throw [ArgumentError] if the given [uri] is not the defining compilation
   /// unit for a library (that is, is a part of a library).
+  @Deprecated('Use getParsedLibraryByUri2() instead')
   ParsedLibraryResult getParsedLibraryByUri(Uri uri) {
     var fileOr = _fsState.getFileForUri(uri);
     return fileOr.map(
@@ -762,6 +783,25 @@
     );
   }
 
+  /// Return a [ParsedLibraryResult] for the library with the given [uri].
+  SomeParsedLibraryResult getParsedLibraryByUri2(Uri uri) {
+    var fileOr = _fsState.getFileForUri(uri);
+    return fileOr.map(
+      (file) {
+        if (file == null) {
+          return CannotResolveUriResult();
+        }
+        if (file.isPart) {
+          return NotLibraryButPartResult();
+        }
+        return getParsedLibrary(file.path);
+      },
+      (externalLibrary) {
+        return UriOfExternalLibraryResult();
+      },
+    );
+  }
+
   /// Return a [Future] that completes with a [ResolvedLibraryResult] for the
   /// Dart library file with the given [path].  If the file is not a Dart file
   /// or cannot be analyzed, the [Future] completes with `null`.
@@ -1096,10 +1136,25 @@
   /// The parsing is performed in the method itself, and the result is not
   /// produced through the [results] stream (just because it is not a fully
   /// resolved unit).
+  @Deprecated('Use parseFile2() instead')
   Future<ParsedUnitResult> parseFile(String path) async {
     return parseFileSync(path);
   }
 
+  /// Return a [Future] that completes with a [ParsedUnitResult] for the file
+  /// with the given [path].
+  ///
+  /// The [path] must be absolute and normalized.
+  ///
+  /// The [path] can be any file - explicitly or implicitly analyzed, or neither.
+  ///
+  /// The parsing is performed in the method itself, and the result is not
+  /// produced through the [results] stream (just because it is not a fully
+  /// resolved unit).
+  Future<SomeParsedUnitResult> parseFile2(String path) async {
+    return parseFileSync2(path);
+  }
+
   /// Return a [ParsedUnitResult] for the file with the given [path].
   ///
   /// The [path] must be absolute and normalized.
@@ -1109,8 +1164,27 @@
   /// The parsing is performed in the method itself, and the result is not
   /// produced through the [results] stream (just because it is not a fully
   /// resolved unit).
+  @Deprecated('Use parseFileSync2() instead')
   ParsedUnitResult parseFileSync(String path) {
     _throwIfNotAbsolutePath(path);
+
+    return parseFileSync2(path) as ParsedUnitResult;
+  }
+
+  /// Return a [ParsedUnitResult] for the file with the given [path].
+  ///
+  /// The [path] must be absolute and normalized.
+  ///
+  /// The [path] can be any file - explicitly or implicitly analyzed, or neither.
+  ///
+  /// The parsing is performed in the method itself, and the result is not
+  /// produced through the [results] stream (just because it is not a fully
+  /// resolved unit).
+  SomeParsedUnitResult parseFileSync2(String path) {
+    if (!_isAbsolutePath(path)) {
+      return InvalidPathResult();
+    }
+
     FileState file = _fileTracker.getFile(path);
     RecordingErrorListener listener = RecordingErrorListener();
     CompilationUnit unit = file.parse(listener);
diff --git a/pkg/analyzer/lib/src/dart/analysis/session.dart b/pkg/analyzer/lib/src/dart/analysis/session.dart
index fe0a088..fbc5371 100644
--- a/pkg/analyzer/lib/src/dart/analysis/session.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/session.dart
@@ -95,6 +95,7 @@
     return _driver.getLibraryByUri2(uri);
   }
 
+  @Deprecated('Use getParsedLibrary2() instead')
   @override
   ParsedLibraryResult getParsedLibrary(String path) {
     _checkConsistency();
@@ -102,6 +103,13 @@
   }
 
   @override
+  SomeParsedLibraryResult getParsedLibrary2(String path) {
+    _checkConsistency();
+    return _driver.getParsedLibrary2(path);
+  }
+
+  @Deprecated('Use getParsedLibraryByElement2() instead')
+  @override
   ParsedLibraryResult getParsedLibraryByElement(LibraryElement element) {
     _checkConsistency();
     _checkElementOfThisSession(element);
@@ -109,11 +117,29 @@
   }
 
   @override
+  SomeParsedLibraryResult getParsedLibraryByElement2(LibraryElement element) {
+    _checkConsistency();
+
+    if (element.session != this) {
+      return NotElementOfThisSessionResult();
+    }
+
+    return _driver.getParsedLibraryByUri2(element.source.uri);
+  }
+
+  @Deprecated('Use getParsedUnit2() instead')
+  @override
   ParsedUnitResult getParsedUnit(String path) {
     _checkConsistency();
     return _driver.parseFileSync(path);
   }
 
+  @override
+  SomeParsedUnitResult getParsedUnit2(String path) {
+    _checkConsistency();
+    return _driver.parseFileSync2(path);
+  }
+
   @Deprecated('Use getResolvedLibrary2() instead')
   @override
   Future<ResolvedLibraryResult> getResolvedLibrary(String path) {
diff --git a/pkg/analyzer/test/src/dart/analysis/driver_test.dart b/pkg/analyzer/test/src/dart/analysis/driver_test.dart
index 793b2a6..87cdde7 100644
--- a/pkg/analyzer/test/src/dart/analysis/driver_test.dart
+++ b/pkg/analyzer/test/src/dart/analysis/driver_test.dart
@@ -1513,6 +1513,57 @@
     }, throwsArgumentError);
   }
 
+  test_getParsedLibrary2() async {
+    var content = 'class A {}';
+    addTestFile(content);
+    var result = driver.getParsedLibrary2(testFile);
+    result as ParsedLibraryResult;
+    expect(result.units, hasLength(1));
+    expect(result.units![0].path, testFile);
+    expect(result.units![0].content, content);
+    expect(result.units![0].unit, isNotNull);
+    expect(result.units![0].errors, isEmpty);
+  }
+
+  test_getParsedLibrary2_invalidPath_notAbsolute() async {
+    var result = driver.getParsedLibrary2('not_absolute.dart');
+    expect(result, isA<InvalidPathResult>());
+  }
+
+  test_getParsedLibrary2_notLibraryButPart() async {
+    addTestFile('part of my;');
+    var result = driver.getParsedLibrary2(testFile);
+    expect(result, isA<NotLibraryButPartResult>());
+  }
+
+  test_getParsedLibraryByUri2() async {
+    var content = 'class A {}';
+    addTestFile(content);
+
+    var uri = Uri.parse('package:test/test.dart');
+    var result = driver.getParsedLibraryByUri2(uri);
+    result as ParsedLibraryResult;
+    expect(result.uri, uri);
+    expect(result.units, hasLength(1));
+    expect(result.units![0].uri, uri);
+    expect(result.units![0].path, testFile);
+    expect(result.units![0].content, content);
+  }
+
+  test_getParsedLibraryByUri2_notLibrary() async {
+    addTestFile('part of my;');
+
+    var uri = Uri.parse('package:test/test.dart');
+    var result = driver.getParsedLibraryByUri2(uri);
+    expect(result, isA<NotLibraryButPartResult>());
+  }
+
+  test_getParsedLibraryByUri2_unresolvedUri() async {
+    var uri = Uri.parse('package:unknown/a.dart');
+    var result = driver.getParsedLibraryByUri2(uri);
+    expect(result, isA<CannotResolveUriResult>());
+  }
+
   test_getResolvedLibrary2() async {
     var content = 'class A {}';
     addTestFile(content);
@@ -2480,6 +2531,70 @@
     expect(error.errorCode, CompileTimeErrorCode.MISSING_DART_LIBRARY);
   }
 
+  test_parseFile2_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 {}');
+
+    // Parse 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.
+    {
+      var parseResult = await driver.parseFile2(a) as ParsedUnitResult;
+      expect(parseResult.unit.declarations, isEmpty);
+    }
+
+    // We have not read `a.dart`, so `A` is still not declared.
+    {
+      var bResult = await driver.getResultValid(b);
+      expect(bResult.errors, isNotEmpty);
+    }
+
+    // Notify the driver that the file was changed.
+    driver.changeFile(a);
+
+    // So, `class A {}` is declared now.
+    {
+      var parseResult = driver.parseFileSync2(a) as ParsedUnitResult;
+      expect(parseResult.unit.declarations, hasLength(1));
+    }
+    {
+      var bResult = await driver.getResultValid(b);
+      expect(bResult.errors, isEmpty);
+    }
+  }
+
+  test_parseFile2_notAbsolutePath() async {
+    var result = await driver.parseFile2('not_absolute.dart');
+    expect(result, isA<InvalidPathResult>());
+  }
+
+  test_parseFile2_notDart() async {
+    var p = convertPath('/test/bin/a.txt');
+    newFile(p, content: 'class A {}');
+
+    var parseResult = await driver.parseFile2(p) as ParsedUnitResult;
+    expect(parseResult, isNotNull);
+    expect(driver.knownFiles, contains(p));
+  }
+
+  @deprecated
   test_parseFile_changedFile() async {
     var a = convertPath('/test/lib/a.dart');
     var b = convertPath('/test/lib/b.dart');
@@ -2529,12 +2644,14 @@
     }
   }
 
+  @deprecated
   test_parseFile_notAbsolutePath() async {
     expect(() async {
       await driver.parseFile('not_absolute.dart');
     }, throwsArgumentError);
   }
 
+  @deprecated
   test_parseFile_notDart() async {
     var p = convertPath('/test/bin/a.txt');
     newFile(p, content: 'class A {}');
@@ -2544,6 +2661,138 @@
     expect(driver.knownFiles, contains(p));
   }
 
+  test_parseFileSync2_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 {}');
+
+    // Parse 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.
+    {
+      var parseResult = driver.parseFileSync2(a) as ParsedUnitResult;
+      expect(parseResult.unit.declarations, isEmpty);
+    }
+
+    // We have not read `a.dart`, so `A` is still not declared.
+    {
+      var bResult = await driver.getResultValid(b);
+      expect(bResult.errors, isNotEmpty);
+    }
+
+    // Notify the driver that the file was changed.
+    driver.changeFile(a);
+
+    // So, `class A {}` is declared now.
+    {
+      var parseResult = driver.parseFileSync2(a) as ParsedUnitResult;
+      expect(parseResult.unit.declarations, hasLength(1));
+    }
+    {
+      var bResult = await driver.getResultValid(b);
+      expect(bResult.errors, isEmpty);
+    }
+  }
+
+  test_parseFileSync2_doesNotReadImportedFiles() 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';
+''');
+
+    expect(driver.fsState.knownFilePaths, isEmpty);
+
+    // Don't read `a.dart` when parse.
+    driver.parseFileSync2(b);
+    expect(driver.fsState.knownFilePaths, unorderedEquals([b]));
+
+    // Still don't read `a.dart` when parse the second time.
+    driver.parseFileSync2(b);
+    expect(driver.fsState.knownFilePaths, unorderedEquals([b]));
+  }
+
+  test_parseFileSync2_doesNotReadPartedFiles() async {
+    var a = convertPath('/test/lib/a.dart');
+    var b = convertPath('/test/lib/b.dart');
+
+    newFile(a, content: r'''
+part of my;
+''');
+    newFile(b, content: r'''
+library my;
+part 'a.dart';
+''');
+
+    expect(driver.fsState.knownFilePaths, isEmpty);
+
+    // Don't read `a.dart` when parse.
+    driver.parseFileSync2(b);
+    expect(driver.fsState.knownFilePaths, unorderedEquals([b]));
+
+    // Still don't read `a.dart` when parse the second time.
+    driver.parseFileSync2(b);
+    expect(driver.fsState.knownFilePaths, unorderedEquals([b]));
+  }
+
+  test_parseFileSync2_languageVersion() async {
+    var path = convertPath('/test/lib/test.dart');
+
+    newFile(path, content: r'''
+// @dart = 2.7
+class A {}
+''');
+
+    var parseResult = driver.parseFileSync2(path) as ParsedUnitResult;
+    var languageVersion = parseResult.unit.languageVersionToken!;
+    expect(languageVersion.major, 2);
+    expect(languageVersion.minor, 7);
+  }
+
+  test_parseFileSync2_languageVersion_null() async {
+    var path = convertPath('/test/lib/test.dart');
+
+    newFile(path, content: r'''
+class A {}
+''');
+
+    var parseResult = driver.parseFileSync2(path) as ParsedUnitResult;
+    expect(parseResult.unit.languageVersionToken, isNull);
+  }
+
+  test_parseFileSync2_notAbsolutePath() {
+    var result = driver.parseFileSync2('not_absolute.dart');
+    expect(result, isA<InvalidPathResult>());
+  }
+
+  test_parseFileSync2_notDart() {
+    var p = convertPath('/test/bin/a.txt');
+    newFile(p, content: 'class A {}');
+
+    var parseResult = driver.parseFileSync2(p) as ParsedUnitResult;
+    expect(parseResult, isNotNull);
+    expect(driver.knownFiles, contains(p));
+  }
+
+  @deprecated
   test_parseFileSync_changedFile() async {
     var a = convertPath('/test/lib/a.dart');
     var b = convertPath('/test/lib/b.dart');
@@ -2593,6 +2842,7 @@
     }
   }
 
+  @deprecated
   test_parseFileSync_doesNotReadImportedFiles() async {
     var a = convertPath('/test/lib/a.dart');
     var b = convertPath('/test/lib/b.dart');
@@ -2613,6 +2863,7 @@
     expect(driver.fsState.knownFilePaths, unorderedEquals([b]));
   }
 
+  @deprecated
   test_parseFileSync_doesNotReadPartedFiles() async {
     var a = convertPath('/test/lib/a.dart');
     var b = convertPath('/test/lib/b.dart');
@@ -2636,6 +2887,7 @@
     expect(driver.fsState.knownFilePaths, unorderedEquals([b]));
   }
 
+  @deprecated
   test_parseFileSync_languageVersion() async {
     var path = convertPath('/test/lib/test.dart');
 
@@ -2650,6 +2902,7 @@
     expect(languageVersion.minor, 7);
   }
 
+  @deprecated
   test_parseFileSync_languageVersion_null() async {
     var path = convertPath('/test/lib/test.dart');
 
@@ -2661,12 +2914,14 @@
     expect(parseResult.unit.languageVersionToken, isNull);
   }
 
-  test_parseFileSync_notAbsolutePath() async {
+  @deprecated
+  test_parseFileSync_notAbsolutePath() {
     expect(() {
       driver.parseFileSync('not_absolute.dart');
     }, throwsArgumentError);
   }
 
+  @deprecated
   test_parseFileSync_notDart() {
     var p = convertPath('/test/bin/a.txt');
     newFile(p, content: 'class A {}');
diff --git a/pkg/analyzer/test/src/dart/analysis/results/get_element_declaration_test.dart b/pkg/analyzer/test/src/dart/analysis/results/get_element_declaration_test.dart
index 6984d0e..89fdeda 100644
--- a/pkg/analyzer/test/src/dart/analysis/results/get_element_declaration_test.dart
+++ b/pkg/analyzer/test/src/dart/analysis/results/get_element_declaration_test.dart
@@ -5,7 +5,6 @@
 import 'package:analyzer/dart/analysis/results.dart';
 import 'package:analyzer/dart/ast/ast.dart';
 import 'package:analyzer/dart/element/element.dart';
-import 'package:analyzer/src/dart/analysis/results.dart';
 import 'package:test/test.dart';
 import 'package:test_reflective_loader/test_reflective_loader.dart';
 
@@ -438,9 +437,9 @@
     return library.getElementDeclaration(element);
   }
 
-  ParsedLibraryResultImpl _getParsedLibrary(String path) {
+  ParsedLibraryResult _getParsedLibrary(String path) {
     var session = contextFor(path).currentSession;
-    return session.getParsedLibrary(path) as ParsedLibraryResultImpl;
+    return session.getParsedLibrary2(path) as ParsedLibraryResult;
   }
 }
 
diff --git a/pkg/analyzer/test/src/dart/analysis/session_test.dart b/pkg/analyzer/test/src/dart/analysis/session_test.dart
index e75afcd..5af5179 100644
--- a/pkg/analyzer/test/src/dart/analysis/session_test.dart
+++ b/pkg/analyzer/test/src/dart/analysis/session_test.dart
@@ -79,6 +79,16 @@
     expect(result.uri.toString(), 'package:dart.my/a.dart');
   }
 
+  void test_getParsedLibrary2_notFileOfUri() async {
+    var relPath = 'dart/my/lib/a.dart';
+    newFile('$workspaceRootPath/bazel-bin/$relPath');
+
+    var path = convertPath('$workspaceRootPath/$relPath');
+    var session = contextFor(path).currentSession;
+    var result = session.getParsedLibrary2(path);
+    expect(result, isA<NotPathOfUriResult>());
+  }
+
   void test_getResolvedLibrary2_notFileOfUri() async {
     var relPath = 'dart/my/lib/a.dart';
     newFile('$workspaceRootPath/bazel-bin/$relPath');
@@ -298,6 +308,7 @@
     }, throwsArgumentError);
   }
 
+  @deprecated
   test_getParsedLibrary() async {
     newFile(testPath, content: r'''
 class A {}
@@ -319,6 +330,95 @@
     }
   }
 
+  test_getParsedLibrary2() async {
+    newFile(testPath, content: r'''
+class A {}
+class B {}
+''');
+
+    var parsedLibrary = session.getParsedLibraryValid(testPath);
+    expect(parsedLibrary.session, session);
+    expect(parsedLibrary.path, testPath);
+    expect(parsedLibrary.uri, Uri.parse('package:test/test.dart'));
+
+    expect(parsedLibrary.units, hasLength(1));
+    {
+      var parsedUnit = parsedLibrary.units![0];
+      expect(parsedUnit.session, session);
+      expect(parsedUnit.path, testPath);
+      expect(parsedUnit.uri, Uri.parse('package:test/test.dart'));
+      expect(parsedUnit.unit.declarations, hasLength(2));
+    }
+  }
+
+  test_getParsedLibrary2_invalidPath_notAbsolute() async {
+    var result = session.getParsedLibrary2('not_absolute.dart');
+    expect(result, isA<InvalidPathResult>());
+  }
+
+  test_getParsedLibrary2_notLibrary() async {
+    newFile(testPath, content: 'part of "a.dart";');
+    expect(session.getParsedLibrary2(testPath), isA<NotLibraryButPartResult>());
+  }
+
+  test_getParsedLibrary2_parts() async {
+    var a = convertPath('/home/test/lib/a.dart');
+    var b = convertPath('/home/test/lib/b.dart');
+    var c = convertPath('/home/test/lib/c.dart');
+
+    var aContent = r'''
+part 'b.dart';
+part 'c.dart';
+
+class A {}
+''';
+
+    var bContent = r'''
+part of 'a.dart';
+
+class B1 {}
+class B2 {}
+''';
+
+    var cContent = r'''
+part of 'a.dart';
+
+class C1 {}
+class C2 {}
+class C3 {}
+''';
+
+    newFile(a, content: aContent);
+    newFile(b, content: bContent);
+    newFile(c, content: cContent);
+
+    var parsedLibrary = session.getParsedLibraryValid(a);
+    expect(parsedLibrary.path, a);
+    expect(parsedLibrary.uri, Uri.parse('package:test/a.dart'));
+    expect(parsedLibrary.units, hasLength(3));
+
+    {
+      var aUnit = parsedLibrary.units![0];
+      expect(aUnit.path, a);
+      expect(aUnit.uri, Uri.parse('package:test/a.dart'));
+      expect(aUnit.unit.declarations, hasLength(1));
+    }
+
+    {
+      var bUnit = parsedLibrary.units![1];
+      expect(bUnit.path, b);
+      expect(bUnit.uri, Uri.parse('package:test/b.dart'));
+      expect(bUnit.unit.declarations, hasLength(2));
+    }
+
+    {
+      var cUnit = parsedLibrary.units![2];
+      expect(cUnit.path, c);
+      expect(cUnit.uri, Uri.parse('package:test/c.dart'));
+      expect(cUnit.unit.declarations, hasLength(3));
+    }
+  }
+
   test_getParsedLibrary_getElementDeclaration_class() async {
     newFile(testPath, content: r'''
 class A {}
@@ -328,7 +428,7 @@
     var libraryResult = await session.getLibraryByUriValid(
       'package:test/test.dart',
     );
-    var parsedLibrary = session.getParsedLibrary(testPath);
+    var parsedLibrary = session.getParsedLibraryValid(testPath);
 
     var element = libraryResult.element.getType('A')!;
     var declaration = parsedLibrary.getElementDeclaration(element)!;
@@ -361,7 +461,7 @@
     var typeProvider = resolvedUnit.typeProvider;
     var intClass = typeProvider.intType.element;
 
-    var parsedLibrary = session.getParsedLibrary(testPath);
+    var parsedLibrary = session.getParsedLibraryValid(testPath);
 
     expect(() {
       parsedLibrary.getElementDeclaration(intClass);
@@ -373,7 +473,7 @@
 int foo = 0;
 ''');
 
-    var parsedLibrary = session.getParsedLibrary(testPath);
+    var parsedLibrary = session.getParsedLibraryValid(testPath);
 
     var unitResult = await session.getUnitElement2(testPath);
     var unitElement = (unitResult as UnitElementResult).element;
@@ -425,7 +525,7 @@
 part 'c.dart';
 ''');
 
-    var parsedLibrary = session.getParsedLibrary(testPath);
+    var parsedLibrary = session.getParsedLibraryValid(testPath);
 
     expect(parsedLibrary.units, hasLength(3));
     expect(
@@ -442,6 +542,7 @@
     );
   }
 
+  @deprecated
   test_getParsedLibrary_notLibrary() async {
     newFile(testPath, content: 'part of "a.dart";');
 
@@ -450,6 +551,7 @@
     }, throwsArgumentError);
   }
 
+  @deprecated
   test_getParsedLibrary_parts() async {
     var a = convertPath('/home/test/lib/a.dart');
     var b = convertPath('/home/test/lib/b.dart');
@@ -508,6 +610,7 @@
     }
   }
 
+  @deprecated
   test_getParsedLibraryByElement() async {
     newFile(testPath, content: '');
 
@@ -523,6 +626,37 @@
     expect(parsedLibrary.units, hasLength(1));
   }
 
+  test_getParsedLibraryByElement2() async {
+    newFile(testPath, content: '');
+
+    var libraryResult = await session.getLibraryByUriValid(
+      'package:test/test.dart',
+    );
+    var element = libraryResult.element;
+
+    var parsedLibrary = session.getParsedLibraryByElementValid(element);
+    expect(parsedLibrary.session, session);
+    expect(parsedLibrary.path, testPath);
+    expect(parsedLibrary.uri, Uri.parse('package:test/test.dart'));
+    expect(parsedLibrary.units, hasLength(1));
+  }
+
+  test_getParsedLibraryByElement2_differentSession() async {
+    newFile(testPath, content: '');
+
+    var libraryResult = await session.getLibraryByUriValid(
+      'package:test/test.dart',
+    );
+    var element = libraryResult.element;
+
+    var aaaSession =
+        contextCollection.contextFor(aaaContextPath).currentSession;
+
+    var result = aaaSession.getParsedLibraryByElement2(element);
+    expect(result, isA<NotElementOfThisSessionResult>());
+  }
+
+  @deprecated
   test_getParsedLibraryByElement_differentSession() async {
     newFile(testPath, content: '');
 
@@ -539,6 +673,7 @@
     }, throwsArgumentError);
   }
 
+  @deprecated
   test_getParsedUnit() async {
     newFile(testPath, content: r'''
 class A {}
@@ -552,6 +687,24 @@
     expect(unitResult.unit.declarations, hasLength(2));
   }
 
+  test_getParsedUnit2() async {
+    newFile(testPath, content: r'''
+class A {}
+class B {}
+''');
+
+    var unitResult = session.getParsedUnitValid(testPath);
+    expect(unitResult.session, session);
+    expect(unitResult.path, testPath);
+    expect(unitResult.uri, Uri.parse('package:test/test.dart'));
+    expect(unitResult.unit.declarations, hasLength(2));
+  }
+
+  test_getParsedUnit2_invalidPath_notAbsolute() async {
+    var result = session.getParsedUnit2('not_absolute.dart');
+    expect(result, isA<InvalidPathResult>());
+  }
+
   test_getResolvedLibrary() async {
     var a = convertPath('/home/test/lib/a.dart');
     var b = convertPath('/home/test/lib/b.dart');
@@ -846,6 +999,14 @@
     return await getUnitElement2(path) as UnitElementResult;
   }
 
+  ParsedLibraryResult getParsedLibraryValid(String path) {
+    return getParsedLibrary2(path) as ParsedLibraryResult;
+  }
+
+  ParsedUnitResult getParsedUnitValid(String path) {
+    return getParsedUnit2(path) as ParsedUnitResult;
+  }
+
   Future<ResolvedLibraryResult> getResolvedLibraryValid(String path) async {
     return await getResolvedLibrary2(path) as ResolvedLibraryResult;
   }
@@ -859,6 +1020,10 @@
     return await getResolvedLibraryByElement2(element) as ResolvedLibraryResult;
   }
 
+  ParsedLibraryResult getParsedLibraryByElementValid(LibraryElement element) {
+    return getParsedLibraryByElement2(element) as ParsedLibraryResult;
+  }
+
   Future<ErrorsResult> getErrorsValid(String path) async {
     return await getErrors2(path) as ErrorsResult;
   }
diff --git a/pkg/analyzer/test/verify_diagnostics_test.dart b/pkg/analyzer/test/verify_diagnostics_test.dart
index f99f600..c1c68c6 100644
--- a/pkg/analyzer/test/verify_diagnostics_test.dart
+++ b/pkg/analyzer/test/verify_diagnostics_test.dart
@@ -251,8 +251,8 @@
   /// [path] and return the result.
   ParsedUnitResult _parse(AnalysisContextCollection collection, String path) {
     AnalysisSession session = collection.contextFor(path).currentSession;
-    ParsedUnitResult result = session.getParsedUnit(path);
-    if (result.state != ResultState.VALID) {
+    var result = session.getParsedUnit2(path);
+    if (result is! ParsedUnitResult) {
       throw StateError('Unable to parse "$path"');
     }
     return result;
diff --git a/pkg/analyzer/tool/diagnostics/generate.dart b/pkg/analyzer/tool/diagnostics/generate.dart
index 5f8db9e..b95e8dc 100644
--- a/pkg/analyzer/tool/diagnostics/generate.dart
+++ b/pkg/analyzer/tool/diagnostics/generate.dart
@@ -361,8 +361,8 @@
   /// [path] and return the result.
   ParsedUnitResult _parse(AnalysisContextCollection collection, String path) {
     AnalysisSession session = collection.contextFor(path).currentSession;
-    ParsedUnitResult result = session.getParsedUnit(path);
-    if (result.state != ResultState.VALID) {
+    var result = session.getParsedUnit2(path);
+    if (result is! ParsedUnitResult) {
       throw StateError('Unable to parse "$path"');
     }
     return result;
diff --git a/pkg/analyzer_plugin/lib/utilities/navigation/navigation_dart.dart b/pkg/analyzer_plugin/lib/utilities/navigation/navigation_dart.dart
index dde44ba..897f2d7 100644
--- a/pkg/analyzer_plugin/lib/utilities/navigation/navigation_dart.dart
+++ b/pkg/analyzer_plugin/lib/utilities/navigation/navigation_dart.dart
@@ -2,6 +2,7 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
+import 'package:analyzer/dart/analysis/results.dart';
 import 'package:analyzer/dart/ast/ast.dart';
 import 'package:analyzer/dart/ast/token.dart';
 import 'package:analyzer/dart/ast/visitor.dart';
@@ -130,13 +131,7 @@
     // Read the declaration so we can get the offset after the doc comments.
     // TODO(dantup): Skip this for parts (getParsedLibrary will throw), but find
     // a better solution.
-    var session = codeElement.session;
-    final declaration =
-        session != null && !session.getFile(location.file).isPart
-            ? session
-                .getParsedLibrary(location.file)
-                .getElementDeclaration(codeElement)
-            : null;
+    final declaration = _parsedDeclaration(codeElement);
     var node = declaration?.node;
     if (node is VariableDeclaration) {
       node = node.parent;
@@ -152,6 +147,25 @@
     return converter.locationFromElement(element,
         offset: codeOffset, length: codeLength);
   }
+
+  static ElementDeclarationResult? _parsedDeclaration(Element element) {
+    var session = element.session;
+    if (session == null) {
+      return null;
+    }
+
+    var libraryPath = element.library?.source.fullName;
+    if (libraryPath == null) {
+      return null;
+    }
+
+    var parsedLibrary = session.getParsedLibrary2(libraryPath);
+    if (parsedLibrary is! ParsedLibraryResult) {
+      return null;
+    }
+
+    return parsedLibrary.getElementDeclaration(element);
+  }
 }
 
 class _DartNavigationComputerVisitor extends RecursiveAstVisitor<void> {
diff --git a/pkg/analyzer_utilities/lib/verify_tests.dart b/pkg/analyzer_utilities/lib/verify_tests.dart
index d6fad18..201e88d 100644
--- a/pkg/analyzer_utilities/lib/verify_tests.dart
+++ b/pkg/analyzer_utilities/lib/verify_tests.dart
@@ -103,8 +103,8 @@
       if (isOkForTestAllToBeMissing(directory)) {
         fail('Found "test_all.dart" in $relativePath but did not expect one');
       }
-      var result = session.getParsedUnit(testAllFile.path);
-      if (result.state != ResultState.VALID) {
+      var result = session.getParsedUnit2(testAllFile.path);
+      if (result is! ParsedUnitResult) {
         fail('Could not parse ${testAllFile.path}');
       }
       var importedFiles = <String>[];
diff --git a/pkg/front_end/lib/src/fasta/kernel/constant_evaluator.dart b/pkg/front_end/lib/src/fasta/kernel/constant_evaluator.dart
index 5d38a56..315781f 100644
--- a/pkg/front_end/lib/src/fasta/kernel/constant_evaluator.dart
+++ b/pkg/front_end/lib/src/fasta/kernel/constant_evaluator.dart
@@ -2089,9 +2089,9 @@
     // This is a white-listed set of methods we need to support on constants.
     if (receiver is StringConstant) {
       if (arguments.length == 1) {
+        final Constant other = arguments[0];
         switch (op) {
           case '+':
-            final Constant other = arguments[0];
             if (other is StringConstant) {
               return canonicalize(
                   new StringConstant(receiver.value + other.value));
@@ -2104,6 +2104,32 @@
                     typeEnvironment.coreTypes.stringLegacyRawType,
                     other.getType(_staticTypeContext),
                     isNonNullableByDefault));
+          case '[]':
+            if (enableConstFunctions) {
+              if (intFolder.isInt(other)) {
+                int index;
+                if (intFolder is JsConstantIntFolder) {
+                  index = (other as DoubleConstant).value.toInt();
+                } else if (intFolder is VmConstantIntFolder) {
+                  index = (other as IntConstant).value;
+                }
+                assert(index != null);
+
+                if (index < 0 || index >= receiver.value.length) {
+                  return new _AbortDueToThrowConstant(
+                      node, new RangeError.index(index, receiver.value));
+                }
+                return canonicalize(new StringConstant(receiver.value[index]));
+              }
+              return createErrorConstant(
+                  node,
+                  templateConstEvalInvalidBinaryOperandType.withArguments(
+                      '[]',
+                      receiver,
+                      typeEnvironment.coreTypes.intNonNullableRawType,
+                      other.getType(_staticTypeContext),
+                      isNonNullableByDefault));
+            }
         }
       }
     } else if (intFolder.isInt(receiver)) {
@@ -3644,6 +3670,12 @@
               .firstWhere((Class klass) => klass.name == 'StateError');
           throwType =
               new InterfaceType(stateErrorClass, Nullability.nonNullable);
+        } else if (throwValue is RangeError) {
+          final Class rangeErrorClass = exprEvaluator
+              .coreTypes.coreLibrary.classes
+              .firstWhere((Class klass) => klass.name == 'RangeError');
+          throwType =
+              new InterfaceType(rangeErrorClass, Nullability.nonNullable);
         }
         assert(throwType != null);
 
diff --git a/pkg/front_end/lib/src/fasta/kernel/expression_generator.dart b/pkg/front_end/lib/src/fasta/kernel/expression_generator.dart
index 19f3191..3069d7d 100644
--- a/pkg/front_end/lib/src/fasta/kernel/expression_generator.dart
+++ b/pkg/front_end/lib/src/fasta/kernel/expression_generator.dart
@@ -927,13 +927,12 @@
 
   @override
   void printOn(StringSink sink) {
-    NameSystem syntheticNames = new NameSystem();
     sink.write(", name: ");
     sink.write(name.text);
     sink.write(", getter: ");
-    printQualifiedNameOn(getter, sink, syntheticNames: syntheticNames);
+    printQualifiedNameOn(getter, sink);
     sink.write(", setter: ");
-    printQualifiedNameOn(setter, sink, syntheticNames: syntheticNames);
+    printQualifiedNameOn(setter, sink);
   }
 }
 
@@ -1303,9 +1302,9 @@
     sink.write(", index: ");
     printNodeOn(index, sink, syntheticNames: syntheticNames);
     sink.write(", getter: ");
-    printQualifiedNameOn(getter, sink, syntheticNames: syntheticNames);
+    printQualifiedNameOn(getter, sink);
     sink.write(", setter: ");
-    printQualifiedNameOn(setter, sink, syntheticNames: syntheticNames);
+    printQualifiedNameOn(setter, sink);
   }
 }
 
@@ -1503,13 +1502,12 @@
 
   @override
   void printOn(StringSink sink) {
-    NameSystem syntheticNames = new NameSystem();
     sink.write(", targetName: ");
     sink.write(targetName);
     sink.write(", readTarget: ");
-    printQualifiedNameOn(readTarget, sink, syntheticNames: syntheticNames);
+    printQualifiedNameOn(readTarget, sink);
     sink.write(", writeTarget: ");
-    printQualifiedNameOn(writeTarget, sink, syntheticNames: syntheticNames);
+    printQualifiedNameOn(writeTarget, sink);
   }
 }
 
@@ -1777,13 +1775,12 @@
 
   @override
   void printOn(StringSink sink) {
-    NameSystem syntheticNames = new NameSystem();
     sink.write(", targetName: ");
     sink.write(targetName);
     sink.write(", readTarget: ");
-    printQualifiedNameOn(readTarget, sink, syntheticNames: syntheticNames);
+    printQualifiedNameOn(readTarget, sink);
     sink.write(", writeTarget: ");
-    printQualifiedNameOn(writeTarget, sink, syntheticNames: syntheticNames);
+    printQualifiedNameOn(writeTarget, sink);
   }
 }
 
@@ -2192,13 +2189,12 @@
 
   @override
   void printOn(StringSink sink) {
-    NameSystem syntheticNames = new NameSystem();
     sink.write(", targetName: ");
     sink.write(targetName);
     sink.write(", readTarget: ");
-    printQualifiedNameOn(readTarget, sink, syntheticNames: syntheticNames);
+    printQualifiedNameOn(readTarget, sink);
     sink.write(", writeTarget: ");
-    printQualifiedNameOn(writeTarget, sink, syntheticNames: syntheticNames);
+    printQualifiedNameOn(writeTarget, sink);
   }
 }
 
@@ -2475,9 +2471,9 @@
     sink.write(", index: ");
     printNodeOn(index, sink, syntheticNames: syntheticNames);
     sink.write(", readTarget: ");
-    printQualifiedNameOn(readTarget, sink, syntheticNames: syntheticNames);
+    printQualifiedNameOn(readTarget, sink);
     sink.write(", writeTarget: ");
-    printQualifiedNameOn(writeTarget, sink, syntheticNames: syntheticNames);
+    printQualifiedNameOn(writeTarget, sink);
   }
 }
 
diff --git a/pkg/front_end/lib/src/fasta/kernel/invalid_type.dart b/pkg/front_end/lib/src/fasta/kernel/invalid_type.dart
index 3cafb52..2a81180 100644
--- a/pkg/front_end/lib/src/fasta/kernel/invalid_type.dart
+++ b/pkg/front_end/lib/src/fasta/kernel/invalid_type.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE.md file.
 
-// @dart = 2.9
-
 import 'package:kernel/ast.dart';
 
 import '../type_inference/type_schema.dart';
@@ -81,7 +79,7 @@
   bool visitFunctionType(FunctionType node, Set<TypedefType> visitedTypedefs) {
     if (node.returnType.accept1(this, visitedTypedefs)) return true;
     for (TypeParameter typeParameter in node.typeParameters) {
-      if (typeParameter.bound.accept1(this, visitedTypedefs)) return true;
+      if (typeParameter.bound!.accept1(this, visitedTypedefs)) return true;
       // TODO(dmitryas): Check defaultTypes as well if they cause cascading
       // errors.
     }
@@ -91,8 +89,8 @@
     for (NamedType parameter in node.namedParameters) {
       if (parameter.type.accept1(this, visitedTypedefs)) return true;
     }
-    if (node.typedefType != null && visitedTypedefs.add(node.typedefType)) {
-      if (node.typedefType.accept1(this, visitedTypedefs)) return true;
+    if (node.typedefType != null && visitedTypedefs.add(node.typedefType!)) {
+      if (node.typedefType!.accept1(this, visitedTypedefs)) return true;
     }
     return false;
   }
@@ -105,7 +103,7 @@
     for (DartType typeArgument in node.typeArguments) {
       if (typeArgument.accept1(this, visitedTypedefs)) return true;
     }
-    if (node.typedefNode.type.accept1(this, visitedTypedefs)) return true;
+    if (node.typedefNode.type!.accept1(this, visitedTypedefs)) return true;
     return false;
   }
 
@@ -116,7 +114,7 @@
     // automatically means that the potential errors related to the occurrences
     // of the type-parameter type itself are reported.
     if (node.promotedBound != null &&
-        node.promotedBound.accept1(this, visitedTypedefs)) {
+        node.promotedBound!.accept1(this, visitedTypedefs)) {
       return true;
     }
     return false;
diff --git a/pkg/front_end/lib/src/fasta/kernel/kernel_api.dart b/pkg/front_end/lib/src/fasta/kernel/kernel_api.dart
index 8724cfa..40f86af 100644
--- a/pkg/front_end/lib/src/fasta/kernel/kernel_api.dart
+++ b/pkg/front_end/lib/src/fasta/kernel/kernel_api.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.9
-
 /// This library exports all API from Kernel that can be used throughout fasta.
 library fasta.kernel_api;
 
@@ -27,7 +25,7 @@
 
 import 'package:kernel/ast.dart' show Class, Member, Node;
 
-void printNodeOn(Node node, StringSink sink, {NameSystem syntheticNames}) {
+void printNodeOn(Node? node, StringSink sink, {NameSystem? syntheticNames}) {
   if (node == null) {
     sink.write("null");
   } else {
@@ -36,19 +34,17 @@
   }
 }
 
-void printQualifiedNameOn(Member member, StringSink sink,
-    {NameSystem syntheticNames}) {
+void printQualifiedNameOn(Member? member, StringSink sink) {
   if (member == null) {
     sink.write("null");
   } else {
-    syntheticNames ??= new NameSystem();
     sink.write(member.enclosingLibrary.importUri);
     sink.write("::");
-    Class cls = member.enclosingClass;
+    Class? cls = member.enclosingClass;
     if (cls != null) {
-      sink.write(cls.name ?? syntheticNames.nameClass(cls));
+      sink.write(cls.name);
       sink.write("::");
     }
-    sink.write(member.name?.text ?? syntheticNames.nameMember(member));
+    sink.write(member.name.text);
   }
 }
diff --git a/pkg/front_end/lib/src/fasta/kernel/utils.dart b/pkg/front_end/lib/src/fasta/kernel/utils.dart
index 917607e..22ca5d8 100644
--- a/pkg/front_end/lib/src/fasta/kernel/utils.dart
+++ b/pkg/front_end/lib/src/fasta/kernel/utils.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart = 2.9
-
 import 'dart:io' show BytesBuilder, File, IOSink;
 
 import 'dart:typed_data' show Uint8List;
@@ -29,8 +27,8 @@
 /// Print the given [component].  Do nothing if it is `null`.  If the
 /// [libraryFilter] is provided, then only libraries that satisfy it are
 /// printed.
-void printComponentText(Component component,
-    {bool libraryFilter(Library library)}) {
+void printComponentText(Component? component,
+    {bool Function(Library library)? libraryFilter}) {
   if (component == null) return;
   StringBuffer sb = new StringBuffer();
   Printer printer = new Printer(sb);
@@ -45,7 +43,7 @@
 
 /// Write [component] to file only including libraries that match [filter].
 Future<Null> writeComponentToFile(Component component, Uri uri,
-    {bool filter(Library library)}) async {
+    {bool Function(Library library)? filter}) async {
   File output = new File.fromUri(uri);
   IOSink sink = output.openWrite();
   try {
@@ -58,7 +56,7 @@
 
 /// Serialize the libraries in [component] that match [filter].
 Uint8List serializeComponent(Component component,
-    {bool filter(Library library),
+    {bool Function(Library library)? filter,
     bool includeSources: true,
     bool includeOffsets: true}) {
   ByteSink byteSink = new ByteSink();
@@ -82,7 +80,7 @@
     ..nonNullableByDefaultCompiledMode =
         realLibrary.nonNullableByDefaultCompiledMode;
 
-  TreeNode realClass = procedure.parent;
+  TreeNode? realClass = procedure.parent;
   if (realClass is Class) {
     Class fakeClass = new Class(name: kDebugClassName, fileUri: uri)
       ..parent = fakeLibrary;
@@ -100,14 +98,15 @@
         typeSubstitution: typeSubstitution, typeParams: typeParams);
 
     for (TypeParameter typeParam in realClass.typeParameters) {
-      fakeClass.typeParameters.add(typeParam.accept<TreeNode>(cloner));
+      fakeClass.typeParameters
+          .add(typeParam.accept<TreeNode>(cloner) as TypeParameter);
     }
 
     if (realClass.supertype != null) {
       // supertype is null for Object.
       fakeClass.supertype = new Supertype.byReference(
-          realClass.supertype.className,
-          realClass.supertype.typeArguments.map(cloner.visitType).toList());
+          realClass.supertype!.className,
+          realClass.supertype!.typeArguments.map(cloner.visitType).toList());
     }
 
     // Rebind the type parameters in the procedure.
diff --git a/pkg/front_end/lib/src/fasta/type_inference/standard_bounds.dart b/pkg/front_end/lib/src/fasta/type_inference/standard_bounds.dart
index 5f149f6..b9261dd 100644
--- a/pkg/front_end/lib/src/fasta/type_inference/standard_bounds.dart
+++ b/pkg/front_end/lib/src/fasta/type_inference/standard_bounds.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE.md file.
 
-// @dart = 2.9
-
 import 'package:kernel/ast.dart' show DartType, Library, NeverType;
 
 import 'package:kernel/src/standard_bounds.dart';
diff --git a/pkg/front_end/lib/src/fasta/type_inference/type_schema.dart b/pkg/front_end/lib/src/fasta/type_inference/type_schema.dart
index cce226f..9be3b48 100644
--- a/pkg/front_end/lib/src/fasta/type_inference/type_schema.dart
+++ b/pkg/front_end/lib/src/fasta/type_inference/type_schema.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE.md file.
 
-// @dart = 2.9
-
 import 'package:kernel/ast.dart'
     show
         DartType,
@@ -38,10 +36,10 @@
 /// Extension of [Printer] that represents the unknown type as `?`.
 class TypeSchemaPrinter extends Printer {
   TypeSchemaPrinter(StringSink sink,
-      {NameSystem syntheticNames,
+      {NameSystem? syntheticNames,
       bool showOffsets: false,
-      ImportTable importTable,
-      Annotator annotator})
+      ImportTable? importTable,
+      Annotator? annotator})
       : super(sink,
             syntheticNames: syntheticNames,
             showOffsets: showOffsets,
@@ -64,16 +62,16 @@
   const UnknownType();
 
   @override
-  Nullability get declaredNullability => null;
+  Nullability get declaredNullability => Nullability.undetermined;
 
   @override
-  Nullability get nullability => null;
+  Nullability get nullability => Nullability.undetermined;
 
   @override
   bool operator ==(Object other) => equals(other, null);
 
   @override
-  bool equals(Object other, Assumptions assumptions) {
+  bool equals(Object other, Assumptions? assumptions) {
     // This class doesn't have any fields so all instances of `UnknownType` are
     // equal.
     return other is UnknownType;
@@ -124,7 +122,7 @@
     for (NamedType namedParameterType in node.namedParameters) {
       if (!namedParameterType.type.accept(this)) return false;
     }
-    if (node.typedefType != null && !node.typedefType.accept(this)) {
+    if (node.typedefType != null && !node.typedefType!.accept(this)) {
       return false;
     }
     return true;
diff --git a/pkg/front_end/lib/src/fasta/type_inference/type_schema_elimination.dart b/pkg/front_end/lib/src/fasta/type_inference/type_schema_elimination.dart
index 9e7c2ea..8927d85 100644
--- a/pkg/front_end/lib/src/fasta/type_inference/type_schema_elimination.dart
+++ b/pkg/front_end/lib/src/fasta/type_inference/type_schema_elimination.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE.md file.
 
-// @dart = 2.9
-
 import 'package:kernel/ast.dart';
 import 'package:kernel/src/replacement_visitor.dart';
 
@@ -56,7 +54,7 @@
   _TypeSchemaEliminationVisitor(this.topType, this.bottomType);
 
   @override
-  DartType defaultDartType(DartType node, int variance) {
+  DartType? defaultDartType(DartType node, int variance) {
     bool isLeastClosure = variance == Variance.covariant;
     if (node is UnknownType) {
       return isLeastClosure ? bottomType : topType;
@@ -79,7 +77,7 @@
         bottomType == const NeverType.nonNullable() || bottomType is NullType);
     _TypeSchemaEliminationVisitor visitor =
         new _TypeSchemaEliminationVisitor(topType, bottomType);
-    DartType result = schema.accept1(
+    DartType? result = schema.accept1(
         visitor, isLeastClosure ? Variance.covariant : Variance.contravariant);
     return result ?? schema;
   }
diff --git a/pkg/front_end/testcases/const_functions/const_functions_string.dart b/pkg/front_end/testcases/const_functions/const_functions_string.dart
new file mode 100644
index 0000000..e0f0f73
--- /dev/null
+++ b/pkg/front_end/testcases/const_functions/const_functions_string.dart
@@ -0,0 +1,34 @@
+// Copyright (c) 2021, the Dart project authors.  Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+// Tests string usage with const functions.
+
+import "package:expect/expect.dart";
+
+const String str = "str";
+const var1 = str[2];
+
+const var2 = fn();
+fn() {
+  String local = "str";
+  return local[0];
+}
+
+const var3 = "str"[0];
+
+const var4 = fn2();
+fn2() {
+  try {
+    var x = str[-1];
+  } on RangeError {
+    return 2;
+  }
+}
+
+void main() {
+  Expect.equals(var1, 'r');
+  Expect.equals(var2, 's');
+  Expect.equals(var3, 's');
+  Expect.equals(var4, 2);
+}
diff --git a/pkg/front_end/testcases/const_functions/const_functions_string.dart.strong.expect b/pkg/front_end/testcases/const_functions/const_functions_string.dart.strong.expect
new file mode 100644
index 0000000..f573022
--- /dev/null
+++ b/pkg/front_end/testcases/const_functions/const_functions_string.dart.strong.expect
@@ -0,0 +1,37 @@
+library /*isNonNullableByDefault*/;
+import self as self;
+import "dart:core" as core;
+import "package:expect/expect.dart" as exp;
+
+import "package:expect/expect.dart";
+
+static const field core::String str = #C1;
+static const field core::String var1 = #C2;
+static const field dynamic var2 = #C3;
+static const field core::String var3 = #C3;
+static const field dynamic var4 = #C4;
+static method fn() → dynamic {
+  core::String local = "str";
+  return local.{core::String::[]}(0);
+}
+static method fn2() → dynamic {
+  try {
+    core::String x = (#C1).{core::String::[]}(1.{core::int::unary-}());
+  }
+  on core::RangeError catch(no-exception-var) {
+    return 2;
+  }
+}
+static method main() → void {
+  exp::Expect::equals(#C2, "r");
+  exp::Expect::equals(#C3, "s");
+  exp::Expect::equals(#C3, "s");
+  exp::Expect::equals(#C4, 2);
+}
+
+constants  {
+  #C1 = "str"
+  #C2 = "r"
+  #C3 = "s"
+  #C4 = 2
+}
diff --git a/pkg/front_end/testcases/const_functions/const_functions_string.dart.strong.transformed.expect b/pkg/front_end/testcases/const_functions/const_functions_string.dart.strong.transformed.expect
new file mode 100644
index 0000000..9ba5e5c
--- /dev/null
+++ b/pkg/front_end/testcases/const_functions/const_functions_string.dart.strong.transformed.expect
@@ -0,0 +1,41 @@
+library /*isNonNullableByDefault*/;
+import self as self;
+import "dart:core" as core;
+import "package:expect/expect.dart" as exp;
+
+import "package:expect/expect.dart";
+
+static const field core::String str = #C1;
+static const field core::String var1 = #C2;
+static const field dynamic var2 = #C3;
+static const field core::String var3 = #C3;
+static const field dynamic var4 = #C4;
+static method fn() → dynamic {
+  core::String local = "str";
+  return local.{core::String::[]}(0);
+}
+static method fn2() → dynamic {
+  try {
+    core::String x = (#C1).{core::String::[]}(1.{core::int::unary-}());
+  }
+  on core::RangeError catch(no-exception-var) {
+    return 2;
+  }
+}
+static method main() → void {
+  exp::Expect::equals(#C2, "r");
+  exp::Expect::equals(#C3, "s");
+  exp::Expect::equals(#C3, "s");
+  exp::Expect::equals(#C4, 2);
+}
+
+constants  {
+  #C1 = "str"
+  #C2 = "r"
+  #C3 = "s"
+  #C4 = 2
+}
+
+Extra constant evaluation status:
+Evaluated: MethodInvocation @ org-dartlang-testcase:///const_functions_string.dart:23:17 -> IntConstant(-1)
+Extra constant evaluation: evaluated: 8, effectively constant: 1
diff --git a/pkg/front_end/testcases/const_functions/const_functions_string.dart.textual_outline.expect b/pkg/front_end/testcases/const_functions/const_functions_string.dart.textual_outline.expect
new file mode 100644
index 0000000..07c61ae
--- /dev/null
+++ b/pkg/front_end/testcases/const_functions/const_functions_string.dart.textual_outline.expect
@@ -0,0 +1,10 @@
+import "package:expect/expect.dart";
+
+const String str = "str";
+const var1 = str[2];
+const var2 = fn();
+fn() {}
+const var3 = "str"[0];
+const var4 = fn2();
+fn2() {}
+void main() {}
diff --git a/pkg/front_end/testcases/const_functions/const_functions_string.dart.textual_outline_modelled.expect b/pkg/front_end/testcases/const_functions/const_functions_string.dart.textual_outline_modelled.expect
new file mode 100644
index 0000000..2785bbc
--- /dev/null
+++ b/pkg/front_end/testcases/const_functions/const_functions_string.dart.textual_outline_modelled.expect
@@ -0,0 +1,10 @@
+import "package:expect/expect.dart";
+
+const String str = "str";
+const var1 = str[2];
+const var2 = fn();
+const var3 = "str"[0];
+const var4 = fn2();
+fn() {}
+fn2() {}
+void main() {}
diff --git a/pkg/front_end/testcases/const_functions/const_functions_string.dart.weak.expect b/pkg/front_end/testcases/const_functions/const_functions_string.dart.weak.expect
new file mode 100644
index 0000000..f573022
--- /dev/null
+++ b/pkg/front_end/testcases/const_functions/const_functions_string.dart.weak.expect
@@ -0,0 +1,37 @@
+library /*isNonNullableByDefault*/;
+import self as self;
+import "dart:core" as core;
+import "package:expect/expect.dart" as exp;
+
+import "package:expect/expect.dart";
+
+static const field core::String str = #C1;
+static const field core::String var1 = #C2;
+static const field dynamic var2 = #C3;
+static const field core::String var3 = #C3;
+static const field dynamic var4 = #C4;
+static method fn() → dynamic {
+  core::String local = "str";
+  return local.{core::String::[]}(0);
+}
+static method fn2() → dynamic {
+  try {
+    core::String x = (#C1).{core::String::[]}(1.{core::int::unary-}());
+  }
+  on core::RangeError catch(no-exception-var) {
+    return 2;
+  }
+}
+static method main() → void {
+  exp::Expect::equals(#C2, "r");
+  exp::Expect::equals(#C3, "s");
+  exp::Expect::equals(#C3, "s");
+  exp::Expect::equals(#C4, 2);
+}
+
+constants  {
+  #C1 = "str"
+  #C2 = "r"
+  #C3 = "s"
+  #C4 = 2
+}
diff --git a/pkg/front_end/testcases/const_functions/const_functions_string.dart.weak.outline.expect b/pkg/front_end/testcases/const_functions/const_functions_string.dart.weak.outline.expect
new file mode 100644
index 0000000..8da9073
--- /dev/null
+++ b/pkg/front_end/testcases/const_functions/const_functions_string.dart.weak.outline.expect
@@ -0,0 +1,22 @@
+library /*isNonNullableByDefault*/;
+import self as self;
+import "dart:core" as core;
+
+import "package:expect/expect.dart";
+
+static const field core::String str = "str";
+static const field core::String var1 = self::str.{core::String::[]}(2);
+static const field dynamic var2 = self::fn();
+static const field core::String var3 = "str".{core::String::[]}(0);
+static const field dynamic var4 = self::fn2();
+static method fn() → dynamic
+  ;
+static method fn2() → dynamic
+  ;
+static method main() → void
+  ;
+
+
+Extra constant evaluation status:
+Evaluated: StaticGet @ org-dartlang-testcase:///const_functions_string.dart:10:14 -> StringConstant("str")
+Extra constant evaluation: evaluated: 5, effectively constant: 1
diff --git a/pkg/front_end/testcases/const_functions/const_functions_string.dart.weak.transformed.expect b/pkg/front_end/testcases/const_functions/const_functions_string.dart.weak.transformed.expect
new file mode 100644
index 0000000..9ba5e5c
--- /dev/null
+++ b/pkg/front_end/testcases/const_functions/const_functions_string.dart.weak.transformed.expect
@@ -0,0 +1,41 @@
+library /*isNonNullableByDefault*/;
+import self as self;
+import "dart:core" as core;
+import "package:expect/expect.dart" as exp;
+
+import "package:expect/expect.dart";
+
+static const field core::String str = #C1;
+static const field core::String var1 = #C2;
+static const field dynamic var2 = #C3;
+static const field core::String var3 = #C3;
+static const field dynamic var4 = #C4;
+static method fn() → dynamic {
+  core::String local = "str";
+  return local.{core::String::[]}(0);
+}
+static method fn2() → dynamic {
+  try {
+    core::String x = (#C1).{core::String::[]}(1.{core::int::unary-}());
+  }
+  on core::RangeError catch(no-exception-var) {
+    return 2;
+  }
+}
+static method main() → void {
+  exp::Expect::equals(#C2, "r");
+  exp::Expect::equals(#C3, "s");
+  exp::Expect::equals(#C3, "s");
+  exp::Expect::equals(#C4, 2);
+}
+
+constants  {
+  #C1 = "str"
+  #C2 = "r"
+  #C3 = "s"
+  #C4 = 2
+}
+
+Extra constant evaluation status:
+Evaluated: MethodInvocation @ org-dartlang-testcase:///const_functions_string.dart:23:17 -> IntConstant(-1)
+Extra constant evaluation: evaluated: 8, effectively constant: 1
diff --git a/pkg/front_end/testcases/const_functions/const_functions_string_error.dart b/pkg/front_end/testcases/const_functions/const_functions_string_error.dart
new file mode 100644
index 0000000..5f892a6
--- /dev/null
+++ b/pkg/front_end/testcases/const_functions/const_functions_string_error.dart
@@ -0,0 +1,31 @@
+// Copyright (c) 2021, the Dart project authors.  Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+// Tests erroneous string usage with const functions.
+
+import "package:expect/expect.dart";
+
+const String str = "str";
+const var1 = str[-1];
+const var2 = str[3];
+
+const var3 = fn();
+fn() {
+  String s = "str";
+  return str[-1];
+}
+
+const var4 = fn2();
+fn2() {
+  String s = "str";
+  return str[3];
+}
+
+const var5 = fn3();
+fn3() {
+  String s = "str";
+  return str[1.1];
+}
+
+void main() {}
diff --git a/pkg/front_end/testcases/const_functions/const_functions_string_error.dart.strong.expect b/pkg/front_end/testcases/const_functions/const_functions_string_error.dart.strong.expect
new file mode 100644
index 0000000..0cdd42f
--- /dev/null
+++ b/pkg/front_end/testcases/const_functions/const_functions_string_error.dart.strong.expect
@@ -0,0 +1,68 @@
+library /*isNonNullableByDefault*/;
+//
+// Problems in library:
+//
+// pkg/front_end/testcases/const_functions/const_functions_string_error.dart:28:14: Error: A value of type 'double' can't be assigned to a variable of type 'int'.
+//   return str[1.1];
+//              ^
+//
+// pkg/front_end/testcases/const_functions/const_functions_string_error.dart:10:17: Error: Constant evaluation error:
+// const var1 = str[-1];
+//                 ^
+// pkg/front_end/testcases/const_functions/const_functions_string_error.dart:10:17: Context: Unhandled core exception: RangeError: Index out of range: index must not be negative: -1
+// const var1 = str[-1];
+//                 ^
+//
+// pkg/front_end/testcases/const_functions/const_functions_string_error.dart:11:17: Error: Constant evaluation error:
+// const var2 = str[3];
+//                 ^
+// pkg/front_end/testcases/const_functions/const_functions_string_error.dart:11:17: Context: Unhandled core exception: RangeError: Index out of range: index should be less than 3: 3
+// const var2 = str[3];
+//                 ^
+//
+// pkg/front_end/testcases/const_functions/const_functions_string_error.dart:13:14: Error: Constant evaluation error:
+// const var3 = fn();
+//              ^
+// pkg/front_end/testcases/const_functions/const_functions_string_error.dart:16:13: Context: Unhandled core exception: RangeError: Index out of range: index must not be negative: -1
+//   return str[-1];
+//             ^
+//
+// pkg/front_end/testcases/const_functions/const_functions_string_error.dart:19:14: Error: Constant evaluation error:
+// const var4 = fn2();
+//              ^
+// pkg/front_end/testcases/const_functions/const_functions_string_error.dart:22:13: Context: Unhandled core exception: RangeError: Index out of range: index should be less than 3: 3
+//   return str[3];
+//             ^
+//
+import self as self;
+import "dart:core" as core;
+
+import "package:expect/expect.dart";
+
+static const field core::String str = #C1;
+static const field core::String var1 = invalid-expression "Unhandled core exception: RangeError: Index out of range: index must not be negative: -1";
+static const field core::String var2 = invalid-expression "Unhandled core exception: RangeError: Index out of range: index should be less than 3: 3";
+static const field dynamic var3 = invalid-expression "Unhandled core exception: RangeError: Index out of range: index must not be negative: -1";
+static const field dynamic var4 = invalid-expression "Unhandled core exception: RangeError: Index out of range: index should be less than 3: 3";
+static const field dynamic var5 = invalid-expression "pkg/front_end/testcases/const_functions/const_functions_string_error.dart:28:14: Error: A value of type 'double' can't be assigned to a variable of type 'int'.
+  return str[1.1];
+             ^";
+static method fn() → dynamic {
+  core::String s = "str";
+  return (#C1).{core::String::[]}(1.{core::int::unary-}());
+}
+static method fn2() → dynamic {
+  core::String s = "str";
+  return (#C1).{core::String::[]}(3);
+}
+static method fn3() → dynamic {
+  core::String s = "str";
+  return (#C1).{core::String::[]}(let final Never #t1 = invalid-expression "pkg/front_end/testcases/const_functions/const_functions_string_error.dart:28:14: Error: A value of type 'double' can't be assigned to a variable of type 'int'.
+  return str[1.1];
+             ^" in 1.1 as{TypeError,ForNonNullableByDefault} core::int);
+}
+static method main() → void {}
+
+constants  {
+  #C1 = "str"
+}
diff --git a/pkg/front_end/testcases/const_functions/const_functions_string_error.dart.strong.transformed.expect b/pkg/front_end/testcases/const_functions/const_functions_string_error.dart.strong.transformed.expect
new file mode 100644
index 0000000..e7133c8
--- /dev/null
+++ b/pkg/front_end/testcases/const_functions/const_functions_string_error.dart.strong.transformed.expect
@@ -0,0 +1,72 @@
+library /*isNonNullableByDefault*/;
+//
+// Problems in library:
+//
+// pkg/front_end/testcases/const_functions/const_functions_string_error.dart:28:14: Error: A value of type 'double' can't be assigned to a variable of type 'int'.
+//   return str[1.1];
+//              ^
+//
+// pkg/front_end/testcases/const_functions/const_functions_string_error.dart:10:17: Error: Constant evaluation error:
+// const var1 = str[-1];
+//                 ^
+// pkg/front_end/testcases/const_functions/const_functions_string_error.dart:10:17: Context: Unhandled core exception: RangeError: Index out of range: index must not be negative: -1
+// const var1 = str[-1];
+//                 ^
+//
+// pkg/front_end/testcases/const_functions/const_functions_string_error.dart:11:17: Error: Constant evaluation error:
+// const var2 = str[3];
+//                 ^
+// pkg/front_end/testcases/const_functions/const_functions_string_error.dart:11:17: Context: Unhandled core exception: RangeError: Index out of range: index should be less than 3: 3
+// const var2 = str[3];
+//                 ^
+//
+// pkg/front_end/testcases/const_functions/const_functions_string_error.dart:13:14: Error: Constant evaluation error:
+// const var3 = fn();
+//              ^
+// pkg/front_end/testcases/const_functions/const_functions_string_error.dart:16:13: Context: Unhandled core exception: RangeError: Index out of range: index must not be negative: -1
+//   return str[-1];
+//             ^
+//
+// pkg/front_end/testcases/const_functions/const_functions_string_error.dart:19:14: Error: Constant evaluation error:
+// const var4 = fn2();
+//              ^
+// pkg/front_end/testcases/const_functions/const_functions_string_error.dart:22:13: Context: Unhandled core exception: RangeError: Index out of range: index should be less than 3: 3
+//   return str[3];
+//             ^
+//
+import self as self;
+import "dart:core" as core;
+
+import "package:expect/expect.dart";
+
+static const field core::String str = #C1;
+static const field core::String var1 = invalid-expression "Unhandled core exception: RangeError: Index out of range: index must not be negative: -1";
+static const field core::String var2 = invalid-expression "Unhandled core exception: RangeError: Index out of range: index should be less than 3: 3";
+static const field dynamic var3 = invalid-expression "Unhandled core exception: RangeError: Index out of range: index must not be negative: -1";
+static const field dynamic var4 = invalid-expression "Unhandled core exception: RangeError: Index out of range: index should be less than 3: 3";
+static const field dynamic var5 = invalid-expression "pkg/front_end/testcases/const_functions/const_functions_string_error.dart:28:14: Error: A value of type 'double' can't be assigned to a variable of type 'int'.
+  return str[1.1];
+             ^";
+static method fn() → dynamic {
+  core::String s = "str";
+  return (#C1).{core::String::[]}(1.{core::int::unary-}());
+}
+static method fn2() → dynamic {
+  core::String s = "str";
+  return (#C1).{core::String::[]}(3);
+}
+static method fn3() → dynamic {
+  core::String s = "str";
+  return (#C1).{core::String::[]}(let final Never #t1 = invalid-expression "pkg/front_end/testcases/const_functions/const_functions_string_error.dart:28:14: Error: A value of type 'double' can't be assigned to a variable of type 'int'.
+  return str[1.1];
+             ^" in 1.1 as{TypeError,ForNonNullableByDefault} core::int);
+}
+static method main() → void {}
+
+constants  {
+  #C1 = "str"
+}
+
+Extra constant evaluation status:
+Evaluated: MethodInvocation @ org-dartlang-testcase:///const_functions_string_error.dart:16:14 -> IntConstant(-1)
+Extra constant evaluation: evaluated: 6, effectively constant: 1
diff --git a/pkg/front_end/testcases/const_functions/const_functions_string_error.dart.textual_outline.expect b/pkg/front_end/testcases/const_functions/const_functions_string_error.dart.textual_outline.expect
new file mode 100644
index 0000000..27583e1
--- /dev/null
+++ b/pkg/front_end/testcases/const_functions/const_functions_string_error.dart.textual_outline.expect
@@ -0,0 +1,12 @@
+import "package:expect/expect.dart";
+
+const String str = "str";
+const var1 = str[-1];
+const var2 = str[3];
+const var3 = fn();
+fn() {}
+const var4 = fn2();
+fn2() {}
+const var5 = fn3();
+fn3() {}
+void main() {}
diff --git a/pkg/front_end/testcases/const_functions/const_functions_string_error.dart.textual_outline_modelled.expect b/pkg/front_end/testcases/const_functions/const_functions_string_error.dart.textual_outline_modelled.expect
new file mode 100644
index 0000000..9227263
--- /dev/null
+++ b/pkg/front_end/testcases/const_functions/const_functions_string_error.dart.textual_outline_modelled.expect
@@ -0,0 +1,12 @@
+import "package:expect/expect.dart";
+
+const String str = "str";
+const var1 = str[-1];
+const var2 = str[3];
+const var3 = fn();
+const var4 = fn2();
+const var5 = fn3();
+fn() {}
+fn2() {}
+fn3() {}
+void main() {}
diff --git a/pkg/front_end/testcases/const_functions/const_functions_string_error.dart.weak.expect b/pkg/front_end/testcases/const_functions/const_functions_string_error.dart.weak.expect
new file mode 100644
index 0000000..0cdd42f
--- /dev/null
+++ b/pkg/front_end/testcases/const_functions/const_functions_string_error.dart.weak.expect
@@ -0,0 +1,68 @@
+library /*isNonNullableByDefault*/;
+//
+// Problems in library:
+//
+// pkg/front_end/testcases/const_functions/const_functions_string_error.dart:28:14: Error: A value of type 'double' can't be assigned to a variable of type 'int'.
+//   return str[1.1];
+//              ^
+//
+// pkg/front_end/testcases/const_functions/const_functions_string_error.dart:10:17: Error: Constant evaluation error:
+// const var1 = str[-1];
+//                 ^
+// pkg/front_end/testcases/const_functions/const_functions_string_error.dart:10:17: Context: Unhandled core exception: RangeError: Index out of range: index must not be negative: -1
+// const var1 = str[-1];
+//                 ^
+//
+// pkg/front_end/testcases/const_functions/const_functions_string_error.dart:11:17: Error: Constant evaluation error:
+// const var2 = str[3];
+//                 ^
+// pkg/front_end/testcases/const_functions/const_functions_string_error.dart:11:17: Context: Unhandled core exception: RangeError: Index out of range: index should be less than 3: 3
+// const var2 = str[3];
+//                 ^
+//
+// pkg/front_end/testcases/const_functions/const_functions_string_error.dart:13:14: Error: Constant evaluation error:
+// const var3 = fn();
+//              ^
+// pkg/front_end/testcases/const_functions/const_functions_string_error.dart:16:13: Context: Unhandled core exception: RangeError: Index out of range: index must not be negative: -1
+//   return str[-1];
+//             ^
+//
+// pkg/front_end/testcases/const_functions/const_functions_string_error.dart:19:14: Error: Constant evaluation error:
+// const var4 = fn2();
+//              ^
+// pkg/front_end/testcases/const_functions/const_functions_string_error.dart:22:13: Context: Unhandled core exception: RangeError: Index out of range: index should be less than 3: 3
+//   return str[3];
+//             ^
+//
+import self as self;
+import "dart:core" as core;
+
+import "package:expect/expect.dart";
+
+static const field core::String str = #C1;
+static const field core::String var1 = invalid-expression "Unhandled core exception: RangeError: Index out of range: index must not be negative: -1";
+static const field core::String var2 = invalid-expression "Unhandled core exception: RangeError: Index out of range: index should be less than 3: 3";
+static const field dynamic var3 = invalid-expression "Unhandled core exception: RangeError: Index out of range: index must not be negative: -1";
+static const field dynamic var4 = invalid-expression "Unhandled core exception: RangeError: Index out of range: index should be less than 3: 3";
+static const field dynamic var5 = invalid-expression "pkg/front_end/testcases/const_functions/const_functions_string_error.dart:28:14: Error: A value of type 'double' can't be assigned to a variable of type 'int'.
+  return str[1.1];
+             ^";
+static method fn() → dynamic {
+  core::String s = "str";
+  return (#C1).{core::String::[]}(1.{core::int::unary-}());
+}
+static method fn2() → dynamic {
+  core::String s = "str";
+  return (#C1).{core::String::[]}(3);
+}
+static method fn3() → dynamic {
+  core::String s = "str";
+  return (#C1).{core::String::[]}(let final Never #t1 = invalid-expression "pkg/front_end/testcases/const_functions/const_functions_string_error.dart:28:14: Error: A value of type 'double' can't be assigned to a variable of type 'int'.
+  return str[1.1];
+             ^" in 1.1 as{TypeError,ForNonNullableByDefault} core::int);
+}
+static method main() → void {}
+
+constants  {
+  #C1 = "str"
+}
diff --git a/pkg/front_end/testcases/const_functions/const_functions_string_error.dart.weak.outline.expect b/pkg/front_end/testcases/const_functions/const_functions_string_error.dart.weak.outline.expect
new file mode 100644
index 0000000..183676d
--- /dev/null
+++ b/pkg/front_end/testcases/const_functions/const_functions_string_error.dart.weak.outline.expect
@@ -0,0 +1,27 @@
+library /*isNonNullableByDefault*/;
+import self as self;
+import "dart:core" as core;
+
+import "package:expect/expect.dart";
+
+static const field core::String str = "str";
+static const field core::String var1 = self::str.{core::String::[]}(1.{core::int::unary-}());
+static const field core::String var2 = self::str.{core::String::[]}(3);
+static const field dynamic var3 = self::fn();
+static const field dynamic var4 = self::fn2();
+static const field dynamic var5 = self::fn3();
+static method fn() → dynamic
+  ;
+static method fn2() → dynamic
+  ;
+static method fn3() → dynamic
+  ;
+static method main() → void
+  ;
+
+
+Extra constant evaluation status:
+Evaluated: StaticGet @ org-dartlang-testcase:///const_functions_string_error.dart:10:14 -> StringConstant("str")
+Evaluated: MethodInvocation @ org-dartlang-testcase:///const_functions_string_error.dart:10:18 -> IntConstant(-1)
+Evaluated: StaticGet @ org-dartlang-testcase:///const_functions_string_error.dart:11:14 -> StringConstant("str")
+Extra constant evaluation: evaluated: 8, effectively constant: 3
diff --git a/pkg/front_end/testcases/const_functions/const_functions_string_error.dart.weak.transformed.expect b/pkg/front_end/testcases/const_functions/const_functions_string_error.dart.weak.transformed.expect
new file mode 100644
index 0000000..e7133c8
--- /dev/null
+++ b/pkg/front_end/testcases/const_functions/const_functions_string_error.dart.weak.transformed.expect
@@ -0,0 +1,72 @@
+library /*isNonNullableByDefault*/;
+//
+// Problems in library:
+//
+// pkg/front_end/testcases/const_functions/const_functions_string_error.dart:28:14: Error: A value of type 'double' can't be assigned to a variable of type 'int'.
+//   return str[1.1];
+//              ^
+//
+// pkg/front_end/testcases/const_functions/const_functions_string_error.dart:10:17: Error: Constant evaluation error:
+// const var1 = str[-1];
+//                 ^
+// pkg/front_end/testcases/const_functions/const_functions_string_error.dart:10:17: Context: Unhandled core exception: RangeError: Index out of range: index must not be negative: -1
+// const var1 = str[-1];
+//                 ^
+//
+// pkg/front_end/testcases/const_functions/const_functions_string_error.dart:11:17: Error: Constant evaluation error:
+// const var2 = str[3];
+//                 ^
+// pkg/front_end/testcases/const_functions/const_functions_string_error.dart:11:17: Context: Unhandled core exception: RangeError: Index out of range: index should be less than 3: 3
+// const var2 = str[3];
+//                 ^
+//
+// pkg/front_end/testcases/const_functions/const_functions_string_error.dart:13:14: Error: Constant evaluation error:
+// const var3 = fn();
+//              ^
+// pkg/front_end/testcases/const_functions/const_functions_string_error.dart:16:13: Context: Unhandled core exception: RangeError: Index out of range: index must not be negative: -1
+//   return str[-1];
+//             ^
+//
+// pkg/front_end/testcases/const_functions/const_functions_string_error.dart:19:14: Error: Constant evaluation error:
+// const var4 = fn2();
+//              ^
+// pkg/front_end/testcases/const_functions/const_functions_string_error.dart:22:13: Context: Unhandled core exception: RangeError: Index out of range: index should be less than 3: 3
+//   return str[3];
+//             ^
+//
+import self as self;
+import "dart:core" as core;
+
+import "package:expect/expect.dart";
+
+static const field core::String str = #C1;
+static const field core::String var1 = invalid-expression "Unhandled core exception: RangeError: Index out of range: index must not be negative: -1";
+static const field core::String var2 = invalid-expression "Unhandled core exception: RangeError: Index out of range: index should be less than 3: 3";
+static const field dynamic var3 = invalid-expression "Unhandled core exception: RangeError: Index out of range: index must not be negative: -1";
+static const field dynamic var4 = invalid-expression "Unhandled core exception: RangeError: Index out of range: index should be less than 3: 3";
+static const field dynamic var5 = invalid-expression "pkg/front_end/testcases/const_functions/const_functions_string_error.dart:28:14: Error: A value of type 'double' can't be assigned to a variable of type 'int'.
+  return str[1.1];
+             ^";
+static method fn() → dynamic {
+  core::String s = "str";
+  return (#C1).{core::String::[]}(1.{core::int::unary-}());
+}
+static method fn2() → dynamic {
+  core::String s = "str";
+  return (#C1).{core::String::[]}(3);
+}
+static method fn3() → dynamic {
+  core::String s = "str";
+  return (#C1).{core::String::[]}(let final Never #t1 = invalid-expression "pkg/front_end/testcases/const_functions/const_functions_string_error.dart:28:14: Error: A value of type 'double' can't be assigned to a variable of type 'int'.
+  return str[1.1];
+             ^" in 1.1 as{TypeError,ForNonNullableByDefault} core::int);
+}
+static method main() → void {}
+
+constants  {
+  #C1 = "str"
+}
+
+Extra constant evaluation status:
+Evaluated: MethodInvocation @ org-dartlang-testcase:///const_functions_string_error.dart:16:14 -> IntConstant(-1)
+Extra constant evaluation: evaluated: 6, effectively constant: 1
diff --git a/runtime/vm/elf.h b/runtime/vm/elf.h
index d0f8a96..fb27dc2 100644
--- a/runtime/vm/elf.h
+++ b/runtime/vm/elf.h
@@ -32,7 +32,7 @@
 
   Elf(Zone* zone, BaseWriteStream* stream, Type type, Dwarf* dwarf = nullptr);
 
-  static constexpr intptr_t kPageSize = 4096;
+  static constexpr intptr_t kPageSize = 16 * KB;
   static constexpr uword kNoSectionStart = 0;
 
   bool IsStripped() const { return dwarf_ == nullptr; }
diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc
index 08b8d07..4256646 100644
--- a/runtime/vm/object.cc
+++ b/runtime/vm/object.cc
@@ -10148,19 +10148,25 @@
 }
 
 void Field::DisableFieldUnboxing() const {
-  Thread* thread = Thread::Current();
   ASSERT(!IsOriginal());
   const Field& original = Field::Handle(Original());
   if (!original.is_unboxing_candidate()) {
     return;
   }
+  auto thread = Thread::Current();
   SafepointWriteRwLocker ml(thread, thread->isolate_group()->program_lock());
   if (!original.is_unboxing_candidate()) {
     return;
   }
-  original.set_is_unboxing_candidate(false);
-  set_is_unboxing_candidate(false);
-  original.DeoptimizeDependentCode();
+
+  // Ensures that to-be-disabled existing code won't continue running as we
+  // update field properties as it might write into now boxed field thinking
+  // it still holds unboxed(reusable box) value.
+  thread->isolate_group()->RunWithStoppedMutators([&]() {
+    original.set_is_unboxing_candidate(false);
+    set_is_unboxing_candidate(false);
+    original.DeoptimizeDependentCode();
+  });
 }
 
 intptr_t Field::guarded_cid() const {
diff --git a/tests/language/const_functions/const_functions_string_error_test.dart b/tests/language/const_functions/const_functions_string_error_test.dart
new file mode 100644
index 0000000..2d89d66
--- /dev/null
+++ b/tests/language/const_functions/const_functions_string_error_test.dart
@@ -0,0 +1,50 @@
+// Copyright (c) 2021, the Dart project authors.  Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+// Tests erroneous string usage with const functions.
+
+// SharedOptions=--enable-experiment=const-functions
+
+import "package:expect/expect.dart";
+
+const String str = "str";
+const var1 = str[-1];
+//           ^^^^^^^
+// [analyzer] COMPILE_TIME_ERROR.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE
+//              ^
+// [cfe] Constant evaluation error:
+const var2 = str[3];
+//           ^^^^^^
+// [analyzer] COMPILE_TIME_ERROR.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE
+//              ^
+// [cfe] Constant evaluation error:
+
+const var3 = fn();
+//           ^^^^
+// [analyzer] COMPILE_TIME_ERROR.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE
+// [cfe] Constant evaluation error:
+fn() {
+  String s = "str";
+  return str[-1];
+}
+
+const var4 = fn2();
+//           ^^^^^
+// [analyzer] COMPILE_TIME_ERROR.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE
+// [cfe] Constant evaluation error:
+fn2() {
+  String s = "str";
+  return str[3];
+}
+
+const var5 = fn3();
+//           ^^^^^
+// [analyzer] COMPILE_TIME_ERROR.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE
+fn3() {
+  String s = "str";
+  return str[1.1];
+  //         ^^^
+  // [analyzer] COMPILE_TIME_ERROR.ARGUMENT_TYPE_NOT_ASSIGNABLE
+  // [cfe] A value of type 'double' can't be assigned to a variable of type 'int'.
+}
diff --git a/tests/language/const_functions/const_functions_string_test.dart b/tests/language/const_functions/const_functions_string_test.dart
new file mode 100644
index 0000000..1cbc4396
--- /dev/null
+++ b/tests/language/const_functions/const_functions_string_test.dart
@@ -0,0 +1,44 @@
+// Copyright (c) 2021, the Dart project authors.  Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+// Tests string usage with const functions.
+
+// SharedOptions=--enable-experiment=const-functions
+
+import "package:expect/expect.dart";
+
+const String str = "str";
+const var1 = str[2];
+//           ^^^^^^
+// [analyzer] COMPILE_TIME_ERROR.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE
+
+const var2 = fn();
+//           ^^^^
+// [analyzer] COMPILE_TIME_ERROR.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE
+fn() {
+  String local = "str";
+  return local[0];
+}
+
+const var3 = "str"[0];
+//           ^^^^^^^^
+// [analyzer] COMPILE_TIME_ERROR.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE
+
+const var4 = fn2();
+//           ^^^^^
+// [analyzer] COMPILE_TIME_ERROR.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE
+fn2() {
+  try {
+    var x = str[-1];
+  } on RangeError {
+    return 2;
+  }
+}
+
+void main() {
+  Expect.equals(var1, 'r');
+  Expect.equals(var2, 's');
+  Expect.equals(var3, 's');
+  Expect.equals(var4, 2);
+}
diff --git a/tools/VERSION b/tools/VERSION
index c1ed934..a536092 100644
--- a/tools/VERSION
+++ b/tools/VERSION
@@ -27,5 +27,5 @@
 MAJOR 2
 MINOR 14
 PATCH 0
-PRERELEASE 16
+PRERELEASE 17
 PRERELEASE_PATCH 0
\ No newline at end of file
diff --git a/tools/spec_parse.py b/tools/spec_parse.py
index d9238f5..777475f 100755
--- a/tools/spec_parse.py
+++ b/tools/spec_parse.py
@@ -14,12 +14,9 @@
 #   - the ANTLR3 jar is available as /usr/share/java/antlr4-runtime.jar.
 
 import os
-import string
 import subprocess
 import sys
 
-import utils
-
 
 def Help(missing):
     print('Execution of the spec parser failed. Missing: ' + missing)
@@ -33,18 +30,14 @@
     spec_parser_dir = os.path.join(tools_dir, 'spec_parser')
     spec_parser_file = os.path.join(spec_parser_dir, 'SpecParser.class')
     antlr_jar = '/usr/share/java/antlr4-runtime.jar'
-    class_path = string.join([spec_parser_dir, antlr_jar], ':')
+    class_path = ':'.join([spec_parser_dir, antlr_jar])
     command = ['java', '-cp', class_path, 'SpecParser'] + args
 
     if not os.path.exists(antlr_jar): Help(antlr_jar)
     if not os.path.exists(spec_parser_file):
         Help('"make parser" in spec_parser')
 
-    with utils.CoreDumpArchiver(args):
-        exit_code = subprocess.call(command)
-
-    utils.DiagnoseExitCode(exit_code, command)
-    return exit_code
+    return subprocess.call(command)
 
 
 if __name__ == '__main__':