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