Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(254)

Side by Side Diff: pkg/analyzer/lib/src/context/context.dart

Issue 1737693004: Update SOURCE_KIND when a missing source file appears (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/dart/ast/ast.dart'; 10 import 'package:analyzer/dart/ast/ast.dart';
(...skipping 999 matching lines...) Expand 10 before | Expand all | Expand 10 after
1010 Source source, String originalContents, String newContents, bool notify) { 1010 Source source, String originalContents, String newContents, bool notify) {
1011 CacheEntry entry = _cache.get(source); 1011 CacheEntry entry = _cache.get(source);
1012 if (entry == null) { 1012 if (entry == null) {
1013 return false; 1013 return false;
1014 } 1014 }
1015 bool changed = newContents != originalContents; 1015 bool changed = newContents != originalContents;
1016 if (newContents != null) { 1016 if (newContents != null) {
1017 if (changed) { 1017 if (changed) {
1018 if (!analysisOptions.incremental || 1018 if (!analysisOptions.incremental ||
1019 !_tryPoorMansIncrementalResolution(source, newContents)) { 1019 !_tryPoorMansIncrementalResolution(source, newContents)) {
1020 _sourceChanged(source); 1020 // Equals check won't work because newContents is already in cache.
1021 // Disable it since we know the file changed.
Brian Wilkerson 2016/02/26 15:07:32 Why is the new content in the cache? I'm guessing
skybrian 2016/02/26 18:09:01 Within the analyzer, the only caller of handleCont
1022 _sourceChanged(source, skipIfEqual: false);
1021 } 1023 }
1022 entry.modificationTime = _contentCache.getModificationStamp(source); 1024 entry.modificationTime = _contentCache.getModificationStamp(source);
1023 entry.setValue(CONTENT, newContents, TargetedResult.EMPTY_LIST); 1025 entry.setValue(CONTENT, newContents, TargetedResult.EMPTY_LIST);
1024 } else { 1026 } else {
1025 entry.modificationTime = _contentCache.getModificationStamp(source); 1027 entry.modificationTime = _contentCache.getModificationStamp(source);
1026 } 1028 }
1027 } else if (originalContents != null) { 1029 } else if (originalContents != null) {
1028 // We are removing the overlay for the file, check if the file's 1030 // We are removing the overlay for the file, check if the file's
1029 // contents is the same as it was in the overlay. 1031 // contents is the same as it was in the overlay.
1030 try { 1032 try {
(...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after
1747 } else { 1749 } else {
1748 entry.explicitlyAdded = true; 1750 entry.explicitlyAdded = true;
1749 entry.modificationTime = getModificationStamp(source); 1751 entry.modificationTime = getModificationStamp(source);
1750 entry.setState(CONTENT, CacheState.INVALID); 1752 entry.setState(CONTENT, CacheState.INVALID);
1751 } 1753 }
1752 } 1754 }
1753 1755
1754 /** 1756 /**
1755 * Invalidate the [source] that was changed and any sources that referenced 1757 * Invalidate the [source] that was changed and any sources that referenced
1756 * the source before it existed. 1758 * the source before it existed.
1759 *
1760 * Note: source may be considered "changed" if it was previously missing,
1761 * but pointed to by an import or export directive.
1757 */ 1762 */
1758 void _sourceChanged(Source source) { 1763 void _sourceChanged(Source source, {skipIfEqual: true}) {
1759 CacheEntry entry = _cache.get(source); 1764 CacheEntry entry = _cache.get(source);
1760 // If the source is removed, we don't care about it. 1765 // If the source has no cache entry, there is nothing to invalidate.
1761 if (entry == null) { 1766 if (entry == null) {
1762 return; 1767 return;
1763 } 1768 }
1764 // Check whether the content of the source is the same as it was the last 1769 // Check whether the content of the source is the same as it was the last
1765 // time. 1770 // time.
1766 String sourceContent = entry.getValue(CONTENT); 1771 String sourceContent = entry.getValue(CONTENT);
1767 if (sourceContent != null) { 1772 if (sourceContent != null && skipIfEqual) {
1768 entry.setState(CONTENT, CacheState.FLUSHED); 1773 entry.setState(CONTENT, CacheState.FLUSHED);
1769 try { 1774 try {
1770 TimestampedData<String> fileContents = getContents(source); 1775 TimestampedData<String> fileContents = getContents(source);
1771 if (fileContents.data == sourceContent) { 1776 if (fileContents.data == sourceContent) {
1772 int time = fileContents.modificationTime; 1777 int time = fileContents.modificationTime;
1773 for (CacheEntry entry in _entriesFor(source)) { 1778 for (CacheEntry entry in _entriesFor(source)) {
1774 entry.modificationTime = time; 1779 entry.modificationTime = time;
1775 } 1780 }
1776 return; 1781 return;
1777 } 1782 }
(...skipping 28 matching lines...) Expand all
1806 // print( 1811 // print(
1807 // 'dartDelta: add=${dartDelta.addedNames} remove=${dartDelta.r emovedNames}'); 1812 // 'dartDelta: add=${dartDelta.addedNames} remove=${dartDelta.r emovedNames}');
1808 delta = dartDelta; 1813 delta = dartDelta;
1809 entry.setState(CONTENT, CacheState.INVALID, delta: delta); 1814 entry.setState(CONTENT, CacheState.INVALID, delta: delta);
1810 return; 1815 return;
1811 } 1816 }
1812 } 1817 }
1813 } 1818 }
1814 } 1819 }
1815 entry.setState(CONTENT, CacheState.INVALID); 1820 entry.setState(CONTENT, CacheState.INVALID);
1821 // Ensure that the SOURCE_KIND is recalculated when a missing
1822 // source file is created.
1823 entry.setState(MODIFICATION_TIME, CacheState.INVALID);
Brian Wilkerson 2016/02/26 15:07:32 If we're trying to ensure that SOURCE_KIND is reca
skybrian 2016/02/26 18:09:01 I thought it would be less brittle this way. Since
Brian Wilkerson 2016/02/26 18:35:57 It probably doesn't matter here, but in general I'
1816 } 1824 }
1817 driver.reset(); 1825 driver.reset();
1818 for (WorkManager workManager in workManagers) { 1826 for (WorkManager workManager in workManagers) {
1819 workManager.applyChange( 1827 workManager.applyChange(
1820 Source.EMPTY_LIST, <Source>[source], Source.EMPTY_LIST); 1828 Source.EMPTY_LIST, <Source>[source], Source.EMPTY_LIST);
1821 } 1829 }
1822 } 1830 }
1823 1831
1824 /** 1832 /**
1825 * Record that the give [source] has been deleted. 1833 * Record that the give [source] has been deleted.
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
2128 } 2136 }
2129 DartSdk sdk = factory.dartSdk; 2137 DartSdk sdk = factory.dartSdk;
2130 if (sdk == null) { 2138 if (sdk == null) {
2131 throw new IllegalArgumentException( 2139 throw new IllegalArgumentException(
2132 "The source factory for an SDK analysis context must have a DartUriRes olver"); 2140 "The source factory for an SDK analysis context must have a DartUriRes olver");
2133 } 2141 }
2134 return new AnalysisCache( 2142 return new AnalysisCache(
2135 <CachePartition>[AnalysisEngine.instance.partitionManager.forSdk(sdk)]); 2143 <CachePartition>[AnalysisEngine.instance.partitionManager.forSdk(sdk)]);
2136 } 2144 }
2137 } 2145 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/context/source.dart » ('j') | pkg/analyzer/lib/src/context/source.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698