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

Unified 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, 10 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/context/context.dart
diff --git a/pkg/analyzer/lib/src/context/context.dart b/pkg/analyzer/lib/src/context/context.dart
index cc1d41e3f9acc5b3b378dab14d5c1d5dfd9d2e08..ea63ec3e66144430d0e755c82964b168c83d0d24 100644
--- a/pkg/analyzer/lib/src/context/context.dart
+++ b/pkg/analyzer/lib/src/context/context.dart
@@ -1017,7 +1017,9 @@ class AnalysisContextImpl implements InternalAnalysisContext {
if (changed) {
if (!analysisOptions.incremental ||
!_tryPoorMansIncrementalResolution(source, newContents)) {
- _sourceChanged(source);
+ // Don't compare with old contents because the cache has already been
+ // updated, and we know at this point that it changed.
+ _sourceChanged(source, compareWithOld: false);
}
entry.modificationTime = _contentCache.getModificationStamp(source);
entry.setValue(CONTENT, newContents, TargetedResult.EMPTY_LIST);
@@ -1754,21 +1756,28 @@ class AnalysisContextImpl implements InternalAnalysisContext {
/**
* Invalidate the [source] that was changed and any sources that referenced
* the source before it existed.
+ *
+ * Note: source may be considered "changed" if it was previously missing,
+ * but pointed to by an import or export directive.
*/
- void _sourceChanged(Source source) {
+ void _sourceChanged(Source source, {bool compareWithOld: true}) {
CacheEntry entry = _cache.get(source);
- // If the source is removed, we don't care about it.
+ // If the source has no cache entry, there is nothing to invalidate.
if (entry == null) {
return;
}
- // Check whether the content of the source is the same as it was the last
- // time.
- String sourceContent = entry.getValue(CONTENT);
- if (sourceContent != null) {
- entry.setState(CONTENT, CacheState.FLUSHED);
+
+ String oldContents = compareWithOld ? entry.getValue(CONTENT) : null;
+
+ // Flush so that from now on we will get new contents.
+ // (For example, in getLibrariesContaining.)
+ entry.setState(CONTENT, CacheState.FLUSHED);
+
+ if (oldContents != null) {
+ // Fast path if the content is the same as it was last time.
try {
TimestampedData<String> fileContents = getContents(source);
- if (fileContents.data == sourceContent) {
+ if (fileContents.data == oldContents) {
int time = fileContents.modificationTime;
for (CacheEntry entry in _entriesFor(source)) {
entry.modificationTime = time;
@@ -1813,6 +1822,8 @@ class AnalysisContextImpl implements InternalAnalysisContext {
}
}
entry.setState(CONTENT, CacheState.INVALID);
+ entry.setState(MODIFICATION_TIME, CacheState.INVALID);
+ entry.setState(SOURCE_KIND, CacheState.INVALID);
}
driver.reset();
for (WorkManager workManager in workManagers) {
« 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