diff --git a/pkg/analysis_server/test/abstract_context.dart b/pkg/analysis_server/test/abstract_context.dart index a5ac7d5b586..eeb14710f7b 100644 --- a/pkg/analysis_server/test/abstract_context.dart +++ b/pkg/analysis_server/test/abstract_context.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/dart/analysis/analysis_context.dart'; import 'package:analyzer/dart/analysis/results.dart'; import 'package:analyzer/dart/analysis/session.dart'; @@ -26,8 +24,8 @@ import 'package:meta/meta.dart'; import 'src/utilities/mock_packages.dart'; /// Finds an [Element] with the given [name]. -Element findChildElement(Element root, String name, [ElementKind kind]) { - Element result; +Element? findChildElement(Element root, String name, [ElementKind? kind]) { + Element? result; root.accept(_ElementVisitorFunctionWrapper((Element element) { if (element.name != name) { return; @@ -49,11 +47,11 @@ class AbstractContextTest with ResourceProviderMixin { final ByteStore _byteStore = MemoryByteStore(); final Map _declaredVariables = {}; - AnalysisContextCollectionImpl _analysisContextCollection; + AnalysisContextCollectionImpl? _analysisContextCollection; List get allDrivers { _createAnalysisContexts(); - return _analysisContextCollection.contexts.map((e) => e.driver).toList(); + return _analysisContextCollection!.contexts.map((e) => e.driver).toList(); } /// The file system specific `/home/test/analysis_options.yaml` path. @@ -73,7 +71,7 @@ class AbstractContextTest with ResourceProviderMixin { AnalysisSession get session => contextFor('/home/test').currentSession; - String get testPackageLanguageVersion => '2.9'; + String? get testPackageLanguageVersion => '2.9'; String get testPackageLibPath => '$testPackageRootPath/lib'; @@ -107,9 +105,9 @@ class AbstractContextTest with ResourceProviderMixin { /// Create an analysis options file based on the given arguments. void createAnalysisOptionsFile({ - List experiments, - bool implicitCasts, - List lints, + List? experiments, + bool? implicitCasts, + List? lints, }) { var buffer = StringBuffer(); @@ -147,16 +145,16 @@ class AbstractContextTest with ResourceProviderMixin { /// Return the existing analysis context that should be used to analyze the /// given [path], or throw [StateError] if the [path] is not analyzed in any /// of the created analysis contexts. - AnalysisContext getContext(String path) { + DriverBasedAnalysisContext getContext(String path) { path = convertPath(path); - return _analysisContextCollection.contextFor(path); + return _analysisContextCollection!.contextFor(path); } /// Return the existing analysis driver that should be used to analyze the /// given [path], or throw [StateError] if the [path] is not analyzed in any /// of the created analysis contexts. AnalysisDriver getDriver(String path) { - DriverBasedAnalysisContext context = getContext(path); + var context = getContext(path); return context.driver; } @@ -210,8 +208,8 @@ class AbstractContextTest with ResourceProviderMixin { } void writeTestPackageConfig({ - PackageConfigFileBuilder config, - String languageVersion, + PackageConfigFileBuilder? config, + String? languageVersion, bool flutter = false, bool meta = false, bool vector_math = false, @@ -254,7 +252,7 @@ class AbstractContextTest with ResourceProviderMixin { } void _addAnalyzedFilesToDrivers() { - for (var analysisContext in _analysisContextCollection.contexts) { + for (var analysisContext in _analysisContextCollection!.contexts) { for (var path in analysisContext.contextRoot.analyzedFiles()) { if (file_paths.isDart(resourceProvider.pathContext, path)) { analysisContext.driver.addFile(path); @@ -264,8 +262,9 @@ class AbstractContextTest with ResourceProviderMixin { } void _addAnalyzedFileToDrivers(String path) { - if (_analysisContextCollection != null) { - for (var analysisContext in _analysisContextCollection.contexts) { + var collection = _analysisContextCollection; + if (collection != null) { + for (var analysisContext in collection.contexts) { if (analysisContext.contextRoot.isAnalyzed(path)) { analysisContext.driver.addFile(path); } @@ -277,7 +276,7 @@ class AbstractContextTest with ResourceProviderMixin { _createAnalysisContexts(); path = convertPath(path); - return _analysisContextCollection.contextFor(path); + return _analysisContextCollection!.contextFor(path); } /// Create all analysis contexts in [collectionIncludedPaths]. @@ -302,7 +301,7 @@ class AbstractContextTest with ResourceProviderMixin { mixin WithNonFunctionTypeAliasesMixin on AbstractContextTest { @override - String get testPackageLanguageVersion => null; + String? get testPackageLanguageVersion => null; @override void setUp() { diff --git a/pkg/analysis_server/test/abstract_single_unit.dart b/pkg/analysis_server/test/abstract_single_unit.dart index 96e5da9ed08..6e2a9e50156 100644 --- a/pkg/analysis_server/test/abstract_single_unit.dart +++ b/pkg/analysis_server/test/abstract_single_unit.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/dart/analysis/results.dart'; import 'package:analyzer/dart/ast/ast.dart'; import 'package:analyzer/dart/element/element.dart'; @@ -23,14 +21,14 @@ class AbstractSingleUnitTest extends AbstractContextTest { /// Whether to rewrite line endings in test code based on platform. bool useLineEndingsForPlatform = false; - String testCode; - String testFile; - ResolvedUnitResult testAnalysisResult; - CompilationUnit testUnit; - CompilationUnitElement testUnitElement; - LibraryElement testLibraryElement; - FindNode findNode; - FindElement findElement; + late String testCode; + late String testFile; + ResolvedUnitResult? testAnalysisResult; + late CompilationUnit testUnit; + late CompilationUnitElement testUnitElement; + late LibraryElement testLibraryElement; + late FindNode findNode; + late FindElement findElement; @override void addSource(String path, String content) { @@ -72,11 +70,12 @@ class AbstractSingleUnitTest extends AbstractContextTest { } Future resolveTestFile() async { - testAnalysisResult = await session.getResolvedUnit(testFile); - testCode = testAnalysisResult.content; - testUnit = testAnalysisResult.unit; + var result = await session.getResolvedUnit(testFile); + testAnalysisResult = result; + testCode = result.content!; + testUnit = result.unit!; if (verifyNoTestUnitErrors) { - expect(testAnalysisResult.errors.where((AnalysisError error) { + expect(result.errors.where((AnalysisError error) { return error.errorCode != HintCode.DEAD_CODE && error.errorCode != HintCode.UNUSED_CATCH_CLAUSE && error.errorCode != HintCode.UNUSED_CATCH_STACK && @@ -86,7 +85,7 @@ class AbstractSingleUnitTest extends AbstractContextTest { error.errorCode != HintCode.UNUSED_LOCAL_VARIABLE; }), isEmpty); } - testUnitElement = testUnit.declaredElement; + testUnitElement = testUnit.declaredElement!; testLibraryElement = testUnitElement.library; findNode = FindNode(testCode, testUnit); findElement = FindElement(testUnit); diff --git a/pkg/analysis_server/test/src/utilities/mock_packages.dart b/pkg/analysis_server/test/src/utilities/mock_packages.dart index 714c50c7153..3df14ee8f1b 100644 --- a/pkg/analysis_server/test/src/utilities/mock_packages.dart +++ b/pkg/analysis_server/test/src/utilities/mock_packages.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/file_system/file_system.dart'; import 'package:analyzer/file_system/memory_file_system.dart'; import 'package:analyzer/file_system/physical_file_system.dart'; @@ -59,13 +57,13 @@ class BazelMockPackages { Folder _addFiles(MemoryResourceProvider provider, String packageName) { var packagesPath = provider.convertPath('/workspace/third_party/dart'); - for (var relativePosixPath in _cachedFiles.keys) { + for (var entry in _cachedFiles.entries) { + var relativePosixPath = entry.key; var relativePathComponents = relativePosixPath.split('/'); if (relativePathComponents[0] == packageName) { var relativePath = provider.pathContext.joinAll(relativePathComponents); var path = provider.pathContext.join(packagesPath, relativePath); - var content = _cachedFiles[relativePosixPath]; - provider.newFile(path, content); + provider.newFile(path, entry.value); } } @@ -114,13 +112,13 @@ class MockPackages { Folder _addFiles(MemoryResourceProvider provider, String packageName) { var packagesPath = provider.convertPath('/packages'); - for (var relativePosixPath in _cachedFiles.keys) { + for (var entry in _cachedFiles.entries) { + var relativePosixPath = entry.key; var relativePathComponents = relativePosixPath.split('/'); if (relativePathComponents[0] == packageName) { var relativePath = provider.pathContext.joinAll(relativePathComponents); var path = provider.pathContext.join(packagesPath, relativePath); - var content = _cachedFiles[relativePosixPath]; - provider.newFile(path, content); + provider.newFile(path, entry.value); } }