| Index: pkg/analysis_server/lib/plugin/edit/fix/fix_dart.dart
|
| diff --git a/pkg/analysis_server/lib/plugin/edit/fix/fix_dart.dart b/pkg/analysis_server/lib/plugin/edit/fix/fix_dart.dart
|
| index 9ff487e9819817ac48b8d1c409cffddc74de5ff0..e5b0f1f5625ed95db6f2b13874c2f91874f31b4d 100644
|
| --- a/pkg/analysis_server/lib/plugin/edit/fix/fix_dart.dart
|
| +++ b/pkg/analysis_server/lib/plugin/edit/fix/fix_dart.dart
|
| @@ -7,16 +7,13 @@ import 'dart:async';
|
| import 'package:analysis_server/plugin/edit/fix/fix_core.dart';
|
| import 'package:analysis_server/src/services/correction/fix_internal.dart'
|
| show DartFixContextImpl;
|
| -import 'package:analysis_server/src/services/correction/namespace.dart'
|
| - show getExportedElement;
|
| import 'package:analyzer/dart/ast/ast.dart';
|
| -import 'package:analyzer/dart/element/element.dart';
|
| -import 'package:analyzer/src/dart/analysis/ast_provider_context.dart';
|
| +import 'package:analyzer/src/dart/analysis/ast_provider_driver.dart';
|
| +import 'package:analyzer/src/dart/analysis/driver.dart';
|
| import 'package:analyzer/src/dart/analysis/top_level_declaration.dart';
|
| import 'package:analyzer/src/dart/element/ast_provider.dart';
|
| import 'package:analyzer/src/generated/engine.dart';
|
| import 'package:analyzer/src/generated/source.dart';
|
| -import 'package:analyzer/src/task/dart.dart' show LIBRARY_ELEMENT4;
|
|
|
| /**
|
| * Complete with top-level declarations with the given [name].
|
| @@ -55,25 +52,17 @@ abstract class DartFixContext implements FixContext {
|
| abstract class DartFixContributor implements FixContributor {
|
| @override
|
| Future<List<Fix>> computeFixes(FixContext context) async {
|
| - AnalysisContext analysisContext = context.analysisContext;
|
| + AnalysisDriver driver = context.analysisDriver;
|
| Source source = context.error.source;
|
| if (!AnalysisEngine.isDartFileName(source.fullName)) {
|
| return Fix.EMPTY_LIST;
|
| }
|
| - List<Source> libraries = analysisContext.getLibrariesContaining(source);
|
| - if (libraries.isEmpty) {
|
| - return Fix.EMPTY_LIST;
|
| - }
|
| - CompilationUnit unit =
|
| - analysisContext.getResolvedCompilationUnit2(source, libraries[0]);
|
| + CompilationUnit unit = (await driver.getResult(source.fullName)).unit;
|
| if (unit == null) {
|
| return Fix.EMPTY_LIST;
|
| }
|
| - DartFixContext dartContext = new DartFixContextImpl(
|
| - context,
|
| - _getTopLevelDeclarations(analysisContext),
|
| - new AstProviderForContext(analysisContext),
|
| - unit);
|
| + DartFixContext dartContext =
|
| + new DartFixContextImpl(context, new AstProviderForDriver(driver), unit);
|
| return internalComputeFixes(dartContext);
|
| }
|
|
|
| @@ -81,43 +70,4 @@ abstract class DartFixContributor implements FixContributor {
|
| * Return a list of fixes for the given [context].
|
| */
|
| Future<List<Fix>> internalComputeFixes(DartFixContext context);
|
| -
|
| - GetTopLevelDeclarations _getTopLevelDeclarations(AnalysisContext context) {
|
| - return (String name) async {
|
| - List<TopLevelDeclarationInSource> declarations = [];
|
| - List<Source> librarySources = context.librarySources;
|
| - for (Source librarySource in librarySources) {
|
| - // Prepare the LibraryElement.
|
| - LibraryElement libraryElement =
|
| - context.getResult(librarySource, LIBRARY_ELEMENT4);
|
| - if (libraryElement == null) {
|
| - continue;
|
| - }
|
| - // Prepare the exported Element.
|
| - Element element = getExportedElement(libraryElement, name);
|
| - if (element == null) {
|
| - continue;
|
| - }
|
| - if (element is PropertyAccessorElement) {
|
| - element = (element as PropertyAccessorElement).variable;
|
| - }
|
| - // Add a new declaration.
|
| - TopLevelDeclarationKind topLevelKind;
|
| - if (element.kind == ElementKind.CLASS ||
|
| - element.kind == ElementKind.FUNCTION_TYPE_ALIAS) {
|
| - topLevelKind = TopLevelDeclarationKind.type;
|
| - } else if (element.kind == ElementKind.FUNCTION) {
|
| - topLevelKind = TopLevelDeclarationKind.function;
|
| - } else if (element.kind == ElementKind.TOP_LEVEL_VARIABLE) {
|
| - topLevelKind = TopLevelDeclarationKind.variable;
|
| - }
|
| - if (topLevelKind != null) {
|
| - bool isExported = element.librarySource != librarySource;
|
| - declarations.add(new TopLevelDeclarationInSource(librarySource,
|
| - new TopLevelDeclaration(topLevelKind, element.name), isExported));
|
| - }
|
| - }
|
| - return declarations;
|
| - };
|
| - }
|
| }
|
|
|