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