| OLD | NEW |
| 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 1870 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1881 Source librarySource = source; | 1881 Source librarySource = source; |
| 1882 // Try to find an old unit which has element model. | 1882 // Try to find an old unit which has element model. |
| 1883 CacheEntry unitEntry = | 1883 CacheEntry unitEntry = |
| 1884 getCacheEntry(new LibrarySpecificUnit(librarySource, source)); | 1884 getCacheEntry(new LibrarySpecificUnit(librarySource, source)); |
| 1885 CompilationUnit oldUnit = RESOLVED_UNIT_RESULTS | 1885 CompilationUnit oldUnit = RESOLVED_UNIT_RESULTS |
| 1886 .skipWhile((result) => result != RESOLVED_UNIT2) | 1886 .skipWhile((result) => result != RESOLVED_UNIT2) |
| 1887 .map(unitEntry.getValue) | 1887 .map(unitEntry.getValue) |
| 1888 .firstWhere((unit) => unit != null, orElse: () => null); | 1888 .firstWhere((unit) => unit != null, orElse: () => null); |
| 1889 // If we have the old unit, we can try to update it. | 1889 // If we have the old unit, we can try to update it. |
| 1890 if (oldUnit != null) { | 1890 if (oldUnit != null) { |
| 1891 CompilationUnit newUnit = parseCompilationUnit(source); | 1891 // Safely parse the source. |
| 1892 IncrementalCompilationUnitElementBuilder builder = | 1892 CompilationUnit newUnit; |
| 1893 new IncrementalCompilationUnitElementBuilder(oldUnit, newUnit); | 1893 try { |
| 1894 builder.build(); | 1894 newUnit = parseCompilationUnit(source); |
| 1895 CompilationUnitElementDelta unitDelta = builder.unitDelta; | 1895 } catch (_) { |
| 1896 if (!unitDelta.hasDirectiveChange) { | 1896 // The source might have been removed by this time. |
| 1897 unitEntry.setValueIncremental( | 1897 // We cannot perform incremental invalidation. |
| 1898 COMPILATION_UNIT_CONSTANTS, builder.unitConstants, false); | 1898 } |
| 1899 DartDelta dartDelta = new DartDelta(source); | 1899 // If the new unit was parsed successfully, continue. |
| 1900 unitDelta.addedDeclarations.forEach(dartDelta.elementChanged); | 1900 if (newUnit != null) { |
| 1901 unitDelta.removedDeclarations.forEach(dartDelta.elementChanged); | 1901 IncrementalCompilationUnitElementBuilder builder = |
| 1902 unitDelta.classDeltas.values.forEach(dartDelta.classChanged); | 1902 new IncrementalCompilationUnitElementBuilder( |
| 1903 entry.setState(CONTENT, CacheState.INVALID, delta: dartDelta); | 1903 oldUnit, newUnit); |
| 1904 return; | 1904 builder.build(); |
| 1905 CompilationUnitElementDelta unitDelta = builder.unitDelta; |
| 1906 if (!unitDelta.hasDirectiveChange) { |
| 1907 unitEntry.setValueIncremental( |
| 1908 COMPILATION_UNIT_CONSTANTS, builder.unitConstants, false); |
| 1909 DartDelta dartDelta = new DartDelta(source); |
| 1910 unitDelta.addedDeclarations.forEach(dartDelta.elementChanged); |
| 1911 unitDelta.removedDeclarations.forEach(dartDelta.elementChanged); |
| 1912 unitDelta.classDeltas.values.forEach(dartDelta.classChanged); |
| 1913 entry.setState(CONTENT, CacheState.INVALID, delta: dartDelta); |
| 1914 return; |
| 1915 } |
| 1905 } | 1916 } |
| 1906 } | 1917 } |
| 1907 } | 1918 } |
| 1908 } | 1919 } |
| 1909 entry.setState(CONTENT, CacheState.INVALID); | 1920 entry.setState(CONTENT, CacheState.INVALID); |
| 1910 entry.setState(MODIFICATION_TIME, CacheState.INVALID); | 1921 entry.setState(MODIFICATION_TIME, CacheState.INVALID); |
| 1911 entry.setState(SOURCE_KIND, CacheState.INVALID); | 1922 entry.setState(SOURCE_KIND, CacheState.INVALID); |
| 1912 } | 1923 } |
| 1913 for (WorkManager workManager in workManagers) { | 1924 for (WorkManager workManager in workManagers) { |
| 1914 workManager.applyChange( | 1925 workManager.applyChange( |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2276 } | 2287 } |
| 2277 DartSdk sdk = factory.dartSdk; | 2288 DartSdk sdk = factory.dartSdk; |
| 2278 if (sdk == null) { | 2289 if (sdk == null) { |
| 2279 throw new ArgumentError( | 2290 throw new ArgumentError( |
| 2280 "The source factory for an SDK analysis context must have a DartUriRes
olver"); | 2291 "The source factory for an SDK analysis context must have a DartUriRes
olver"); |
| 2281 } | 2292 } |
| 2282 return new AnalysisCache( | 2293 return new AnalysisCache( |
| 2283 <CachePartition>[AnalysisEngine.instance.partitionManager.forSdk(sdk)]); | 2294 <CachePartition>[AnalysisEngine.instance.partitionManager.forSdk(sdk)]); |
| 2284 } | 2295 } |
| 2285 } | 2296 } |
| OLD | NEW |