| 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.src.utilities.change_builder_dart; | 5 import 'dart:async'; |
| 6 | 6 |
| 7 import 'package:analysis_server/plugin/protocol/protocol.dart' hide ElementKind; | 7 import 'package:analysis_server/plugin/protocol/protocol.dart' hide ElementKind; |
| 8 import 'package:analysis_server/src/provisional/edit/utilities/change_builder_co
re.dart'; | 8 import 'package:analysis_server/src/provisional/edit/utilities/change_builder_co
re.dart'; |
| 9 import 'package:analysis_server/src/provisional/edit/utilities/change_builder_da
rt.dart'; | 9 import 'package:analysis_server/src/provisional/edit/utilities/change_builder_da
rt.dart'; |
| 10 import 'package:analysis_server/src/services/correction/name_suggestion.dart'; | 10 import 'package:analysis_server/src/services/correction/name_suggestion.dart'; |
| 11 import 'package:analysis_server/src/services/correction/util.dart'; | 11 import 'package:analysis_server/src/services/correction/util.dart'; |
| 12 import 'package:analysis_server/src/utilities/change_builder_core.dart'; | 12 import 'package:analysis_server/src/utilities/change_builder_core.dart'; |
| 13 import 'package:analyzer/dart/ast/ast.dart'; | 13 import 'package:analyzer/dart/ast/ast.dart'; |
| 14 import 'package:analyzer/dart/ast/token.dart'; | 14 import 'package:analyzer/dart/ast/token.dart'; |
| 15 import 'package:analyzer/dart/element/element.dart'; | 15 import 'package:analyzer/dart/element/element.dart'; |
| 16 import 'package:analyzer/dart/element/type.dart'; | 16 import 'package:analyzer/dart/element/type.dart'; |
| 17 import 'package:analyzer/src/generated/engine.dart'; | 17 import 'package:analyzer/src/dart/analysis/driver.dart'; |
| 18 import 'package:analyzer/src/generated/source.dart'; | 18 import 'package:analyzer/src/generated/source.dart'; |
| 19 import 'package:analyzer/src/generated/utilities_dart.dart'; | 19 import 'package:analyzer/src/generated/utilities_dart.dart'; |
| 20 | 20 |
| 21 /** | 21 /** |
| 22 * A [ChangeBuilder] used to build changes in Dart files. | 22 * A [ChangeBuilder] used to build changes in Dart files. |
| 23 */ | 23 */ |
| 24 class DartChangeBuilderImpl extends ChangeBuilderImpl | 24 class DartChangeBuilderImpl extends ChangeBuilderImpl |
| 25 implements DartChangeBuilder { | 25 implements DartChangeBuilder { |
| 26 /** | 26 /** |
| 27 * The analysis context in which the files being edited were analyzed. | 27 * The analysis driver in which the files being edited were analyzed. |
| 28 */ | 28 */ |
| 29 final AnalysisContext context; | 29 final AnalysisDriver driver; |
| 30 | 30 |
| 31 /** | 31 /** |
| 32 * Initialize a newly created change builder. | 32 * Initialize a newly created change builder. |
| 33 */ | 33 */ |
| 34 DartChangeBuilderImpl(this.context); | 34 DartChangeBuilderImpl(this.driver); |
| 35 | 35 |
| 36 @override | 36 @override |
| 37 DartFileEditBuilderImpl createFileEditBuilder(Source source, int fileStamp) { | 37 Future<DartFileEditBuilderImpl> createFileEditBuilder( |
| 38 return new DartFileEditBuilderImpl(this, source, fileStamp); | 38 String path, int fileStamp) async { |
| 39 AnalysisResult result = await driver.getResult(path); |
| 40 return new DartFileEditBuilderImpl(this, path, fileStamp, result.unit); |
| 39 } | 41 } |
| 40 } | 42 } |
| 41 | 43 |
| 42 /** | 44 /** |
| 43 * An [EditBuilder] used to build edits in Dart files. | 45 * An [EditBuilder] used to build edits in Dart files. |
| 44 */ | 46 */ |
| 45 class DartEditBuilderImpl extends EditBuilderImpl implements DartEditBuilder { | 47 class DartEditBuilderImpl extends EditBuilderImpl implements DartEditBuilder { |
| 46 /** | 48 /** |
| 47 * A utility class used to help build the source code. | 49 * A utility class used to help build the source code. |
| 48 */ | 50 */ |
| (...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 | 461 |
| 460 /** | 462 /** |
| 461 * A set containing the sources of the libraries that need to be imported in | 463 * A set containing the sources of the libraries that need to be imported in |
| 462 * order to make visible the names used in generated code. | 464 * order to make visible the names used in generated code. |
| 463 */ | 465 */ |
| 464 Set<Source> librariesToImport = new Set<Source>(); | 466 Set<Source> librariesToImport = new Set<Source>(); |
| 465 | 467 |
| 466 /** | 468 /** |
| 467 * Initialize a newly created builder to build a source file edit within the | 469 * Initialize a newly created builder to build a source file edit within the |
| 468 * change being built by the given [changeBuilder]. The file being edited has | 470 * change being built by the given [changeBuilder]. The file being edited has |
| 469 * the given [source] and [timeStamp]. | 471 * the given [source] and [timeStamp], and the given fully resolved [unit]. |
| 470 */ | 472 */ |
| 471 DartFileEditBuilderImpl( | 473 DartFileEditBuilderImpl(DartChangeBuilderImpl changeBuilder, String path, |
| 472 DartChangeBuilderImpl changeBuilder, Source source, int timeStamp) | 474 int timeStamp, this.unit) |
| 473 : super(changeBuilder, source, timeStamp) { | 475 : super(changeBuilder, path, timeStamp) { |
| 474 AnalysisContext context = changeBuilder.context; | |
| 475 List<Source> librariesContaining = context.getLibrariesContaining(source); | |
| 476 if (librariesContaining.length < 1) { | |
| 477 throw new StateError('Cannot build edits for ${source.fullName}'); | |
| 478 } | |
| 479 unit = context.resolveCompilationUnit2(source, librariesContaining[0]); | |
| 480 utils = new CorrectionUtils(unit); | 476 utils = new CorrectionUtils(unit); |
| 481 } | 477 } |
| 482 | 478 |
| 483 @override | 479 @override |
| 484 DartEditBuilderImpl createEditBuilder(int offset, int length) { | 480 DartEditBuilderImpl createEditBuilder(int offset, int length) { |
| 485 return new DartEditBuilderImpl(this, offset, length); | 481 return new DartEditBuilderImpl(this, offset, length); |
| 486 } | 482 } |
| 487 } | 483 } |
| OLD | NEW |