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

Unified Diff: pkg/analyzer/lib/src/context/context.dart

Issue 2337073003: Safe handle removed file while incremental invalidation. (Closed)
Patch Set: Created 4 years, 3 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/src/context/context_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 f83c3497c0cb231f26e62d9d883a84678ce0db6d..ba82c4d21c5d0c7eef6ba1cb906246700de8447d 100644
--- a/pkg/analyzer/lib/src/context/context.dart
+++ b/pkg/analyzer/lib/src/context/context.dart
@@ -1888,20 +1888,31 @@ class AnalysisContextImpl implements InternalAnalysisContext {
.firstWhere((unit) => unit != null, orElse: () => null);
// If we have the old unit, we can try to update it.
if (oldUnit != null) {
- CompilationUnit newUnit = parseCompilationUnit(source);
- IncrementalCompilationUnitElementBuilder builder =
- new IncrementalCompilationUnitElementBuilder(oldUnit, newUnit);
- builder.build();
- CompilationUnitElementDelta unitDelta = builder.unitDelta;
- if (!unitDelta.hasDirectiveChange) {
- unitEntry.setValueIncremental(
- COMPILATION_UNIT_CONSTANTS, builder.unitConstants, false);
- DartDelta dartDelta = new DartDelta(source);
- unitDelta.addedDeclarations.forEach(dartDelta.elementChanged);
- unitDelta.removedDeclarations.forEach(dartDelta.elementChanged);
- unitDelta.classDeltas.values.forEach(dartDelta.classChanged);
- entry.setState(CONTENT, CacheState.INVALID, delta: dartDelta);
- return;
+ // Safely parse the source.
+ CompilationUnit newUnit;
+ try {
+ newUnit = parseCompilationUnit(source);
+ } catch (_) {
+ // The source might have been removed by this time.
+ // We cannot perform incremental invalidation.
+ }
+ // If the new unit was parsed successfully, continue.
+ if (newUnit != null) {
+ IncrementalCompilationUnitElementBuilder builder =
+ new IncrementalCompilationUnitElementBuilder(
+ oldUnit, newUnit);
+ builder.build();
+ CompilationUnitElementDelta unitDelta = builder.unitDelta;
+ if (!unitDelta.hasDirectiveChange) {
+ unitEntry.setValueIncremental(
+ COMPILATION_UNIT_CONSTANTS, builder.unitConstants, false);
+ DartDelta dartDelta = new DartDelta(source);
+ unitDelta.addedDeclarations.forEach(dartDelta.elementChanged);
+ unitDelta.removedDeclarations.forEach(dartDelta.elementChanged);
+ unitDelta.classDeltas.values.forEach(dartDelta.classChanged);
+ entry.setState(CONTENT, CacheState.INVALID, delta: dartDelta);
+ return;
+ }
}
}
}
« no previous file with comments | « no previous file | pkg/analyzer/test/src/context/context_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698