Chromium Code Reviews| 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'; |
| 10 import 'package:analysis_server/src/services/correction/fix_internal.dart' | |
| 11 show DartFixContextImpl; | |
| 8 import 'package:analyzer/file_system/file_system.dart'; | 12 import 'package:analyzer/file_system/file_system.dart'; |
| 9 import 'package:analyzer/src/generated/ast.dart'; | 13 import 'package:analyzer/src/generated/ast.dart'; |
| 10 import 'package:analyzer/src/generated/engine.dart'; | 14 import 'package:analyzer/src/generated/engine.dart'; |
| 11 import 'package:analyzer/src/generated/error.dart'; | 15 import 'package:analyzer/src/generated/error.dart'; |
| 12 import 'package:analyzer/src/generated/source.dart'; | 16 import 'package:analyzer/src/generated/source.dart'; |
| 13 | 17 |
| 14 /** | 18 /** |
| 19 * An object used to provide context information for [DartFixContributor]s. | |
| 20 * | |
| 21 * Clients may not extend, implement or mix-in this class. | |
| 22 */ | |
| 23 abstract class DartFixContext { | |
|
Brian Wilkerson
2015/11/20 22:11:59
Why not extend FixContext?
scheglov
2015/11/20 22:56:08
Done.
| |
| 24 /** | |
| 25 * The [AnalysisContext] to get fixes in. | |
| 26 */ | |
| 27 AnalysisContext get analysisContext; | |
| 28 | |
| 29 /** | |
| 30 * The error to fix, should be reported in the given [analysisContext]. | |
| 31 */ | |
| 32 AnalysisError get error; | |
| 33 | |
| 34 /** | |
| 35 * The [ResourceProvider] to access files and folders. | |
| 36 */ | |
| 37 ResourceProvider get resourceProvider; | |
| 38 | |
| 39 /** | |
| 40 * The [CompilationUnit] to compute fixes in. | |
| 41 */ | |
| 42 CompilationUnit get unit; | |
| 43 } | |
| 44 | |
| 45 /** | |
| 15 * A [FixContributor] that can be used to contribute fixes for errors in Dart | 46 * A [FixContributor] that can be used to contribute fixes for errors in Dart |
| 16 * files. | 47 * files. |
| 17 * | 48 * |
| 18 * Clients may extend this class when implementing plugins. | 49 * Clients may extend this class when implementing plugins. |
| 19 */ | 50 */ |
| 20 abstract class DartFixContributor implements FixContributor { | 51 abstract class DartFixContributor implements FixContributor { |
| 21 @override | 52 @override |
| 22 List<Fix> computeFixes(ResourceProvider resourceProvider, | 53 Future<List<Fix>> computeFixes(FixContext context) async { |
| 23 AnalysisContext context, AnalysisError error) { | 54 AnalysisContext analysisContext = context.analysisContext; |
| 24 Source source = error.source; | 55 Source source = context.error.source; |
| 25 if (!AnalysisEngine.isDartFileName(source.fullName)) { | 56 if (!AnalysisEngine.isDartFileName(source.fullName)) { |
| 26 return Fix.EMPTY_LIST; | 57 return Fix.EMPTY_LIST; |
| 27 } | 58 } |
| 28 List<Source> libraries = context.getLibrariesContaining(source); | 59 List<Source> libraries = analysisContext.getLibrariesContaining(source); |
| 29 if (libraries.isEmpty) { | 60 if (libraries.isEmpty) { |
| 30 return Fix.EMPTY_LIST; | 61 return Fix.EMPTY_LIST; |
| 31 } | 62 } |
| 32 CompilationUnit unit = | 63 CompilationUnit unit = |
| 33 context.resolveCompilationUnit2(source, libraries[0]); | 64 analysisContext.resolveCompilationUnit2(source, libraries[0]); |
| 34 if (unit == null) { | 65 if (unit == null) { |
| 35 return Fix.EMPTY_LIST; | 66 return Fix.EMPTY_LIST; |
| 36 } | 67 } |
| 37 return internalComputeFixes(resourceProvider, unit, error); | 68 DartFixContext dartContext = new DartFixContextImpl(context, unit); |
| 69 return internalComputeFixes(dartContext); | |
| 38 } | 70 } |
| 39 | 71 |
| 40 /** | 72 /** |
| 41 * Return a list of fixes for the given [error]. The error was reported | 73 * Return a list of fixes for the given [context]. |
| 42 * against the given compilation [unit]. | |
| 43 */ | 74 */ |
| 44 List<Fix> internalComputeFixes(ResourceProvider resourceProvider, | 75 Future<List<Fix>> internalComputeFixes(DartFixContext context); |
| 45 CompilationUnit unit, AnalysisError error); | |
| 46 } | 76 } |
| OLD | NEW |