| 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 analyzer.src.context.cache; | 5 library analyzer.src.context.cache; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 | 9 |
| 10 import 'package:analyzer/src/generated/engine.dart' | 10 import 'package:analyzer/src/generated/engine.dart' |
| (...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 483 data.state = CacheState.VALID; | 483 data.state = CacheState.VALID; |
| 484 data.value = value == null ? descriptor.defaultValue : value; | 484 data.value = value == null ? descriptor.defaultValue : value; |
| 485 } | 485 } |
| 486 | 486 |
| 487 /** | 487 /** |
| 488 * Set the value of the result represented by the given [descriptor] to the | 488 * Set the value of the result represented by the given [descriptor] to the |
| 489 * given [value], keep its dependency, invalidate all the dependent result. | 489 * given [value], keep its dependency, invalidate all the dependent result. |
| 490 */ | 490 */ |
| 491 void setValueIncremental(ResultDescriptor descriptor, dynamic value) { | 491 void setValueIncremental(ResultDescriptor descriptor, dynamic value) { |
| 492 ResultData data = getResultData(descriptor); | 492 ResultData data = getResultData(descriptor); |
| 493 List<TargetedResult> dependedOn = data.dependedOnResults; | 493 _invalidateDependentResults(data, null); |
| 494 _invalidate(descriptor, null); | 494 data.state = CacheState.VALID; |
| 495 setValue(descriptor, value, dependedOn); | 495 data.value = value; |
| 496 } | 496 } |
| 497 | 497 |
| 498 @override | 498 @override |
| 499 String toString() { | 499 String toString() { |
| 500 StringBuffer buffer = new StringBuffer(); | 500 StringBuffer buffer = new StringBuffer(); |
| 501 _writeOn(buffer); | 501 _writeOn(buffer); |
| 502 return buffer.toString(); | 502 return buffer.toString(); |
| 503 } | 503 } |
| 504 | 504 |
| 505 /** | 505 /** |
| (...skipping 27 matching lines...) Expand all Loading... |
| 533 } | 533 } |
| 534 // Stop depending on other results. | 534 // Stop depending on other results. |
| 535 TargetedResult thisResult = new TargetedResult(target, descriptor); | 535 TargetedResult thisResult = new TargetedResult(target, descriptor); |
| 536 for (TargetedResult dependedOnResult in thisData.dependedOnResults) { | 536 for (TargetedResult dependedOnResult in thisData.dependedOnResults) { |
| 537 ResultData data = _partition._getDataFor(dependedOnResult); | 537 ResultData data = _partition._getDataFor(dependedOnResult); |
| 538 if (data != null && deltaResult != DeltaResult.KEEP_CONTINUE) { | 538 if (data != null && deltaResult != DeltaResult.KEEP_CONTINUE) { |
| 539 data.dependentResults.remove(thisResult); | 539 data.dependentResults.remove(thisResult); |
| 540 } | 540 } |
| 541 } | 541 } |
| 542 // Invalidate results that depend on this result. | 542 // Invalidate results that depend on this result. |
| 543 List<TargetedResult> dependentResults = thisData.dependentResults.toList(); | 543 _invalidateDependentResults(thisData, delta); |
| 544 for (TargetedResult dependentResult in dependentResults) { | |
| 545 CacheEntry entry = _partition.get(dependentResult.target); | |
| 546 if (entry != null) { | |
| 547 entry._invalidate(dependentResult.result, delta); | |
| 548 } | |
| 549 } | |
| 550 // If empty, remove the entry altogether. | 544 // If empty, remove the entry altogether. |
| 551 if (_resultMap.isEmpty) { | 545 if (_resultMap.isEmpty) { |
| 552 _partition._targetMap.remove(target); | 546 _partition._targetMap.remove(target); |
| 553 _partition._removeIfSource(target); | 547 _partition._removeIfSource(target); |
| 554 } | 548 } |
| 555 // Notify controller. | 549 // Notify controller. |
| 556 _partition.onResultInvalidated | 550 _partition.onResultInvalidated |
| 557 .add(new InvalidatedResult(this, descriptor, thisData.value)); | 551 .add(new InvalidatedResult(this, descriptor, thisData.value)); |
| 558 } | 552 } |
| 559 | 553 |
| 560 /** | 554 /** |
| 561 * Invalidates all the results of this entry, with propagation. | 555 * Invalidates all the results of this entry, with propagation. |
| 562 */ | 556 */ |
| 563 void _invalidateAll() { | 557 void _invalidateAll() { |
| 564 List<ResultDescriptor> results = _resultMap.keys.toList(); | 558 List<ResultDescriptor> results = _resultMap.keys.toList(); |
| 565 for (ResultDescriptor result in results) { | 559 for (ResultDescriptor result in results) { |
| 566 _invalidate(result, null); | 560 _invalidate(result, null); |
| 567 } | 561 } |
| 568 } | 562 } |
| 569 | 563 |
| 570 /** | 564 /** |
| 565 * Invalidate results that depend on [thisData]. |
| 566 */ |
| 567 void _invalidateDependentResults(ResultData thisData, Delta delta) { |
| 568 List<TargetedResult> dependentResults = thisData.dependentResults.toList(); |
| 569 for (TargetedResult dependentResult in dependentResults) { |
| 570 CacheEntry entry = _partition.get(dependentResult.target); |
| 571 if (entry != null) { |
| 572 entry._invalidate(dependentResult.result, delta); |
| 573 } |
| 574 } |
| 575 } |
| 576 |
| 577 /** |
| 571 * Set the [dependedOn] on which this result depends. | 578 * Set the [dependedOn] on which this result depends. |
| 572 */ | 579 */ |
| 573 void _setDependedOnResults(ResultData thisData, TargetedResult thisResult, | 580 void _setDependedOnResults(ResultData thisData, TargetedResult thisResult, |
| 574 List<TargetedResult> dependedOn) { | 581 List<TargetedResult> dependedOn) { |
| 575 thisData.dependedOnResults.forEach((TargetedResult dependedOnResult) { | 582 thisData.dependedOnResults.forEach((TargetedResult dependedOnResult) { |
| 576 ResultData data = _partition._getDataFor(dependedOnResult); | 583 ResultData data = _partition._getDataFor(dependedOnResult); |
| 577 if (data != null) { | 584 if (data != null) { |
| 578 data.dependentResults.remove(thisResult); | 585 data.dependentResults.remove(thisResult); |
| 579 } | 586 } |
| 580 }); | 587 }); |
| (...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1166 void resultAccessed(TargetedResult result) {} | 1173 void resultAccessed(TargetedResult result) {} |
| 1167 | 1174 |
| 1168 @override | 1175 @override |
| 1169 List<TargetedResult> resultStored(TargetedResult newResult, newValue) { | 1176 List<TargetedResult> resultStored(TargetedResult newResult, newValue) { |
| 1170 return TargetedResult.EMPTY_LIST; | 1177 return TargetedResult.EMPTY_LIST; |
| 1171 } | 1178 } |
| 1172 | 1179 |
| 1173 @override | 1180 @override |
| 1174 void targetRemoved(AnalysisTarget target) {} | 1181 void targetRemoved(AnalysisTarget target) {} |
| 1175 } | 1182 } |
| OLD | NEW |