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.task.dart_work_manager; | 5 library analyzer.src.task.dart_work_manager; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 | 8 |
9 import 'package:analyzer/src/context/cache.dart'; | 9 import 'package:analyzer/src/context/cache.dart'; |
10 import 'package:analyzer/src/generated/engine.dart' | 10 import 'package:analyzer/src/generated/engine.dart' |
11 show | 11 show |
12 AnalysisEngine, | 12 AnalysisEngine, |
13 AnalysisErrorInfo, | 13 AnalysisErrorInfo, |
14 AnalysisErrorInfoImpl, | 14 AnalysisErrorInfoImpl, |
15 AnalysisOptions, | 15 AnalysisOptions, |
16 CacheState, | 16 CacheState, |
17 InternalAnalysisContext; | 17 InternalAnalysisContext; |
18 import 'package:analyzer/src/generated/error.dart'; | 18 import 'package:analyzer/src/generated/error.dart'; |
19 import 'package:analyzer/src/generated/source.dart'; | 19 import 'package:analyzer/src/generated/source.dart'; |
20 import 'package:analyzer/src/generated/utilities_collection.dart'; | 20 import 'package:analyzer/src/generated/utilities_collection.dart'; |
21 import 'package:analyzer/src/task/dart.dart'; | 21 import 'package:analyzer/src/task/dart.dart'; |
22 import 'package:analyzer/src/task/driver.dart'; | 22 import 'package:analyzer/src/task/driver.dart'; |
23 import 'package:analyzer/task/dart.dart'; | 23 import 'package:analyzer/task/dart.dart'; |
24 import 'package:analyzer/task/general.dart'; | |
25 import 'package:analyzer/task/model.dart'; | 24 import 'package:analyzer/task/model.dart'; |
| 25 import 'package:analyzer/src/task/html.dart'; |
26 | 26 |
27 /** | 27 /** |
28 * The manager for Dart specific analysis. | 28 * The manager for Dart specific analysis. |
29 */ | 29 */ |
30 class DartWorkManager implements WorkManager { | 30 class DartWorkManager implements WorkManager { |
31 /** | 31 /** |
32 * The list of errors that are reported for raw Dart [Source]s. | 32 * The list of errors that are reported for raw Dart [Source]s. |
33 */ | 33 */ |
34 static final List<ResultDescriptor> _SOURCE_ERRORS = <ResultDescriptor>[ | 34 static final List<ResultDescriptor> _SOURCE_ERRORS = <ResultDescriptor>[ |
35 BUILD_DIRECTIVES_ERRORS, | 35 BUILD_DIRECTIVES_ERRORS, |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 context.privateAnalysisCachePartition; | 106 context.privateAnalysisCachePartition; |
107 | 107 |
108 /** | 108 /** |
109 * Specifies that the client want the given [result] of the given [target] | 109 * Specifies that the client want the given [result] of the given [target] |
110 * to be computed with priority. | 110 * to be computed with priority. |
111 */ | 111 */ |
112 void addPriorityResult(AnalysisTarget target, ResultDescriptor result) { | 112 void addPriorityResult(AnalysisTarget target, ResultDescriptor result) { |
113 priorityResultQueue.add(new TargetedResult(target, result)); | 113 priorityResultQueue.add(new TargetedResult(target, result)); |
114 } | 114 } |
115 | 115 |
116 /** | 116 @override |
117 * Notifies the manager about changes in the explicit source list. | |
118 */ | |
119 void applyChange(List<Source> addedSources, List<Source> changedSources, | 117 void applyChange(List<Source> addedSources, List<Source> changedSources, |
120 List<Source> removedSources) { | 118 List<Source> removedSources) { |
121 addedSources = addedSources.where(_isDartSource).toList(); | 119 addedSources = addedSources.where(_isDartSource).toList(); |
122 changedSources = changedSources.where(_isDartSource).toList(); | 120 changedSources = changedSources.where(_isDartSource).toList(); |
123 removedSources = removedSources.where(_isDartSource).toList(); | 121 removedSources = removedSources.where(_isDartSource).toList(); |
124 // unknown queue | 122 // unknown queue |
125 unknownSourceQueue.addAll(addedSources); | 123 unknownSourceQueue.addAll(addedSources); |
126 unknownSourceQueue.addAll(changedSources); | 124 unknownSourceQueue.addAll(changedSources); |
127 unknownSourceQueue.removeAll(removedSources); | 125 unknownSourceQueue.removeAll(removedSources); |
128 // library queue | 126 // library queue |
(...skipping 30 matching lines...) Expand all Loading... |
159 } else if (sourceKind == SourceKind.PART) { | 157 } else if (sourceKind == SourceKind.PART) { |
160 List<Source> libraries = context.getLibrariesContaining(target); | 158 List<Source> libraries = context.getLibrariesContaining(target); |
161 for (Source library in libraries) { | 159 for (Source library in libraries) { |
162 addPriorityResult(library, LIBRARY_ERRORS_READY); | 160 addPriorityResult(library, LIBRARY_ERRORS_READY); |
163 } | 161 } |
164 } | 162 } |
165 } | 163 } |
166 } | 164 } |
167 } | 165 } |
168 | 166 |
169 /** | 167 @override |
170 * Return an [AnalysisErrorInfo] containing the list of all of the errors and | 168 List<AnalysisError> getErrors(Source source) { |
171 * the line info associated with the given [source]. The list of errors will | 169 if (!_isDartSource(source) && source is! DartScript) { |
172 * be empty if the source is not known to the context or if there are no | 170 return AnalysisError.NO_ERRORS; |
173 * errors in the source. The errors contained in the list can be incomplete. | 171 } |
174 */ | 172 // If analysis is finished, use all the errors. |
175 AnalysisErrorInfo getErrors(Source source) { | |
176 if (analysisCache.getState(source, DART_ERRORS) == CacheState.VALID) { | 173 if (analysisCache.getState(source, DART_ERRORS) == CacheState.VALID) { |
177 List<AnalysisError> errors = analysisCache.getValue(source, DART_ERRORS); | 174 return analysisCache.getValue(source, DART_ERRORS); |
178 LineInfo lineInfo = analysisCache.getValue(source, LINE_INFO); | |
179 return new AnalysisErrorInfoImpl(errors, lineInfo); | |
180 } | 175 } |
| 176 // If analysis is in progress, combine all known partial results. |
181 List<AnalysisError> errors = <AnalysisError>[]; | 177 List<AnalysisError> errors = <AnalysisError>[]; |
182 for (ResultDescriptor descriptor in _SOURCE_ERRORS) { | 178 for (ResultDescriptor descriptor in _SOURCE_ERRORS) { |
183 errors.addAll(analysisCache.getValue(source, descriptor)); | 179 errors.addAll(analysisCache.getValue(source, descriptor)); |
184 } | 180 } |
185 for (Source library in context.getLibrariesContaining(source)) { | 181 for (Source library in context.getLibrariesContaining(source)) { |
186 LibrarySpecificUnit unit = new LibrarySpecificUnit(library, source); | 182 LibrarySpecificUnit unit = new LibrarySpecificUnit(library, source); |
187 for (ResultDescriptor descriptor in _UNIT_ERRORS) { | 183 for (ResultDescriptor descriptor in _UNIT_ERRORS) { |
188 errors.addAll(analysisCache.getValue(unit, descriptor)); | 184 errors.addAll(analysisCache.getValue(unit, descriptor)); |
189 } | 185 } |
190 } | 186 } |
191 LineInfo lineInfo = analysisCache.getValue(source, LINE_INFO); | 187 return errors; |
192 return new AnalysisErrorInfoImpl(errors, lineInfo); | |
193 } | 188 } |
194 | 189 |
195 /** | 190 /** |
196 * Returns libraries containing the given [part]. | 191 * Returns libraries containing the given [part]. |
197 * Maybe empty, but not null. | 192 * Maybe empty, but not null. |
198 */ | 193 */ |
199 List<Source> getLibrariesContainingPart(Source part) { | 194 List<Source> getLibrariesContainingPart(Source part) { |
200 List<Source> libraries = partLibrariesMap[part]; | 195 List<Source> libraries = partLibrariesMap[part]; |
201 return libraries != null ? libraries : Source.EMPTY_LIST; | 196 return libraries != null ? libraries : Source.EMPTY_LIST; |
202 } | 197 } |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 outputs.forEach((ResultDescriptor descriptor, value) { | 303 outputs.forEach((ResultDescriptor descriptor, value) { |
309 if (descriptor == PARSED_UNIT && value != null) { | 304 if (descriptor == PARSED_UNIT && value != null) { |
310 context.getNotice(target).parsedDartUnit = value; | 305 context.getNotice(target).parsedDartUnit = value; |
311 shouldSetErrors = true; | 306 shouldSetErrors = true; |
312 } | 307 } |
313 if (descriptor == DART_ERRORS) { | 308 if (descriptor == DART_ERRORS) { |
314 shouldSetErrors = true; | 309 shouldSetErrors = true; |
315 } | 310 } |
316 }); | 311 }); |
317 if (shouldSetErrors) { | 312 if (shouldSetErrors) { |
318 AnalysisErrorInfo info = getErrors(target); | 313 AnalysisErrorInfo info = context.getErrors(target); |
319 context.getNotice(target).setErrors(info.errors, info.lineInfo); | 314 context.getNotice(target).setErrors(info.errors, info.lineInfo); |
320 } | 315 } |
321 } | 316 } |
322 if (target is LibrarySpecificUnit) { | 317 if (target is LibrarySpecificUnit) { |
323 Source source = target.source; | 318 Source source = target.source; |
324 bool shouldSetErrors = false; | 319 bool shouldSetErrors = false; |
325 outputs.forEach((ResultDescriptor descriptor, value) { | 320 outputs.forEach((ResultDescriptor descriptor, value) { |
326 if (descriptor == RESOLVED_UNIT && value != null) { | 321 if (descriptor == RESOLVED_UNIT && value != null) { |
327 context.getNotice(source).resolvedDartUnit = value; | 322 context.getNotice(source).resolvedDartUnit = value; |
328 shouldSetErrors = true; | 323 shouldSetErrors = true; |
329 } | 324 } |
330 }); | 325 }); |
331 if (shouldSetErrors) { | 326 if (shouldSetErrors) { |
332 AnalysisErrorInfo info = getErrors(source); | 327 AnalysisErrorInfo info = context.getErrors(source); |
333 context.getNotice(source).setErrors(info.errors, info.lineInfo); | 328 context.getNotice(source).setErrors(info.errors, info.lineInfo); |
334 } | 329 } |
335 } | 330 } |
336 } | 331 } |
337 | 332 |
338 void unitIncrementallyResolved(Source librarySource, Source unitSource) { | 333 void unitIncrementallyResolved(Source librarySource, Source unitSource) { |
339 librarySourceQueue.add(librarySource); | 334 librarySourceQueue.add(librarySource); |
340 } | 335 } |
341 | 336 |
342 /** | 337 /** |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 } | 432 } |
438 } | 433 } |
439 | 434 |
440 bool _shouldErrorsBeComputed(Source source) => | 435 bool _shouldErrorsBeComputed(Source source) => |
441 context.shouldErrorsBeAnalyzed(source, null); | 436 context.shouldErrorsBeAnalyzed(source, null); |
442 | 437 |
443 static bool _isDartSource(AnalysisTarget target) { | 438 static bool _isDartSource(AnalysisTarget target) { |
444 return target is Source && AnalysisEngine.isDartFileName(target.fullName); | 439 return target is Source && AnalysisEngine.isDartFileName(target.fullName); |
445 } | 440 } |
446 } | 441 } |
OLD | NEW |