| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 library analysis_server.plugin.edit.fix.fix_dart; | 5 library analysis_server.plugin.edit.fix.fix_dart; |
| 6 | 6 |
| 7 import 'dart:async'; |
| 8 |
| 7 import 'package:analysis_server/plugin/edit/fix/fix_core.dart'; | 9 import 'package:analysis_server/plugin/edit/fix/fix_core.dart'; |
| 8 import 'package:analyzer/file_system/file_system.dart'; | 10 import 'package:analysis_server/src/services/correction/fix_internal.dart' |
| 11 show DartFixContextImpl; |
| 9 import 'package:analyzer/src/generated/ast.dart'; | 12 import 'package:analyzer/src/generated/ast.dart'; |
| 10 import 'package:analyzer/src/generated/engine.dart'; | 13 import 'package:analyzer/src/generated/engine.dart'; |
| 11 import 'package:analyzer/src/generated/error.dart'; | |
| 12 import 'package:analyzer/src/generated/source.dart'; | 14 import 'package:analyzer/src/generated/source.dart'; |
| 13 | 15 |
| 14 /** | 16 /** |
| 17 * An object used to provide context information for [DartFixContributor]s. |
| 18 * |
| 19 * Clients may not extend, implement or mix-in this class. |
| 20 */ |
| 21 abstract class DartFixContext extends FixContext { |
| 22 /** |
| 23 * The [CompilationUnit] to compute fixes in. |
| 24 */ |
| 25 CompilationUnit get unit; |
| 26 } |
| 27 |
| 28 /** |
| 15 * A [FixContributor] that can be used to contribute fixes for errors in Dart | 29 * A [FixContributor] that can be used to contribute fixes for errors in Dart |
| 16 * files. | 30 * files. |
| 17 * | 31 * |
| 18 * Clients may extend this class when implementing plugins. | 32 * Clients may extend this class when implementing plugins. |
| 19 */ | 33 */ |
| 20 abstract class DartFixContributor implements FixContributor { | 34 abstract class DartFixContributor implements FixContributor { |
| 21 @override | 35 @override |
| 22 List<Fix> computeFixes(ResourceProvider resourceProvider, | 36 Future<List<Fix>> computeFixes(FixContext context) async { |
| 23 AnalysisContext context, AnalysisError error) { | 37 AnalysisContext analysisContext = context.analysisContext; |
| 24 Source source = error.source; | 38 Source source = context.error.source; |
| 25 if (!AnalysisEngine.isDartFileName(source.fullName)) { | 39 if (!AnalysisEngine.isDartFileName(source.fullName)) { |
| 26 return Fix.EMPTY_LIST; | 40 return Fix.EMPTY_LIST; |
| 27 } | 41 } |
| 28 List<Source> libraries = context.getLibrariesContaining(source); | 42 List<Source> libraries = analysisContext.getLibrariesContaining(source); |
| 29 if (libraries.isEmpty) { | 43 if (libraries.isEmpty) { |
| 30 return Fix.EMPTY_LIST; | 44 return Fix.EMPTY_LIST; |
| 31 } | 45 } |
| 32 CompilationUnit unit = | 46 CompilationUnit unit = |
| 33 context.resolveCompilationUnit2(source, libraries[0]); | 47 analysisContext.resolveCompilationUnit2(source, libraries[0]); |
| 34 if (unit == null) { | 48 if (unit == null) { |
| 35 return Fix.EMPTY_LIST; | 49 return Fix.EMPTY_LIST; |
| 36 } | 50 } |
| 37 return internalComputeFixes(resourceProvider, unit, error); | 51 DartFixContext dartContext = new DartFixContextImpl(context, unit); |
| 52 return internalComputeFixes(dartContext); |
| 38 } | 53 } |
| 39 | 54 |
| 40 /** | 55 /** |
| 41 * Return a list of fixes for the given [error]. The error was reported | 56 * Return a list of fixes for the given [context]. |
| 42 * against the given compilation [unit]. | |
| 43 */ | 57 */ |
| 44 List<Fix> internalComputeFixes(ResourceProvider resourceProvider, | 58 Future<List<Fix>> internalComputeFixes(DartFixContext context); |
| 45 CompilationUnit unit, AnalysisError error); | |
| 46 } | 59 } |
| OLD | NEW |