Index: pkg/analyzer/lib/src/task/general.dart |
diff --git a/pkg/analyzer/lib/src/task/general.dart b/pkg/analyzer/lib/src/task/general.dart |
index 38d67dfb7035f1b202a38a9bd890d095ff07516c..6b9b13af55233d6cba28102c9f7b607ab15357da 100644 |
--- a/pkg/analyzer/lib/src/task/general.dart |
+++ b/pkg/analyzer/lib/src/task/general.dart |
@@ -4,6 +4,7 @@ |
library analyzer.src.task.general; |
+import 'package:analyzer/src/context/cache.dart'; |
import 'package:analyzer/src/generated/engine.dart'; |
import 'package:analyzer/src/generated/source.dart'; |
import 'package:analyzer/task/general.dart'; |
@@ -33,13 +34,36 @@ class GetContentTask extends SourceBasedAnalysisTask { |
@override |
internalPerform() { |
Source source = getRequiredSource(); |
+ String content; |
+ int modificationTime; |
try { |
TimestampedData<String> data = context.getContents(source); |
- outputs[CONTENT] = data.data; |
- outputs[MODIFICATION_TIME] = data.modificationTime; |
+ content = data.data; |
+ modificationTime = data.modificationTime; |
} catch (exception) { |
- outputs[CONTENT] = ''; |
- outputs[MODIFICATION_TIME] = -1; |
+ content = ''; |
+ modificationTime = -1; |
+ } |
+ outputs[CONTENT] = content; |
+ outputs[MODIFICATION_TIME] = modificationTime; |
+ _validateModificationTimeConsistency(modificationTime); |
+ } |
+ |
+ /** |
+ * Validate that the [target] cache entry has the same modification time |
+ * as the given. Otherwise throw a new [ModificationTimeMismatchError] and |
+ * instruct to invalidate targets content. |
+ */ |
+ void _validateModificationTimeConsistency(int modificationTime) { |
+ AnalysisContext context = this.context; |
+ if (context is InternalAnalysisContext) { |
+ CacheEntry entry = context.getCacheEntry(target); |
+ if (entry != null && entry.modificationTime != modificationTime) { |
+ entry.modificationTime = modificationTime; |
+ entry.setState(CONTENT, CacheState.INVALID); |
+ entry.setState(MODIFICATION_TIME, CacheState.INVALID); |
+ throw new ModificationTimeMismatchError(target); |
+ } |
} |
} |