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.html_work_manager; | 5 library analyzer.src.task.html_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/driver.dart'; | 21 import 'package:analyzer/src/task/driver.dart'; |
22 import 'package:analyzer/src/task/html.dart'; | 22 import 'package:analyzer/src/task/html.dart'; |
23 import 'package:analyzer/task/general.dart'; | |
24 import 'package:analyzer/task/html.dart'; | 23 import 'package:analyzer/task/html.dart'; |
25 import 'package:analyzer/task/model.dart'; | 24 import 'package:analyzer/task/model.dart'; |
26 | 25 |
27 /** | 26 /** |
28 * The manager for HTML specific analysis. | 27 * The manager for HTML specific analysis. |
29 */ | 28 */ |
30 class HtmlWorkManager implements WorkManager { | 29 class HtmlWorkManager implements WorkManager { |
31 /** | 30 /** |
32 * The context for which work is being managed. | 31 * The context for which work is being managed. |
33 */ | 32 */ |
(...skipping 30 matching lines...) Expand all Loading... |
64 context.privateAnalysisCachePartition; | 63 context.privateAnalysisCachePartition; |
65 | 64 |
66 /** | 65 /** |
67 * Specifies that the client want the given [result] of the given [target] | 66 * Specifies that the client want the given [result] of the given [target] |
68 * to be computed with priority. | 67 * to be computed with priority. |
69 */ | 68 */ |
70 void addPriorityResult(AnalysisTarget target, ResultDescriptor result) { | 69 void addPriorityResult(AnalysisTarget target, ResultDescriptor result) { |
71 priorityResultQueue.add(new TargetedResult(target, result)); | 70 priorityResultQueue.add(new TargetedResult(target, result)); |
72 } | 71 } |
73 | 72 |
74 /** | 73 @override |
75 * Notifies the manager about changes in the explicit source list. | |
76 */ | |
77 void applyChange(List<Source> addedSources, List<Source> changedSources, | 74 void applyChange(List<Source> addedSources, List<Source> changedSources, |
78 List<Source> removedSources) { | 75 List<Source> removedSources) { |
79 addedSources = addedSources.where(_isHtmlSource).toList(); | 76 addedSources = addedSources.where(_isHtmlSource).toList(); |
80 changedSources = changedSources.where(_isHtmlSource).toList(); | 77 changedSources = changedSources.where(_isHtmlSource).toList(); |
81 removedSources = removedSources.where(_isHtmlSource).toList(); | 78 removedSources = removedSources.where(_isHtmlSource).toList(); |
82 // source queue | 79 // source queue |
83 sourceQueue.addAll(addedSources); | 80 sourceQueue.addAll(addedSources); |
84 sourceQueue.addAll(changedSources); | 81 sourceQueue.addAll(changedSources); |
85 sourceQueue.removeAll(removedSources); | 82 sourceQueue.removeAll(removedSources); |
86 } | 83 } |
87 | 84 |
88 @override | 85 @override |
89 void applyPriorityTargets(List<AnalysisTarget> targets) { | 86 void applyPriorityTargets(List<AnalysisTarget> targets) { |
90 // Unschedule the old targets. | 87 // Unschedule the old targets. |
91 List<TargetedResult> resultsToUnschedule = <TargetedResult>[]; | 88 List<TargetedResult> resultsToUnschedule = <TargetedResult>[]; |
92 for (TargetedResult result in priorityResultQueue) { | 89 for (TargetedResult result in priorityResultQueue) { |
93 if (result.result == HTML_ERRORS) { | 90 if (result.result == HTML_ERRORS) { |
94 resultsToUnschedule.add(result); | 91 resultsToUnschedule.add(result); |
95 } | 92 } |
96 } | 93 } |
97 priorityResultQueue.removeAll(resultsToUnschedule); | 94 priorityResultQueue.removeAll(resultsToUnschedule); |
98 // Schedule new targets. | 95 // Schedule new targets. |
99 for (AnalysisTarget target in targets) { | 96 for (AnalysisTarget target in targets) { |
100 if (_isHtmlSource(target)) { | 97 if (_isHtmlSource(target)) { |
101 addPriorityResult(target, HTML_ERRORS); | 98 addPriorityResult(target, HTML_ERRORS); |
102 } | 99 } |
103 } | 100 } |
104 } | 101 } |
105 | 102 |
106 /** | 103 @override |
107 * Return an [AnalysisErrorInfo] containing the list of all of the errors and | 104 List<AnalysisError> getErrors(Source source) { |
108 * the line info associated with the given [source]. The list of errors will | 105 if (!_isHtmlSource(source)) { |
109 * be empty if the source is not known to the context or if there are no | 106 return AnalysisError.NO_ERRORS; |
110 * errors in the source. The errors contained in the list can be incomplete. | 107 } |
111 */ | 108 // If analysis is finished, use all the errors. |
112 AnalysisErrorInfo getErrors(Source source) { | |
113 if (analysisCache.getState(source, HTML_ERRORS) == CacheState.VALID) { | 109 if (analysisCache.getState(source, HTML_ERRORS) == CacheState.VALID) { |
114 List<AnalysisError> errors = analysisCache.getValue(source, HTML_ERRORS); | 110 return analysisCache.getValue(source, HTML_ERRORS); |
115 LineInfo lineInfo = analysisCache.getValue(source, LINE_INFO); | |
116 return new AnalysisErrorInfoImpl(errors, lineInfo); | |
117 } | 111 } |
| 112 // If analysis is in progress, combine all known partial results. |
118 List<AnalysisError> errors = <AnalysisError>[]; | 113 List<AnalysisError> errors = <AnalysisError>[]; |
119 errors.addAll(analysisCache.getValue(source, HTML_DOCUMENT_ERRORS)); | 114 errors.addAll(analysisCache.getValue(source, HTML_DOCUMENT_ERRORS)); |
120 List<DartScript> scripts = analysisCache.getValue(source, DART_SCRIPTS); | 115 List<DartScript> scripts = analysisCache.getValue(source, DART_SCRIPTS); |
121 for (DartScript script in scripts) { | 116 for (DartScript script in scripts) { |
122 errors.addAll(context.getErrors(script).errors); | 117 errors.addAll(context.getErrors(script).errors); |
123 } | 118 } |
124 LineInfo lineInfo = analysisCache.getValue(source, LINE_INFO); | 119 return errors; |
125 return new AnalysisErrorInfoImpl(errors, lineInfo); | |
126 } | 120 } |
127 | 121 |
128 @override | 122 @override |
129 TargetedResult getNextResult() { | 123 TargetedResult getNextResult() { |
130 // Try to find a priority result to compute. | 124 // Try to find a priority result to compute. |
131 while (priorityResultQueue.isNotEmpty) { | 125 while (priorityResultQueue.isNotEmpty) { |
132 TargetedResult result = priorityResultQueue.first; | 126 TargetedResult result = priorityResultQueue.first; |
133 if (!_needsComputing(result.target, result.result)) { | 127 if (!_needsComputing(result.target, result.result)) { |
134 priorityResultQueue.remove(result); | 128 priorityResultQueue.remove(result); |
135 continue; | 129 continue; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 if (priorityResultQueue.contains(target)) { | 197 if (priorityResultQueue.contains(target)) { |
204 // TODO(brianwilkerson) Add the scripts to the DartWorkManager's | 198 // TODO(brianwilkerson) Add the scripts to the DartWorkManager's |
205 // priority queue. | 199 // priority queue. |
206 } else { | 200 } else { |
207 // TODO(brianwilkerson) Add the scripts to the DartWorkManager's | 201 // TODO(brianwilkerson) Add the scripts to the DartWorkManager's |
208 // library queue. | 202 // library queue. |
209 } | 203 } |
210 } | 204 } |
211 }); | 205 }); |
212 if (shouldSetErrors) { | 206 if (shouldSetErrors) { |
213 AnalysisErrorInfo info = getErrors(target); | 207 AnalysisErrorInfo info = context.getErrors(target); |
214 context.getNotice(target).setErrors(info.errors, info.lineInfo); | 208 context.getNotice(target).setErrors(info.errors, info.lineInfo); |
215 } | 209 } |
216 } | 210 } |
217 } | 211 } |
218 | 212 |
219 /** | 213 /** |
220 * Invalidate all of the resolution results computed by this context. The flag | 214 * Invalidate all of the resolution results computed by this context. The flag |
221 * [invalidateUris] should be `true` if the cached results of converting URIs | 215 * [invalidateUris] should be `true` if the cached results of converting URIs |
222 * to source files should also be invalidated. | 216 * to source files should also be invalidated. |
223 */ | 217 */ |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 return state != CacheState.VALID && state != CacheState.ERROR; | 252 return state != CacheState.VALID && state != CacheState.ERROR; |
259 } | 253 } |
260 | 254 |
261 /** | 255 /** |
262 * Return `true` if the given target is an HTML source. | 256 * Return `true` if the given target is an HTML source. |
263 */ | 257 */ |
264 static bool _isHtmlSource(AnalysisTarget target) { | 258 static bool _isHtmlSource(AnalysisTarget target) { |
265 return target is Source && AnalysisEngine.isHtmlFileName(target.fullName); | 259 return target is Source && AnalysisEngine.isHtmlFileName(target.fullName); |
266 } | 260 } |
267 } | 261 } |
OLD | NEW |