| 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'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 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' | 10 import 'package:analysis_server/src/services/correction/fix_internal.dart' |
| 11 show DartFixContextImpl; | 11 show DartFixContextImpl; |
| 12 import 'package:analysis_server/src/services/correction/namespace.dart' | 12 import 'package:analysis_server/src/services/correction/namespace.dart' |
| 13 show getExportedElement; | 13 show getExportedElement; |
| 14 import 'package:analyzer/dart/ast/ast.dart'; | 14 import 'package:analyzer/dart/ast/ast.dart'; |
| 15 import 'package:analyzer/dart/element/element.dart'; | 15 import 'package:analyzer/dart/element/element.dart'; |
| 16 import 'package:analyzer/src/dart/analysis/ast_provider_context.dart'; |
| 16 import 'package:analyzer/src/dart/analysis/top_level_declaration.dart'; | 17 import 'package:analyzer/src/dart/analysis/top_level_declaration.dart'; |
| 18 import 'package:analyzer/src/dart/element/ast_provider.dart'; |
| 17 import 'package:analyzer/src/generated/engine.dart'; | 19 import 'package:analyzer/src/generated/engine.dart'; |
| 18 import 'package:analyzer/src/generated/source.dart'; | 20 import 'package:analyzer/src/generated/source.dart'; |
| 19 import 'package:analyzer/src/task/dart.dart' show LIBRARY_ELEMENT4; | 21 import 'package:analyzer/src/task/dart.dart' show LIBRARY_ELEMENT4; |
| 20 | 22 |
| 21 /** | 23 /** |
| 22 * Complete with top-level declarations with the given [name]. | 24 * Complete with top-level declarations with the given [name]. |
| 23 */ | 25 */ |
| 24 typedef Future<List<TopLevelDeclarationInSource>> GetTopLevelDeclarations( | 26 typedef Future<List<TopLevelDeclarationInSource>> GetTopLevelDeclarations( |
| 25 String name); | 27 String name); |
| 26 | 28 |
| 27 /** | 29 /** |
| 28 * An object used to provide context information for [DartFixContributor]s. | 30 * An object used to provide context information for [DartFixContributor]s. |
| 29 * | 31 * |
| 30 * Clients may not extend, implement or mix-in this class. | 32 * Clients may not extend, implement or mix-in this class. |
| 31 */ | 33 */ |
| 32 abstract class DartFixContext implements FixContext { | 34 abstract class DartFixContext implements FixContext { |
| 33 /** | 35 /** |
| 36 * The provider for parsed or resolved ASTs. |
| 37 */ |
| 38 AstProvider get astProvider; |
| 39 |
| 40 /** |
| 34 * The function to get top-level declarations from. | 41 * The function to get top-level declarations from. |
| 35 */ | 42 */ |
| 36 GetTopLevelDeclarations get getTopLevelDeclarations; | 43 GetTopLevelDeclarations get getTopLevelDeclarations; |
| 37 | 44 |
| 38 /** | 45 /** |
| 39 * The [CompilationUnit] to compute fixes in. | 46 * The [CompilationUnit] to compute fixes in. |
| 40 */ | 47 */ |
| 41 CompilationUnit get unit; | 48 CompilationUnit get unit; |
| 42 } | 49 } |
| 43 | 50 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 58 List<Source> libraries = analysisContext.getLibrariesContaining(source); | 65 List<Source> libraries = analysisContext.getLibrariesContaining(source); |
| 59 if (libraries.isEmpty) { | 66 if (libraries.isEmpty) { |
| 60 return Fix.EMPTY_LIST; | 67 return Fix.EMPTY_LIST; |
| 61 } | 68 } |
| 62 CompilationUnit unit = | 69 CompilationUnit unit = |
| 63 analysisContext.getResolvedCompilationUnit2(source, libraries[0]); | 70 analysisContext.getResolvedCompilationUnit2(source, libraries[0]); |
| 64 if (unit == null) { | 71 if (unit == null) { |
| 65 return Fix.EMPTY_LIST; | 72 return Fix.EMPTY_LIST; |
| 66 } | 73 } |
| 67 DartFixContext dartContext = new DartFixContextImpl( | 74 DartFixContext dartContext = new DartFixContextImpl( |
| 68 context, _getTopLevelDeclarations(analysisContext), unit); | 75 context, |
| 76 _getTopLevelDeclarations(analysisContext), |
| 77 new AstProviderForContext(analysisContext), |
| 78 unit); |
| 69 return internalComputeFixes(dartContext); | 79 return internalComputeFixes(dartContext); |
| 70 } | 80 } |
| 71 | 81 |
| 72 /** | 82 /** |
| 73 * Return a list of fixes for the given [context]. | 83 * Return a list of fixes for the given [context]. |
| 74 */ | 84 */ |
| 75 Future<List<Fix>> internalComputeFixes(DartFixContext context); | 85 Future<List<Fix>> internalComputeFixes(DartFixContext context); |
| 76 | 86 |
| 77 GetTopLevelDeclarations _getTopLevelDeclarations(AnalysisContext context) { | 87 GetTopLevelDeclarations _getTopLevelDeclarations(AnalysisContext context) { |
| 78 return (String name) async { | 88 return (String name) async { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 106 if (topLevelKind != null) { | 116 if (topLevelKind != null) { |
| 107 bool isExported = element.librarySource != librarySource; | 117 bool isExported = element.librarySource != librarySource; |
| 108 declarations.add(new TopLevelDeclarationInSource(librarySource, | 118 declarations.add(new TopLevelDeclarationInSource(librarySource, |
| 109 new TopLevelDeclaration(topLevelKind, element.name), isExported)); | 119 new TopLevelDeclaration(topLevelKind, element.name), isExported)); |
| 110 } | 120 } |
| 111 } | 121 } |
| 112 return declarations; | 122 return declarations; |
| 113 }; | 123 }; |
| 114 } | 124 } |
| 115 } | 125 } |
| OLD | NEW |