From c38742cdbcd41961786d54536d5aeb1350c4ccfc Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Fri, 15 May 2020 16:49:32 +0000 Subject: [PATCH] Migration: remove references from analysis_server to nnbd_migration. Change-Id: I90b562b8b3e82b770f197d7ef2c4e10ac9f99100 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/148160 Reviewed-by: Janice Collins Commit-Queue: Paul Berry --- .../lib/src/analysis_server_abstract.dart | 2 +- .../lib/src/api_for_nnbd_migration.dart} | 23 ++- .../lib/src/edit/edit_dartfix.dart | 25 --- .../lib/src/edit/fix/dartfix_info.dart | 12 -- .../lib/src/edit/fix/dartfix_listener.dart | 13 +- .../lib/src/edit/fix/fix_code_task.dart | 11 -- pkg/analysis_server/pubspec.yaml | 1 - .../test/domain_edit_dartfix_test.dart | 86 ----------- .../src/edit/fix/dartfix_listener_test.dart | 36 ----- .../src/edit/fix/non_nullable_fix_test.dart | 143 ------------------ .../test/src/edit/fix/test_all.dart | 15 -- .../test/src/edit/test_all.dart | 13 -- pkg/analysis_server/test/src/test_all.dart | 2 - .../driver_provider.dart | 14 -- pkg/nnbd_migration/lib/migration_cli.dart | 9 +- .../lib/src/front_end/info_builder.dart | 3 +- .../lib/src/front_end/migration_state.dart | 2 +- .../lib/src/front_end}/non_nullable_fix.dart | 6 +- .../front_end/nnbd_migration_test_base.dart | 8 +- .../test/migration_cli_test.dart | 2 +- 20 files changed, 41 insertions(+), 385 deletions(-) rename pkg/{nnbd_migration/lib/api_for_analysis_server/dartfix_listener_interface.dart => analysis_server/lib/src/api_for_nnbd_migration.dart} (54%) delete mode 100644 pkg/analysis_server/test/src/edit/fix/dartfix_listener_test.dart delete mode 100644 pkg/analysis_server/test/src/edit/fix/non_nullable_fix_test.dart delete mode 100644 pkg/analysis_server/test/src/edit/fix/test_all.dart delete mode 100644 pkg/analysis_server/test/src/edit/test_all.dart delete mode 100644 pkg/nnbd_migration/lib/api_for_analysis_server/driver_provider.dart rename pkg/{analysis_server/lib/src/edit/fix => nnbd_migration/lib/src/front_end}/non_nullable_fix.dart (98%) diff --git a/pkg/analysis_server/lib/src/analysis_server_abstract.dart b/pkg/analysis_server/lib/src/analysis_server_abstract.dart index c7a9f6580d1..31adb88f06b 100644 --- a/pkg/analysis_server/lib/src/analysis_server_abstract.dart +++ b/pkg/analysis_server/lib/src/analysis_server_abstract.dart @@ -7,6 +7,7 @@ import 'dart:core'; import 'dart:io' as io; import 'package:analysis_server/src/analysis_server.dart'; +import 'package:analysis_server/src/api_for_nnbd_migration.dart'; import 'package:analysis_server/src/collections.dart'; import 'package:analysis_server/src/context_manager.dart'; import 'package:analysis_server/src/domains/completion/available_suggestions.dart'; @@ -47,7 +48,6 @@ import 'package:analyzer/src/generated/engine.dart'; import 'package:analyzer/src/generated/sdk.dart'; import 'package:analyzer/src/services/available_declarations.dart'; import 'package:analyzer/src/util/glob.dart'; -import 'package:nnbd_migration/api_for_analysis_server/driver_provider.dart'; /// Implementations of [AbstractAnalysisServer] implement a server that listens /// on a [CommunicationChannel] for analysis messages and process them. diff --git a/pkg/nnbd_migration/lib/api_for_analysis_server/dartfix_listener_interface.dart b/pkg/analysis_server/lib/src/api_for_nnbd_migration.dart similarity index 54% rename from pkg/nnbd_migration/lib/api_for_analysis_server/dartfix_listener_interface.dart rename to pkg/analysis_server/lib/src/api_for_nnbd_migration.dart index c2505a2bfe3..f39fbd374a5 100644 --- a/pkg/nnbd_migration/lib/api_for_analysis_server/dartfix_listener_interface.dart +++ b/pkg/analysis_server/lib/src/api_for_nnbd_migration.dart @@ -2,10 +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. +import 'package:analyzer/dart/analysis/session.dart'; +import 'package:analyzer/file_system/file_system.dart'; import 'package:analyzer/src/generated/source.dart'; import 'package:analyzer_plugin/protocol/protocol_common.dart'; -import 'package:nnbd_migration/api_for_analysis_server/driver_provider.dart'; +/// Abstract interface formerly used by NNBD migration to report changes to the +/// analysis server. Now that the analysis server no longer integrates with +/// NNBD migration, this exists only to support some tests that haven't yet been +/// modified to use the new NNBD migration infrastructure. +/// +/// TODO(paulberry): remove this interface once it's no longer needed. abstract class DartFixListenerInterface { DriverProvider get server; @@ -34,3 +41,17 @@ abstract class DartFixListenerInterface { /// [addEditWithoutRecommendation]. void addSuggestion(String description, Location location); } + +/// Abstract interface formerly used by NNBD migration to access the resource +/// provider and the analysis session. Now that the analysis server no longer +/// integrates with NNBD migration, this exists only to support some tests that +/// haven't yet been modified to use the new NNBD migration infrastructure. +/// +/// TODO(paulberry): remove this interface once it's no longer needed. +abstract class DriverProvider { + ResourceProvider get resourceProvider; + + /// Return the appropriate analysis session for the file with the given + /// [path]. + AnalysisSession getAnalysisSession(String path); +} diff --git a/pkg/analysis_server/lib/src/edit/edit_dartfix.dart b/pkg/analysis_server/lib/src/edit/edit_dartfix.dart index 82bb849d9c5..ef883bcfddc 100644 --- a/pkg/analysis_server/lib/src/edit/edit_dartfix.dart +++ b/pkg/analysis_server/lib/src/edit/edit_dartfix.dart @@ -14,7 +14,6 @@ import 'package:analysis_server/src/edit/fix/fix_lint_task.dart'; import 'package:analyzer/dart/analysis/results.dart'; import 'package:analyzer/dart/analysis/session.dart'; import 'package:analyzer/file_system/file_system.dart'; -import 'package:analyzer/src/dart/analysis/driver.dart'; import 'package:analyzer/src/generated/engine.dart' show AnalysisOptionsImpl; import 'package:analyzer/src/generated/source.dart' show SourceKind; @@ -122,9 +121,6 @@ class EditDartFix }; }); - // Set up the rerun function on the NNBD migration for interactivity. - nonNullableFixTask?.rerunFunction = rerunTasks; - bool hasErrors; try { hasErrors = await runAllTasks(); @@ -148,7 +144,6 @@ class EditDartFix hasErrors, listener.sourceChange.edits, details: listener.details, - urls: nonNullableFixTask?.previewUrls, ).toResponse(request.id); } @@ -250,26 +245,6 @@ class EditDartFix } } - Future rerunTasks([List changedPaths]) async { - listener.reset(); - if (changedPaths == null) { - final drivers = {}; - for (var path in getPathsToProcess()) { - drivers.add(server.getAnalysisDriver(path)); - } - for (final driver in drivers) { - driver.knownFiles.forEach(driver.changeFile); - } - } else { - for (var path in changedPaths) { - var driver = server.getAnalysisDriver(path); - driver.changeFile(path); - } - } - - return await runAllTasks(); - } - Future runAllTasks() async { // Process each package for (var pkgFolder in pkgFolders) { diff --git a/pkg/analysis_server/lib/src/edit/fix/dartfix_info.dart b/pkg/analysis_server/lib/src/edit/fix/dartfix_info.dart index 80f3f5ae1e4..0fe5aba1b2f 100644 --- a/pkg/analysis_server/lib/src/edit/fix/dartfix_info.dart +++ b/pkg/analysis_server/lib/src/edit/fix/dartfix_info.dart @@ -9,7 +9,6 @@ import 'package:analysis_server/src/edit/fix/dartfix_listener.dart'; import 'package:analysis_server/src/edit/fix/dartfix_registrar.dart'; import 'package:analysis_server/src/edit/fix/fix_error_task.dart'; import 'package:analysis_server/src/edit/fix/fix_lint_task.dart'; -import 'package:analysis_server/src/edit/fix/non_nullable_fix.dart'; import 'package:analysis_server/src/edit/fix/prefer_mixin_fix.dart'; import 'package:analysis_server/src/services/correction/fix.dart'; import 'package:analyzer/src/lint/registry.dart'; @@ -96,17 +95,6 @@ final allFixes = [ LintFixInfo.unnecessaryThis, LintFixInfo.useFunctionTypeSyntaxForParameters, LintFixInfo.useRethrowWhenPossible, - // - // Experimental fixes - // - DartFixInfo( - 'non-nullable', - ''' -EXPERIMENTAL: Update sources to be non-nullable by default. -This requires the experimental non-nullable flag to be enabled -when running the updated application.''', - NonNullableFix.task, - ), ]; /// [DartFixInfo] represents a fix that can be applied by [EditDartFix]. diff --git a/pkg/analysis_server/lib/src/edit/fix/dartfix_listener.dart b/pkg/analysis_server/lib/src/edit/fix/dartfix_listener.dart index 7fb7a80c503..fd2b337d96f 100644 --- a/pkg/analysis_server/lib/src/edit/fix/dartfix_listener.dart +++ b/pkg/analysis_server/lib/src/edit/fix/dartfix_listener.dart @@ -4,12 +4,12 @@ import 'package:analysis_server/protocol/protocol_generated.dart'; import 'package:analysis_server/src/analysis_server.dart'; +import 'package:analysis_server/src/api_for_nnbd_migration.dart'; import 'package:analyzer/dart/analysis/results.dart'; import 'package:analyzer/file_system/file_system.dart'; import 'package:analyzer/src/generated/source.dart'; import 'package:analyzer_plugin/protocol/protocol_common.dart' show Location, SourceChange, SourceEdit, SourceFileEdit; -import 'package:nnbd_migration/api_for_analysis_server/dartfix_listener_interface.dart'; /// Tasks use this API to report results. class DartFixListener implements DartFixListenerInterface { @@ -100,15 +100,4 @@ class DartFixListener implements DartFixListenerInterface { result.path, offset, length, locInfo.lineNumber, locInfo.columnNumber); return location; } - - /// Reset this listener so that it can accrue a new set of changes. - void reset() { - suggestions.clear(); - otherSuggestions.clear(); - sourceChange - ..edits.clear() - ..linkedEditGroups.clear() - ..selection = null - ..id = null; - } } diff --git a/pkg/analysis_server/lib/src/edit/fix/fix_code_task.dart b/pkg/analysis_server/lib/src/edit/fix/fix_code_task.dart index bdd3a487da2..fff1df7283d 100644 --- a/pkg/analysis_server/lib/src/edit/fix/fix_code_task.dart +++ b/pkg/analysis_server/lib/src/edit/fix/fix_code_task.dart @@ -5,7 +5,6 @@ import 'dart:math' show max; import 'package:analysis_server/src/edit/edit_dartfix.dart'; -import 'package:analysis_server/src/edit/fix/non_nullable_fix.dart'; import 'package:analyzer/dart/analysis/results.dart'; import 'package:analyzer/file_system/file_system.dart'; @@ -15,16 +14,6 @@ mixin FixCodeProcessor { int _numPhases = 0; - /// Return the task used to migrate to NNBD. - NonNullableFix get nonNullableFixTask { - for (var task in _codeTasks) { - if (task is NonNullableFix) { - return task; - } - } - return null; - } - int get numPhases => _numPhases; Future finishCodeTasks() async { diff --git a/pkg/analysis_server/pubspec.yaml b/pkg/analysis_server/pubspec.yaml index b33c8d0a99d..03a88e3d248 100644 --- a/pkg/analysis_server/pubspec.yaml +++ b/pkg/analysis_server/pubspec.yaml @@ -16,7 +16,6 @@ dependencies: linter: any logging: any meta: any - nnbd_migration: any pub_semver: any source_span: any stream_channel: any diff --git a/pkg/analysis_server/test/domain_edit_dartfix_test.dart b/pkg/analysis_server/test/domain_edit_dartfix_test.dart index 69a64aa34ac..0d639ac1ed7 100644 --- a/pkg/analysis_server/test/domain_edit_dartfix_test.dart +++ b/pkg/analysis_server/test/domain_edit_dartfix_test.dart @@ -68,7 +68,6 @@ class EditDartfixDomainHandlerTest extends AbstractAnalysisTest { var fix = EditDartFix(server, request); final response = await fix.compute(); - fix.nonNullableFixTask?.shutdownServer(); expect(response.id, id); return response; } @@ -161,91 +160,6 @@ const double myDouble = 42.0; expect(result.error, isNotNull); } - Future test_nonNullable() async { - createAnalysisOptionsFile(experiments: ['non-nullable']); - addTestFile(''' -int f(int i) => 0; -int g(int i) => f(i); -void test() { - g(null); -} -'''); - createProject(); - expectLater(() async => await performFix(includedFixes: ['non-nullable']), - throwsA(TypeMatcher())); - } - - Future test_nonNullable_pubspec_environmentAdded() async { - var originalContent = ''' -name: foo -'''; - newFile('/project/pubspec.yaml', content: originalContent); - createProject(); - var result = await performFix(includedFixes: ['non-nullable']); - expect(result.suggestions.length, greaterThanOrEqualTo(1)); - expect(result.hasErrors, isFalse); - expect(result.edits, hasLength(1)); - expectFileEdits(originalContent, result.edits[0], ''' -environment: - sdk: '>=2.9.0 <2.10.0' - -name: foo -'''); - } - - Future test_nonNullable_pubspec_sdkAdded() async { - var originalContent = ''' -name: foo -environment: - x: y -'''; - newFile('/project/pubspec.yaml', content: originalContent); - createProject(); - var result = await performFix(includedFixes: ['non-nullable']); - expect(result.suggestions.length, greaterThanOrEqualTo(1)); - expect(result.hasErrors, isFalse); - expect(result.edits, hasLength(1)); - expectFileEdits(originalContent, result.edits[0], ''' -name: foo -environment: - x: y - sdk: '>=2.9.0 <2.10.0' -'''); - } - - Future test_nonNullable_pubspec_sdkNotUpdated() async { - var originalContent = ''' -name: foo -environment: - sdk: '>=2.9.0 <2.10.0' -'''; - newFile('/project/pubspec.yaml', content: originalContent); - createProject(); - var result = await performFix(includedFixes: ['non-nullable']); - expect(result.suggestions, isEmpty); - expect(result.hasErrors, isFalse); - expect(result.edits, isEmpty); - } - - Future test_nonNullable_pubspec_sdkUpdated() async { - var originalContent = ''' -name: foo -environment: - sdk: '>=2.7.0 <3.0.0' -'''; - newFile('/project/pubspec.yaml', content: originalContent); - createProject(); - var result = await performFix(includedFixes: ['non-nullable']); - expect(result.suggestions.length, greaterThanOrEqualTo(1)); - expect(result.hasErrors, isFalse); - expect(result.edits, hasLength(1)); - expectFileEdits(originalContent, result.edits[0], ''' -name: foo -environment: - sdk: '>=2.9.0 <2.10.0' -'''); - } - Future test_partFile() async { newFile('/project/lib/lib.dart', content: ''' library lib2; diff --git a/pkg/analysis_server/test/src/edit/fix/dartfix_listener_test.dart b/pkg/analysis_server/test/src/edit/fix/dartfix_listener_test.dart deleted file mode 100644 index a904622eff9..00000000000 --- a/pkg/analysis_server/test/src/edit/fix/dartfix_listener_test.dart +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (c) 2020, 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. - -import 'package:analysis_server/src/edit/fix/dartfix_listener.dart'; -import 'package:analysis_server/src/protocol_server.dart'; -import 'package:test/test.dart'; -import 'package:test_reflective_loader/test_reflective_loader.dart'; - -void main() { - defineReflectiveSuite(() { - defineReflectiveTests(DartFixListenerTest); - }); -} - -@reflectiveTest -class DartFixListenerTest { - DartFixListener listener; - - void setUp() { - listener = DartFixListener(null); - } - - void test_clear_clears_edits() { - listener.addSourceChange( - 'Example', - null, - SourceChange('foo') - ..edits = [ - SourceFileEdit('foo', 2, edits: [SourceEdit(0, 0, 'foo')]) - ]); - expect(listener.sourceChange.edits, hasLength(1)); - listener.reset(); - expect(listener.sourceChange.edits, isEmpty); - } -} diff --git a/pkg/analysis_server/test/src/edit/fix/non_nullable_fix_test.dart b/pkg/analysis_server/test/src/edit/fix/non_nullable_fix_test.dart deleted file mode 100644 index 658b3093f9d..00000000000 --- a/pkg/analysis_server/test/src/edit/fix/non_nullable_fix_test.dart +++ /dev/null @@ -1,143 +0,0 @@ -// Copyright (c) 2019, 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. - -import 'package:analysis_server/protocol/protocol.dart'; -import 'package:analysis_server/protocol/protocol_generated.dart'; -import 'package:analysis_server/src/edit/edit_dartfix.dart'; -import 'package:analysis_server/src/edit/fix/dartfix_listener.dart'; -import 'package:analysis_server/src/edit/fix/non_nullable_fix.dart'; -import 'package:analyzer/file_system/memory_file_system.dart'; -import 'package:path/path.dart' as path; -import 'package:test/test.dart'; -import 'package:test_reflective_loader/test_reflective_loader.dart'; - -import '../../../analysis_abstract.dart'; - -void main() { - defineReflectiveSuite(() { - defineReflectiveTests(NonNullableFixTest); - }); -} - -@reflectiveTest -class NonNullableFixTest extends AbstractAnalysisTest { - int requestId = 30; - - path.Context context; - - DartFixListener listener; - - String get nextRequestId => (++requestId).toString(); - - Future performFix({List included}) async { - final id = nextRequestId; - final params = EditDartfixParams(included); - params.includedFixes = ['non-nullable']; - var request = Request(id, 'edit.dartfix', params.toJson()); - var response = await EditDartFix(server, request).compute(); - expect(response.id, id); - expect(response.error, isNull); - return EditDartfixResult.fromResponse(response); - } - - @override - Future setUp() async { - context = path.style == path.Style.windows - // On Windows, ensure that the current drive matches - // the drive inserted by MemoryResourceProvider.convertPath - // so that packages are mapped to the correct drive - ? path.Context(current: 'C:\\project') - : path.Context(current: '/project'); - resourceProvider = MemoryResourceProvider(context: context); - super.setUp(); - newFile('/project/bin/bin.dart', content: 'var x = 1;'); - newFile('/project/lib/lib1.dart', content: 'var x = 1;'); - newFile('/project/lib/lib2.dart', content: 'var x = 1;'); - newFile('/project/lib/src/lib3.dart', content: 'var x = 1;'); - newFile('/project/test/test.dart', content: 'var x = 1;'); - newFile('/project2/bin/bin.dart', content: 'var x = 1;'); - newFile('/project2/lib/lib1.dart', content: 'var x = 1;'); - newFile('/project2/lib/lib2.dart', content: 'var x = 1;'); - newFile('/project2/lib/src/lib3.dart', content: 'var x = 1;'); - newFile('/project2/test/test.dart', content: 'var x = 1;'); - // Compute the analysis results. - server.setAnalysisRoots( - '0', [resourceProvider.pathContext.dirname(testFile)], [], {}); - await server - .getAnalysisDriver(testFile) - .currentSession - .getResolvedUnit(testFile); - listener = DartFixListener(server); - } - - Future test_included_multipleRelativeDirectories() async { - var fix = - NonNullableFix(listener, resourceProvider, included: ['lib', 'test']); - expect(fix.includedRoot, equals(convertPath('/project'))); - } - - Future test_included_multipleRelativeDirectories_nonCanonical() async { - var fix = NonNullableFix(listener, resourceProvider, included: [ - convertPath('../project2/lib'), - convertPath('../project2/lib/src') - ]); - expect(fix.includedRoot, equals(convertPath('/project2/lib'))); - } - - Future - test_included_multipleRelativeDirectories_nonCanonical_atRoot() async { - var fix = NonNullableFix(listener, resourceProvider, included: [ - convertPath('../project2/lib'), - convertPath('../project/lib') - ]); - expect(fix.includedRoot, equals(convertPath('/'))); - } - - Future - test_included_multipleRelativeDirectories_subAndSuperDirectories() async { - var fix = - NonNullableFix(listener, resourceProvider, included: ['lib', '.']); - expect(fix.includedRoot, equals(convertPath('/project'))); - } - - Future test_included_multipleRelativeFiles() async { - var fix = NonNullableFix(listener, resourceProvider, included: [ - convertPath('lib/lib1.dart'), - convertPath('test/test.dart') - ]); - expect(fix.includedRoot, equals(convertPath('/project'))); - } - - Future test_included_multipleRelativeFiles_sameDirectory() async { - var fix = NonNullableFix(listener, resourceProvider, - included: [convertPath('lib/lib1.dart'), convertPath('lib/lib2.dart')]); - expect(fix.includedRoot, equals(convertPath('/project/lib'))); - } - - Future test_included_multipleRelativeFilesAndDirectories() async { - var fix = NonNullableFix(listener, resourceProvider, included: [ - convertPath('lib/lib1.dart'), - convertPath('lib/src'), - convertPath('../project/lib/src/lib3.dart') - ]); - expect(fix.includedRoot, equals(convertPath('/project/lib'))); - } - - Future test_included_singleAbsoluteDirectory() async { - var fix = NonNullableFix(listener, resourceProvider, - included: [convertPath('/project')]); - expect(fix.includedRoot, equals(convertPath('/project'))); - } - - Future test_included_singleAbsoluteFile() async { - var fix = NonNullableFix(listener, resourceProvider, - included: [convertPath('/project/bin/bin.dart')]); - expect(fix.includedRoot, equals(convertPath('/project/bin'))); - } - - Future test_included_singleRelativeDirectory() async { - var fix = NonNullableFix(listener, resourceProvider, included: ['.']); - expect(fix.includedRoot, equals(convertPath('/project'))); - } -} diff --git a/pkg/analysis_server/test/src/edit/fix/test_all.dart b/pkg/analysis_server/test/src/edit/fix/test_all.dart deleted file mode 100644 index d503cd95830..00000000000 --- a/pkg/analysis_server/test/src/edit/fix/test_all.dart +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) 2019, 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. - -import 'package:test_reflective_loader/test_reflective_loader.dart'; - -import 'dartfix_listener_test.dart' as dartfix_listener; -import 'non_nullable_fix_test.dart' as non_nullable_fix; - -void main() { - defineReflectiveSuite(() { - dartfix_listener.main(); - non_nullable_fix.main(); - }, name: 'fix'); -} diff --git a/pkg/analysis_server/test/src/edit/test_all.dart b/pkg/analysis_server/test/src/edit/test_all.dart deleted file mode 100644 index b91a43d598a..00000000000 --- a/pkg/analysis_server/test/src/edit/test_all.dart +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (c) 2019, 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. - -import 'package:test_reflective_loader/test_reflective_loader.dart'; - -import 'fix/test_all.dart' as fix; - -void main() { - defineReflectiveSuite(() { - fix.main(); - }, name: 'edit'); -} diff --git a/pkg/analysis_server/test/src/test_all.dart b/pkg/analysis_server/test/src/test_all.dart index 1681eccfd2e..0cb76aaa085 100644 --- a/pkg/analysis_server/test/src/test_all.dart +++ b/pkg/analysis_server/test/src/test_all.dart @@ -8,7 +8,6 @@ import 'cider/test_all.dart' as cider; import 'computer/test_all.dart' as computer; import 'domain_abstract_test.dart' as domain_abstract; import 'domains/test_all.dart' as domains; -import 'edit/test_all.dart' as edit; import 'flutter/test_all.dart' as flutter; import 'lsp/test_all.dart' as lsp; import 'plugin/test_all.dart' as plugin; @@ -22,7 +21,6 @@ void main() { computer.main(); domain_abstract.main(); domains.main(); - edit.main(); flutter.main(); lsp.main(); plugin.main(); diff --git a/pkg/nnbd_migration/lib/api_for_analysis_server/driver_provider.dart b/pkg/nnbd_migration/lib/api_for_analysis_server/driver_provider.dart deleted file mode 100644 index 2079378112a..00000000000 --- a/pkg/nnbd_migration/lib/api_for_analysis_server/driver_provider.dart +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (c) 2020, 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. - -import 'package:analyzer/dart/analysis/session.dart'; -import 'package:analyzer/file_system/file_system.dart'; - -abstract class DriverProvider { - ResourceProvider get resourceProvider; - - /// Return the appropriate analysis session for the file with the given - /// [path]. - AnalysisSession getAnalysisSession(String path); -} diff --git a/pkg/nnbd_migration/lib/migration_cli.dart b/pkg/nnbd_migration/lib/migration_cli.dart index 4e4b3d9fea0..f7bb4f69c72 100644 --- a/pkg/nnbd_migration/lib/migration_cli.dart +++ b/pkg/nnbd_migration/lib/migration_cli.dart @@ -5,8 +5,8 @@ import 'dart:async'; import 'dart:io' hide File; +import 'package:analysis_server/src/api_for_nnbd_migration.dart'; import 'package:analysis_server/src/edit/fix/fix_code_task.dart'; -import 'package:analysis_server/src/edit/fix/non_nullable_fix.dart'; import 'package:analyzer/dart/analysis/analysis_context.dart'; import 'package:analyzer/dart/analysis/results.dart'; import 'package:analyzer/dart/analysis/session.dart'; @@ -26,9 +26,8 @@ import 'package:args/args.dart'; import 'package:args/command_runner.dart'; import 'package:cli_util/cli_logging.dart'; import 'package:meta/meta.dart'; -import 'package:nnbd_migration/api_for_analysis_server/dartfix_listener_interface.dart'; -import 'package:nnbd_migration/api_for_analysis_server/driver_provider.dart'; import 'package:nnbd_migration/src/edit_plan.dart'; +import 'package:nnbd_migration/src/front_end/non_nullable_fix.dart'; import 'package:nnbd_migration/src/utilities/source_edit_diff_formatter.dart'; import 'package:path/path.dart' show Context; @@ -274,6 +273,7 @@ class MigrationCli { summaryPath: options.summary); nonNullableFix.rerunFunction = _rerunFunction; _fixCodeProcessor.registerCodeTask(nonNullableFix); + _fixCodeProcessor.nonNullableFixTask = nonNullableFix; try { await _fixCodeProcessor.runFirstPhase(); @@ -660,6 +660,9 @@ class _FixCodeProcessor extends Object with FixCodeProcessor { final MigrationCli _migrationCli; + /// The task used to migrate to NNBD. + NonNullableFix nonNullableFixTask; + _FixCodeProcessor(this.context, this._migrationCli) : pathsToProcess = _computePathsToProcess(context); diff --git a/pkg/nnbd_migration/lib/src/front_end/info_builder.dart b/pkg/nnbd_migration/lib/src/front_end/info_builder.dart index 02bc65d0efa..cc9580f441e 100644 --- a/pkg/nnbd_migration/lib/src/front_end/info_builder.dart +++ b/pkg/nnbd_migration/lib/src/front_end/info_builder.dart @@ -4,6 +4,7 @@ import 'dart:collection'; +import 'package:analysis_server/src/api_for_nnbd_migration.dart'; import 'package:analyzer/dart/analysis/results.dart'; import 'package:analyzer/dart/ast/ast.dart'; import 'package:analyzer/file_system/file_system.dart'; @@ -13,8 +14,6 @@ import 'package:analyzer_plugin/protocol/protocol_common.dart' as protocol; import 'package:analyzer_plugin/src/utilities/navigation/navigation.dart'; import 'package:analyzer_plugin/utilities/navigation/navigation_dart.dart'; import 'package:meta/meta.dart'; -import 'package:nnbd_migration/api_for_analysis_server/dartfix_listener_interface.dart'; -import 'package:nnbd_migration/api_for_analysis_server/driver_provider.dart'; import 'package:nnbd_migration/fix_reason_target.dart'; import 'package:nnbd_migration/instrumentation.dart'; import 'package:nnbd_migration/nnbd_migration.dart'; diff --git a/pkg/nnbd_migration/lib/src/front_end/migration_state.dart b/pkg/nnbd_migration/lib/src/front_end/migration_state.dart index ebca6e00a55..f61a5fd0944 100644 --- a/pkg/nnbd_migration/lib/src/front_end/migration_state.dart +++ b/pkg/nnbd_migration/lib/src/front_end/migration_state.dart @@ -2,7 +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:nnbd_migration/api_for_analysis_server/dartfix_listener_interface.dart'; +import 'package:analysis_server/src/api_for_nnbd_migration.dart'; import 'package:nnbd_migration/nnbd_migration.dart'; import 'package:nnbd_migration/instrumentation.dart'; import 'package:nnbd_migration/src/front_end/info_builder.dart'; diff --git a/pkg/analysis_server/lib/src/edit/fix/non_nullable_fix.dart b/pkg/nnbd_migration/lib/src/front_end/non_nullable_fix.dart similarity index 98% rename from pkg/analysis_server/lib/src/edit/fix/non_nullable_fix.dart rename to pkg/nnbd_migration/lib/src/front_end/non_nullable_fix.dart index 0dbbd4e6421..1e5c2c82401 100644 --- a/pkg/analysis_server/lib/src/edit/fix/non_nullable_fix.dart +++ b/pkg/nnbd_migration/lib/src/front_end/non_nullable_fix.dart @@ -3,6 +3,7 @@ // BSD-style license that can be found in the LICENSE file. import 'package:analysis_server/protocol/protocol_generated.dart'; +import 'package:analysis_server/src/api_for_nnbd_migration.dart'; import 'package:analysis_server/src/edit/fix/dartfix_listener.dart'; import 'package:analysis_server/src/edit/fix/dartfix_registrar.dart'; import 'package:analysis_server/src/edit/fix/fix_code_task.dart'; @@ -13,7 +14,6 @@ import 'package:analyzer/src/generated/source.dart'; import 'package:analyzer_plugin/protocol/protocol_common.dart'; import 'package:charcode/charcode.dart'; import 'package:meta/meta.dart'; -import 'package:nnbd_migration/api_for_analysis_server/dartfix_listener_interface.dart'; import 'package:nnbd_migration/api_for_analysis_server/http_preview_server.dart'; import 'package:nnbd_migration/api_for_analysis_server/instrumentation_listener.dart'; import 'package:nnbd_migration/api_for_analysis_server/migration_state.dart'; @@ -147,7 +147,7 @@ class NonNullableFix extends FixCodeTask { return; } try { - pubspecMap = loadYaml(pubspecContent); + pubspecMap = loadYaml(pubspecContent) as YamlNode; } on YamlException catch (e) { processYamlException('parse', pubspecFile.path, e); return; @@ -207,7 +207,7 @@ environment: sdk: '$_intendedSdkVersionConstraint'"""; insertAfterParent(environmentOptions.span, content); } else if (sdk is YamlScalar) { - var currentConstraint = VersionConstraint.parse(sdk.value); + var currentConstraint = VersionConstraint.parse(sdk.value as String); var minimumVersion = Version.parse(_intendedMinimumSdkVersion); if (currentConstraint is VersionRange && currentConstraint.min >= minimumVersion) { diff --git a/pkg/nnbd_migration/test/front_end/nnbd_migration_test_base.dart b/pkg/nnbd_migration/test/front_end/nnbd_migration_test_base.dart index 17e805c3472..0fae1f0c9fc 100644 --- a/pkg/nnbd_migration/test/front_end/nnbd_migration_test_base.dart +++ b/pkg/nnbd_migration/test/front_end/nnbd_migration_test_base.dart @@ -3,7 +3,6 @@ // BSD-style license that can be found in the LICENSE file. import 'package:analysis_server/src/edit/fix/dartfix_listener.dart'; -import 'package:analysis_server/src/edit/fix/non_nullable_fix.dart'; import 'package:analyzer/dart/analysis/results.dart'; import 'package:analyzer/source/line_info.dart'; import 'package:meta/meta.dart'; @@ -12,6 +11,7 @@ import 'package:nnbd_migration/instrumentation.dart'; import 'package:nnbd_migration/src/front_end/info_builder.dart'; import 'package:nnbd_migration/src/front_end/instrumentation_listener.dart'; import 'package:nnbd_migration/src/front_end/migration_info.dart'; +import 'package:nnbd_migration/src/front_end/non_nullable_fix.dart'; import 'package:nnbd_migration/src/front_end/offset_mapper.dart'; import 'package:test/test.dart'; import 'package:test_reflective_loader/test_reflective_loader.dart'; @@ -157,7 +157,8 @@ class NnbdMigrationTestBase extends AbstractAnalysisTest { removeViaComments: removeViaComments, warnOnWeakCode: warnOnWeakCode); // Ignore info for dart:core. var filteredInfos = [ - for (var info in infos) if (!info.path.contains('core.dart')) info + for (var info in infos) + if (!info.path.contains('core.dart')) info ]; expect(filteredInfos, hasLength(1)); var unit = filteredInfos[0]; @@ -180,7 +181,8 @@ class NnbdMigrationTestBase extends AbstractAnalysisTest { await _buildMigrationInfo(testPaths, includedRoot: includedRoot); // Ignore info for dart:core. var filteredInfos = [ - for (var info in infos) if (!info.path.contains('core.dart')) info + for (var info in infos) + if (!info.path.contains('core.dart')) info ]; return filteredInfos; } diff --git a/pkg/nnbd_migration/test/migration_cli_test.dart b/pkg/nnbd_migration/test/migration_cli_test.dart index 6bbf4e41210..1fad3f834ad 100644 --- a/pkg/nnbd_migration/test/migration_cli_test.dart +++ b/pkg/nnbd_migration/test/migration_cli_test.dart @@ -6,7 +6,6 @@ import 'dart:async'; import 'dart:convert'; import 'dart:io'; -import 'package:analysis_server/src/edit/fix/non_nullable_fix.dart'; import 'package:analyzer/file_system/memory_file_system.dart'; import 'package:analyzer/file_system/physical_file_system.dart'; import 'package:analyzer/src/test_utilities/mock_sdk.dart' as mock_sdk; @@ -15,6 +14,7 @@ import 'package:cli_util/cli_logging.dart'; import 'package:http/http.dart' as http; import 'package:meta/meta.dart'; import 'package:nnbd_migration/migration_cli.dart'; +import 'package:nnbd_migration/src/front_end/non_nullable_fix.dart'; import 'package:path/path.dart' as path; import 'package:test/test.dart'; import 'package:test_reflective_loader/test_reflective_loader.dart';