Chromium Code Reviews| 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.context; | 5 library analyzer.src.context.context; |
| 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/cancelable_future.dart'; | 10 import 'package:analyzer/src/cancelable_future.dart'; |
| (...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 630 for (List<PendingFuture> pendingFutures in _pendingFutureTargets.values) { | 630 for (List<PendingFuture> pendingFutures in _pendingFutureTargets.values) { |
| 631 for (PendingFuture pendingFuture in pendingFutures) { | 631 for (PendingFuture pendingFuture in pendingFutures) { |
| 632 pendingFuture.forciblyComplete(); | 632 pendingFuture.forciblyComplete(); |
| 633 } | 633 } |
| 634 } | 634 } |
| 635 _pendingFutureTargets.clear(); | 635 _pendingFutureTargets.clear(); |
| 636 } | 636 } |
| 637 | 637 |
| 638 @override | 638 @override |
| 639 List<CompilationUnit> ensureResolvedDartUnits(Source unitSource) { | 639 List<CompilationUnit> ensureResolvedDartUnits(Source unitSource) { |
| 640 // TODO(brianwilkerson) Implement this. | 640 // Check every library. |
| 641 List<CompilationUnit> units = <CompilationUnit>[]; | |
| 642 List<Source> containingLibraries = getLibrariesContaining(unitSource); | |
| 643 for (Source librarySource in containingLibraries) { | |
| 644 LibrarySpecificUnit target = | |
| 645 new LibrarySpecificUnit(librarySource, unitSource); | |
| 646 CompilationUnit unit = _getResult(target, RESOLVED_UNIT); | |
| 647 if (unit == null) { | |
| 648 units = null; | |
| 649 break; | |
| 650 } | |
| 651 units.add(unit); | |
| 652 } | |
| 653 // If we have results, then we're done. | |
| 654 if (units != null) { | |
| 655 return units; | |
| 656 } | |
| 657 // Schedule recomputing RESOLVED_UNIT results. | |
| 658 for (Source librarySource in containingLibraries) { | |
| 659 LibrarySpecificUnit target = | |
| 660 new LibrarySpecificUnit(librarySource, unitSource); | |
| 661 if (_getResultState(target, RESOLVED_UNIT) == CacheState.FLUSHED) { | |
| 662 dartWorkManager.addPriorityResult(target, RESOLVED_UNIT); | |
| 663 } | |
| 664 } | |
| 641 return null; | 665 return null; |
| 642 // cache.CacheEntry entry = _cache.get(unitSource); | |
| 643 // // Check every library. | |
| 644 // List<CompilationUnit> units = <CompilationUnit>[]; | |
| 645 // List<Source> containingLibraries = entry.containingLibraries; | |
| 646 // for (Source librarySource in containingLibraries) { | |
| 647 // CompilationUnit unit = | |
| 648 // entry.getValueInLibrary(DartEntry.RESOLVED_UNIT, librarySource); | |
| 649 // if (unit == null) { | |
| 650 // units = null; | |
| 651 // break; | |
| 652 // } | |
| 653 // units.add(unit); | |
| 654 // } | |
| 655 // // Invalidate the flushed RESOLVED_UNIT to force it eventually. | |
| 656 // if (units == null) { | |
| 657 // bool shouldBeScheduled = false; | |
| 658 // for (Source librarySource in containingLibraries) { | |
| 659 // if (entry.getStateInLibrary(DartEntry.RESOLVED_UNIT, librarySource) == | |
| 660 // CacheState.FLUSHED) { | |
| 661 // entry.setStateInLibrary( | |
| 662 // DartEntry.RESOLVED_UNIT, librarySource, CacheState.INVALID); | |
| 663 // shouldBeScheduled = true; | |
| 664 // } | |
| 665 // } | |
| 666 // if (shouldBeScheduled) { | |
| 667 // _workManager.add(unitSource, SourcePriority.UNKNOWN); | |
| 668 // } | |
| 669 // // We cannot provide resolved units right now, | |
| 670 // // but the future analysis will. | |
| 671 // return null; | |
| 672 // } | |
| 673 // // done | |
| 674 // return units; | |
| 675 } | 666 } |
| 676 | 667 |
| 677 @override | 668 @override |
| 678 bool exists(Source source) { | 669 bool exists(Source source) { |
| 679 if (source == null) { | 670 if (source == null) { |
| 680 return false; | 671 return false; |
| 681 } | 672 } |
| 682 if (_contentCache.getContents(source) != null) { | 673 if (_contentCache.getContents(source) != null) { |
| 683 return true; | 674 return true; |
| 684 } | 675 } |
| (...skipping 790 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1475 cache.CacheEntry entry = _cache.get(target); | 1466 cache.CacheEntry entry = _cache.get(target); |
| 1476 if (entry == null) { | 1467 if (entry == null) { |
| 1477 return descriptor.defaultValue; | 1468 return descriptor.defaultValue; |
| 1478 } | 1469 } |
| 1479 if (entry.isValid(descriptor)) { | 1470 if (entry.isValid(descriptor)) { |
| 1480 return entry.getValue(descriptor); | 1471 return entry.getValue(descriptor); |
| 1481 } | 1472 } |
| 1482 return descriptor.defaultValue; | 1473 return descriptor.defaultValue; |
| 1483 } | 1474 } |
| 1484 | 1475 |
| 1476 CacheState _getResultState( | |
|
Brian Wilkerson
2015/05/11 18:36:49
Should this be moved to AnalysisCache?
scheglov
2015/05/11 18:46:07
Will move getValue() and getState() in the followi
| |
| 1477 AnalysisTarget target, ResultDescriptor descriptor) { | |
| 1478 cache.CacheEntry entry = _cache.get(target); | |
| 1479 if (entry == null) { | |
| 1480 return CacheState.INVALID; | |
| 1481 } | |
| 1482 return entry.getState(descriptor); | |
| 1483 } | |
| 1484 | |
| 1485 /** | 1485 /** |
| 1486 * Return a list containing all of the sources known to this context that have | 1486 * Return a list containing all of the sources known to this context that have |
| 1487 * the given [kind]. | 1487 * the given [kind]. |
| 1488 */ | 1488 */ |
| 1489 List<Source> _getSources(SourceKind kind) { | 1489 List<Source> _getSources(SourceKind kind) { |
| 1490 List<Source> sources = new List<Source>(); | 1490 List<Source> sources = new List<Source>(); |
| 1491 MapIterator<AnalysisTarget, cache.CacheEntry> iterator = _cache.iterator(); | 1491 MapIterator<AnalysisTarget, cache.CacheEntry> iterator = _cache.iterator(); |
| 1492 while (iterator.moveNext()) { | 1492 while (iterator.moveNext()) { |
| 1493 if (iterator.value.getValue(SOURCE_KIND) == kind && | 1493 if (iterator.value.getValue(SOURCE_KIND) == kind && |
| 1494 iterator.key is Source) { | 1494 iterator.key is Source) { |
| (...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2084 PendingFuture pendingFuture = | 2084 PendingFuture pendingFuture = |
| 2085 new PendingFuture<T>(_context, target, computeValue); | 2085 new PendingFuture<T>(_context, target, computeValue); |
| 2086 if (!pendingFuture.evaluate(entry)) { | 2086 if (!pendingFuture.evaluate(entry)) { |
| 2087 _context._pendingFutureTargets | 2087 _context._pendingFutureTargets |
| 2088 .putIfAbsent(target, () => <PendingFuture>[]) | 2088 .putIfAbsent(target, () => <PendingFuture>[]) |
| 2089 .add(pendingFuture); | 2089 .add(pendingFuture); |
| 2090 } | 2090 } |
| 2091 return pendingFuture.future; | 2091 return pendingFuture.future; |
| 2092 } | 2092 } |
| 2093 } | 2093 } |
| OLD | NEW |