| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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_cli.src.incremental_analyzer; | 5 library analyzer_cli.src.incremental_analyzer; |
| 6 | 6 |
| 7 import 'dart:io' as io; | 7 import 'dart:io' as io; |
| 8 | 8 |
| 9 import 'package:analyzer/dart/element/element.dart'; | 9 import 'package:analyzer/dart/element/element.dart'; |
| 10 import 'package:analyzer/file_system/physical_file_system.dart'; | 10 import 'package:analyzer/file_system/physical_file_system.dart'; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 CacheStorage storage = new FolderCacheStorage( | 41 CacheStorage storage = new FolderCacheStorage( |
| 42 PhysicalResourceProvider.INSTANCE.getFolder(cachePath), | 42 PhysicalResourceProvider.INSTANCE.getFolder(cachePath), |
| 43 '${io.pid}.temp'); | 43 '${io.pid}.temp'); |
| 44 List<int> configSalt = <int>[ | 44 List<int> configSalt = <int>[ |
| 45 context.analysisOptions.encodeCrossContextOptions() | 45 context.analysisOptions.encodeCrossContextOptions() |
| 46 ]; | 46 ]; |
| 47 IncrementalCache cache = new IncrementalCache(storage, context, configSalt); | 47 IncrementalCache cache = new IncrementalCache(storage, context, configSalt); |
| 48 context.resultProvider = new _CacheBasedResultProvider(context, cache); | 48 context.resultProvider = new _CacheBasedResultProvider(context, cache); |
| 49 // Listen for new libraries to put into the cache. | 49 // Listen for new libraries to put into the cache. |
| 50 _IncrementalAnalysisSession session = | 50 _IncrementalAnalysisSession session = |
| 51 new _IncrementalAnalysisSession(options, context, cache); | 51 new _IncrementalAnalysisSession(options, storage, context, cache); |
| 52 context | 52 context |
| 53 .onResultChanged(LIBRARY_ELEMENT1) | 53 .onResultChanged(LIBRARY_ELEMENT1) |
| 54 .listen((ResultChangedEvent event) { | 54 .listen((ResultChangedEvent event) { |
| 55 if (event.wasComputed) { | 55 if (event.wasComputed) { |
| 56 session.newLibrarySources.add(event.target.source); | 56 session.newLibrarySources.add(event.target.source); |
| 57 } | 57 } |
| 58 }); | 58 }); |
| 59 return session; | 59 return session; |
| 60 } | 60 } |
| 61 // Incremental analysis cannot be used. | 61 // Incremental analysis cannot be used. |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 if (addedLibraryBundleIds.add(bundleWithId.id)) { | 165 if (addedLibraryBundleIds.add(bundleWithId.id)) { |
| 166 addBundle(null, bundleWithId.bundle); | 166 addBundle(null, bundleWithId.bundle); |
| 167 } | 167 } |
| 168 } | 168 } |
| 169 return true; | 169 return true; |
| 170 } | 170 } |
| 171 } | 171 } |
| 172 | 172 |
| 173 class _IncrementalAnalysisSession implements IncrementalAnalysisSession { | 173 class _IncrementalAnalysisSession implements IncrementalAnalysisSession { |
| 174 final CommandLineOptions commandLineOptions; | 174 final CommandLineOptions commandLineOptions; |
| 175 final CacheStorage cacheStorage; |
| 175 final AnalysisContext context; | 176 final AnalysisContext context; |
| 176 final IncrementalCache cache; | 177 final IncrementalCache cache; |
| 177 | 178 |
| 178 final Set<Source> newLibrarySources = new Set<Source>(); | 179 final Set<Source> newLibrarySources = new Set<Source>(); |
| 179 | 180 |
| 180 _IncrementalAnalysisSession( | 181 _IncrementalAnalysisSession( |
| 181 this.commandLineOptions, this.context, this.cache); | 182 this.commandLineOptions, this.cacheStorage, this.context, this.cache); |
| 182 | 183 |
| 183 @override | 184 @override |
| 184 void finish() { | 185 void finish() { |
| 185 // Finish computing new libraries and put them into the cache. | 186 // Finish computing new libraries and put them into the cache. |
| 186 for (Source librarySource in newLibrarySources) { | 187 for (Source librarySource in newLibrarySources) { |
| 187 if (!commandLineOptions.machineFormat) { | 188 if (!commandLineOptions.machineFormat) { |
| 188 print('Compute library element for $librarySource'); | 189 print('Compute library element for $librarySource'); |
| 189 } | 190 } |
| 190 _putLibrary(librarySource); | 191 _putLibrary(librarySource); |
| 191 } | 192 } |
| 193 // Compact the cache. |
| 194 cacheStorage.compact(); |
| 192 } | 195 } |
| 193 | 196 |
| 194 @override | 197 @override |
| 195 void setAnalyzedSources(Iterable<Source> sources) { | 198 void setAnalyzedSources(Iterable<Source> sources) { |
| 196 for (Source source in sources) { | 199 for (Source source in sources) { |
| 197 SourceKind kind = context.computeKindOf(source); | 200 SourceKind kind = context.computeKindOf(source); |
| 198 if (kind == SourceKind.LIBRARY) { | 201 if (kind == SourceKind.LIBRARY) { |
| 199 context.computeResult(source, LINE_INFO); | 202 context.computeResult(source, LINE_INFO); |
| 200 context.computeResult(source, IGNORE_INFO); | 203 context.computeResult(source, IGNORE_INFO); |
| 201 context.computeResult(source, INCLUDED_PARTS); | 204 context.computeResult(source, INCLUDED_PARTS); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 214 // Write errors for the library units. | 217 // Write errors for the library units. |
| 215 for (CompilationUnitElement unit in libraryElement.units) { | 218 for (CompilationUnitElement unit in libraryElement.units) { |
| 216 Source unitSource = unit.source; | 219 Source unitSource = unit.source; |
| 217 List<AnalysisError> errors = context.computeResult( | 220 List<AnalysisError> errors = context.computeResult( |
| 218 new LibrarySpecificUnit(librarySource, unitSource), | 221 new LibrarySpecificUnit(librarySource, unitSource), |
| 219 LIBRARY_UNIT_ERRORS); | 222 LIBRARY_UNIT_ERRORS); |
| 220 cache.putSourceErrorsInLibrary(librarySource, unitSource, errors); | 223 cache.putSourceErrorsInLibrary(librarySource, unitSource, errors); |
| 221 } | 224 } |
| 222 } | 225 } |
| 223 } | 226 } |
| OLD | NEW |