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

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: oops, fix the test 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
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/compile_time_error_code_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // Don't compare with old contents because the cache has already been
1021 // updated, and we know at this point that it changed.
1022 _sourceChanged(source, compareWithOld: 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, {bool compareWithOld: 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
1765 // time. 1770 String oldContents = compareWithOld ? entry.getValue(CONTENT) : null;
1766 String sourceContent = entry.getValue(CONTENT); 1771
1767 if (sourceContent != null) { 1772 // Flush so that from now on we will get new contents.
1768 entry.setState(CONTENT, CacheState.FLUSHED); 1773 // (For example, in getLibrariesContaining.)
1774 entry.setState(CONTENT, CacheState.FLUSHED);
1775
1776 if (oldContents != null) {
1777 // Fast path if the content is the same as it was last time.
1769 try { 1778 try {
1770 TimestampedData<String> fileContents = getContents(source); 1779 TimestampedData<String> fileContents = getContents(source);
1771 if (fileContents.data == sourceContent) { 1780 if (fileContents.data == oldContents) {
1772 int time = fileContents.modificationTime; 1781 int time = fileContents.modificationTime;
1773 for (CacheEntry entry in _entriesFor(source)) { 1782 for (CacheEntry entry in _entriesFor(source)) {
1774 entry.modificationTime = time; 1783 entry.modificationTime = time;
1775 } 1784 }
1776 return; 1785 return;
1777 } 1786 }
1778 } catch (e) { 1787 } catch (e) {
1779 entry.modificationTime = -1; 1788 entry.modificationTime = -1;
1780 } 1789 }
1781 } 1790 }
(...skipping 24 matching lines...) Expand all
1806 // print( 1815 // print(
1807 // 'dartDelta: add=${dartDelta.addedNames} remove=${dartDelta.r emovedNames}'); 1816 // 'dartDelta: add=${dartDelta.addedNames} remove=${dartDelta.r emovedNames}');
1808 delta = dartDelta; 1817 delta = dartDelta;
1809 entry.setState(CONTENT, CacheState.INVALID, delta: delta); 1818 entry.setState(CONTENT, CacheState.INVALID, delta: delta);
1810 return; 1819 return;
1811 } 1820 }
1812 } 1821 }
1813 } 1822 }
1814 } 1823 }
1815 entry.setState(CONTENT, CacheState.INVALID); 1824 entry.setState(CONTENT, CacheState.INVALID);
1825 entry.setState(MODIFICATION_TIME, CacheState.INVALID);
1826 entry.setState(SOURCE_KIND, CacheState.INVALID);
1816 } 1827 }
1817 driver.reset(); 1828 driver.reset();
1818 for (WorkManager workManager in workManagers) { 1829 for (WorkManager workManager in workManagers) {
1819 workManager.applyChange( 1830 workManager.applyChange(
1820 Source.EMPTY_LIST, <Source>[source], Source.EMPTY_LIST); 1831 Source.EMPTY_LIST, <Source>[source], Source.EMPTY_LIST);
1821 } 1832 }
1822 } 1833 }
1823 1834
1824 /** 1835 /**
1825 * Record that the give [source] has been deleted. 1836 * Record that the give [source] has been deleted.
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
2128 } 2139 }
2129 DartSdk sdk = factory.dartSdk; 2140 DartSdk sdk = factory.dartSdk;
2130 if (sdk == null) { 2141 if (sdk == null) {
2131 throw new IllegalArgumentException( 2142 throw new IllegalArgumentException(
2132 "The source factory for an SDK analysis context must have a DartUriRes olver"); 2143 "The source factory for an SDK analysis context must have a DartUriRes olver");
2133 } 2144 }
2134 return new AnalysisCache( 2145 return new AnalysisCache(
2135 <CachePartition>[AnalysisEngine.instance.partitionManager.forSdk(sdk)]); 2146 <CachePartition>[AnalysisEngine.instance.partitionManager.forSdk(sdk)]);
2136 } 2147 }
2137 } 2148 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/compile_time_error_code_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698