Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(350)

Side by Side Diff: pkg/analysis_server/test/services/correction/fix_test.dart

Issue 2894403003: Convert quick fix support to use AnalysisDriver (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'dart:async'; 5 import 'dart:async';
6 6
7 import 'package:analysis_server/plugin/edit/fix/fix_core.dart'; 7 import 'package:analysis_server/plugin/edit/fix/fix_core.dart';
8 import 'package:analysis_server/plugin/edit/fix/fix_dart.dart'; 8 import 'package:analysis_server/plugin/edit/fix/fix_dart.dart';
9 import 'package:analysis_server/src/services/correction/fix.dart'; 9 import 'package:analysis_server/src/services/correction/fix.dart';
10 import 'package:analysis_server/src/services/correction/fix_internal.dart'; 10 import 'package:analysis_server/src/services/correction/fix_internal.dart';
11 import 'package:analyzer/dart/ast/ast.dart'; 11 import 'package:analyzer/dart/ast/ast.dart';
12 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; 12 import 'package:analyzer/dart/ast/standard_resolution_map.dart';
13 import 'package:analyzer/error/error.dart'; 13 import 'package:analyzer/error/error.dart';
14 import 'package:analyzer/file_system/file_system.dart'; 14 import 'package:analyzer/file_system/file_system.dart';
15 import 'package:analyzer/source/package_map_resolver.dart'; 15 import 'package:analyzer/source/package_map_resolver.dart';
16 import 'package:analyzer/src/dart/analysis/ast_provider_driver.dart'; 16 import 'package:analyzer/src/dart/analysis/ast_provider_driver.dart';
17 import 'package:analyzer/src/dart/analysis/driver.dart';
17 import 'package:analyzer/src/dart/element/ast_provider.dart'; 18 import 'package:analyzer/src/dart/element/ast_provider.dart';
18 import 'package:analyzer/src/error/codes.dart'; 19 import 'package:analyzer/src/error/codes.dart';
19 import 'package:analyzer/src/generated/engine.dart';
20 import 'package:analyzer/src/generated/parser.dart'; 20 import 'package:analyzer/src/generated/parser.dart';
21 import 'package:analyzer/src/generated/source.dart'; 21 import 'package:analyzer/src/generated/source.dart';
22 import 'package:analyzer_plugin/protocol/protocol_common.dart' 22 import 'package:analyzer_plugin/protocol/protocol_common.dart'
23 hide AnalysisError; 23 hide AnalysisError;
24 import 'package:test/test.dart'; 24 import 'package:test/test.dart';
25 import 'package:test_reflective_loader/test_reflective_loader.dart'; 25 import 'package:test_reflective_loader/test_reflective_loader.dart';
26 26
27 import '../../abstract_single_unit.dart'; 27 import '../../abstract_single_unit.dart';
28 import 'flutter_util.dart'; 28 import 'flutter_util.dart';
29 29
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 return (await driver.getResult(testFile)).errors; 157 return (await driver.getResult(testFile)).errors;
158 } else { 158 } else {
159 return context.computeErrors(testSource); 159 return context.computeErrors(testSource);
160 } 160 }
161 } 161 }
162 162
163 /** 163 /**
164 * Computes fixes for the given [error] in [testUnit]. 164 * Computes fixes for the given [error] in [testUnit].
165 */ 165 */
166 Future<List<Fix>> _computeFixes(AnalysisError error) async { 166 Future<List<Fix>> _computeFixes(AnalysisError error) async {
167 if (enableNewAnalysisDriver) { 167 DartFixContext fixContext = new _DartFixContextImpl(
168 DartFixContext fixContext = new _DartFixContextImpl( 168 provider, driver, new AstProviderForDriver(driver), testUnit, error);
169 provider, 169 return await new DefaultFixContributor().internalComputeFixes(fixContext);
170 driver.getTopLevelNameDeclarations,
171 resolutionMap.elementDeclaredByCompilationUnit(testUnit).context,
172 new AstProviderForDriver(driver),
173 testUnit,
174 error);
175 return await new DefaultFixContributor().internalComputeFixes(fixContext);
176 } else {
177 FixContextImpl fixContext = new FixContextImpl(provider, context, error);
178 DefaultFixContributor contributor = new DefaultFixContributor();
179 return contributor.computeFixes(fixContext);
180 }
181 } 170 }
182 171
183 /** 172 /**
184 * Configures the [SourceFactory] to have the `my_pkg` package in 173 * Configures the [SourceFactory] to have the `my_pkg` package in
185 * `/packages/my_pkg/lib` folder. 174 * `/packages/my_pkg/lib` folder.
186 */ 175 */
187 void _configureMyPkg(Map<String, String> pathToCode) { 176 void _configureMyPkg(Map<String, String> pathToCode) {
188 pathToCode.forEach((path, code) { 177 pathToCode.forEach((path, code) {
189 provider.newFile('$myPkgLibPath/$path', code); 178 provider.newFile('$myPkgLibPath/$path', code);
190 }); 179 });
(...skipping 6699 matching lines...) Expand 10 before | Expand all | Expand 10 after
6890 return a.toString; 6879 return a.toString;
6891 } 6880 }
6892 '''); 6881 ''');
6893 } 6882 }
6894 6883
6895 void verifyResult(String expectedResult) { 6884 void verifyResult(String expectedResult) {
6896 expect(resultCode, expectedResult); 6885 expect(resultCode, expectedResult);
6897 } 6886 }
6898 } 6887 }
6899 6888
6900 class _DartFixContextImpl implements DartFixContext { 6889 class _DartFixContextImpl implements DartFixContext {
scheglov 2017/05/22 15:48:55 It seems to me that separation between FixContext,
Brian Wilkerson 2017/05/22 16:03:01 I would like to share as much code as possible bet
6901 @override 6890 @override
6902 final ResourceProvider resourceProvider; 6891 final ResourceProvider resourceProvider;
6903 6892
6904 @override 6893 @override
6905 final GetTopLevelDeclarations getTopLevelDeclarations; 6894 final AnalysisDriver analysisDriver;
6906
6907 @override
6908 final AnalysisContext analysisContext;
6909 6895
6910 @override 6896 @override
6911 final AstProvider astProvider; 6897 final AstProvider astProvider;
6912 6898
6913 @override 6899 @override
6914 final CompilationUnit unit; 6900 final CompilationUnit unit;
6915 6901
6916 @override 6902 @override
6917 final AnalysisError error; 6903 final AnalysisError error;
6918 6904
6919 _DartFixContextImpl(this.resourceProvider, this.getTopLevelDeclarations, 6905 _DartFixContextImpl(this.resourceProvider, this.analysisDriver,
6920 this.analysisContext, this.astProvider, this.unit, this.error); 6906 this.astProvider, this.unit, this.error);
6907
6908 @override
6909 GetTopLevelDeclarations get getTopLevelDeclarations =>
6910 analysisDriver.getTopLevelNameDeclarations;
6921 } 6911 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698