| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 analyzer.src.generated.incremental_resolver; | 5 library analyzer.src.generated.incremental_resolver; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 import 'dart:math' as math; | 8 import 'dart:math' as math; |
| 9 | 9 |
| 10 import 'package:analyzer/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 import 'package:analyzer/src/generated/parser.dart'; | 29 import 'package:analyzer/src/generated/parser.dart'; |
| 30 import 'package:analyzer/src/generated/resolver.dart'; | 30 import 'package:analyzer/src/generated/resolver.dart'; |
| 31 import 'package:analyzer/src/generated/source.dart'; | 31 import 'package:analyzer/src/generated/source.dart'; |
| 32 import 'package:analyzer/src/generated/utilities_dart.dart'; | 32 import 'package:analyzer/src/generated/utilities_dart.dart'; |
| 33 import 'package:analyzer/src/task/dart.dart'; | 33 import 'package:analyzer/src/task/dart.dart'; |
| 34 import 'package:analyzer/task/dart.dart'; | 34 import 'package:analyzer/task/dart.dart'; |
| 35 import 'package:analyzer/task/general.dart' show CONTENT, LINE_INFO; | 35 import 'package:analyzer/task/general.dart' show CONTENT, LINE_INFO; |
| 36 import 'package:analyzer/task/model.dart'; | 36 import 'package:analyzer/task/model.dart'; |
| 37 | 37 |
| 38 /** | 38 /** |
| 39 * If `true`, an attempt to resolve API-changing modifications is made. | |
| 40 */ | |
| 41 bool _resolveApiChanges = false; | |
| 42 | |
| 43 /** | |
| 44 * This method is used to enable/disable API-changing modifications resolution. | |
| 45 */ | |
| 46 void set test_resolveApiChanges(bool value) { | |
| 47 _resolveApiChanges = value; | |
| 48 } | |
| 49 | |
| 50 /** | |
| 51 * The [Delta] implementation used by incremental resolver. | 39 * The [Delta] implementation used by incremental resolver. |
| 52 * It keeps Dart results that are either don't change or are updated. | 40 * It keeps Dart results that are either don't change or are updated. |
| 53 */ | 41 */ |
| 54 class IncrementalBodyDelta extends Delta { | 42 class IncrementalBodyDelta extends Delta { |
| 55 /** | 43 /** |
| 56 * The offset of the changed contents. | 44 * The offset of the changed contents. |
| 57 */ | 45 */ |
| 58 final int updateOffset; | 46 final int updateOffset; |
| 59 | 47 |
| 60 /** | 48 /** |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 _source = definingUnit.source, | 238 _source = definingUnit.source, |
| 251 _librarySource = definingUnit.library.source, | 239 _librarySource = definingUnit.library.source, |
| 252 _updateEndOld = updateEndOld, | 240 _updateEndOld = updateEndOld, |
| 253 _updateEndNew = updateEndNew, | 241 _updateEndNew = updateEndNew, |
| 254 _updateDelta = updateEndNew - updateEndOld; | 242 _updateDelta = updateEndNew - updateEndOld; |
| 255 | 243 |
| 256 /** | 244 /** |
| 257 * Resolve [body], reporting any errors or warnings to the given listener. | 245 * Resolve [body], reporting any errors or warnings to the given listener. |
| 258 * | 246 * |
| 259 * [body] - the root of the AST structure to be resolved. | 247 * [body] - the root of the AST structure to be resolved. |
| 260 * | |
| 261 * Returns `true` if resolution was successful. | |
| 262 */ | 248 */ |
| 263 bool resolve(BlockFunctionBody body) { | 249 void resolve(BlockFunctionBody body) { |
| 264 logger.enter('resolve: $_definingUnit'); | 250 logger.enter('resolve: $_definingUnit'); |
| 265 try { | 251 try { |
| 266 Declaration executable = _findResolutionRoot(body); | 252 Declaration executable = _findResolutionRoot(body); |
| 267 _prepareResolutionContext(executable); | 253 _prepareResolutionContext(executable); |
| 268 // update elements | 254 // update elements |
| 269 _updateCache(); | 255 _updateCache(); |
| 270 _updateElementNameOffsets(); | 256 _updateElementNameOffsets(); |
| 271 _buildElements(executable, body); | 257 _buildElements(executable, body); |
| 272 // resolve | 258 // resolve |
| 273 _resolveReferences(executable); | 259 _resolveReferences(executable); |
| 274 _computeConstants(executable); | 260 _computeConstants(executable); |
| 275 _resolveErrors = errorListener.getErrorsForSource(_source); | 261 _resolveErrors = errorListener.getErrorsForSource(_source); |
| 276 // verify | 262 // verify |
| 277 _verify(executable); | 263 _verify(executable); |
| 278 _context.invalidateLibraryHints(_librarySource); | 264 _context.invalidateLibraryHints(_librarySource); |
| 279 // update entry errors | 265 // update entry errors |
| 280 _updateEntry(); | 266 _updateEntry(); |
| 281 // OK | |
| 282 return true; | |
| 283 } finally { | 267 } finally { |
| 284 logger.exit(); | 268 logger.exit(); |
| 285 } | 269 } |
| 286 } | 270 } |
| 287 | 271 |
| 288 void _buildElements(Declaration executable, AstNode node) { | 272 void _buildElements(Declaration executable, AstNode node) { |
| 289 LoggingTimer timer = logger.startTimer(); | 273 LoggingTimer timer = logger.startTimer(); |
| 290 try { | 274 try { |
| 291 ElementHolder holder = new ElementHolder(); | 275 ElementHolder holder = new ElementHolder(); |
| 292 ElementBuilder builder = new ElementBuilder(holder, _definingUnit); | 276 ElementBuilder builder = new ElementBuilder(holder, _definingUnit); |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 List<AnalysisError> _newScanErrors = <AnalysisError>[]; | 524 List<AnalysisError> _newScanErrors = <AnalysisError>[]; |
| 541 List<AnalysisError> _newParseErrors = <AnalysisError>[]; | 525 List<AnalysisError> _newParseErrors = <AnalysisError>[]; |
| 542 | 526 |
| 543 PoorMansIncrementalResolver( | 527 PoorMansIncrementalResolver( |
| 544 this._typeProvider, | 528 this._typeProvider, |
| 545 this._unitSource, | 529 this._unitSource, |
| 546 this._cache, | 530 this._cache, |
| 547 this._sourceEntry, | 531 this._sourceEntry, |
| 548 this._unitEntry, | 532 this._unitEntry, |
| 549 this._oldUnit, | 533 this._oldUnit, |
| 550 bool resolveApiChanges) { | 534 bool resolveApiChanges); |
| 551 _resolveApiChanges = resolveApiChanges; | |
| 552 } | |
| 553 | 535 |
| 554 /** | 536 /** |
| 555 * Attempts to update [_oldUnit] to the state corresponding to [newCode]. | 537 * Attempts to update [_oldUnit] to the state corresponding to [newCode]. |
| 556 * Returns `true` if success, or `false` otherwise. | 538 * Returns `true` if success, or `false` otherwise. |
| 557 * The [_oldUnit] might be damaged. | 539 * The [_oldUnit] might be damaged. |
| 558 */ | 540 */ |
| 559 bool resolve(String newCode) { | 541 bool resolve(String newCode) { |
| 560 logger.enter('diff/resolve $_unitSource'); | 542 logger.enter('diff/resolve $_unitSource'); |
| 561 try { | 543 try { |
| 562 // prepare old unit | 544 // prepare old unit |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 725 } | 707 } |
| 726 // perform incremental resolution | 708 // perform incremental resolution |
| 727 IncrementalResolver incrementalResolver = new IncrementalResolver( | 709 IncrementalResolver incrementalResolver = new IncrementalResolver( |
| 728 _cache, | 710 _cache, |
| 729 _sourceEntry, | 711 _sourceEntry, |
| 730 _unitEntry, | 712 _unitEntry, |
| 731 _unitElement, | 713 _unitElement, |
| 732 _updateOffset, | 714 _updateOffset, |
| 733 _updateEndOld, | 715 _updateEndOld, |
| 734 _updateEndNew); | 716 _updateEndNew); |
| 735 bool success = incrementalResolver.resolve(newNode); | 717 incrementalResolver.resolve(newNode); |
| 736 // check if success | |
| 737 if (!success) { | |
| 738 logger.log('Failure: element model changed.'); | |
| 739 return false; | |
| 740 } | |
| 741 // update DartEntry | 718 // update DartEntry |
| 742 _updateEntry(); | 719 _updateEntry(); |
| 743 logger.log('Success.'); | 720 logger.log('Success.'); |
| 744 return true; | 721 return true; |
| 745 } | 722 } |
| 746 } catch (e, st) { | 723 } catch (e, st) { |
| 747 logger.logException(e, st); | 724 logger.logException(e, st); |
| 748 logger.log('Failure: exception.'); | 725 logger.log('Failure: exception.'); |
| 749 // The incremental resolver log is usually turned off, | 726 // The incremental resolver log is usually turned off, |
| 750 // so also log the exception to the instrumentation log. | 727 // so also log the exception to the instrumentation log. |
| (...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1311 @override | 1288 @override |
| 1312 String toString() => name; | 1289 String toString() => name; |
| 1313 } | 1290 } |
| 1314 | 1291 |
| 1315 class _TokenPair { | 1292 class _TokenPair { |
| 1316 final _TokenDifferenceKind kind; | 1293 final _TokenDifferenceKind kind; |
| 1317 final Token oldToken; | 1294 final Token oldToken; |
| 1318 final Token newToken; | 1295 final Token newToken; |
| 1319 _TokenPair(this.kind, this.oldToken, this.newToken); | 1296 _TokenPair(this.kind, this.oldToken, this.newToken); |
| 1320 } | 1297 } |
| OLD | NEW |