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 'package:analysis_server/plugin/edit/fix/fix_core.dart'; | 7 import 'package:analysis_server/plugin/edit/fix/fix_core.dart'; |
8 import 'package:analyzer/file_system/file_system.dart'; | 8 import 'package:analyzer/file_system/file_system.dart'; |
9 import 'package:analyzer/src/generated/ast.dart'; | 9 import 'package:analyzer/src/generated/ast.dart'; |
10 import 'package:analyzer/src/generated/engine.dart'; | 10 import 'package:analyzer/src/generated/engine.dart'; |
11 import 'package:analyzer/src/generated/error.dart'; | 11 import 'package:analyzer/src/generated/error.dart'; |
12 import 'package:analyzer/src/generated/source.dart'; | 12 import 'package:analyzer/src/generated/source.dart'; |
13 | 13 |
14 /** | 14 /** |
15 * A [FixContributor] that can be used to contribute fixes for errors in Dart | 15 * A [FixContributor] that can be used to contribute fixes for errors in Dart |
16 * files. | 16 * files. |
17 * | 17 * |
18 * Clients are expected to extend this class when implementing plugins. | 18 * Clients may extend this class when implementing plugins. |
19 */ | 19 */ |
20 abstract class DartFixContributor extends FixContributor { | 20 abstract class DartFixContributor implements FixContributor { |
21 @override | 21 @override |
22 List<Fix> computeFixes(ResourceProvider resourceProvider, | 22 List<Fix> computeFixes(ResourceProvider resourceProvider, |
23 AnalysisContext context, AnalysisError error) { | 23 AnalysisContext context, AnalysisError error) { |
24 Source source = error.source; | 24 Source source = error.source; |
25 if (!AnalysisEngine.isDartFileName(source.fullName)) { | 25 if (!AnalysisEngine.isDartFileName(source.fullName)) { |
26 return Fix.EMPTY_LIST; | 26 return Fix.EMPTY_LIST; |
27 } | 27 } |
28 List<Source> libraries = context.getLibrariesContaining(source); | 28 List<Source> libraries = context.getLibrariesContaining(source); |
29 if (libraries.isEmpty) { | 29 if (libraries.isEmpty) { |
30 return Fix.EMPTY_LIST; | 30 return Fix.EMPTY_LIST; |
31 } | 31 } |
32 CompilationUnit unit = | 32 CompilationUnit unit = |
33 context.resolveCompilationUnit2(source, libraries[0]); | 33 context.resolveCompilationUnit2(source, libraries[0]); |
34 if (unit == null) { | 34 if (unit == null) { |
35 return Fix.EMPTY_LIST; | 35 return Fix.EMPTY_LIST; |
36 } | 36 } |
37 return internalComputeFixes(resourceProvider, unit, error); | 37 return internalComputeFixes(resourceProvider, unit, error); |
38 } | 38 } |
39 | 39 |
40 /** | 40 /** |
41 * Return a list of fixes for the given [error]. The error was reported | 41 * Return a list of fixes for the given [error]. The error was reported |
42 * against the given compilation [unit]. | 42 * against the given compilation [unit]. |
43 */ | 43 */ |
44 List<Fix> internalComputeFixes(ResourceProvider resourceProvider, | 44 List<Fix> internalComputeFixes(ResourceProvider resourceProvider, |
45 CompilationUnit unit, AnalysisError error); | 45 CompilationUnit unit, AnalysisError error); |
46 } | 46 } |
OLD | NEW |