| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 // This code was auto-generated, is not intended to be edited, and is subject to | 5 // This code was auto-generated, is not intended to be edited, and is subject to |
| 6 // significant change. Please see the README file for more information. | 6 // significant change. Please see the README file for more information. |
| 7 | 7 |
| 8 library engine; | 8 library engine; |
| 9 | 9 |
| 10 import "dart:math" as math; | 10 import "dart:math" as math; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 * The function may also throw an exception, in which case the corresponding | 52 * The function may also throw an exception, in which case the corresponding |
| 53 * future will be completed with failure. | 53 * future will be completed with failure. |
| 54 * | 54 * |
| 55 * Since this function is called while the state of analysis is being updated, | 55 * Since this function is called while the state of analysis is being updated, |
| 56 * it should be free of side effects so that it doesn't cause reentrant | 56 * it should be free of side effects so that it doesn't cause reentrant |
| 57 * changes to the analysis state. | 57 * changes to the analysis state. |
| 58 */ | 58 */ |
| 59 typedef T PendingFutureComputer<T>(SourceEntry sourceEntry); | 59 typedef T PendingFutureComputer<T>(SourceEntry sourceEntry); |
| 60 | 60 |
| 61 /** | 61 /** |
| 62 * Instances of the class `AnalysisCache` implement an LRU cache of information
related to | 62 * An LRU cache of information related to analysis. |
| 63 * analysis. | |
| 64 */ | 63 */ |
| 65 class AnalysisCache { | 64 class AnalysisCache { |
| 66 /** | 65 /** |
| 67 * A flag used to control whether trace information should be produced when th
e content of the | 66 * A flag used to control whether trace information should be produced when |
| 68 * cache is modified. | 67 * the content of the cache is modified. |
| 69 */ | 68 */ |
| 70 static bool _TRACE_CHANGES = false; | 69 static bool _TRACE_CHANGES = false; |
| 71 | 70 |
| 72 /** | 71 /** |
| 73 * An array containing the partitions of which this cache is comprised. | 72 * A list containing the partitions of which this cache is comprised. |
| 74 */ | 73 */ |
| 75 final List<CachePartition> _partitions; | 74 final List<CachePartition> _partitions; |
| 76 | 75 |
| 77 /** | 76 /** |
| 78 * Initialize a newly created cache to have the given partitions. The partitio
ns will be searched | 77 * Initialize a newly created cache to have the given [_partitions]. The |
| 79 * in the order in which they appear in the array, so the most specific partit
ion (usually an | 78 * partitions will be searched in the order in which they appear in the list, |
| 80 * [SdkCachePartition]) should be first and the most general (usually a | 79 * so the most specific partition (usually an [SdkCachePartition]) should be |
| 81 * [UniversalCachePartition]) last. | 80 * first and the most general (usually a [UniversalCachePartition]) last. |
| 82 * | |
| 83 * @param partitions the partitions for the newly created cache | |
| 84 */ | 81 */ |
| 85 AnalysisCache(this._partitions); | 82 AnalysisCache(this._partitions); |
| 86 | 83 |
| 87 /** | 84 /** |
| 88 * Return the number of entries in this cache that have an AST associated with
them. | 85 * Return the number of entries in this cache that have an AST associated with |
| 89 * | 86 * them. |
| 90 * @return the number of entries in this cache that have an AST associated wit
h them | |
| 91 */ | 87 */ |
| 92 int get astSize => _partitions[_partitions.length - 1].astSize; | 88 int get astSize => _partitions[_partitions.length - 1].astSize; |
| 93 | 89 |
| 94 /** | 90 /** |
| 95 * Return information about each of the partitions in this cache. | 91 * Return information about each of the partitions in this cache. |
| 96 * | |
| 97 * @return information about each of the partitions in this cache | |
| 98 */ | 92 */ |
| 99 List<AnalysisContextStatistics_PartitionData> get partitionData { | 93 List<AnalysisContextStatistics_PartitionData> get partitionData { |
| 100 int count = _partitions.length; | 94 int count = _partitions.length; |
| 101 List<AnalysisContextStatistics_PartitionData> data = | 95 List<AnalysisContextStatistics_PartitionData> data = |
| 102 new List<AnalysisContextStatistics_PartitionData>(count); | 96 new List<AnalysisContextStatistics_PartitionData>(count); |
| 103 for (int i = 0; i < count; i++) { | 97 for (int i = 0; i < count; i++) { |
| 104 CachePartition partition = _partitions[i]; | 98 CachePartition partition = _partitions[i]; |
| 105 data[i] = new AnalysisContextStatisticsImpl_PartitionDataImpl( | 99 data[i] = new AnalysisContextStatisticsImpl_PartitionDataImpl( |
| 106 partition.astSize, partition.map.length); | 100 partition.astSize, partition.map.length); |
| 107 } | 101 } |
| 108 return data; | 102 return data; |
| 109 } | 103 } |
| 110 | 104 |
| 111 /** | 105 /** |
| 112 * Record that the AST associated with the given source was just read from the
cache. | 106 * Record that the AST associated with the given [source] was just read from |
| 113 * | 107 * the cache. |
| 114 * @param source the source whose AST was accessed | |
| 115 */ | 108 */ |
| 116 void accessedAst(Source source) { | 109 void accessedAst(Source source) { |
| 117 int count = _partitions.length; | 110 int count = _partitions.length; |
| 118 for (int i = 0; i < count; i++) { | 111 for (int i = 0; i < count; i++) { |
| 119 if (_partitions[i].contains(source)) { | 112 if (_partitions[i].contains(source)) { |
| 120 _partitions[i].accessedAst(source); | 113 _partitions[i].accessedAst(source); |
| 121 return; | 114 return; |
| 122 } | 115 } |
| 123 } | 116 } |
| 124 } | 117 } |
| 125 | 118 |
| 126 /** | 119 /** |
| 127 * Return the entry associated with the given source. | 120 * Return the entry associated with the given [source]. |
| 128 * | |
| 129 * @param source the source whose entry is to be returned | |
| 130 * @return the entry associated with the given source | |
| 131 */ | 121 */ |
| 132 SourceEntry get(Source source) { | 122 SourceEntry get(Source source) { |
| 133 int count = _partitions.length; | 123 int count = _partitions.length; |
| 134 for (int i = 0; i < count; i++) { | 124 for (int i = 0; i < count; i++) { |
| 135 if (_partitions[i].contains(source)) { | 125 if (_partitions[i].contains(source)) { |
| 136 return _partitions[i].get(source); | 126 return _partitions[i].get(source); |
| 137 } | 127 } |
| 138 } | 128 } |
| 139 // | 129 // |
| 140 // We should never get to this point because the last partition should | 130 // We should never get to this point because the last partition should |
| 141 // always be a universal partition, except in the case of the SDK context, | 131 // always be a universal partition, except in the case of the SDK context, |
| 142 // in which case the source should always be part of the SDK. | 132 // in which case the source should always be part of the SDK. |
| 143 // | 133 // |
| 144 return null; | 134 return null; |
| 145 } | 135 } |
| 146 | 136 |
| 147 /** | 137 /** |
| 148 * Return context that owns the given source. | 138 * Return context that owns the given [source]. |
| 149 * | |
| 150 * @param source the source whose context is to be returned | |
| 151 * @return the context that owns the partition that contains the source | |
| 152 */ | 139 */ |
| 153 InternalAnalysisContext getContextFor(Source source) { | 140 InternalAnalysisContext getContextFor(Source source) { |
| 154 int count = _partitions.length; | 141 int count = _partitions.length; |
| 155 for (int i = 0; i < count; i++) { | 142 for (int i = 0; i < count; i++) { |
| 156 if (_partitions[i].contains(source)) { | 143 if (_partitions[i].contains(source)) { |
| 157 return _partitions[i].context; | 144 return _partitions[i].context; |
| 158 } | 145 } |
| 159 } | 146 } |
| 160 // | 147 // |
| 161 // We should never get to this point because the last partition should | 148 // We should never get to this point because the last partition should |
| 162 // always be a universal partition, except in the case of the SDK context, | 149 // always be a universal partition, except in the case of the SDK context, |
| 163 // in which case the source should always be part of the SDK. | 150 // in which case the source should always be part of the SDK. |
| 164 // | 151 // |
| 165 AnalysisEngine.instance.logger.logInformation( | 152 AnalysisEngine.instance.logger.logInformation( |
| 166 "Could not find context for ${source.fullName}", | 153 "Could not find context for ${source.fullName}", |
| 167 new CaughtException(new AnalysisException(), null)); | 154 new CaughtException(new AnalysisException(), null)); |
| 168 return null; | 155 return null; |
| 169 } | 156 } |
| 170 | 157 |
| 171 /** | 158 /** |
| 172 * Return an iterator returning all of the map entries mapping sources to cach
e entries. | 159 * Return an iterator returning all of the map entries mapping sources to |
| 173 * | 160 * cache entries. |
| 174 * @return an iterator returning all of the map entries mapping sources to cac
he entries | |
| 175 */ | 161 */ |
| 176 MapIterator<Source, SourceEntry> iterator() { | 162 MapIterator<Source, SourceEntry> iterator() { |
| 177 int count = _partitions.length; | 163 int count = _partitions.length; |
| 178 List<Map<Source, SourceEntry>> maps = new List<Map>(count); | 164 List<Map<Source, SourceEntry>> maps = new List<Map>(count); |
| 179 for (int i = 0; i < count; i++) { | 165 for (int i = 0; i < count; i++) { |
| 180 maps[i] = _partitions[i].map; | 166 maps[i] = _partitions[i].map; |
| 181 } | 167 } |
| 182 return new MultipleMapIterator<Source, SourceEntry>(maps); | 168 return new MultipleMapIterator<Source, SourceEntry>(maps); |
| 183 } | 169 } |
| 184 | 170 |
| 185 /** | 171 /** |
| 186 * Associate the given entry with the given source. | 172 * Associate the given [entry] with the given [source]. |
| 187 * | |
| 188 * @param source the source with which the entry is to be associated | |
| 189 * @param entry the entry to be associated with the source | |
| 190 */ | 173 */ |
| 191 void put(Source source, SourceEntry entry) { | 174 void put(Source source, SourceEntry entry) { |
| 192 entry.fixExceptionState(); | 175 entry.fixExceptionState(); |
| 193 int count = _partitions.length; | 176 int count = _partitions.length; |
| 194 for (int i = 0; i < count; i++) { | 177 for (int i = 0; i < count; i++) { |
| 195 if (_partitions[i].contains(source)) { | 178 if (_partitions[i].contains(source)) { |
| 196 if (_TRACE_CHANGES) { | 179 if (_TRACE_CHANGES) { |
| 197 try { | 180 try { |
| 198 SourceEntry oldEntry = _partitions[i].get(source); | 181 SourceEntry oldEntry = _partitions[i].get(source); |
| 199 if (oldEntry == null) { | 182 if (oldEntry == null) { |
| 200 AnalysisEngine.instance.logger.logInformation( | 183 AnalysisEngine.instance.logger.logInformation( |
| 201 "Added a cache entry for '${source.fullName}'."); | 184 "Added a cache entry for '${source.fullName}'."); |
| 202 } else { | 185 } else { |
| 203 AnalysisEngine.instance.logger.logInformation( | 186 AnalysisEngine.instance.logger.logInformation( |
| 204 "Modified the cache entry for ${source.fullName}'. Diff = ${en
try.getDiff(oldEntry)}"); | 187 "Modified the cache entry for ${source.fullName}'. Diff = ${en
try.getDiff(oldEntry)}"); |
| 205 } | 188 } |
| 206 } catch (exception) { | 189 } catch (exception) { |
| 207 // Ignored | 190 // Ignored |
| 208 JavaSystem.currentTimeMillis(); | 191 JavaSystem.currentTimeMillis(); |
| 209 } | 192 } |
| 210 } | 193 } |
| 211 _partitions[i].put(source, entry); | 194 _partitions[i].put(source, entry); |
| 212 return; | 195 return; |
| 213 } | 196 } |
| 214 } | 197 } |
| 215 } | 198 } |
| 216 | 199 |
| 217 /** | 200 /** |
| 218 * Remove all information related to the given source from this cache. | 201 * Remove all information related to the given [source] from this cache. |
| 219 * | |
| 220 * @param source the source to be removed | |
| 221 */ | 202 */ |
| 222 void remove(Source source) { | 203 void remove(Source source) { |
| 223 int count = _partitions.length; | 204 int count = _partitions.length; |
| 224 for (int i = 0; i < count; i++) { | 205 for (int i = 0; i < count; i++) { |
| 225 if (_partitions[i].contains(source)) { | 206 if (_partitions[i].contains(source)) { |
| 226 if (_TRACE_CHANGES) { | 207 if (_TRACE_CHANGES) { |
| 227 try { | 208 try { |
| 228 AnalysisEngine.instance.logger.logInformation( | 209 AnalysisEngine.instance.logger.logInformation( |
| 229 "Removed the cache entry for ${source.fullName}'."); | 210 "Removed the cache entry for ${source.fullName}'."); |
| 230 } catch (exception) { | 211 } catch (exception) { |
| 231 // Ignored | 212 // Ignored |
| 232 JavaSystem.currentTimeMillis(); | 213 JavaSystem.currentTimeMillis(); |
| 233 } | 214 } |
| 234 } | 215 } |
| 235 _partitions[i].remove(source); | 216 _partitions[i].remove(source); |
| 236 return; | 217 return; |
| 237 } | 218 } |
| 238 } | 219 } |
| 239 } | 220 } |
| 240 | 221 |
| 241 /** | 222 /** |
| 242 * Record that the AST associated with the given source was just removed from
the cache. | 223 * Record that the AST associated with the given [source] was just removed |
| 243 * | 224 * from the cache. |
| 244 * @param source the source whose AST was removed | |
| 245 */ | 225 */ |
| 246 void removedAst(Source source) { | 226 void removedAst(Source source) { |
| 247 int count = _partitions.length; | 227 int count = _partitions.length; |
| 248 for (int i = 0; i < count; i++) { | 228 for (int i = 0; i < count; i++) { |
| 249 if (_partitions[i].contains(source)) { | 229 if (_partitions[i].contains(source)) { |
| 250 _partitions[i].removedAst(source); | 230 _partitions[i].removedAst(source); |
| 251 return; | 231 return; |
| 252 } | 232 } |
| 253 } | 233 } |
| 254 } | 234 } |
| 255 | 235 |
| 256 /** | 236 /** |
| 257 * Return the number of sources that are mapped to cache entries. | 237 * Return the number of sources that are mapped to cache entries. |
| 258 * | |
| 259 * @return the number of sources that are mapped to cache entries | |
| 260 */ | 238 */ |
| 261 int size() { | 239 int size() { |
| 262 int size = 0; | 240 int size = 0; |
| 263 int count = _partitions.length; | 241 int count = _partitions.length; |
| 264 for (int i = 0; i < count; i++) { | 242 for (int i = 0; i < count; i++) { |
| 265 size += _partitions[i].size(); | 243 size += _partitions[i].size(); |
| 266 } | 244 } |
| 267 return size; | 245 return size; |
| 268 } | 246 } |
| 269 | 247 |
| 270 /** | 248 /** |
| 271 * Record that the AST associated with the given source was just stored to the
cache. | 249 * Record that the AST associated with the given [source] was just stored to |
| 272 * | 250 * the cache. |
| 273 * @param source the source whose AST was stored | |
| 274 */ | 251 */ |
| 275 void storedAst(Source source) { | 252 void storedAst(Source source) { |
| 276 int count = _partitions.length; | 253 int count = _partitions.length; |
| 277 for (int i = 0; i < count; i++) { | 254 for (int i = 0; i < count; i++) { |
| 278 if (_partitions[i].contains(source)) { | 255 if (_partitions[i].contains(source)) { |
| 279 _partitions[i].storedAst(source); | 256 _partitions[i].storedAst(source); |
| 280 return; | 257 return; |
| 281 } | 258 } |
| 282 } | 259 } |
| 283 } | 260 } |
| 284 } | 261 } |
| 285 | 262 |
| 286 /** | 263 /** |
| 287 * The interface `AnalysisContext` defines the behavior of objects that represen
t a context in | 264 * A context in which a single analysis can be performed and incrementally |
| 288 * which a single analysis can be performed and incrementally maintained. The co
ntext includes such | 265 * maintained. The context includes such information as the version of the SDK |
| 289 * information as the version of the SDK being analyzed against as well as the p
ackage-root used to | 266 * being analyzed against as well as the package-root used to resolve 'package:' |
| 290 * resolve 'package:' URI's. (Both of which are known indirectly through the [So
urceFactory | 267 * URI's. (Both of which are known indirectly through the [SourceFactory].) |
| 291 ].) | |
| 292 * | 268 * |
| 293 * An analysis context also represents the state of the analysis, which includes
knowing which | 269 * An analysis context also represents the state of the analysis, which includes |
| 294 * sources have been included in the analysis (either directly or indirectly) an
d the results of the | 270 * knowing which sources have been included in the analysis (either directly or |
| 295 * analysis. Sources must be added and removed from the context using the method | 271 * indirectly) and the results of the analysis. Sources must be added and |
| 296 * [applyChanges], which is also used to notify the context when sources have be
en | 272 * removed from the context using the method [applyChanges], which is also used |
| 297 * modified and, consequently, previously known results might have been invalida
ted. | 273 * to notify the context when sources have been modified and, consequently, |
| 274 * previously known results might have been invalidated. |
| 298 * | 275 * |
| 299 * There are two ways to access the results of the analysis. The most common is
to use one of the | 276 * There are two ways to access the results of the analysis. The most common is |
| 300 * 'get' methods to access the results. The 'get' methods have the advantage tha
t they will always | 277 * to use one of the 'get' methods to access the results. The 'get' methods have |
| 301 * return quickly, but have the disadvantage that if the results are not current
ly available they | 278 * the advantage that they will always return quickly, but have the disadvantage |
| 302 * will return either nothing or in some cases an incomplete result. The second
way to access | 279 * that if the results are not currently available they will return either |
| 303 * results is by using one of the 'compute' methods. The 'compute' methods will
always attempt to | 280 * nothing or in some cases an incomplete result. The second way to access |
| 304 * compute the requested results but might block the caller for a significant pe
riod of time. | 281 * results is by using one of the 'compute' methods. The 'compute' methods will |
| 282 * always attempt to compute the requested results but might block the caller |
| 283 * for a significant period of time. |
| 305 * | 284 * |
| 306 * When results have been invalidated, have never been computed (as is the case
for newly added | 285 * When results have been invalidated, have never been computed (as is the case |
| 307 * sources), or have been removed from the cache, they are <b>not</b> automatica
lly recreated. They | 286 * for newly added sources), or have been removed from the cache, they are |
| 308 * will only be recreated if one of the 'compute' methods is invoked. | 287 * <b>not</b> automatically recreated. They will only be recreated if one of the |
| 288 * 'compute' methods is invoked. |
| 309 * | 289 * |
| 310 * However, this is not always acceptable. Some clients need to keep the analysi
s results | 290 * However, this is not always acceptable. Some clients need to keep the |
| 311 * up-to-date. For such clients there is a mechanism that allows them to increme
ntally perform | 291 * analysis results up-to-date. For such clients there is a mechanism that |
| 312 * needed analysis and get notified of the consequent changes to the analysis re
sults. This | 292 * allows them to incrementally perform needed analysis and get notified of the |
| 313 * mechanism is realized by the method [performAnalysisTask]. | 293 * consequent changes to the analysis results. This mechanism is realized by the |
| 294 * method [performAnalysisTask]. |
| 314 * | 295 * |
| 315 * Analysis engine allows for having more than one context. This can be used, fo
r example, to | 296 * Analysis engine allows for having more than one context. This can be used, |
| 316 * perform one analysis based on the state of files on disk and a separate analy
sis based on the | 297 * for example, to perform one analysis based on the state of files on disk and |
| 317 * state of those files in open editors. It can also be used to perform an analy
sis based on a | 298 * a separate analysis based on the state of those files in open editors. It can |
| 318 * proposed future state, such as the state after a refactoring. | 299 * also be used to perform an analysis based on a proposed future state, such as |
| 300 * the state after a refactoring. |
| 319 */ | 301 */ |
| 320 abstract class AnalysisContext { | 302 abstract class AnalysisContext { |
| 321 | |
| 322 /** | 303 /** |
| 323 * An empty list of contexts. | 304 * An empty list of contexts. |
| 324 */ | 305 */ |
| 325 static const List<AnalysisContext> EMPTY_LIST = const <AnalysisContext>[]; | 306 static const List<AnalysisContext> EMPTY_LIST = const <AnalysisContext>[]; |
| 326 | 307 |
| 327 /** | 308 /** |
| 328 * Return the set of analysis options controlling the behavior of this context
. Clients should not | 309 * Return the set of analysis options controlling the behavior of this |
| 329 * modify the returned set of options. The options should only be set by invok
ing the method | 310 * context. Clients should not modify the returned set of options. The options |
| 330 * [setAnalysisOptions]. | 311 * should only be set by invoking the method [setAnalysisOptions]. |
| 331 * | |
| 332 * @return the set of analysis options controlling the behavior of this contex
t | |
| 333 */ | 312 */ |
| 334 AnalysisOptions get analysisOptions; | 313 AnalysisOptions get analysisOptions; |
| 335 | 314 |
| 336 /** | 315 /** |
| 337 * Set the set of analysis options controlling the behavior of this context to
the given options. | 316 * Set the set of analysis options controlling the behavior of this context to |
| 338 * Clients can safely assume that all necessary analysis results have been inv
alidated. | 317 * the given [options]. Clients can safely assume that all necessary analysis |
| 339 * | 318 * results have been invalidated. |
| 340 * @param options the set of analysis options that will control the behavior o
f this context | |
| 341 */ | 319 */ |
| 342 void set analysisOptions(AnalysisOptions options); | 320 void set analysisOptions(AnalysisOptions options); |
| 343 | 321 |
| 344 /** | 322 /** |
| 345 * Set the order in which sources will be analyzed by [performAnalysisTask] to
match the | 323 * Set the order in which sources will be analyzed by [performAnalysisTask] to |
| 346 * order of the sources in the given list. If a source that needs to be analyz
ed is not contained | 324 * match the order of the sources in the given list of [sources]. If a source |
| 347 * in the list, then it will be treated as if it were at the end of the list.
If the list is empty | 325 * that needs to be analyzed is not contained in the list, then it will be |
| 348 * (or `null`) then no sources will be given priority over other sources. | 326 * treated as if it were at the end of the list. If the list is empty (or |
| 327 * `null`) then no sources will be given priority over other sources. |
| 349 * | 328 * |
| 350 * Changes made to the list after this method returns will <b>not</b> be refle
cted in the priority | 329 * Changes made to the list after this method returns will <b>not</b> be |
| 351 * order. | 330 * reflected in the priority order. |
| 352 * | |
| 353 * @param sources the sources to be given priority over other sources | |
| 354 */ | 331 */ |
| 355 void set analysisPriorityOrder(List<Source> sources); | 332 void set analysisPriorityOrder(List<Source> sources); |
| 356 | 333 |
| 357 /** | 334 /** |
| 358 * Return the set of declared variables used when computing constant values. | 335 * Return the set of declared variables used when computing constant values. |
| 359 * | |
| 360 * @return the set of declared variables used when computing constant values | |
| 361 */ | 336 */ |
| 362 DeclaredVariables get declaredVariables; | 337 DeclaredVariables get declaredVariables; |
| 363 | 338 |
| 364 /** | 339 /** |
| 365 * Return an array containing all of the sources known to this context that re
present HTML files. | 340 * Return a list containing all of the sources known to this context that |
| 366 * The contents of the array can be incomplete. | 341 * represent HTML files. The contents of the list can be incomplete. |
| 367 * | |
| 368 * @return the sources known to this context that represent HTML files | |
| 369 */ | 342 */ |
| 370 List<Source> get htmlSources; | 343 List<Source> get htmlSources; |
| 371 | 344 |
| 372 /** | 345 /** |
| 373 * Returns `true` if this context was disposed using [dispose]. | 346 * Returns `true` if this context was disposed using [dispose]. |
| 374 * | |
| 375 * @return `true` if this context was disposed | |
| 376 */ | 347 */ |
| 377 bool get isDisposed; | 348 bool get isDisposed; |
| 378 | 349 |
| 379 /** | 350 /** |
| 380 * Return an array containing all of the sources known to this context that re
present the defining | 351 * Return a list containing all of the sources known to this context that |
| 381 * compilation unit of a library that can be run within a browser. The sources
that are returned | 352 * represent the defining compilation unit of a library that can be run within |
| 382 * represent libraries that have a 'main' method and are either referenced by
an HTML file or | 353 * a browser. The sources that are returned represent libraries that have a |
| 383 * import, directly or indirectly, a client-only library. The contents of the
array can be | 354 * 'main' method and are either referenced by an HTML file or import, directly |
| 355 * or indirectly, a client-only library. The contents of the list can be |
| 384 * incomplete. | 356 * incomplete. |
| 385 * | |
| 386 * @return the sources known to this context that represent the defining compi
lation unit of a | |
| 387 * library that can be run within a browser | |
| 388 */ | 357 */ |
| 389 List<Source> get launchableClientLibrarySources; | 358 List<Source> get launchableClientLibrarySources; |
| 390 | 359 |
| 391 /** | 360 /** |
| 392 * Return an array containing all of the sources known to this context that re
present the defining | 361 * Return a list containing all of the sources known to this context that |
| 393 * compilation unit of a library that can be run outside of a browser. The con
tents of the array | 362 * represent the defining compilation unit of a library that can be run |
| 394 * can be incomplete. | 363 * outside of a browser. The contents of the list can be incomplete. |
| 395 * | |
| 396 * @return the sources known to this context that represent the defining compi
lation unit of a | |
| 397 * library that can be run outside of a browser | |
| 398 */ | 364 */ |
| 399 List<Source> get launchableServerLibrarySources; | 365 List<Source> get launchableServerLibrarySources; |
| 400 | 366 |
| 401 /** | 367 /** |
| 402 * Return an array containing all of the sources known to this context that re
present the defining | 368 * Return a list containing all of the sources known to this context that |
| 403 * compilation unit of a library. The contents of the array can be incomplete. | 369 * represent the defining compilation unit of a library. The contents of the |
| 404 * | 370 * list can be incomplete. |
| 405 * @return the sources known to this context that represent the defining compi
lation unit of a | |
| 406 * library | |
| 407 */ | 371 */ |
| 408 List<Source> get librarySources; | 372 List<Source> get librarySources; |
| 409 | 373 |
| 410 /** | 374 /** |
| 411 * Return a client-provided name used to identify this context, or `null` if | 375 * Return a client-provided name used to identify this context, or `null` if |
| 412 * the client has not provided a name. | 376 * the client has not provided a name. |
| 413 */ | 377 */ |
| 414 String get name; | 378 String get name; |
| 415 | 379 |
| 416 /** | 380 /** |
| 417 * Set the client-provided name used to identify this context to the given | 381 * Set the client-provided name used to identify this context to the given |
| 418 * [name]. | 382 * [name]. |
| 419 */ | 383 */ |
| 420 set name(String name); | 384 set name(String name); |
| 421 | 385 |
| 422 /** | 386 /** |
| 423 * The stream that is notified when sources have been added or removed, | 387 * The stream that is notified when sources have been added or removed, |
| 424 * or the source's content has changed. | 388 * or the source's content has changed. |
| 425 */ | 389 */ |
| 426 Stream<SourcesChangedEvent> get onSourcesChanged; | 390 Stream<SourcesChangedEvent> get onSourcesChanged; |
| 427 | 391 |
| 428 /** | 392 /** |
| 429 * Return an array containing all of the sources known to this context and the
ir resolution state | 393 * Return a list containing all of the sources known to this context whose |
| 430 * is not valid or flush. So, these sources are not safe to update during refa
ctoring, because we | 394 * state is neither valid or flushed. These sources are not safe to update |
| 431 * may be don't know all the references in them. | 395 * during refactoring, because we might not know all the references in them. |
| 432 * | |
| 433 * @return the sources known to this context and are not safe for refactoring | |
| 434 */ | 396 */ |
| 435 List<Source> get refactoringUnsafeSources; | 397 List<Source> get refactoringUnsafeSources; |
| 436 | 398 |
| 437 /** | 399 /** |
| 438 * Return the source factory used to create the sources that can be analyzed i
n this context. | 400 * Return the source factory used to create the sources that can be analyzed |
| 439 * | 401 * in this context. |
| 440 * @return the source factory used to create the sources that can be analyzed
in this context | |
| 441 */ | 402 */ |
| 442 SourceFactory get sourceFactory; | 403 SourceFactory get sourceFactory; |
| 443 | 404 |
| 444 /** | 405 /** |
| 445 * Set the source factory used to create the sources that can be analyzed in t
his context to the | 406 * Set the source factory used to create the sources that can be analyzed in |
| 446 * given source factory. Clients can safely assume that all analysis results h
ave been | 407 * this context to the given source [factory]. Clients can safely assume that |
| 447 * invalidated. | 408 * all analysis results have been invalidated. |
| 448 * | |
| 449 * @param factory the source factory used to create the sources that can be an
alyzed in this | |
| 450 * context | |
| 451 */ | 409 */ |
| 452 void set sourceFactory(SourceFactory factory); | 410 void set sourceFactory(SourceFactory factory); |
| 453 | 411 |
| 454 /** | 412 /** |
| 455 * Return an array containing all of the sources known to this context. | 413 * Return a list containing all of the sources known to this context. |
| 456 * | |
| 457 * @return all of the sources known to this context | |
| 458 */ | 414 */ |
| 459 List<Source> get sources; | 415 List<Source> get sources; |
| 460 | 416 |
| 461 /** | 417 /** |
| 462 * Returns a type provider for this context or throws [AnalysisException] if | 418 * Return a type provider for this context or throw [AnalysisException] if |
| 463 * `dart:core` or `dart:async` cannot be resolved. | 419 * either `dart:core` or `dart:async` cannot be resolved. |
| 464 */ | 420 */ |
| 465 TypeProvider get typeProvider; | 421 TypeProvider get typeProvider; |
| 466 | 422 |
| 467 /** | 423 /** |
| 468 * Add the given listener to the list of objects that are to be notified when
various analysis | 424 * Add the given [listener] to the list of objects that are to be notified |
| 469 * results are produced in this context. | 425 * when various analysis results are produced in this context. |
| 470 * | |
| 471 * @param listener the listener to be added | |
| 472 */ | 426 */ |
| 473 void addListener(AnalysisListener listener); | 427 void addListener(AnalysisListener listener); |
| 474 | 428 |
| 475 /** | 429 /** |
| 476 * Apply the given delta to change the level of analysis that will be performe
d for the sources | 430 * Apply the given [delta] to change the level of analysis that will be |
| 477 * known to this context. | 431 * performed for the sources known to this context. |
| 478 * | |
| 479 * @param delta a description of the level of analysis that should be performe
d for some sources | |
| 480 */ | 432 */ |
| 481 void applyAnalysisDelta(AnalysisDelta delta); | 433 void applyAnalysisDelta(AnalysisDelta delta); |
| 482 | 434 |
| 483 /** | 435 /** |
| 484 * Apply the changes specified by the given change set to this context. Any an
alysis results that | 436 * Apply the changes specified by the given [changeSet] to this context. Any |
| 485 * have been invalidated by these changes will be removed. | 437 * analysis results that have been invalidated by these changes will be |
| 486 * | 438 * removed. |
| 487 * @param changeSet a description of the changes that are to be applied | |
| 488 */ | 439 */ |
| 489 void applyChanges(ChangeSet changeSet); | 440 void applyChanges(ChangeSet changeSet); |
| 490 | 441 |
| 491 /** | 442 /** |
| 492 * Return the documentation comment for the given element as it appears in the
original source | 443 * Return the documentation comment for the given [element] as it appears in |
| 493 * (complete with the beginning and ending delimiters) for block documentation
comments, or lines | 444 * the original source (complete with the beginning and ending delimiters) for |
| 494 * starting with `"///"` and separated with `"\n"` characters for end-of-line | 445 * block documentation comments, or lines starting with `"///"` and separated |
| 495 * documentation comments, or `null` if the element does not have a documentat
ion comment | 446 * with `"\n"` characters for end-of-line documentation comments, or `null` if |
| 496 * associated with it. This can be a long-running operation if the information
needed to access | 447 * the element does not have a documentation comment associated with it. This |
| 497 * the comment is not cached. | 448 * can be a long-running operation if the information needed to access the |
| 449 * comment is not cached. |
| 450 * |
| 451 * Throws an [AnalysisException] if the documentation comment could not be |
| 452 * determined because the analysis could not be performed. |
| 498 * | 453 * |
| 499 * <b>Note:</b> This method cannot be used in an async environment. | 454 * <b>Note:</b> This method cannot be used in an async environment. |
| 500 * | |
| 501 * @param element the element whose documentation comment is to be returned | |
| 502 * @return the element's documentation comment | |
| 503 * @throws AnalysisException if the documentation comment could not be determi
ned because the | |
| 504 * analysis could not be performed | |
| 505 */ | 455 */ |
| 506 String computeDocumentationComment(Element element); | 456 String computeDocumentationComment(Element element); |
| 507 | 457 |
| 508 /** | 458 /** |
| 509 * Return an array containing all of the errors associated with the given sour
ce. If the errors | 459 * Return a list containing all of the errors associated with the given |
| 510 * are not already known then the source will be analyzed in order to determin
e the errors | 460 * [source]. If the errors are not already known then the source will be |
| 511 * associated with it. | 461 * analyzed in order to determine the errors associated with it. |
| 462 * |
| 463 * Throws an [AnalysisException] if the errors could not be determined because |
| 464 * the analysis could not be performed. |
| 512 * | 465 * |
| 513 * <b>Note:</b> This method cannot be used in an async environment. | 466 * <b>Note:</b> This method cannot be used in an async environment. |
| 514 * | 467 * |
| 515 * @param source the source whose errors are to be returned | |
| 516 * @return all of the errors associated with the given source | |
| 517 * @throws AnalysisException if the errors could not be determined because the
analysis could not | |
| 518 * be performed | |
| 519 * See [getErrors]. | 468 * See [getErrors]. |
| 520 */ | 469 */ |
| 521 List<AnalysisError> computeErrors(Source source); | 470 List<AnalysisError> computeErrors(Source source); |
| 522 | 471 |
| 523 /** | 472 /** |
| 524 * Return the element model corresponding to the HTML file defined by the give
n source. If the | 473 * Return the element model corresponding to the HTML file defined by the |
| 525 * element model does not yet exist it will be created. The process of creatin
g an element model | 474 * given [source]. If the element model does not yet exist it will be created. |
| 526 * for an HTML file can be long-running, depending on the size of the file and
the number of | 475 * The process of creating an element model for an HTML file can be |
| 527 * libraries that are defined in it (via script tags) that also need to have a
model built for | 476 * long-running, depending on the size of the file and the number of libraries |
| 528 * them. | 477 * that are defined in it (via script tags) that also need to have a model |
| 478 * built for them. |
| 479 * |
| 480 * Throws AnalysisException if the element model could not be determined |
| 481 * because the analysis could not be performed. |
| 529 * | 482 * |
| 530 * <b>Note:</b> This method cannot be used in an async environment. | 483 * <b>Note:</b> This method cannot be used in an async environment. |
| 531 * | 484 * |
| 532 * @param source the source defining the HTML file whose element model is to b
e returned | |
| 533 * @return the element model corresponding to the HTML file defined by the giv
en source | |
| 534 * @throws AnalysisException if the element model could not be determined beca
use the analysis | |
| 535 * could not be performed | |
| 536 * See [getHtmlElement]. | 485 * See [getHtmlElement]. |
| 537 */ | 486 */ |
| 538 HtmlElement computeHtmlElement(Source source); | 487 HtmlElement computeHtmlElement(Source source); |
| 539 | 488 |
| 540 /** | 489 /** |
| 541 * Return the kind of the given source, computing it's kind if it is not alrea
dy known. Return | 490 * Return the kind of the given [source], computing it's kind if it is not |
| 542 * [SourceKind.UNKNOWN] if the source is not contained in this context. | 491 * already known. Return [SourceKind.UNKNOWN] if the source is not contained |
| 492 * in this context. |
| 543 * | 493 * |
| 544 * <b>Note:</b> This method cannot be used in an async environment. | 494 * <b>Note:</b> This method cannot be used in an async environment. |
| 545 * | 495 * |
| 546 * @param source the source whose kind is to be returned | |
| 547 * @return the kind of the given source | |
| 548 * See [getKindOf]. | 496 * See [getKindOf]. |
| 549 */ | 497 */ |
| 550 SourceKind computeKindOf(Source source); | 498 SourceKind computeKindOf(Source source); |
| 551 | 499 |
| 552 /** | 500 /** |
| 553 * Return the element model corresponding to the library defined by the given
source. If the | 501 * Return the element model corresponding to the library defined by the given |
| 554 * element model does not yet exist it will be created. The process of creatin
g an element model | 502 * [source]. If the element model does not yet exist it will be created. The |
| 555 * for a library can long-running, depending on the size of the library and th
e number of | 503 * process of creating an element model for a library can long-running, |
| 556 * libraries that are imported into it that also need to have a model built fo
r them. | 504 * depending on the size of the library and the number of libraries that are |
| 505 * imported into it that also need to have a model built for them. |
| 506 * |
| 507 * Throws an [AnalysisException] if the element model could not be determined |
| 508 * because the analysis could not be performed. |
| 557 * | 509 * |
| 558 * <b>Note:</b> This method cannot be used in an async environment. | 510 * <b>Note:</b> This method cannot be used in an async environment. |
| 559 * | 511 * |
| 560 * @param source the source defining the library whose element model is to be
returned | |
| 561 * @return the element model corresponding to the library defined by the given
source | |
| 562 * @throws AnalysisException if the element model could not be determined beca
use the analysis | |
| 563 * could not be performed | |
| 564 * See [getLibraryElement]. | 512 * See [getLibraryElement]. |
| 565 */ | 513 */ |
| 566 LibraryElement computeLibraryElement(Source source); | 514 LibraryElement computeLibraryElement(Source source); |
| 567 | 515 |
| 568 /** | 516 /** |
| 569 * Return the line information for the given source, or `null` if the source i
s not of a | 517 * Return the line information for the given [source], or `null` if the source |
| 570 * recognized kind (neither a Dart nor HTML file). If the line information was
not previously | 518 * is not of a recognized kind (neither a Dart nor HTML file). If the line |
| 571 * known it will be created. The line information is used to map offsets from
the beginning of the | 519 * information was not previously known it will be created. The line |
| 572 * source to line and column pairs. | 520 * information is used to map offsets from the beginning of the source to line |
| 521 * and column pairs. |
| 522 * |
| 523 * Throws an [AnalysisException] if the line information could not be |
| 524 * determined because the analysis could not be performed. |
| 573 * | 525 * |
| 574 * <b>Note:</b> This method cannot be used in an async environment. | 526 * <b>Note:</b> This method cannot be used in an async environment. |
| 575 * | 527 * |
| 576 * @param source the source whose line information is to be returned | |
| 577 * @return the line information for the given source | |
| 578 * @throws AnalysisException if the line information could not be determined b
ecause the analysis | |
| 579 * could not be performed | |
| 580 * See [getLineInfo]. | 528 * See [getLineInfo]. |
| 581 */ | 529 */ |
| 582 LineInfo computeLineInfo(Source source); | 530 LineInfo computeLineInfo(Source source); |
| 583 | 531 |
| 584 /** | 532 /** |
| 585 * Return a future which will be completed with the fully resolved AST for a | 533 * Return a future which will be completed with the fully resolved AST for a |
| 586 * single compilation unit within the given library, once that AST is up to | 534 * single compilation unit within the given library, once that AST is up to |
| 587 * date. | 535 * date. |
| 588 * | 536 * |
| 589 * If the resolved AST can't be computed for some reason, the future will be | 537 * If the resolved AST can't be computed for some reason, the future will be |
| 590 * completed with an error. One possible error is AnalysisNotScheduledError, | 538 * completed with an error. One possible error is AnalysisNotScheduledError, |
| 591 * which means that the resolved AST can't be computed because the given | 539 * which means that the resolved AST can't be computed because the given |
| 592 * source file is not scheduled to be analyzed within the context of the | 540 * source file is not scheduled to be analyzed within the context of the |
| 593 * given library. | 541 * given library. |
| 594 */ | 542 */ |
| 595 CancelableFuture<CompilationUnit> computeResolvedCompilationUnitAsync( | 543 CancelableFuture<CompilationUnit> computeResolvedCompilationUnitAsync( |
| 596 Source source, Source librarySource); | 544 Source source, Source librarySource); |
| 597 | 545 |
| 598 /** | 546 /** |
| 599 * Notifies the context that the client is going to stop using this context. | 547 * Notifies the context that the client is going to stop using this context. |
| 600 */ | 548 */ |
| 601 void dispose(); | 549 void dispose(); |
| 602 | 550 |
| 603 /** | 551 /** |
| 604 * Return `true` if the given source exists. | 552 * Return `true` if the given [source] exists. |
| 605 * | 553 * |
| 606 * This method should be used rather than the method [Source.exists] because c
ontexts can | 554 * This method should be used rather than the method [Source.exists] because |
| 607 * have local overrides of the content of a source that the source is not awar
e of and a source | 555 * contexts can have local overrides of the content of a source that the |
| 608 * with local content is considered to exist even if there is no file on disk. | 556 * source is not aware of and a source with local content is considered to |
| 609 * | 557 * exist even if there is no file on disk. |
| 610 * @param source the source whose modification stamp is to be returned | |
| 611 * @return `true` if the source exists | |
| 612 */ | 558 */ |
| 613 bool exists(Source source); | 559 bool exists(Source source); |
| 614 | 560 |
| 615 /** | 561 /** |
| 616 * Return the element model corresponding to the compilation unit defined by t
he given source in | 562 * Return the element model corresponding to the compilation unit defined by |
| 617 * the library defined by the given source, or `null` if the element model doe
s not | 563 * the given [unitSource] in the library defined by the given [librarySource], |
| 618 * currently exist or if the library cannot be analyzed for some reason. | 564 * or `null` if the element model does not currently exist or if the library |
| 619 * | 565 * cannot be analyzed for some reason. |
| 620 * @param unitSource the source of the compilation unit | |
| 621 * @param librarySource the source of the defining compilation unit of the lib
rary containing the | |
| 622 * compilation unit | |
| 623 * @return the element model corresponding to the compilation unit defined by
the given source | |
| 624 */ | 566 */ |
| 625 CompilationUnitElement getCompilationUnitElement( | 567 CompilationUnitElement getCompilationUnitElement( |
| 626 Source unitSource, Source librarySource); | 568 Source unitSource, Source librarySource); |
| 627 | 569 |
| 628 /** | 570 /** |
| 629 * Get the contents and timestamp of the given source. | 571 * Return the contents and timestamp of the given [source]. |
| 630 * | 572 * |
| 631 * This method should be used rather than the method [Source.getContents] beca
use contexts | 573 * This method should be used rather than the method [Source.getContents] |
| 632 * can have local overrides of the content of a source that the source is not
aware of. | 574 * because contexts can have local overrides of the content of a source that |
| 633 * | 575 * the source is not aware of. |
| 634 * @param source the source whose content is to be returned | |
| 635 * @return the contents and timestamp of the source | |
| 636 * @throws Exception if the contents of the source could not be accessed | |
| 637 */ | 576 */ |
| 638 TimestampedData<String> getContents(Source source); | 577 TimestampedData<String> getContents(Source source); |
| 639 | 578 |
| 640 /** | 579 /** |
| 641 * Return the element referenced by the given location, or `null` if the eleme
nt is not | 580 * Return the element referenced by the given [location], or `null` if the |
| 642 * immediately available or if there is no element with the given location. Th
e latter condition | 581 * element is not immediately available or if there is no element with the |
| 643 * can occur, for example, if the location describes an element from a differe
nt context or if the | 582 * given location. The latter condition can occur, for example, if the |
| 644 * element has been removed from this context as a result of some change since
it was originally | 583 * location describes an element from a different context or if the element |
| 645 * obtained. | 584 * has been removed from this context as a result of some change since it was |
| 646 * | 585 * originally obtained. |
| 647 * @param location the reference describing the element to be returned | |
| 648 * @return the element referenced by the given location | |
| 649 */ | 586 */ |
| 650 Element getElement(ElementLocation location); | 587 Element getElement(ElementLocation location); |
| 651 | 588 |
| 652 /** | 589 /** |
| 653 * Return an analysis error info containing the array of all of the errors and
the line info | 590 * Return an analysis error info containing the list of all of the errors and |
| 654 * associated with the given source. The array of errors will be empty if the
source is not known | 591 * the line info associated with the given [source]. The list of errors will |
| 655 * to this context or if there are no errors in the source. The errors contain
ed in the array can | 592 * be empty if the source is not known to this context or if there are no |
| 656 * be incomplete. | 593 * errors in the source. The errors contained in the list can be incomplete. |
| 657 * | 594 * |
| 658 * @param source the source whose errors are to be returned | |
| 659 * @return all of the errors associated with the given source and the line inf
o | |
| 660 * See [computeErrors]. | 595 * See [computeErrors]. |
| 661 */ | 596 */ |
| 662 AnalysisErrorInfo getErrors(Source source); | 597 AnalysisErrorInfo getErrors(Source source); |
| 663 | 598 |
| 664 /** | 599 /** |
| 665 * Return the element model corresponding to the HTML file defined by the give
n source, or | 600 * Return the element model corresponding to the HTML file defined by the |
| 666 * `null` if the source does not represent an HTML file, the element represent
ing the file | 601 * given [source], or `null` if the source does not represent an HTML file, |
| 667 * has not yet been created, or the analysis of the HTML file failed for some
reason. | 602 * the element representing the file has not yet been created, or the analysis |
| 603 * of the HTML file failed for some reason. |
| 668 * | 604 * |
| 669 * @param source the source defining the HTML file whose element model is to b
e returned | |
| 670 * @return the element model corresponding to the HTML file defined by the giv
en source | |
| 671 * See [computeHtmlElement]. | 605 * See [computeHtmlElement]. |
| 672 */ | 606 */ |
| 673 HtmlElement getHtmlElement(Source source); | 607 HtmlElement getHtmlElement(Source source); |
| 674 | 608 |
| 675 /** | 609 /** |
| 676 * Return the sources for the HTML files that reference the given compilation
unit. If the source | 610 * Return the sources for the HTML files that reference the compilation unit |
| 677 * does not represent a Dart source or is not known to this context, the retur
ned array will be | 611 * with the given [source]. If the source does not represent a Dart source or |
| 678 * empty. The contents of the array can be incomplete. | 612 * is not known to this context, the returned list will be empty. The contents |
| 679 * | 613 * of the list can be incomplete. |
| 680 * @param source the source referenced by the returned HTML files | |
| 681 * @return the sources for the HTML files that reference the given compilation
unit | |
| 682 */ | 614 */ |
| 683 List<Source> getHtmlFilesReferencing(Source source); | 615 List<Source> getHtmlFilesReferencing(Source source); |
| 684 | 616 |
| 685 /** | 617 /** |
| 686 * Return the kind of the given source, or `null` if the kind is not known to
this context. | 618 * Return the kind of the given [source], or `null` if the kind is not known |
| 619 * to this context. |
| 687 * | 620 * |
| 688 * @param source the source whose kind is to be returned | |
| 689 * @return the kind of the given source | |
| 690 * See [computeKindOf]. | 621 * See [computeKindOf]. |
| 691 */ | 622 */ |
| 692 SourceKind getKindOf(Source source); | 623 SourceKind getKindOf(Source source); |
| 693 | 624 |
| 694 /** | 625 /** |
| 695 * Return the sources for the defining compilation units of any libraries of w
hich the given | 626 * Return the sources for the defining compilation units of any libraries of |
| 696 * source is a part. The array will normally contain a single library because
most Dart sources | 627 * which the given [source] is a part. The list will normally contain a single |
| 697 * are only included in a single library, but it is possible to have a part th
at is contained in | 628 * library because most Dart sources are only included in a single library, |
| 698 * multiple identically named libraries. If the source represents the defining
compilation unit of | 629 * but it is possible to have a part that is contained in multiple identically |
| 699 * a library, then the returned array will contain the given source as its onl
y element. If the | 630 * named libraries. If the source represents the defining compilation unit of |
| 700 * source does not represent a Dart source or is not known to this context, th
e returned array | 631 * a library, then the returned list will contain the given source as its only |
| 701 * will be empty. The contents of the array can be incomplete. | 632 * element. If the source does not represent a Dart source or is not known to |
| 702 * | 633 * this context, the returned list will be empty. The contents of the list can |
| 703 * @param source the source contained in the returned libraries | 634 * be incomplete. |
| 704 * @return the sources for the libraries containing the given source | |
| 705 */ | 635 */ |
| 706 List<Source> getLibrariesContaining(Source source); | 636 List<Source> getLibrariesContaining(Source source); |
| 707 | 637 |
| 708 /** | 638 /** |
| 709 * Return the sources for the defining compilation units of any libraries that
depend on the given | 639 * Return the sources for the defining compilation units of any libraries that |
| 710 * library. One library depends on another if it either imports or exports tha
t library. | 640 * depend on the library defined by the given [librarySource]. One library |
| 711 * | 641 * depends on another if it either imports or exports that library. |
| 712 * @param librarySource the source for the defining compilation unit of the li
brary being depended | |
| 713 * on | |
| 714 * @return the sources for the libraries that depend on the given library | |
| 715 */ | 642 */ |
| 716 List<Source> getLibrariesDependingOn(Source librarySource); | 643 List<Source> getLibrariesDependingOn(Source librarySource); |
| 717 | 644 |
| 718 /** | 645 /** |
| 719 * Return the sources for the defining compilation units of any libraries that
are referenced from | 646 * Return the sources for the defining compilation units of any libraries that |
| 720 * the given HTML file. | 647 * are referenced from the HTML file defined by the given [htmlSource]. |
| 721 * | |
| 722 * @param htmlSource the source for the HTML file | |
| 723 * @return the sources for the libraries that are referenced by the given HTML
file | |
| 724 */ | 648 */ |
| 725 List<Source> getLibrariesReferencedFromHtml(Source htmlSource); | 649 List<Source> getLibrariesReferencedFromHtml(Source htmlSource); |
| 726 | 650 |
| 727 /** | 651 /** |
| 728 * Return the element model corresponding to the library defined by the given
source, or | 652 * Return the element model corresponding to the library defined by the given |
| 729 * `null` if the element model does not currently exist or if the library cann
ot be analyzed | 653 * [source], or `null` if the element model does not currently exist or if the |
| 730 * for some reason. | 654 * library cannot be analyzed for some reason. |
| 731 * | |
| 732 * @param source the source defining the library whose element model is to be
returned | |
| 733 * @return the element model corresponding to the library defined by the given
source | |
| 734 */ | 655 */ |
| 735 LibraryElement getLibraryElement(Source source); | 656 LibraryElement getLibraryElement(Source source); |
| 736 | 657 |
| 737 /** | 658 /** |
| 738 * Return the line information for the given source, or `null` if the line inf
ormation is | 659 * Return the line information for the given [source], or `null` if the line |
| 739 * not known. The line information is used to map offsets from the beginning o
f the source to line | 660 * information is not known. The line information is used to map offsets from |
| 740 * and column pairs. | 661 * the beginning of the source to line and column pairs. |
| 741 * | 662 * |
| 742 * @param source the source whose line information is to be returned | |
| 743 * @return the line information for the given source | |
| 744 * See [computeLineInfo]. | 663 * See [computeLineInfo]. |
| 745 */ | 664 */ |
| 746 LineInfo getLineInfo(Source source); | 665 LineInfo getLineInfo(Source source); |
| 747 | 666 |
| 748 /** | 667 /** |
| 749 * Return the modification stamp for the [source], or a negative value if the | 668 * Return the modification stamp for the [source], or a negative value if the |
| 750 * source does not exist. A modification stamp is a non-negative integer with | 669 * source does not exist. A modification stamp is a non-negative integer with |
| 751 * the property that if the contents of the source have not been modified | 670 * the property that if the contents of the source have not been modified |
| 752 * since the last time the modification stamp was accessed then the same value | 671 * since the last time the modification stamp was accessed then the same value |
| 753 * will be returned, but if the contents of the source have been modified one | 672 * will be returned, but if the contents of the source have been modified one |
| 754 * or more times (even if the net change is zero) the stamps will be different
. | 673 * or more times (even if the net change is zero) the stamps will be different
. |
| 755 * | 674 * |
| 756 * This method should be used rather than the method | 675 * This method should be used rather than the method |
| 757 * [Source.getModificationStamp] because contexts can have local overrides of | 676 * [Source.getModificationStamp] because contexts can have local overrides of |
| 758 * the content of a source that the source is not aware of. | 677 * the content of a source that the source is not aware of. |
| 759 */ | 678 */ |
| 760 int getModificationStamp(Source source); | 679 int getModificationStamp(Source source); |
| 761 | 680 |
| 762 /** | 681 /** |
| 763 * Return a fully resolved AST for a single compilation unit within the given
library, or | 682 * Return a fully resolved AST for the compilation unit defined by the given |
| 764 * `null` if the resolved AST is not already computed. | 683 * [unitSource] within the given [library], or `null` if the resolved AST is |
| 684 * not already computed. |
| 765 * | 685 * |
| 766 * @param unitSource the source of the compilation unit | |
| 767 * @param library the library containing the compilation unit | |
| 768 * @return a fully resolved AST for the compilation unit | |
| 769 * See [resolveCompilationUnit]. | 686 * See [resolveCompilationUnit]. |
| 770 */ | 687 */ |
| 771 CompilationUnit getResolvedCompilationUnit( | 688 CompilationUnit getResolvedCompilationUnit( |
| 772 Source unitSource, LibraryElement library); | 689 Source unitSource, LibraryElement library); |
| 773 | 690 |
| 774 /** | 691 /** |
| 775 * Return a fully resolved AST for a single compilation unit within the given
library, or | 692 * Return a fully resolved AST for the compilation unit defined by the given |
| 693 * [unitSource] within the library defined by the given [librarySource], or |
| 776 * `null` if the resolved AST is not already computed. | 694 * `null` if the resolved AST is not already computed. |
| 777 * | 695 * |
| 778 * @param unitSource the source of the compilation unit | 696 * See [resolveCompilationUnit2]. |
| 779 * @param librarySource the source of the defining compilation unit of the lib
rary containing the | |
| 780 * compilation unit | |
| 781 * @return a fully resolved AST for the compilation unit | |
| 782 * See [resolveCompilationUnit]. | |
| 783 */ | 697 */ |
| 784 CompilationUnit getResolvedCompilationUnit2( | 698 CompilationUnit getResolvedCompilationUnit2( |
| 785 Source unitSource, Source librarySource); | 699 Source unitSource, Source librarySource); |
| 786 | 700 |
| 787 /** | 701 /** |
| 788 * Return a fully resolved HTML unit, or `null` if the resolved unit is not al
ready | 702 * Return the fully resolved HTML unit defined by the given [htmlSource], or |
| 789 * computed. | 703 * `null` if the resolved unit is not already computed. |
| 790 * | 704 * |
| 791 * @param htmlSource the source of the HTML unit | |
| 792 * @return a fully resolved HTML unit | |
| 793 * See [resolveHtmlUnit]. | 705 * See [resolveHtmlUnit]. |
| 794 */ | 706 */ |
| 795 ht.HtmlUnit getResolvedHtmlUnit(Source htmlSource); | 707 ht.HtmlUnit getResolvedHtmlUnit(Source htmlSource); |
| 796 | 708 |
| 797 /** | 709 /** |
| 798 * Return a list of the sources being analyzed in this context whose full path | 710 * Return a list of the sources being analyzed in this context whose full path |
| 799 * is equal to the given [path]. | 711 * is equal to the given [path]. |
| 800 */ | 712 */ |
| 801 List<Source> getSourcesWithFullName(String path); | 713 List<Source> getSourcesWithFullName(String path); |
| 802 | 714 |
| 803 /** | 715 /** |
| 804 * Return `true` if the given source is known to be the defining compilation u
nit of a | 716 * Return `true` if the given [librarySource] is known to be the defining |
| 805 * library that can be run on a client (references 'dart:html', either directl
y or indirectly). | 717 * compilation unit of a library that can be run on a client (references |
| 718 * 'dart:html', either directly or indirectly). |
| 806 * | 719 * |
| 807 * <b>Note:</b> In addition to the expected case of returning `false` if the s
ource is known | 720 * <b>Note:</b> In addition to the expected case of returning `false` if the |
| 808 * to be a library that cannot be run on a client, this method will also retur
n `false` if | 721 * source is known to be a library that cannot be run on a client, this method |
| 809 * the source is not known to be a library or if we do not know whether it can
be run on a client. | 722 * will also return `false` if the source is not known to be a library or if |
| 810 * | 723 * we do not know whether it can be run on a client. |
| 811 * @param librarySource the source being tested | |
| 812 * @return `true` if the given source is known to be a library that can be run
on a client | |
| 813 */ | 724 */ |
| 814 bool isClientLibrary(Source librarySource); | 725 bool isClientLibrary(Source librarySource); |
| 815 | 726 |
| 816 /** | 727 /** |
| 817 * Return `true` if the given source is known to be the defining compilation u
nit of a | 728 * Return `true` if the given [librarySource] is known to be the defining |
| 818 * library that can be run on the server (does not reference 'dart:html', eith
er directly or | 729 * compilation unit of a library that can be run on the server (does not |
| 819 * indirectly). | 730 * reference 'dart:html', either directly or indirectly). |
| 820 * | 731 * |
| 821 * <b>Note:</b> In addition to the expected case of returning `false` if the s
ource is known | 732 * <b>Note:</b> In addition to the expected case of returning `false` if the |
| 822 * to be a library that cannot be run on the server, this method will also ret
urn `false` if | 733 * source is known to be a library that cannot be run on the server, this |
| 823 * the source is not known to be a library or if we do not know whether it can
be run on the | 734 * method will also return `false` if the source is not known to be a library |
| 824 * server. | 735 * or if we do not know whether it can be run on the server. |
| 825 * | |
| 826 * @param librarySource the source being tested | |
| 827 * @return `true` if the given source is known to be a library that can be run
on the server | |
| 828 */ | 736 */ |
| 829 bool isServerLibrary(Source librarySource); | 737 bool isServerLibrary(Source librarySource); |
| 830 | 738 |
| 831 /** | 739 /** |
| 832 * Parse a single source to produce an AST structure. The resulting AST struct
ure may or may not | 740 * Parse the content of the given [source] to produce an AST structure. The |
| 833 * be resolved, and may have a slightly different structure depending upon whe
ther it is resolved. | 741 * resulting AST structure may or may not be resolved, and may have a slightly |
| 742 * different structure depending upon whether it is resolved. |
| 743 * |
| 744 * Throws an [AnalysisException] if the analysis could not be performed |
| 834 * | 745 * |
| 835 * <b>Note:</b> This method cannot be used in an async environment. | 746 * <b>Note:</b> This method cannot be used in an async environment. |
| 836 * | |
| 837 * @param source the source to be parsed | |
| 838 * @return the AST structure representing the content of the source | |
| 839 * @throws AnalysisException if the analysis could not be performed | |
| 840 */ | 747 */ |
| 841 CompilationUnit parseCompilationUnit(Source source); | 748 CompilationUnit parseCompilationUnit(Source source); |
| 842 | 749 |
| 843 /** | 750 /** |
| 844 * Parse a single HTML source to produce an AST structure. The resulting HTML
AST structure may or | 751 * Parse a single HTML [source] to produce an AST structure. The resulting |
| 845 * may not be resolved, and may have a slightly different structure depending
upon whether it is | 752 * HTML AST structure may or may not be resolved, and may have a slightly |
| 846 * resolved. | 753 * different structure depending upon whether it is resolved. |
| 754 * |
| 755 * Throws an [AnalysisException] if the analysis could not be performed |
| 847 * | 756 * |
| 848 * <b>Note:</b> This method cannot be used in an async environment. | 757 * <b>Note:</b> This method cannot be used in an async environment. |
| 849 * | |
| 850 * @param source the HTML source to be parsed | |
| 851 * @return the parse result (not `null`) | |
| 852 * @throws AnalysisException if the analysis could not be performed | |
| 853 */ | 758 */ |
| 854 ht.HtmlUnit parseHtmlUnit(Source source); | 759 ht.HtmlUnit parseHtmlUnit(Source source); |
| 855 | 760 |
| 856 /** | 761 /** |
| 857 * Perform the next unit of work required to keep the analysis results up-to-d
ate and return | 762 * Perform the next unit of work required to keep the analysis results |
| 858 * information about the consequent changes to the analysis results. This meth
od can be long | 763 * up-to-date and return information about the consequent changes to the |
| 859 * running. | 764 * analysis results. This method can be long running. |
| 860 * | |
| 861 * @return the results of performing the analysis | |
| 862 */ | 765 */ |
| 863 AnalysisResult performAnalysisTask(); | 766 AnalysisResult performAnalysisTask(); |
| 864 | 767 |
| 865 /** | 768 /** |
| 866 * Remove the given listener from the list of objects that are to be notified
when various | 769 * Remove the given [listener] from the list of objects that are to be |
| 867 * analysis results are produced in this context. | 770 * notified when various analysis results are produced in this context. |
| 868 * | |
| 869 * @param listener the listener to be removed | |
| 870 */ | 771 */ |
| 871 void removeListener(AnalysisListener listener); | 772 void removeListener(AnalysisListener listener); |
| 872 | 773 |
| 873 /** | 774 /** |
| 874 * Parse and resolve a single source within the given context to produce a ful
ly resolved AST. | 775 * Return a fully resolved AST for the compilation unit defined by the given |
| 776 * [unitSource] within the given [library]. |
| 777 * |
| 778 * Throws an [AnalysisException] if the analysis could not be performed. |
| 875 * | 779 * |
| 876 * <b>Note:</b> This method cannot be used in an async environment. | 780 * <b>Note:</b> This method cannot be used in an async environment. |
| 877 * | 781 * |
| 878 * @param unitSource the source to be parsed and resolved | |
| 879 * @param library the library containing the source to be resolved | |
| 880 * @return the result of resolving the AST structure representing the content
of the source in the | |
| 881 * context of the given library | |
| 882 * @throws AnalysisException if the analysis could not be performed | |
| 883 * See [getResolvedCompilationUnit]. | 782 * See [getResolvedCompilationUnit]. |
| 884 */ | 783 */ |
| 885 CompilationUnit resolveCompilationUnit( | 784 CompilationUnit resolveCompilationUnit( |
| 886 Source unitSource, LibraryElement library); | 785 Source unitSource, LibraryElement library); |
| 887 | 786 |
| 888 /** | 787 /** |
| 889 * Parse and resolve a single source within the given context to produce a ful
ly resolved AST. | 788 * Return a fully resolved AST for the compilation unit defined by the given |
| 890 * Return the resolved AST structure, or `null` if the source could not be eit
her parsed or | 789 * [unitSource] within the library defined by the given [librarySource]. |
| 891 * resolved. | 790 * |
| 791 * Throws an [AnalysisException] if the analysis could not be performed. |
| 892 * | 792 * |
| 893 * <b>Note:</b> This method cannot be used in an async environment. | 793 * <b>Note:</b> This method cannot be used in an async environment. |
| 894 * | 794 * |
| 895 * @param unitSource the source to be parsed and resolved | 795 * See [getResolvedCompilationUnit2]. |
| 896 * @param librarySource the source of the defining compilation unit of the lib
rary containing the | |
| 897 * source to be resolved | |
| 898 * @return the result of resolving the AST structure representing the content
of the source in the | |
| 899 * context of the given library | |
| 900 * @throws AnalysisException if the analysis could not be performed | |
| 901 * See [getResolvedCompilationUnit]. | |
| 902 */ | 796 */ |
| 903 CompilationUnit resolveCompilationUnit2( | 797 CompilationUnit resolveCompilationUnit2( |
| 904 Source unitSource, Source librarySource); | 798 Source unitSource, Source librarySource); |
| 905 | 799 |
| 906 /** | 800 /** |
| 907 * Parse and resolve a single source within the given context to produce a ful
ly resolved AST. | 801 * Parse and resolve a single [htmlSource] within the given context to produce |
| 802 * a fully resolved AST. |
| 803 * |
| 804 * Throws an [AnalysisException] if the analysis could not be performed. |
| 908 * | 805 * |
| 909 * <b>Note:</b> This method cannot be used in an async environment. | 806 * <b>Note:</b> This method cannot be used in an async environment. |
| 910 * | |
| 911 * @param htmlSource the source to be parsed and resolved | |
| 912 * @return the result of resolving the AST structure representing the content
of the source | |
| 913 * @throws AnalysisException if the analysis could not be performed | |
| 914 */ | 807 */ |
| 915 ht.HtmlUnit resolveHtmlUnit(Source htmlSource); | 808 ht.HtmlUnit resolveHtmlUnit(Source htmlSource); |
| 916 | 809 |
| 917 /** | 810 /** |
| 918 * Set the contents of the given source to the given contents and mark the sou
rce as having | 811 * Set the contents of the given [source] to the given [contents] and mark the |
| 919 * changed. The additional offset and length information is used by the contex
t to determine what | 812 * source as having changed. The additional [offset] and [length] information |
| 920 * reanalysis is necessary. | 813 * is used by the context to determine what reanalysis is necessary. |
| 921 * | |
| 922 * @param source the source whose contents are being overridden | |
| 923 * @param contents the text to replace the range in the current contents | |
| 924 * @param offset the offset into the current contents | |
| 925 * @param oldLength the number of characters in the original contents that wer
e replaced | |
| 926 * @param newLength the number of characters in the replacement text | |
| 927 */ | 814 */ |
| 928 void setChangedContents( | 815 void setChangedContents( |
| 929 Source source, String contents, int offset, int oldLength, int newLength); | 816 Source source, String contents, int offset, int oldLength, int newLength); |
| 930 | 817 |
| 931 /** | 818 /** |
| 932 * Set the contents of the given source to the given contents and mark the sou
rce as having | 819 * Set the contents of the given [source] to the given [contents] and mark the |
| 933 * changed. This has the effect of overriding the default contents of the sour
ce. If the contents | 820 * source as having changed. This has the effect of overriding the default |
| 934 * are `null` the override is removed so that the default contents will be ret
urned. | 821 * contents of the source. If the contents are `null` the override is removed |
| 935 * | 822 * so that the default contents will be returned. |
| 936 * @param source the source whose contents are being overridden | |
| 937 * @param contents the new contents of the source | |
| 938 */ | 823 */ |
| 939 void setContents(Source source, String contents); | 824 void setContents(Source source, String contents); |
| 940 } | 825 } |
| 941 | 826 |
| 942 /** | 827 /** |
| 943 * Instances of the class `AnalysisContextImpl` implement an [AnalysisContext]. | 828 * An [AnalysisContext]. |
| 944 */ | 829 */ |
| 945 class AnalysisContextImpl implements InternalAnalysisContext { | 830 class AnalysisContextImpl implements InternalAnalysisContext { |
| 946 /** | 831 /** |
| 947 * The difference between the maximum cache size and the maximum priority orde
r size. The priority | 832 * The difference between the maximum cache size and the maximum priority |
| 948 * list must be capped so that it is less than the cache size. Failure to do s
o can result in an | 833 * order size. The priority list must be capped so that it is less than the |
| 949 * infinite loop in performAnalysisTask() because re-caching one AST structure
can cause another | 834 * cache size. Failure to do so can result in an infinite loop in |
| 950 * priority source's AST structure to be flushed. | 835 * performAnalysisTask() because re-caching one AST structure can cause |
| 836 * another priority source's AST structure to be flushed. |
| 951 */ | 837 */ |
| 952 static int _PRIORITY_ORDER_SIZE_DELTA = 4; | 838 static int _PRIORITY_ORDER_SIZE_DELTA = 4; |
| 953 | 839 |
| 954 /** | 840 /** |
| 955 * A flag indicating whether trace output should be produced as analysis tasks
are performed. Used | 841 * A flag indicating whether trace output should be produced as analysis tasks |
| 956 * for debugging. | 842 * are performed. Used for debugging. |
| 957 */ | 843 */ |
| 958 static bool _TRACE_PERFORM_TASK = false; | 844 static bool _TRACE_PERFORM_TASK = false; |
| 959 | 845 |
| 960 /** | 846 /** |
| 961 * The next context identifier. | 847 * The next context identifier. |
| 962 */ | 848 */ |
| 963 static int _NEXT_ID = 0; | 849 static int _NEXT_ID = 0; |
| 964 | 850 |
| 965 /** | 851 /** |
| 966 * The unique identifier of this context. | 852 * The unique identifier of this context. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 994 * A flag indicating whether this context is disposed. | 880 * A flag indicating whether this context is disposed. |
| 995 */ | 881 */ |
| 996 bool _disposed = false; | 882 bool _disposed = false; |
| 997 | 883 |
| 998 /** | 884 /** |
| 999 * A cache of content used to override the default content of a source. | 885 * A cache of content used to override the default content of a source. |
| 1000 */ | 886 */ |
| 1001 ContentCache _contentCache = new ContentCache(); | 887 ContentCache _contentCache = new ContentCache(); |
| 1002 | 888 |
| 1003 /** | 889 /** |
| 1004 * The source factory used to create the sources that can be analyzed in this
context. | 890 * The source factory used to create the sources that can be analyzed in this |
| 891 * context. |
| 1005 */ | 892 */ |
| 1006 SourceFactory _sourceFactory; | 893 SourceFactory _sourceFactory; |
| 1007 | 894 |
| 1008 /** | 895 /** |
| 1009 * The set of declared variables used when computing constant values. | 896 * The set of declared variables used when computing constant values. |
| 1010 */ | 897 */ |
| 1011 DeclaredVariables _declaredVariables = new DeclaredVariables(); | 898 DeclaredVariables _declaredVariables = new DeclaredVariables(); |
| 1012 | 899 |
| 1013 /** | 900 /** |
| 1014 * A source representing the core library. | 901 * A source representing the core library. |
| 1015 */ | 902 */ |
| 1016 Source _coreLibrarySource; | 903 Source _coreLibrarySource; |
| 1017 | 904 |
| 1018 /** | 905 /** |
| 1019 * A source representing the async library. | 906 * A source representing the async library. |
| 1020 */ | 907 */ |
| 1021 Source _asyncLibrarySource; | 908 Source _asyncLibrarySource; |
| 1022 | 909 |
| 1023 /** | 910 /** |
| 1024 * The partition that contains analysis results that are not shared with other
contexts. | 911 * The partition that contains analysis results that are not shared with other |
| 912 * contexts. |
| 1025 */ | 913 */ |
| 1026 CachePartition _privatePartition; | 914 CachePartition _privatePartition; |
| 1027 | 915 |
| 1028 /** | 916 /** |
| 1029 * A table mapping the sources known to the context to the information known a
bout the source. | 917 * A table mapping the sources known to the context to the information known |
| 918 * about the source. |
| 1030 */ | 919 */ |
| 1031 AnalysisCache _cache; | 920 AnalysisCache _cache; |
| 1032 | 921 |
| 1033 /** | 922 /** |
| 1034 * An array containing sources for which data should not be flushed. | 923 * A list containing sources for which data should not be flushed. |
| 1035 */ | 924 */ |
| 1036 List<Source> _priorityOrder = Source.EMPTY_ARRAY; | 925 List<Source> _priorityOrder = Source.EMPTY_ARRAY; |
| 1037 | 926 |
| 1038 /** | 927 /** |
| 1039 * A map from all sources for which there are futures pending to a list of | 928 * A map from all sources for which there are futures pending to a list of |
| 1040 * the corresponding PendingFuture objects. These sources will be analyzed | 929 * the corresponding PendingFuture objects. These sources will be analyzed |
| 1041 * in the same way as priority sources, except with higher priority. | 930 * in the same way as priority sources, except with higher priority. |
| 1042 * | 931 * |
| 1043 * TODO(paulberry): since the size of this map is not constrained (as it is | 932 * TODO(paulberry): since the size of this map is not constrained (as it is |
| 1044 * for _priorityOrder), we run the risk of creating an analysis loop if | 933 * for _priorityOrder), we run the risk of creating an analysis loop if |
| 1045 * re-caching one AST structure causes the AST structure for another source | 934 * re-caching one AST structure causes the AST structure for another source |
| 1046 * with pending futures to be flushed. However, this is unlikely to happen | 935 * with pending futures to be flushed. However, this is unlikely to happen |
| 1047 * in practice since sources are removed from this hash set as soon as their | 936 * in practice since sources are removed from this hash set as soon as their |
| 1048 * futures have completed. | 937 * futures have completed. |
| 1049 */ | 938 */ |
| 1050 HashMap<Source, List<PendingFuture>> _pendingFutureSources = | 939 HashMap<Source, List<PendingFuture>> _pendingFutureSources = |
| 1051 new HashMap<Source, List<PendingFuture>>(); | 940 new HashMap<Source, List<PendingFuture>>(); |
| 1052 | 941 |
| 1053 /** | 942 /** |
| 1054 * An array containing sources whose AST structure is needed in order to resol
ve the next library | 943 * A list containing sources whose AST structure is needed in order to resolve |
| 1055 * to be resolved. | 944 * the next library to be resolved. |
| 1056 */ | 945 */ |
| 1057 HashSet<Source> _neededForResolution = null; | 946 HashSet<Source> _neededForResolution = null; |
| 1058 | 947 |
| 1059 /** | 948 /** |
| 1060 * A table mapping sources to the change notices that are waiting to be return
ed related to that | 949 * A table mapping sources to the change notices that are waiting to be |
| 1061 * source. | 950 * returned related to that source. |
| 1062 */ | 951 */ |
| 1063 HashMap<Source, ChangeNoticeImpl> _pendingNotices = | 952 HashMap<Source, ChangeNoticeImpl> _pendingNotices = |
| 1064 new HashMap<Source, ChangeNoticeImpl>(); | 953 new HashMap<Source, ChangeNoticeImpl>(); |
| 1065 | 954 |
| 1066 /** | 955 /** |
| 1067 * The object used to record the results of performing an analysis task. | 956 * The object used to record the results of performing an analysis task. |
| 1068 */ | 957 */ |
| 1069 AnalysisContextImpl_AnalysisTaskResultRecorder _resultRecorder; | 958 AnalysisContextImpl_AnalysisTaskResultRecorder _resultRecorder; |
| 1070 | 959 |
| 1071 /** | 960 /** |
| 1072 * Cached information used in incremental analysis or `null` if none. Synchron
ize against | 961 * Cached information used in incremental analysis or `null` if none. |
| 1073 * [cacheLock] before accessing this field. | |
| 1074 */ | 962 */ |
| 1075 IncrementalAnalysisCache _incrementalAnalysisCache; | 963 IncrementalAnalysisCache _incrementalAnalysisCache; |
| 1076 | 964 |
| 1077 /** | 965 /** |
| 1078 * The [TypeProvider] for this context, `null` if not yet created. | 966 * The [TypeProvider] for this context, `null` if not yet created. |
| 1079 */ | 967 */ |
| 1080 TypeProvider _typeProvider; | 968 TypeProvider _typeProvider; |
| 1081 | 969 |
| 1082 /** | 970 /** |
| 1083 * The object used to manage the list of sources that need to be analyzed. | 971 * The object used to manage the list of sources that need to be analyzed. |
| 1084 */ | 972 */ |
| 1085 WorkManager _workManager = new WorkManager(); | 973 WorkManager _workManager = new WorkManager(); |
| 1086 | 974 |
| 1087 /** | 975 /** |
| 1088 * The [Stopwatch] of the current "perform tasks cycle". | 976 * The [Stopwatch] of the current "perform tasks cycle". |
| 1089 */ | 977 */ |
| 1090 Stopwatch _performAnalysisTaskStopwatch; | 978 Stopwatch _performAnalysisTaskStopwatch; |
| 1091 | 979 |
| 1092 /** | 980 /** |
| 1093 * The controller for sending [SourcesChangedEvent]s. | 981 * The controller for sending [SourcesChangedEvent]s. |
| 1094 */ | 982 */ |
| 1095 StreamController<SourcesChangedEvent> _onSourcesChangedController; | 983 StreamController<SourcesChangedEvent> _onSourcesChangedController; |
| 1096 | 984 |
| 1097 /** | 985 /** |
| 1098 * The listeners that are to be notified when various analysis results are pro
duced in this | 986 * The listeners that are to be notified when various analysis results are |
| 1099 * context. | 987 * produced in this context. |
| 1100 */ | 988 */ |
| 1101 List<AnalysisListener> _listeners = new List<AnalysisListener>(); | 989 List<AnalysisListener> _listeners = new List<AnalysisListener>(); |
| 1102 | 990 |
| 1103 /** | 991 /** |
| 1104 * The most recently incrementally resolved [Source]. | 992 * The most recently incrementally resolved source, or `null` when it was |
| 1105 * Is null when it was already validated, or the most recent change was | 993 * already validated, or the most recent change was not incrementally resolved
. |
| 1106 * not incrementally resolved. | |
| 1107 */ | 994 */ |
| 1108 Source incrementalResolutionValidation_lastUnitSource; | 995 Source incrementalResolutionValidation_lastUnitSource; |
| 1109 | 996 |
| 1110 /** | 997 /** |
| 1111 * The most recently incrementally resolved library [Source]. | 998 * The most recently incrementally resolved library source, or `null` when it |
| 1112 * Is null when it was already validated, or the most recent change was | 999 * was already validated, or the most recent change was not incrementally |
| 1113 * not incrementally resolved. | 1000 * resolved. |
| 1114 */ | 1001 */ |
| 1115 Source incrementalResolutionValidation_lastLibrarySource; | 1002 Source incrementalResolutionValidation_lastLibrarySource; |
| 1116 | 1003 |
| 1117 /** | 1004 /** |
| 1118 * The result of incremental resolution result of | 1005 * The result of incremental resolution result of |
| 1119 * [incrementalResolutionValidation_lastSource]. | 1006 * [incrementalResolutionValidation_lastSource]. |
| 1120 */ | 1007 */ |
| 1121 CompilationUnit incrementalResolutionValidation_lastUnit; | 1008 CompilationUnit incrementalResolutionValidation_lastUnit; |
| 1122 | 1009 |
| 1123 /** A factory to override how [ResolverVisitor] is created. */ | 1010 /** |
| 1011 * A factory to override how the [ResolverVisitor] is created. |
| 1012 */ |
| 1124 ResolverVisitorFactory resolverVisitorFactory; | 1013 ResolverVisitorFactory resolverVisitorFactory; |
| 1125 | 1014 |
| 1126 /** A factory to override how [TypeResolverVisitor] is created. */ | 1015 /** |
| 1016 * A factory to override how the [TypeResolverVisitor] is created. |
| 1017 */ |
| 1127 TypeResolverVisitorFactory typeResolverVisitorFactory; | 1018 TypeResolverVisitorFactory typeResolverVisitorFactory; |
| 1128 | 1019 |
| 1129 /** | 1020 /** |
| 1130 * Initialize a newly created analysis context. | 1021 * Initialize a newly created analysis context. |
| 1131 */ | 1022 */ |
| 1132 AnalysisContextImpl() { | 1023 AnalysisContextImpl() { |
| 1133 _resultRecorder = new AnalysisContextImpl_AnalysisTaskResultRecorder(this); | 1024 _resultRecorder = new AnalysisContextImpl_AnalysisTaskResultRecorder(this); |
| 1134 _privatePartition = new UniversalCachePartition(this, | 1025 _privatePartition = new UniversalCachePartition(this, |
| 1135 AnalysisOptionsImpl.DEFAULT_CACHE_SIZE, | 1026 AnalysisOptionsImpl.DEFAULT_CACHE_SIZE, |
| 1136 new AnalysisContextImpl_ContextRetentionPolicy(this)); | 1027 new AnalysisContextImpl_ContextRetentionPolicy(this)); |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1266 // } | 1157 // } |
| 1267 } | 1158 } |
| 1268 } | 1159 } |
| 1269 return sources; | 1160 return sources; |
| 1270 } | 1161 } |
| 1271 | 1162 |
| 1272 @override | 1163 @override |
| 1273 List<Source> get librarySources => _getSources(SourceKind.LIBRARY); | 1164 List<Source> get librarySources => _getSources(SourceKind.LIBRARY); |
| 1274 | 1165 |
| 1275 /** | 1166 /** |
| 1276 * Look through the cache for a task that needs to be performed. Return the ta
sk that was found, | 1167 * Look through the cache for a task that needs to be performed. Return the |
| 1277 * or `null` if there is no more work to be done. | 1168 * task that was found, or `null` if there is no more work to be done. |
| 1278 * | |
| 1279 * @return the next task that needs to be performed | |
| 1280 */ | 1169 */ |
| 1281 AnalysisTask get nextAnalysisTask { | 1170 AnalysisTask get nextAnalysisTask { |
| 1282 bool hintsEnabled = _options.hint; | 1171 bool hintsEnabled = _options.hint; |
| 1283 bool lintsEnabled = _options.lint; | 1172 bool lintsEnabled = _options.lint; |
| 1284 bool hasBlockedTask = false; | 1173 bool hasBlockedTask = false; |
| 1285 // | 1174 // |
| 1286 // Look for incremental analysis | 1175 // Look for incremental analysis |
| 1287 // | 1176 // |
| 1288 if (_incrementalAnalysisCache != null && | 1177 if (_incrementalAnalysisCache != null && |
| 1289 _incrementalAnalysisCache.hasWork) { | 1178 _incrementalAnalysisCache.hasWork) { |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1466 List<Source> get sources { | 1355 List<Source> get sources { |
| 1467 List<Source> sources = new List<Source>(); | 1356 List<Source> sources = new List<Source>(); |
| 1468 MapIterator<Source, SourceEntry> iterator = _cache.iterator(); | 1357 MapIterator<Source, SourceEntry> iterator = _cache.iterator(); |
| 1469 while (iterator.moveNext()) { | 1358 while (iterator.moveNext()) { |
| 1470 sources.add(iterator.key); | 1359 sources.add(iterator.key); |
| 1471 } | 1360 } |
| 1472 return sources; | 1361 return sources; |
| 1473 } | 1362 } |
| 1474 | 1363 |
| 1475 /** | 1364 /** |
| 1476 * Return a list of the sources that would be processed by [performAnalysisTas
k]. This | 1365 * Return a list of the sources that would be processed by |
| 1477 * method duplicates, and must therefore be kept in sync with, [getNextAnalysi
sTask]. | 1366 * [performAnalysisTask]. This method duplicates, and must therefore be kept |
| 1478 * This method is intended to be used for testing purposes only. | 1367 * in sync with, [getNextAnalysisTask]. This method is intended to be used for |
| 1479 * | 1368 * testing purposes only. |
| 1480 * @return a list of the sources that would be processed by [performAnalysisTa
sk] | |
| 1481 */ | 1369 */ |
| 1482 List<Source> get sourcesNeedingProcessing { | 1370 List<Source> get sourcesNeedingProcessing { |
| 1483 HashSet<Source> sources = new HashSet<Source>(); | 1371 HashSet<Source> sources = new HashSet<Source>(); |
| 1484 bool hintsEnabled = _options.hint; | 1372 bool hintsEnabled = _options.hint; |
| 1485 bool lintsEnabled = _options.lint; | 1373 bool lintsEnabled = _options.lint; |
| 1486 | 1374 |
| 1487 // | 1375 // |
| 1488 // Look for priority sources that need to be analyzed. | 1376 // Look for priority sources that need to be analyzed. |
| 1489 // | 1377 // |
| 1490 for (Source source in _priorityOrder) { | 1378 for (Source source in _priorityOrder) { |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1815 throw sourceEntry.exception; | 1703 throw sourceEntry.exception; |
| 1816 } | 1704 } |
| 1817 return sourceEntry.getValueInLibrary( | 1705 return sourceEntry.getValueInLibrary( |
| 1818 DartEntry.RESOLVED_UNIT, librarySource); | 1706 DartEntry.RESOLVED_UNIT, librarySource); |
| 1819 } | 1707 } |
| 1820 throw new AnalysisNotScheduledError(); | 1708 throw new AnalysisNotScheduledError(); |
| 1821 }); | 1709 }); |
| 1822 } | 1710 } |
| 1823 | 1711 |
| 1824 /** | 1712 /** |
| 1825 * Create an analysis cache based on the given source factory. | 1713 * Create an analysis cache based on the given source [factory]. |
| 1826 * | |
| 1827 * @param factory the source factory containing the information needed to crea
te the cache | |
| 1828 * @return the cache that was created | |
| 1829 */ | 1714 */ |
| 1830 AnalysisCache createCacheFromSourceFactory(SourceFactory factory) { | 1715 AnalysisCache createCacheFromSourceFactory(SourceFactory factory) { |
| 1831 if (factory == null) { | 1716 if (factory == null) { |
| 1832 return new AnalysisCache(<CachePartition>[_privatePartition]); | 1717 return new AnalysisCache(<CachePartition>[_privatePartition]); |
| 1833 } | 1718 } |
| 1834 DartSdk sdk = factory.dartSdk; | 1719 DartSdk sdk = factory.dartSdk; |
| 1835 if (sdk == null) { | 1720 if (sdk == null) { |
| 1836 return new AnalysisCache(<CachePartition>[_privatePartition]); | 1721 return new AnalysisCache(<CachePartition>[_privatePartition]); |
| 1837 } | 1722 } |
| 1838 return new AnalysisCache(<CachePartition>[ | 1723 return new AnalysisCache(<CachePartition>[ |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2161 return null; | 2046 return null; |
| 2162 } | 2047 } |
| 2163 if (identical(dartEntry.getValue(DartEntry.ELEMENT), library)) { | 2048 if (identical(dartEntry.getValue(DartEntry.ELEMENT), library)) { |
| 2164 dartEntry.setValue(DartEntry.PUBLIC_NAMESPACE, namespace); | 2049 dartEntry.setValue(DartEntry.PUBLIC_NAMESPACE, namespace); |
| 2165 } | 2050 } |
| 2166 } | 2051 } |
| 2167 return namespace; | 2052 return namespace; |
| 2168 } | 2053 } |
| 2169 | 2054 |
| 2170 /** | 2055 /** |
| 2171 * Return the cache entry associated with the given source, or `null` if there
is no entry | 2056 * Return the cache entry associated with the given [source], or `null` if |
| 2172 * associated with the source. | 2057 * there is no entry associated with the source. |
| 2173 * | |
| 2174 * @param source the source for which a cache entry is being sought | |
| 2175 * @return the source cache entry associated with the given source | |
| 2176 */ | 2058 */ |
| 2177 SourceEntry getReadableSourceEntryOrNull(Source source) => _cache.get(source); | 2059 SourceEntry getReadableSourceEntryOrNull(Source source) => _cache.get(source); |
| 2178 | 2060 |
| 2179 @override | 2061 @override |
| 2180 CompilationUnit getResolvedCompilationUnit( | 2062 CompilationUnit getResolvedCompilationUnit( |
| 2181 Source unitSource, LibraryElement library) { | 2063 Source unitSource, LibraryElement library) { |
| 2182 if (library == null) { | 2064 if (library == null) { |
| 2183 return null; | 2065 return null; |
| 2184 } | 2066 } |
| 2185 return getResolvedCompilationUnit2(unitSource, library.source); | 2067 return getResolvedCompilationUnit2(unitSource, library.source); |
| (...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2680 } | 2562 } |
| 2681 | 2563 |
| 2682 /** | 2564 /** |
| 2683 * Visit all entries of the content cache. | 2565 * Visit all entries of the content cache. |
| 2684 */ | 2566 */ |
| 2685 void visitContentCache(ContentCacheVisitor visitor) { | 2567 void visitContentCache(ContentCacheVisitor visitor) { |
| 2686 _contentCache.accept(visitor); | 2568 _contentCache.accept(visitor); |
| 2687 } | 2569 } |
| 2688 | 2570 |
| 2689 /** | 2571 /** |
| 2690 * Record that we have accessed the AST structure associated with the given so
urce. At the moment, | 2572 * Record that we have accessed the AST structure associated with the given |
| 2691 * there is no differentiation between the parsed and resolved forms of the AS
T. | 2573 * [source]. At the moment, there is no differentiation between the parsed and |
| 2692 * | 2574 * resolved forms of the AST. |
| 2693 * @param source the source whose AST structure was accessed | |
| 2694 */ | 2575 */ |
| 2695 void _accessedAst(Source source) { | 2576 void _accessedAst(Source source) { |
| 2696 _cache.accessedAst(source); | 2577 _cache.accessedAst(source); |
| 2697 } | 2578 } |
| 2698 | 2579 |
| 2699 /** | 2580 /** |
| 2700 * Add all of the sources contained in the given source container to the given
list of sources. | 2581 * Add all of the sources contained in the given source [container] to the |
| 2701 * | 2582 * given list of [sources]. |
| 2702 * Note: This method must only be invoked while we are synchronized on [cacheL
ock]. | |
| 2703 * | |
| 2704 * @param sources the list to which sources are to be added | |
| 2705 * @param container the source container containing the sources to be added to
the list | |
| 2706 */ | 2583 */ |
| 2707 void _addSourcesInContainer(List<Source> sources, SourceContainer container) { | 2584 void _addSourcesInContainer(List<Source> sources, SourceContainer container) { |
| 2708 MapIterator<Source, SourceEntry> iterator = _cache.iterator(); | 2585 MapIterator<Source, SourceEntry> iterator = _cache.iterator(); |
| 2709 while (iterator.moveNext()) { | 2586 while (iterator.moveNext()) { |
| 2710 Source source = iterator.key; | 2587 Source source = iterator.key; |
| 2711 if (container.contains(source)) { | 2588 if (container.contains(source)) { |
| 2712 sources.add(source); | 2589 sources.add(source); |
| 2713 } | 2590 } |
| 2714 } | 2591 } |
| 2715 } | 2592 } |
| 2716 | 2593 |
| 2717 /** | 2594 /** |
| 2718 * Given a source for a Dart file and the library that contains it, return a c
ache entry in which | 2595 * Given the [unitSource] of a Dart file and the [librarySource] of the |
| 2719 * the state of the data represented by the given descriptor is either [CacheS
tate.VALID] or | 2596 * library that contains it, return a cache entry in which the state of the |
| 2720 * [CacheStateERROR]. This method assumes that the data can be produced by gen
erating hints | 2597 * data represented by the given [descriptor] is either [CacheState.VALID] or |
| 2721 * for the library if the data is not already cached. | 2598 * [CacheState.ERROR]. This method assumes that the data can be produced by |
| 2599 * generating hints for the library if the data is not already cached. The |
| 2600 * [dartEntry] is the cache entry associated with the Dart file. |
| 2722 * | 2601 * |
| 2723 * <b>Note:</b> This method cannot be used in an async environment. | 2602 * Throws an [AnalysisException] if data could not be returned because the |
| 2724 * | 2603 * source could not be parsed. |
| 2725 * @param unitSource the source representing the Dart file | |
| 2726 * @param librarySource the source representing the library containing the Dar
t file | |
| 2727 * @param dartEntry the cache entry associated with the Dart file | |
| 2728 * @param descriptor the descriptor representing the data to be returned | |
| 2729 * @return a cache entry containing the required data | |
| 2730 * @throws AnalysisException if data could not be returned because the source
could not be parsed | |
| 2731 */ | 2604 */ |
| 2732 DartEntry _cacheDartHintData(Source unitSource, Source librarySource, | 2605 DartEntry _cacheDartHintData(Source unitSource, Source librarySource, |
| 2733 DartEntry dartEntry, DataDescriptor descriptor) { | 2606 DartEntry dartEntry, DataDescriptor descriptor) { |
| 2734 // | 2607 // |
| 2735 // Check to see whether we already have the information being requested. | 2608 // Check to see whether we already have the information being requested. |
| 2736 // | 2609 // |
| 2737 CacheState state = dartEntry.getStateInLibrary(descriptor, librarySource); | 2610 CacheState state = dartEntry.getStateInLibrary(descriptor, librarySource); |
| 2738 while (state != CacheState.ERROR && state != CacheState.VALID) { | 2611 while (state != CacheState.ERROR && state != CacheState.VALID) { |
| 2739 // | 2612 // |
| 2740 // If not, compute the information. | 2613 // If not, compute the information. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 2768 } | 2641 } |
| 2769 dartEntry = new GenerateDartHintsTask( | 2642 dartEntry = new GenerateDartHintsTask( |
| 2770 this, units, getLibraryElement(librarySource)) | 2643 this, units, getLibraryElement(librarySource)) |
| 2771 .perform(_resultRecorder) as DartEntry; | 2644 .perform(_resultRecorder) as DartEntry; |
| 2772 state = dartEntry.getStateInLibrary(descriptor, librarySource); | 2645 state = dartEntry.getStateInLibrary(descriptor, librarySource); |
| 2773 } | 2646 } |
| 2774 return dartEntry; | 2647 return dartEntry; |
| 2775 } | 2648 } |
| 2776 | 2649 |
| 2777 /** | 2650 /** |
| 2778 * Given a source for a Dart file and the library that contains it, return a c
ache entry in which | 2651 * Given a source for a Dart file and the library that contains it, return a |
| 2779 * the state of the data represented by the given descriptor is either [CacheS
tate.VALID] or | 2652 * cache entry in which the state of the data represented by the given |
| 2780 * [CacheStateERROR]. This method assumes that the data can be produced by gen
erating lints | 2653 * descriptor is either [CacheState.VALID] or [CacheState.ERROR]. This method |
| 2781 * for the library if the data is not already cached. | 2654 * assumes that the data can be produced by generating lints for the library |
| 2655 * if the data is not already cached. |
| 2782 * | 2656 * |
| 2783 * <b>Note:</b> This method cannot be used in an async environment. | 2657 * <b>Note:</b> This method cannot be used in an async environment. |
| 2784 * | |
| 2785 * @param unitSource the source representing the Dart file | |
| 2786 * @param librarySource the source representing the library containing the Dar
t file | |
| 2787 * @param dartEntry the cache entry associated with the Dart file | |
| 2788 * @param descriptor the descriptor representing the data to be returned | |
| 2789 * @return a cache entry containing the required data | |
| 2790 * @throws AnalysisException if data could not be returned because the source
could not be parsed | |
| 2791 */ | 2658 */ |
| 2792 DartEntry _cacheDartLintData(Source unitSource, Source librarySource, | 2659 DartEntry _cacheDartLintData(Source unitSource, Source librarySource, |
| 2793 DartEntry dartEntry, DataDescriptor descriptor) { | 2660 DartEntry dartEntry, DataDescriptor descriptor) { |
| 2794 // | 2661 // |
| 2795 // Check to see whether we already have the information being requested. | 2662 // Check to see whether we already have the information being requested. |
| 2796 // | 2663 // |
| 2797 CacheState state = dartEntry.getStateInLibrary(descriptor, librarySource); | 2664 CacheState state = dartEntry.getStateInLibrary(descriptor, librarySource); |
| 2798 while (state != CacheState.ERROR && state != CacheState.VALID) { | 2665 while (state != CacheState.ERROR && state != CacheState.VALID) { |
| 2799 // | 2666 // |
| 2800 // If not, compute the information. | 2667 // If not, compute the information. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 2829 //TODO(pquitslund): revisit if we need all units or whether one will do | 2696 //TODO(pquitslund): revisit if we need all units or whether one will do |
| 2830 dartEntry = new GenerateDartLintsTask( | 2697 dartEntry = new GenerateDartLintsTask( |
| 2831 this, units, getLibraryElement(librarySource)) | 2698 this, units, getLibraryElement(librarySource)) |
| 2832 .perform(_resultRecorder) as DartEntry; | 2699 .perform(_resultRecorder) as DartEntry; |
| 2833 state = dartEntry.getStateInLibrary(descriptor, librarySource); | 2700 state = dartEntry.getStateInLibrary(descriptor, librarySource); |
| 2834 } | 2701 } |
| 2835 return dartEntry; | 2702 return dartEntry; |
| 2836 } | 2703 } |
| 2837 | 2704 |
| 2838 /** | 2705 /** |
| 2839 * Given a source for a Dart file, return a cache entry in which the state of
the data represented | 2706 * Given a source for a Dart file, return a cache entry in which the state of |
| 2840 * by the given descriptor is either [CacheState.VALID] or [CacheState.ERROR].
This | 2707 * the data represented by the given descriptor is either [CacheState.VALID] |
| 2841 * method assumes that the data can be produced by parsing the source if it is
not already cached. | 2708 * or [CacheState.ERROR]. This method assumes that the data can be produced by |
| 2709 * parsing the source if it is not already cached. |
| 2842 * | 2710 * |
| 2843 * <b>Note:</b> This method cannot be used in an async environment. | 2711 * <b>Note:</b> This method cannot be used in an async environment. |
| 2844 * | |
| 2845 * @param source the source representing the Dart file | |
| 2846 * @param dartEntry the cache entry associated with the Dart file | |
| 2847 * @param descriptor the descriptor representing the data to be returned | |
| 2848 * @return a cache entry containing the required data | |
| 2849 * @throws AnalysisException if data could not be returned because the source
could not be parsed | |
| 2850 */ | 2712 */ |
| 2851 DartEntry _cacheDartParseData( | 2713 DartEntry _cacheDartParseData( |
| 2852 Source source, DartEntry dartEntry, DataDescriptor descriptor) { | 2714 Source source, DartEntry dartEntry, DataDescriptor descriptor) { |
| 2853 if (identical(descriptor, DartEntry.PARSED_UNIT)) { | 2715 if (identical(descriptor, DartEntry.PARSED_UNIT)) { |
| 2854 if (dartEntry.hasResolvableCompilationUnit) { | 2716 if (dartEntry.hasResolvableCompilationUnit) { |
| 2855 return dartEntry; | 2717 return dartEntry; |
| 2856 } | 2718 } |
| 2857 } | 2719 } |
| 2858 // | 2720 // |
| 2859 // Check to see whether we already have the information being requested. | 2721 // Check to see whether we already have the information being requested. |
| 2860 // | 2722 // |
| 2861 CacheState state = dartEntry.getState(descriptor); | 2723 CacheState state = dartEntry.getState(descriptor); |
| 2862 while (state != CacheState.ERROR && state != CacheState.VALID) { | 2724 while (state != CacheState.ERROR && state != CacheState.VALID) { |
| 2863 // | 2725 // |
| 2864 // If not, compute the information. Unless the modification date of the | 2726 // If not, compute the information. Unless the modification date of the |
| 2865 // source continues to change, this loop will eventually terminate. | 2727 // source continues to change, this loop will eventually terminate. |
| 2866 // | 2728 // |
| 2867 dartEntry = _cacheDartScanData(source, dartEntry, DartEntry.TOKEN_STREAM); | 2729 dartEntry = _cacheDartScanData(source, dartEntry, DartEntry.TOKEN_STREAM); |
| 2868 dartEntry = new ParseDartTask(this, source, | 2730 dartEntry = new ParseDartTask(this, source, |
| 2869 dartEntry.getValue(DartEntry.TOKEN_STREAM), | 2731 dartEntry.getValue(DartEntry.TOKEN_STREAM), |
| 2870 dartEntry.getValue(SourceEntry.LINE_INFO)) | 2732 dartEntry.getValue(SourceEntry.LINE_INFO)) |
| 2871 .perform(_resultRecorder) as DartEntry; | 2733 .perform(_resultRecorder) as DartEntry; |
| 2872 state = dartEntry.getState(descriptor); | 2734 state = dartEntry.getState(descriptor); |
| 2873 } | 2735 } |
| 2874 return dartEntry; | 2736 return dartEntry; |
| 2875 } | 2737 } |
| 2876 | 2738 |
| 2877 /** | 2739 /** |
| 2878 * Given a source for a Dart file and the library that contains it, return a c
ache entry in which | 2740 * Given a source for a Dart file and the library that contains it, return a |
| 2879 * the state of the data represented by the given descriptor is either [CacheS
tate.VALID] or | 2741 * cache entry in which the state of the data represented by the given |
| 2880 * [CacheState.ERROR]. This method assumes that the data can be produced by re
solving the | 2742 * descriptor is either [CacheState.VALID] or [CacheState.ERROR]. This method |
| 2881 * source in the context of the library if it is not already cached. | 2743 * assumes that the data can be produced by resolving the source in the |
| 2744 * context of the library if it is not already cached. |
| 2882 * | 2745 * |
| 2883 * <b>Note:</b> This method cannot be used in an async environment. | 2746 * <b>Note:</b> This method cannot be used in an async environment. |
| 2884 * | |
| 2885 * @param unitSource the source representing the Dart file | |
| 2886 * @param librarySource the source representing the library containing the Dar
t file | |
| 2887 * @param dartEntry the cache entry associated with the Dart file | |
| 2888 * @param descriptor the descriptor representing the data to be returned | |
| 2889 * @return a cache entry containing the required data | |
| 2890 * @throws AnalysisException if data could not be returned because the source
could not be parsed | |
| 2891 */ | 2747 */ |
| 2892 DartEntry _cacheDartResolutionData(Source unitSource, Source librarySource, | 2748 DartEntry _cacheDartResolutionData(Source unitSource, Source librarySource, |
| 2893 DartEntry dartEntry, DataDescriptor descriptor) { | 2749 DartEntry dartEntry, DataDescriptor descriptor) { |
| 2894 // | 2750 // |
| 2895 // Check to see whether we already have the information being requested. | 2751 // Check to see whether we already have the information being requested. |
| 2896 // | 2752 // |
| 2897 CacheState state = (identical(descriptor, DartEntry.ELEMENT)) | 2753 CacheState state = (identical(descriptor, DartEntry.ELEMENT)) |
| 2898 ? dartEntry.getState(descriptor) | 2754 ? dartEntry.getState(descriptor) |
| 2899 : dartEntry.getStateInLibrary(descriptor, librarySource); | 2755 : dartEntry.getStateInLibrary(descriptor, librarySource); |
| 2900 while (state != CacheState.ERROR && state != CacheState.VALID) { | 2756 while (state != CacheState.ERROR && state != CacheState.VALID) { |
| 2901 // | 2757 // |
| 2902 // If not, compute the information. Unless the modification date of the | 2758 // If not, compute the information. Unless the modification date of the |
| 2903 // source continues to change, this loop will eventually terminate. | 2759 // source continues to change, this loop will eventually terminate. |
| 2904 // | 2760 // |
| 2905 // TODO(brianwilkerson) As an optimization, if we already have the | 2761 // TODO(brianwilkerson) As an optimization, if we already have the |
| 2906 // element model for the library we can use ResolveDartUnitTask to produce | 2762 // element model for the library we can use ResolveDartUnitTask to produce |
| 2907 // the resolved AST structure much faster. | 2763 // the resolved AST structure much faster. |
| 2908 dartEntry = new ResolveDartLibraryTask(this, unitSource, librarySource) | 2764 dartEntry = new ResolveDartLibraryTask(this, unitSource, librarySource) |
| 2909 .perform(_resultRecorder) as DartEntry; | 2765 .perform(_resultRecorder) as DartEntry; |
| 2910 state = (identical(descriptor, DartEntry.ELEMENT)) | 2766 state = (identical(descriptor, DartEntry.ELEMENT)) |
| 2911 ? dartEntry.getState(descriptor) | 2767 ? dartEntry.getState(descriptor) |
| 2912 : dartEntry.getStateInLibrary(descriptor, librarySource); | 2768 : dartEntry.getStateInLibrary(descriptor, librarySource); |
| 2913 } | 2769 } |
| 2914 return dartEntry; | 2770 return dartEntry; |
| 2915 } | 2771 } |
| 2916 | 2772 |
| 2917 /** | 2773 /** |
| 2918 * Given a source for a Dart file, return a cache entry in which the state of
the data represented | 2774 * Given a source for a Dart file, return a cache entry in which the state of |
| 2919 * by the given descriptor is either [CacheState.VALID] or [CacheState.ERROR].
This | 2775 * the data represented by the given descriptor is either [CacheState.VALID] |
| 2920 * method assumes that the data can be produced by scanning the source if it i
s not already | 2776 * or [CacheState.ERROR]. This method assumes that the data can be produced by |
| 2921 * cached. | 2777 * scanning the source if it is not already cached. |
| 2922 * | 2778 * |
| 2923 * <b>Note:</b> This method cannot be used in an async environment. | 2779 * <b>Note:</b> This method cannot be used in an async environment. |
| 2924 * | |
| 2925 * @param source the source representing the Dart file | |
| 2926 * @param dartEntry the cache entry associated with the Dart file | |
| 2927 * @param descriptor the descriptor representing the data to be returned | |
| 2928 * @return a cache entry containing the required data | |
| 2929 * @throws AnalysisException if data could not be returned because the source
could not be scanned | |
| 2930 */ | 2780 */ |
| 2931 DartEntry _cacheDartScanData( | 2781 DartEntry _cacheDartScanData( |
| 2932 Source source, DartEntry dartEntry, DataDescriptor descriptor) { | 2782 Source source, DartEntry dartEntry, DataDescriptor descriptor) { |
| 2933 // | 2783 // |
| 2934 // Check to see whether we already have the information being requested. | 2784 // Check to see whether we already have the information being requested. |
| 2935 // | 2785 // |
| 2936 CacheState state = dartEntry.getState(descriptor); | 2786 CacheState state = dartEntry.getState(descriptor); |
| 2937 while (state != CacheState.ERROR && state != CacheState.VALID) { | 2787 while (state != CacheState.ERROR && state != CacheState.VALID) { |
| 2938 // | 2788 // |
| 2939 // If not, compute the information. Unless the modification date of the | 2789 // If not, compute the information. Unless the modification date of the |
| (...skipping 12 matching lines...) Expand all Loading... |
| 2952 } catch (exception, stackTrace) { | 2802 } catch (exception, stackTrace) { |
| 2953 throw new AnalysisException( | 2803 throw new AnalysisException( |
| 2954 "Exception", new CaughtException(exception, stackTrace)); | 2804 "Exception", new CaughtException(exception, stackTrace)); |
| 2955 } | 2805 } |
| 2956 state = dartEntry.getState(descriptor); | 2806 state = dartEntry.getState(descriptor); |
| 2957 } | 2807 } |
| 2958 return dartEntry; | 2808 return dartEntry; |
| 2959 } | 2809 } |
| 2960 | 2810 |
| 2961 /** | 2811 /** |
| 2962 * Given a source for a Dart file and the library that contains it, return a c
ache entry in which | 2812 * Given a source for a Dart file and the library that contains it, return a |
| 2963 * the state of the data represented by the given descriptor is either [CacheS
tate.VALID] or | 2813 * cache entry in which the state of the data represented by the given |
| 2964 * [CacheState.ERROR]. This method assumes that the data can be produced by ve
rifying the | 2814 * descriptor is either [CacheState.VALID] or [CacheState.ERROR]. This method |
| 2965 * source in the given library if the data is not already cached. | 2815 * assumes that the data can be produced by verifying the source in the given |
| 2816 * library if the data is not already cached. |
| 2966 * | 2817 * |
| 2967 * <b>Note:</b> This method cannot be used in an async environment. | 2818 * <b>Note:</b> This method cannot be used in an async environment. |
| 2968 * | |
| 2969 * @param unitSource the source representing the Dart file | |
| 2970 * @param librarySource the source representing the library containing the Dar
t file | |
| 2971 * @param dartEntry the cache entry associated with the Dart file | |
| 2972 * @param descriptor the descriptor representing the data to be returned | |
| 2973 * @return a cache entry containing the required data | |
| 2974 * @throws AnalysisException if data could not be returned because the source
could not be parsed | |
| 2975 */ | 2819 */ |
| 2976 DartEntry _cacheDartVerificationData(Source unitSource, Source librarySource, | 2820 DartEntry _cacheDartVerificationData(Source unitSource, Source librarySource, |
| 2977 DartEntry dartEntry, DataDescriptor descriptor) { | 2821 DartEntry dartEntry, DataDescriptor descriptor) { |
| 2978 // | 2822 // |
| 2979 // Check to see whether we already have the information being requested. | 2823 // Check to see whether we already have the information being requested. |
| 2980 // | 2824 // |
| 2981 CacheState state = dartEntry.getStateInLibrary(descriptor, librarySource); | 2825 CacheState state = dartEntry.getStateInLibrary(descriptor, librarySource); |
| 2982 while (state != CacheState.ERROR && state != CacheState.VALID) { | 2826 while (state != CacheState.ERROR && state != CacheState.VALID) { |
| 2983 // | 2827 // |
| 2984 // If not, compute the information. Unless the modification date of the | 2828 // If not, compute the information. Unless the modification date of the |
| 2985 // source continues to change, this loop will eventually terminate. | 2829 // source continues to change, this loop will eventually terminate. |
| 2986 // | 2830 // |
| 2987 LibraryElement library = computeLibraryElement(librarySource); | 2831 LibraryElement library = computeLibraryElement(librarySource); |
| 2988 CompilationUnit unit = resolveCompilationUnit(unitSource, library); | 2832 CompilationUnit unit = resolveCompilationUnit(unitSource, library); |
| 2989 if (unit == null) { | 2833 if (unit == null) { |
| 2990 throw new AnalysisException( | 2834 throw new AnalysisException( |
| 2991 "Could not resolve compilation unit ${unitSource.fullName} in ${libr
arySource.fullName}"); | 2835 "Could not resolve compilation unit ${unitSource.fullName} in ${libr
arySource.fullName}"); |
| 2992 } | 2836 } |
| 2993 dartEntry = new GenerateDartErrorsTask(this, unitSource, unit, library) | 2837 dartEntry = new GenerateDartErrorsTask(this, unitSource, unit, library) |
| 2994 .perform(_resultRecorder) as DartEntry; | 2838 .perform(_resultRecorder) as DartEntry; |
| 2995 state = dartEntry.getStateInLibrary(descriptor, librarySource); | 2839 state = dartEntry.getStateInLibrary(descriptor, librarySource); |
| 2996 } | 2840 } |
| 2997 return dartEntry; | 2841 return dartEntry; |
| 2998 } | 2842 } |
| 2999 | 2843 |
| 3000 /** | 2844 /** |
| 3001 * Given a source for an HTML file, return a cache entry in which all of the d
ata represented by | 2845 * Given a source for an HTML file, return a cache entry in which all of the |
| 3002 * the state of the given descriptors is either [CacheState.VALID] or | 2846 * data represented by the state of the given descriptors is either |
| 3003 * [CacheState.ERROR]. This method assumes that the data can be produced by pa
rsing the | 2847 * [CacheState.VALID] or [CacheState.ERROR]. This method assumes that the data |
| 3004 * source if it is not already cached. | 2848 * can be produced by parsing the source if it is not already cached. |
| 3005 * | 2849 * |
| 3006 * <b>Note:</b> This method cannot be used in an async environment. | 2850 * <b>Note:</b> This method cannot be used in an async environment. |
| 3007 * | |
| 3008 * @param source the source representing the HTML file | |
| 3009 * @param htmlEntry the cache entry associated with the HTML file | |
| 3010 * @param descriptor the descriptor representing the data to be returned | |
| 3011 * @return a cache entry containing the required data | |
| 3012 * @throws AnalysisException if data could not be returned because the source
could not be | |
| 3013 * resolved | |
| 3014 */ | 2851 */ |
| 3015 HtmlEntry _cacheHtmlParseData( | 2852 HtmlEntry _cacheHtmlParseData( |
| 3016 Source source, HtmlEntry htmlEntry, DataDescriptor descriptor) { | 2853 Source source, HtmlEntry htmlEntry, DataDescriptor descriptor) { |
| 3017 if (identical(descriptor, HtmlEntry.PARSED_UNIT)) { | 2854 if (identical(descriptor, HtmlEntry.PARSED_UNIT)) { |
| 3018 ht.HtmlUnit unit = htmlEntry.anyParsedUnit; | 2855 ht.HtmlUnit unit = htmlEntry.anyParsedUnit; |
| 3019 if (unit != null) { | 2856 if (unit != null) { |
| 3020 return htmlEntry; | 2857 return htmlEntry; |
| 3021 } | 2858 } |
| 3022 } | 2859 } |
| 3023 // | 2860 // |
| (...skipping 18 matching lines...) Expand all Loading... |
| 3042 } catch (exception, stackTrace) { | 2879 } catch (exception, stackTrace) { |
| 3043 throw new AnalysisException( | 2880 throw new AnalysisException( |
| 3044 "Exception", new CaughtException(exception, stackTrace)); | 2881 "Exception", new CaughtException(exception, stackTrace)); |
| 3045 } | 2882 } |
| 3046 state = htmlEntry.getState(descriptor); | 2883 state = htmlEntry.getState(descriptor); |
| 3047 } | 2884 } |
| 3048 return htmlEntry; | 2885 return htmlEntry; |
| 3049 } | 2886 } |
| 3050 | 2887 |
| 3051 /** | 2888 /** |
| 3052 * Given a source for an HTML file, return a cache entry in which the state of
the data | 2889 * Given a source for an HTML file, return a cache entry in which the state of |
| 3053 * represented by the given descriptor is either [CacheState.VALID] or | 2890 * the data represented by the given descriptor is either [CacheState.VALID] |
| 3054 * [CacheState.ERROR]. This method assumes that the data can be produced by re
solving the | 2891 * or [CacheState.ERROR]. This method assumes that the data can be produced by |
| 3055 * source if it is not already cached. | 2892 * resolving the source if it is not already cached. |
| 3056 * | 2893 * |
| 3057 * <b>Note:</b> This method cannot be used in an async environment. | 2894 * <b>Note:</b> This method cannot be used in an async environment. |
| 3058 * | |
| 3059 * @param source the source representing the HTML file | |
| 3060 * @param dartEntry the cache entry associated with the HTML file | |
| 3061 * @param descriptor the descriptor representing the data to be returned | |
| 3062 * @return a cache entry containing the required data | |
| 3063 * @throws AnalysisException if data could not be returned because the source
could not be | |
| 3064 * resolved | |
| 3065 */ | 2895 */ |
| 3066 HtmlEntry _cacheHtmlResolutionData( | 2896 HtmlEntry _cacheHtmlResolutionData( |
| 3067 Source source, HtmlEntry htmlEntry, DataDescriptor descriptor) { | 2897 Source source, HtmlEntry htmlEntry, DataDescriptor descriptor) { |
| 3068 // | 2898 // |
| 3069 // Check to see whether we already have the information being requested. | 2899 // Check to see whether we already have the information being requested. |
| 3070 // | 2900 // |
| 3071 CacheState state = htmlEntry.getState(descriptor); | 2901 CacheState state = htmlEntry.getState(descriptor); |
| 3072 while (state != CacheState.ERROR && state != CacheState.VALID) { | 2902 while (state != CacheState.ERROR && state != CacheState.VALID) { |
| 3073 // | 2903 // |
| 3074 // If not, compute the information. Unless the modification date of the | 2904 // If not, compute the information. Unless the modification date of the |
| (...skipping 17 matching lines...) Expand all Loading... |
| 3092 _pendingFutureSources[pendingFuture.source]; | 2922 _pendingFutureSources[pendingFuture.source]; |
| 3093 if (pendingFutures != null) { | 2923 if (pendingFutures != null) { |
| 3094 pendingFutures.remove(pendingFuture); | 2924 pendingFutures.remove(pendingFuture); |
| 3095 if (pendingFutures.isEmpty) { | 2925 if (pendingFutures.isEmpty) { |
| 3096 _pendingFutureSources.remove(pendingFuture.source); | 2926 _pendingFutureSources.remove(pendingFuture.source); |
| 3097 } | 2927 } |
| 3098 } | 2928 } |
| 3099 } | 2929 } |
| 3100 | 2930 |
| 3101 /** | 2931 /** |
| 3102 * Compute the transitive closure of all libraries that depend on the given li
brary by adding such | 2932 * Compute the transitive closure of all libraries that depend on the given |
| 3103 * libraries to the given collection. | 2933 * [library] by adding such libraries to the given collection of |
| 3104 * | 2934 * [librariesToInvalidate]. |
| 3105 * @param library the library on which the other libraries depend | |
| 3106 * @param librariesToInvalidate the libraries that depend on the given library | |
| 3107 */ | 2935 */ |
| 3108 void _computeAllLibrariesDependingOn( | 2936 void _computeAllLibrariesDependingOn( |
| 3109 Source library, HashSet<Source> librariesToInvalidate) { | 2937 Source library, HashSet<Source> librariesToInvalidate) { |
| 3110 if (librariesToInvalidate.add(library)) { | 2938 if (librariesToInvalidate.add(library)) { |
| 3111 for (Source dependentLibrary in getLibrariesDependingOn(library)) { | 2939 for (Source dependentLibrary in getLibrariesDependingOn(library)) { |
| 3112 _computeAllLibrariesDependingOn( | 2940 _computeAllLibrariesDependingOn( |
| 3113 dependentLibrary, librariesToInvalidate); | 2941 dependentLibrary, librariesToInvalidate); |
| 3114 } | 2942 } |
| 3115 } | 2943 } |
| 3116 } | 2944 } |
| 3117 | 2945 |
| 3118 /** | 2946 /** |
| 3119 * Compute the priority that should be used when the source associated with th
e given entry is | 2947 * Return the priority that should be used when the source associated with |
| 3120 * added to the work manager. | 2948 * the given [dartEntry] is added to the work manager. |
| 3121 * | |
| 3122 * @param dartEntry the entry associated with the source | |
| 3123 * @return the priority that was computed | |
| 3124 */ | 2949 */ |
| 3125 SourcePriority _computePriority(DartEntry dartEntry) { | 2950 SourcePriority _computePriority(DartEntry dartEntry) { |
| 3126 SourceKind kind = dartEntry.kind; | 2951 SourceKind kind = dartEntry.kind; |
| 3127 if (kind == SourceKind.LIBRARY) { | 2952 if (kind == SourceKind.LIBRARY) { |
| 3128 return SourcePriority.LIBRARY; | 2953 return SourcePriority.LIBRARY; |
| 3129 } else if (kind == SourceKind.PART) { | 2954 } else if (kind == SourceKind.PART) { |
| 3130 return SourcePriority.NORMAL_PART; | 2955 return SourcePriority.NORMAL_PART; |
| 3131 } | 2956 } |
| 3132 return SourcePriority.UNKNOWN; | 2957 return SourcePriority.UNKNOWN; |
| 3133 } | 2958 } |
| 3134 | 2959 |
| 3135 /** | 2960 /** |
| 3136 * Given the encoded form of a source, use the source factory to reconstitute
the original source. | 2961 * Given the encoded form of a source ([encoding]), use the source factory to |
| 3137 * | 2962 * reconstitute the original source. |
| 3138 * @param encoding the encoded form of a source | |
| 3139 * @return the source represented by the encoding | |
| 3140 */ | 2963 */ |
| 3141 Source _computeSourceFromEncoding(String encoding) => | 2964 Source _computeSourceFromEncoding(String encoding) => |
| 3142 _sourceFactory.fromEncoding(encoding); | 2965 _sourceFactory.fromEncoding(encoding); |
| 3143 | 2966 |
| 3144 /** | 2967 /** |
| 3145 * Return `true` if the given array of sources contains the given source. | 2968 * Return `true` if the given list of [sources] contains the given |
| 3146 * | 2969 * [targetSource]. |
| 3147 * @param sources the sources being searched | |
| 3148 * @param targetSource the source being searched for | |
| 3149 * @return `true` if the given source is in the array | |
| 3150 */ | 2970 */ |
| 3151 bool _contains(List<Source> sources, Source targetSource) { | 2971 bool _contains(List<Source> sources, Source targetSource) { |
| 3152 for (Source source in sources) { | 2972 for (Source source in sources) { |
| 3153 if (source == targetSource) { | 2973 if (source == targetSource) { |
| 3154 return true; | 2974 return true; |
| 3155 } | 2975 } |
| 3156 } | 2976 } |
| 3157 return false; | 2977 return false; |
| 3158 } | 2978 } |
| 3159 | 2979 |
| 3160 /** | 2980 /** |
| 3161 * Return `true` if the given array of sources contains any of the given targe
t sources. | 2981 * Return `true` if the given list of [sources] contains any of the given |
| 3162 * | 2982 * [targetSources]. |
| 3163 * @param sources the sources being searched | |
| 3164 * @param targetSources the sources being searched for | |
| 3165 * @return `true` if any of the given target sources are in the array | |
| 3166 */ | 2983 */ |
| 3167 bool _containsAny(List<Source> sources, List<Source> targetSources) { | 2984 bool _containsAny(List<Source> sources, List<Source> targetSources) { |
| 3168 for (Source targetSource in targetSources) { | 2985 for (Source targetSource in targetSources) { |
| 3169 if (_contains(sources, targetSource)) { | 2986 if (_contains(sources, targetSource)) { |
| 3170 return true; | 2987 return true; |
| 3171 } | 2988 } |
| 3172 } | 2989 } |
| 3173 return false; | 2990 return false; |
| 3174 } | 2991 } |
| 3175 | 2992 |
| 3176 /** | 2993 /** |
| 3177 * Set the contents of the given source to the given contents and mark the sou
rce as having | 2994 * Set the contents of the given [source] to the given [contents] and mark the |
| 3178 * changed. The additional offset and length information is used by the contex
t to determine what | 2995 * source as having changed. The additional [offset], [oldLength] and |
| 3179 * reanalysis is necessary. [setChangedContents] triggers a source changed eve
nt | 2996 * [newLength] information is used by the context to determine what reanalysis |
| 3180 * where as this method does not. | 2997 * is necessary. The method [setChangedContents] triggers a source changed |
| 3181 * | 2998 * event where as this method does not. |
| 3182 * @param source the source whose contents are being overridden | |
| 3183 * @param contents the text to replace the range in the current contents | |
| 3184 * @param offset the offset into the current contents | |
| 3185 * @param oldLength the number of characters in the original contents that wer
e replaced | |
| 3186 * @param newLength the number of characters in the replacement text | |
| 3187 */ | 2999 */ |
| 3188 bool _contentRangeChanged(Source source, String contents, int offset, | 3000 bool _contentRangeChanged(Source source, String contents, int offset, |
| 3189 int oldLength, int newLength) { | 3001 int oldLength, int newLength) { |
| 3190 bool changed = false; | 3002 bool changed = false; |
| 3191 String originalContents = _contentCache.setContents(source, contents); | 3003 String originalContents = _contentCache.setContents(source, contents); |
| 3192 if (contents != null) { | 3004 if (contents != null) { |
| 3193 if (contents != originalContents) { | 3005 if (contents != originalContents) { |
| 3194 if (_options.incremental) { | 3006 if (_options.incremental) { |
| 3195 _incrementalAnalysisCache = IncrementalAnalysisCache.update( | 3007 _incrementalAnalysisCache = IncrementalAnalysisCache.update( |
| 3196 _incrementalAnalysisCache, source, originalContents, contents, | 3008 _incrementalAnalysisCache, source, originalContents, contents, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 3208 } else if (originalContents != null) { | 3020 } else if (originalContents != null) { |
| 3209 _incrementalAnalysisCache = | 3021 _incrementalAnalysisCache = |
| 3210 IncrementalAnalysisCache.clear(_incrementalAnalysisCache, source); | 3022 IncrementalAnalysisCache.clear(_incrementalAnalysisCache, source); |
| 3211 _sourceChanged(source); | 3023 _sourceChanged(source); |
| 3212 changed = true; | 3024 changed = true; |
| 3213 } | 3025 } |
| 3214 return changed; | 3026 return changed; |
| 3215 } | 3027 } |
| 3216 | 3028 |
| 3217 /** | 3029 /** |
| 3218 * Set the contents of the given source to the given contents and mark the sou
rce as having | 3030 * Set the contents of the given [source] to the given [contents] and mark the |
| 3219 * changed. This has the effect of overriding the default contents of the sour
ce. If the contents | 3031 * source as having changed. This has the effect of overriding the default |
| 3220 * are `null` the override is removed so that the default contents will be ret
urned. | 3032 * contents of the source. If the contents are `null` the override is removed |
| 3221 * | 3033 * so that the default contents will be returned. If [notify] is true, a |
| 3222 * If [notify] is true, a source changed event is triggered. | 3034 * source changed event is triggered. |
| 3223 * | |
| 3224 * @param source the source whose contents are being overridden | |
| 3225 * @param contents the new contents of the source | |
| 3226 */ | 3035 */ |
| 3227 void _contentsChanged(Source source, String contents, bool notify) { | 3036 void _contentsChanged(Source source, String contents, bool notify) { |
| 3228 String originalContents = _contentCache.setContents(source, contents); | 3037 String originalContents = _contentCache.setContents(source, contents); |
| 3229 handleContentsChanged(source, originalContents, contents, notify); | 3038 handleContentsChanged(source, originalContents, contents, notify); |
| 3230 } | 3039 } |
| 3231 | 3040 |
| 3232 // /** | |
| 3233 // * Create a [BuildUnitElementTask] for the given [source]. | |
| 3234 // */ | |
| 3235 // AnalysisContextImpl_TaskData _createBuildUnitElementTask(Source source, | |
| 3236 // DartEntry dartEntry, Source librarySource) { | |
| 3237 // CompilationUnit unit = dartEntry.resolvableCompilationUnit; | |
| 3238 // if (unit == null) { | |
| 3239 // return _createParseDartTask(source, dartEntry); | |
| 3240 // } | |
| 3241 // return new AnalysisContextImpl_TaskData( | |
| 3242 // new BuildUnitElementTask(this, source, librarySource, unit), | |
| 3243 // false); | |
| 3244 // } | |
| 3245 | |
| 3246 /** | 3041 /** |
| 3247 * Create a [GenerateDartErrorsTask] for the given source, marking the verific
ation errors | 3042 * Create a [GenerateDartErrorsTask] for the given [unitSource], marking the |
| 3248 * as being in-process. The compilation unit and the library can be the same i
f the compilation | 3043 * verification errors as being in-process. The compilation unit and the |
| 3249 * unit is the defining compilation unit of the library. | 3044 * library can be the same if the compilation unit is the defining compilation |
| 3250 * | 3045 * unit of the library. |
| 3251 * @param unitSource the source for the compilation unit to be verified | |
| 3252 * @param unitEntry the entry for the compilation unit | |
| 3253 * @param librarySource the source for the library containing the compilation
unit | |
| 3254 * @param libraryEntry the entry for the library | |
| 3255 * @return task data representing the created task | |
| 3256 */ | 3046 */ |
| 3257 AnalysisContextImpl_TaskData _createGenerateDartErrorsTask(Source unitSource, | 3047 AnalysisContextImpl_TaskData _createGenerateDartErrorsTask(Source unitSource, |
| 3258 DartEntry unitEntry, Source librarySource, DartEntry libraryEntry) { | 3048 DartEntry unitEntry, Source librarySource, DartEntry libraryEntry) { |
| 3259 if (unitEntry.getStateInLibrary(DartEntry.RESOLVED_UNIT, librarySource) != | 3049 if (unitEntry.getStateInLibrary(DartEntry.RESOLVED_UNIT, librarySource) != |
| 3260 CacheState.VALID || | 3050 CacheState.VALID || |
| 3261 libraryEntry.getState(DartEntry.ELEMENT) != CacheState.VALID) { | 3051 libraryEntry.getState(DartEntry.ELEMENT) != CacheState.VALID) { |
| 3262 return _createResolveDartLibraryTask(librarySource, libraryEntry); | 3052 return _createResolveDartLibraryTask(librarySource, libraryEntry); |
| 3263 } | 3053 } |
| 3264 CompilationUnit unit = | 3054 CompilationUnit unit = |
| 3265 unitEntry.getValueInLibrary(DartEntry.RESOLVED_UNIT, librarySource); | 3055 unitEntry.getValueInLibrary(DartEntry.RESOLVED_UNIT, librarySource); |
| 3266 if (unit == null) { | 3056 if (unit == null) { |
| 3267 CaughtException exception = new CaughtException(new AnalysisException( | 3057 CaughtException exception = new CaughtException(new AnalysisException( |
| 3268 "Entry has VALID state for RESOLVED_UNIT but null value for ${unit
Source.fullName} in ${librarySource.fullName}"), | 3058 "Entry has VALID state for RESOLVED_UNIT but null value for ${unit
Source.fullName} in ${librarySource.fullName}"), |
| 3269 null); | 3059 null); |
| 3270 AnalysisEngine.instance.logger.logInformation( | 3060 AnalysisEngine.instance.logger.logInformation( |
| 3271 exception.toString(), exception); | 3061 exception.toString(), exception); |
| 3272 unitEntry.recordResolutionError(exception); | 3062 unitEntry.recordResolutionError(exception); |
| 3273 return new AnalysisContextImpl_TaskData(null, false); | 3063 return new AnalysisContextImpl_TaskData(null, false); |
| 3274 } | 3064 } |
| 3275 LibraryElement libraryElement = libraryEntry.getValue(DartEntry.ELEMENT); | 3065 LibraryElement libraryElement = libraryEntry.getValue(DartEntry.ELEMENT); |
| 3276 return new AnalysisContextImpl_TaskData( | 3066 return new AnalysisContextImpl_TaskData( |
| 3277 new GenerateDartErrorsTask(this, unitSource, unit, libraryElement), | 3067 new GenerateDartErrorsTask(this, unitSource, unit, libraryElement), |
| 3278 false); | 3068 false); |
| 3279 } | 3069 } |
| 3280 | 3070 |
| 3281 /** | 3071 /** |
| 3282 * Create a [GenerateDartHintsTask] for the given source, marking the hints as
being | 3072 * Create a [GenerateDartHintsTask] for the given [source], marking the hints |
| 3283 * in-process. | 3073 * as being in-process. |
| 3284 * | |
| 3285 * @param source the source whose content is to be verified | |
| 3286 * @param dartEntry the entry for the source | |
| 3287 * @param librarySource the source for the library containing the source | |
| 3288 * @param libraryEntry the entry for the library | |
| 3289 * @return task data representing the created task | |
| 3290 */ | 3074 */ |
| 3291 AnalysisContextImpl_TaskData _createGenerateDartHintsTask(Source source, | 3075 AnalysisContextImpl_TaskData _createGenerateDartHintsTask(Source source, |
| 3292 DartEntry dartEntry, Source librarySource, DartEntry libraryEntry) { | 3076 DartEntry dartEntry, Source librarySource, DartEntry libraryEntry) { |
| 3293 if (libraryEntry.getState(DartEntry.ELEMENT) != CacheState.VALID) { | 3077 if (libraryEntry.getState(DartEntry.ELEMENT) != CacheState.VALID) { |
| 3294 return _createResolveDartLibraryTask(librarySource, libraryEntry); | 3078 return _createResolveDartLibraryTask(librarySource, libraryEntry); |
| 3295 } | 3079 } |
| 3296 LibraryElement libraryElement = libraryEntry.getValue(DartEntry.ELEMENT); | 3080 LibraryElement libraryElement = libraryEntry.getValue(DartEntry.ELEMENT); |
| 3297 CompilationUnitElement definingUnit = | 3081 CompilationUnitElement definingUnit = |
| 3298 libraryElement.definingCompilationUnit; | 3082 libraryElement.definingCompilationUnit; |
| 3299 List<CompilationUnitElement> parts = libraryElement.parts; | 3083 List<CompilationUnitElement> parts = libraryElement.parts; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 3311 // TODO(brianwilkerson) We should return a ResolveDartUnitTask | 3095 // TODO(brianwilkerson) We should return a ResolveDartUnitTask |
| 3312 // (unless there are multiple ASTs that need to be resolved). | 3096 // (unless there are multiple ASTs that need to be resolved). |
| 3313 return _createResolveDartLibraryTask(librarySource, libraryEntry); | 3097 return _createResolveDartLibraryTask(librarySource, libraryEntry); |
| 3314 } | 3098 } |
| 3315 } | 3099 } |
| 3316 return new AnalysisContextImpl_TaskData( | 3100 return new AnalysisContextImpl_TaskData( |
| 3317 new GenerateDartHintsTask(this, units, libraryElement), false); | 3101 new GenerateDartHintsTask(this, units, libraryElement), false); |
| 3318 } | 3102 } |
| 3319 | 3103 |
| 3320 /** | 3104 /** |
| 3321 * Create a [GenerateDartLintsTask] for the given source, marking the lints as | 3105 * Create a [GenerateDartLintsTask] for the given [source], marking the lints |
| 3322 * being in-process. | 3106 * as being in-process. |
| 3323 * | |
| 3324 * @param source the source whose content is to be verified | |
| 3325 * @param dartEntry the entry for the source | |
| 3326 * @param librarySource the source for the library containing the source | |
| 3327 * @param libraryEntry the entry for the library | |
| 3328 * @return task data representing the created task | |
| 3329 */ | 3107 */ |
| 3330 AnalysisContextImpl_TaskData _createGenerateDartLintsTask(Source source, | 3108 AnalysisContextImpl_TaskData _createGenerateDartLintsTask(Source source, |
| 3331 DartEntry dartEntry, Source librarySource, DartEntry libraryEntry) { | 3109 DartEntry dartEntry, Source librarySource, DartEntry libraryEntry) { |
| 3332 if (libraryEntry.getState(DartEntry.ELEMENT) != CacheState.VALID) { | 3110 if (libraryEntry.getState(DartEntry.ELEMENT) != CacheState.VALID) { |
| 3333 return _createResolveDartLibraryTask(librarySource, libraryEntry); | 3111 return _createResolveDartLibraryTask(librarySource, libraryEntry); |
| 3334 } | 3112 } |
| 3335 LibraryElement libraryElement = libraryEntry.getValue(DartEntry.ELEMENT); | 3113 LibraryElement libraryElement = libraryEntry.getValue(DartEntry.ELEMENT); |
| 3336 CompilationUnitElement definingUnit = | 3114 CompilationUnitElement definingUnit = |
| 3337 libraryElement.definingCompilationUnit; | 3115 libraryElement.definingCompilationUnit; |
| 3338 List<CompilationUnitElement> parts = libraryElement.parts; | 3116 List<CompilationUnitElement> parts = libraryElement.parts; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 3351 // (unless there are multiple ASTs that need to be resolved). | 3129 // (unless there are multiple ASTs that need to be resolved). |
| 3352 return _createResolveDartLibraryTask(librarySource, libraryEntry); | 3130 return _createResolveDartLibraryTask(librarySource, libraryEntry); |
| 3353 } | 3131 } |
| 3354 } | 3132 } |
| 3355 //TODO(pquitslund): revisit if we need all units or whether one will do | 3133 //TODO(pquitslund): revisit if we need all units or whether one will do |
| 3356 return new AnalysisContextImpl_TaskData( | 3134 return new AnalysisContextImpl_TaskData( |
| 3357 new GenerateDartLintsTask(this, units, libraryElement), false); | 3135 new GenerateDartLintsTask(this, units, libraryElement), false); |
| 3358 } | 3136 } |
| 3359 | 3137 |
| 3360 /** | 3138 /** |
| 3361 * Create a [GetContentTask] for the given source, marking the content as bein
g in-process. | 3139 * Create a [GetContentTask] for the given [source], marking the content as |
| 3362 * | 3140 * being in-process. |
| 3363 * @param source the source whose content is to be accessed | |
| 3364 * @param sourceEntry the entry for the source | |
| 3365 * @return task data representing the created task | |
| 3366 */ | 3141 */ |
| 3367 AnalysisContextImpl_TaskData _createGetContentTask( | 3142 AnalysisContextImpl_TaskData _createGetContentTask( |
| 3368 Source source, SourceEntry sourceEntry) { | 3143 Source source, SourceEntry sourceEntry) { |
| 3369 return new AnalysisContextImpl_TaskData( | 3144 return new AnalysisContextImpl_TaskData( |
| 3370 new GetContentTask(this, source), false); | 3145 new GetContentTask(this, source), false); |
| 3371 } | 3146 } |
| 3372 | 3147 |
| 3373 /** | 3148 /** |
| 3374 * Create a [ParseDartTask] for the given [source]. | 3149 * Create a [ParseDartTask] for the given [source]. |
| 3375 */ | 3150 */ |
| (...skipping 17 matching lines...) Expand all Loading... |
| 3393 if (htmlEntry.getState(SourceEntry.CONTENT) != CacheState.VALID) { | 3168 if (htmlEntry.getState(SourceEntry.CONTENT) != CacheState.VALID) { |
| 3394 return _createGetContentTask(source, htmlEntry); | 3169 return _createGetContentTask(source, htmlEntry); |
| 3395 } | 3170 } |
| 3396 String content = htmlEntry.getValue(SourceEntry.CONTENT); | 3171 String content = htmlEntry.getValue(SourceEntry.CONTENT); |
| 3397 htmlEntry.setState(SourceEntry.CONTENT, CacheState.FLUSHED); | 3172 htmlEntry.setState(SourceEntry.CONTENT, CacheState.FLUSHED); |
| 3398 return new AnalysisContextImpl_TaskData( | 3173 return new AnalysisContextImpl_TaskData( |
| 3399 new ParseHtmlTask(this, source, content), false); | 3174 new ParseHtmlTask(this, source, content), false); |
| 3400 } | 3175 } |
| 3401 | 3176 |
| 3402 /** | 3177 /** |
| 3403 * Create a [ResolveDartLibraryTask] for the given source, marking ? as being
in-process. | 3178 * Create a [ResolveDartLibraryTask] for the given [source], marking ? as |
| 3404 * | 3179 * being in-process. |
| 3405 * @param source the source whose content is to be resolved | |
| 3406 * @param dartEntry the entry for the source | |
| 3407 * @return task data representing the created task | |
| 3408 */ | 3180 */ |
| 3409 AnalysisContextImpl_TaskData _createResolveDartLibraryTask( | 3181 AnalysisContextImpl_TaskData _createResolveDartLibraryTask( |
| 3410 Source source, DartEntry dartEntry) { | 3182 Source source, DartEntry dartEntry) { |
| 3411 try { | 3183 try { |
| 3412 AnalysisContextImpl_CycleBuilder builder = | 3184 AnalysisContextImpl_CycleBuilder builder = |
| 3413 new AnalysisContextImpl_CycleBuilder(this); | 3185 new AnalysisContextImpl_CycleBuilder(this); |
| 3414 PerformanceStatistics.cycles.makeCurrentWhile(() { | 3186 PerformanceStatistics.cycles.makeCurrentWhile(() { |
| 3415 builder.computeCycleContaining(source); | 3187 builder.computeCycleContaining(source); |
| 3416 }); | 3188 }); |
| 3417 AnalysisContextImpl_TaskData taskData = builder.taskData; | 3189 AnalysisContextImpl_TaskData taskData = builder.taskData; |
| 3418 if (taskData != null) { | 3190 if (taskData != null) { |
| 3419 return taskData; | 3191 return taskData; |
| 3420 } | 3192 } |
| 3421 return new AnalysisContextImpl_TaskData(new ResolveDartLibraryCycleTask( | 3193 return new AnalysisContextImpl_TaskData(new ResolveDartLibraryCycleTask( |
| 3422 this, source, source, builder.librariesInCycle), false); | 3194 this, source, source, builder.librariesInCycle), false); |
| 3423 } on AnalysisException catch (exception, stackTrace) { | 3195 } on AnalysisException catch (exception, stackTrace) { |
| 3424 dartEntry | 3196 dartEntry |
| 3425 .recordResolutionError(new CaughtException(exception, stackTrace)); | 3197 .recordResolutionError(new CaughtException(exception, stackTrace)); |
| 3426 AnalysisEngine.instance.logger.logError( | 3198 AnalysisEngine.instance.logger.logError( |
| 3427 "Internal error trying to create a ResolveDartLibraryTask", | 3199 "Internal error trying to create a ResolveDartLibraryTask", |
| 3428 new CaughtException(exception, stackTrace)); | 3200 new CaughtException(exception, stackTrace)); |
| 3429 } | 3201 } |
| 3430 return new AnalysisContextImpl_TaskData(null, false); | 3202 return new AnalysisContextImpl_TaskData(null, false); |
| 3431 } | 3203 } |
| 3432 | 3204 |
| 3433 /** | 3205 /** |
| 3434 * Create a [ResolveHtmlTask] for the given source, marking the resolved unit
as being | 3206 * Create a [ResolveHtmlTask] for the given [source], marking the resolved |
| 3435 * in-process. | 3207 * unit as being in-process. |
| 3436 * | |
| 3437 * @param source the source whose content is to be resolved | |
| 3438 * @param htmlEntry the entry for the source | |
| 3439 * @return task data representing the created task | |
| 3440 */ | 3208 */ |
| 3441 AnalysisContextImpl_TaskData _createResolveHtmlTask( | 3209 AnalysisContextImpl_TaskData _createResolveHtmlTask( |
| 3442 Source source, HtmlEntry htmlEntry) { | 3210 Source source, HtmlEntry htmlEntry) { |
| 3443 if (htmlEntry.getState(HtmlEntry.PARSED_UNIT) != CacheState.VALID) { | 3211 if (htmlEntry.getState(HtmlEntry.PARSED_UNIT) != CacheState.VALID) { |
| 3444 return _createParseHtmlTask(source, htmlEntry); | 3212 return _createParseHtmlTask(source, htmlEntry); |
| 3445 } | 3213 } |
| 3446 return new AnalysisContextImpl_TaskData(new ResolveHtmlTask(this, source, | 3214 return new AnalysisContextImpl_TaskData(new ResolveHtmlTask(this, source, |
| 3447 htmlEntry.modificationTime, | 3215 htmlEntry.modificationTime, |
| 3448 htmlEntry.getValue(HtmlEntry.PARSED_UNIT)), false); | 3216 htmlEntry.getValue(HtmlEntry.PARSED_UNIT)), false); |
| 3449 } | 3217 } |
| 3450 | 3218 |
| 3451 /** | 3219 /** |
| 3452 * Create a [ScanDartTask] for the given source, marking the scan errors as be
ing | 3220 * Create a [ScanDartTask] for the given [source], marking the scan errors as |
| 3453 * in-process. | 3221 * being in-process. |
| 3454 * | |
| 3455 * @param source the source whose content is to be scanned | |
| 3456 * @param dartEntry the entry for the source | |
| 3457 * @return task data representing the created task | |
| 3458 */ | 3222 */ |
| 3459 AnalysisContextImpl_TaskData _createScanDartTask( | 3223 AnalysisContextImpl_TaskData _createScanDartTask( |
| 3460 Source source, DartEntry dartEntry) { | 3224 Source source, DartEntry dartEntry) { |
| 3461 if (dartEntry.getState(SourceEntry.CONTENT) != CacheState.VALID) { | 3225 if (dartEntry.getState(SourceEntry.CONTENT) != CacheState.VALID) { |
| 3462 return _createGetContentTask(source, dartEntry); | 3226 return _createGetContentTask(source, dartEntry); |
| 3463 } | 3227 } |
| 3464 String content = dartEntry.getValue(SourceEntry.CONTENT); | 3228 String content = dartEntry.getValue(SourceEntry.CONTENT); |
| 3465 dartEntry.setState(SourceEntry.CONTENT, CacheState.FLUSHED); | 3229 dartEntry.setState(SourceEntry.CONTENT, CacheState.FLUSHED); |
| 3466 return new AnalysisContextImpl_TaskData( | 3230 return new AnalysisContextImpl_TaskData( |
| 3467 new ScanDartTask(this, source, content), false); | 3231 new ScanDartTask(this, source, content), false); |
| 3468 } | 3232 } |
| 3469 | 3233 |
| 3470 /** | 3234 /** |
| 3471 * Create a source information object suitable for the given source. Return th
e source information | 3235 * Create a source entry for the given [source]. Return the source entry that |
| 3472 * object that was created, or `null` if the source should not be tracked by t
his context. | 3236 * was created, or `null` if the source should not be tracked by this context. |
| 3473 * | |
| 3474 * @param source the source for which an information object is being created | |
| 3475 * @param explicitlyAdded `true` if the source was explicitly added to the con
text | |
| 3476 * @return the source information object that was created | |
| 3477 */ | 3237 */ |
| 3478 SourceEntry _createSourceEntry(Source source, bool explicitlyAdded) { | 3238 SourceEntry _createSourceEntry(Source source, bool explicitlyAdded) { |
| 3479 String name = source.shortName; | 3239 String name = source.shortName; |
| 3480 if (AnalysisEngine.isHtmlFileName(name)) { | 3240 if (AnalysisEngine.isHtmlFileName(name)) { |
| 3481 HtmlEntry htmlEntry = new HtmlEntry(); | 3241 HtmlEntry htmlEntry = new HtmlEntry(); |
| 3482 htmlEntry.modificationTime = getModificationStamp(source); | 3242 htmlEntry.modificationTime = getModificationStamp(source); |
| 3483 htmlEntry.explicitlyAdded = explicitlyAdded; | 3243 htmlEntry.explicitlyAdded = explicitlyAdded; |
| 3484 _cache.put(source, htmlEntry); | 3244 _cache.put(source, htmlEntry); |
| 3485 return htmlEntry; | 3245 return htmlEntry; |
| 3486 } else { | 3246 } else { |
| 3487 DartEntry dartEntry = new DartEntry(); | 3247 DartEntry dartEntry = new DartEntry(); |
| 3488 dartEntry.modificationTime = getModificationStamp(source); | 3248 dartEntry.modificationTime = getModificationStamp(source); |
| 3489 dartEntry.explicitlyAdded = explicitlyAdded; | 3249 dartEntry.explicitlyAdded = explicitlyAdded; |
| 3490 _cache.put(source, dartEntry); | 3250 _cache.put(source, dartEntry); |
| 3491 return dartEntry; | 3251 return dartEntry; |
| 3492 } | 3252 } |
| 3493 } | 3253 } |
| 3494 | 3254 |
| 3495 /** | 3255 /** |
| 3496 * Return an array containing all of the change notices that are waiting to be
returned. If there | 3256 * Return a list containing all of the change notices that are waiting to be |
| 3497 * are no notices, then return either `null` or an empty array, depending on t
he value of | 3257 * returned. If there are no notices, then return either `null` or an empty |
| 3498 * the argument. | 3258 * list, depending on the value of [nullIfEmpty]. |
| 3499 * | |
| 3500 * @param nullIfEmpty `true` if `null` should be returned when there are no no
tices | |
| 3501 * @return the change notices that are waiting to be returned | |
| 3502 */ | 3259 */ |
| 3503 List<ChangeNotice> _getChangeNotices(bool nullIfEmpty) { | 3260 List<ChangeNotice> _getChangeNotices(bool nullIfEmpty) { |
| 3504 if (_pendingNotices.isEmpty) { | 3261 if (_pendingNotices.isEmpty) { |
| 3505 if (nullIfEmpty) { | 3262 if (nullIfEmpty) { |
| 3506 return null; | 3263 return null; |
| 3507 } | 3264 } |
| 3508 return ChangeNoticeImpl.EMPTY_ARRAY; | 3265 return ChangeNoticeImpl.EMPTY_ARRAY; |
| 3509 } | 3266 } |
| 3510 List<ChangeNotice> notices = new List.from(_pendingNotices.values); | 3267 List<ChangeNotice> notices = new List.from(_pendingNotices.values); |
| 3511 _pendingNotices.clear(); | 3268 _pendingNotices.clear(); |
| 3512 return notices; | 3269 return notices; |
| 3513 } | 3270 } |
| 3514 | 3271 |
| 3515 /** | 3272 /** |
| 3516 * Given a source for a Dart file and the library that contains it, return the
data represented by | 3273 * Given a source for a Dart file and the library that contains it, return the |
| 3517 * the given descriptor that is associated with that source. This method assum
es that the data can | 3274 * data represented by the given descriptor that is associated with that |
| 3518 * be produced by generating hints for the library if it is not already cached
. | 3275 * source. This method assumes that the data can be produced by generating |
| 3276 * hints for the library if it is not already cached. |
| 3277 * |
| 3278 * Throws an [AnalysisException] if data could not be returned because the |
| 3279 * source could not be resolved. |
| 3519 * | 3280 * |
| 3520 * <b>Note:</b> This method cannot be used in an async environment. | 3281 * <b>Note:</b> This method cannot be used in an async environment. |
| 3521 * | |
| 3522 * @param unitSource the source representing the Dart file | |
| 3523 * @param librarySource the source representing the library containing the Dar
t file | |
| 3524 * @param dartEntry the entry representing the Dart file | |
| 3525 * @param descriptor the descriptor representing the data to be returned | |
| 3526 * @return the requested data about the given source | |
| 3527 * @throws AnalysisException if data could not be returned because the source
could not be | |
| 3528 * resolved | |
| 3529 */ | 3282 */ |
| 3530 Object _getDartHintData(Source unitSource, Source librarySource, | 3283 Object _getDartHintData(Source unitSource, Source librarySource, |
| 3531 DartEntry dartEntry, DataDescriptor descriptor) { | 3284 DartEntry dartEntry, DataDescriptor descriptor) { |
| 3532 dartEntry = | 3285 dartEntry = |
| 3533 _cacheDartHintData(unitSource, librarySource, dartEntry, descriptor); | 3286 _cacheDartHintData(unitSource, librarySource, dartEntry, descriptor); |
| 3534 if (identical(descriptor, DartEntry.ELEMENT)) { | 3287 if (identical(descriptor, DartEntry.ELEMENT)) { |
| 3535 return dartEntry.getValue(descriptor); | 3288 return dartEntry.getValue(descriptor); |
| 3536 } | 3289 } |
| 3537 return dartEntry.getValueInLibrary(descriptor, librarySource); | 3290 return dartEntry.getValueInLibrary(descriptor, librarySource); |
| 3538 } | 3291 } |
| 3539 | 3292 |
| 3540 /** | 3293 /** |
| 3541 * Given a source for a Dart file and the library that contains it, return the
data represented by | 3294 * Given a source for a Dart file and the library that contains it, return the |
| 3542 * the given descriptor that is associated with that source. This method assum
es that the data can | 3295 * data represented by the given descriptor that is associated with that |
| 3543 * be produced by generating lints for the library if it is not already cached
. | 3296 * source. This method assumes that the data can be produced by generating |
| 3297 * lints for the library if it is not already cached. |
| 3298 * |
| 3299 * Throws an [AnalysisException] if data could not be returned because the |
| 3300 * source could not be resolved. |
| 3544 * | 3301 * |
| 3545 * <b>Note:</b> This method cannot be used in an async environment. | 3302 * <b>Note:</b> This method cannot be used in an async environment. |
| 3546 * | |
| 3547 * @param unitSource the source representing the Dart file | |
| 3548 * @param librarySource the source representing the library containing the Dar
t file | |
| 3549 * @param dartEntry the entry representing the Dart file | |
| 3550 * @param descriptor the descriptor representing the data to be returned | |
| 3551 * @return the requested data about the given source | |
| 3552 * @throws AnalysisException if data could not be returned because the source
could not be | |
| 3553 * resolved | |
| 3554 */ | 3303 */ |
| 3555 Object _getDartLintData(Source unitSource, Source librarySource, | 3304 Object _getDartLintData(Source unitSource, Source librarySource, |
| 3556 DartEntry dartEntry, DataDescriptor descriptor) { | 3305 DartEntry dartEntry, DataDescriptor descriptor) { |
| 3557 dartEntry = | 3306 dartEntry = |
| 3558 _cacheDartLintData(unitSource, librarySource, dartEntry, descriptor); | 3307 _cacheDartLintData(unitSource, librarySource, dartEntry, descriptor); |
| 3559 if (identical(descriptor, DartEntry.ELEMENT)) { | 3308 if (identical(descriptor, DartEntry.ELEMENT)) { |
| 3560 return dartEntry.getValue(descriptor); | 3309 return dartEntry.getValue(descriptor); |
| 3561 } | 3310 } |
| 3562 return dartEntry.getValueInLibrary(descriptor, librarySource); | 3311 return dartEntry.getValueInLibrary(descriptor, librarySource); |
| 3563 } | 3312 } |
| 3564 | 3313 |
| 3565 /** | 3314 /** |
| 3566 * Given a source for a Dart file, return the data represented by the given de
scriptor that is | 3315 * Given a source for a Dart file, return the data represented by the given |
| 3567 * associated with that source. This method assumes that the data can be produ
ced by parsing the | 3316 * descriptor that is associated with that source. This method assumes that |
| 3568 * source if it is not already cached. | 3317 * the data can be produced by parsing the source if it is not already cached. |
| 3318 * |
| 3319 * Throws an [AnalysisException] if data could not be returned because the |
| 3320 * source could not be parsed. |
| 3569 * | 3321 * |
| 3570 * <b>Note:</b> This method cannot be used in an async environment. | 3322 * <b>Note:</b> This method cannot be used in an async environment. |
| 3571 * | |
| 3572 * @param source the source representing the Dart file | |
| 3573 * @param dartEntry the cache entry associated with the Dart file | |
| 3574 * @param descriptor the descriptor representing the data to be returned | |
| 3575 * @return the requested data about the given source | |
| 3576 * @throws AnalysisException if data could not be returned because the source
could not be parsed | |
| 3577 */ | 3323 */ |
| 3578 Object _getDartParseData( | 3324 Object _getDartParseData( |
| 3579 Source source, DartEntry dartEntry, DataDescriptor descriptor) { | 3325 Source source, DartEntry dartEntry, DataDescriptor descriptor) { |
| 3580 dartEntry = _cacheDartParseData(source, dartEntry, descriptor); | 3326 dartEntry = _cacheDartParseData(source, dartEntry, descriptor); |
| 3581 if (identical(descriptor, DartEntry.PARSED_UNIT)) { | 3327 if (identical(descriptor, DartEntry.PARSED_UNIT)) { |
| 3582 _accessedAst(source); | 3328 _accessedAst(source); |
| 3583 return dartEntry.anyParsedCompilationUnit; | 3329 return dartEntry.anyParsedCompilationUnit; |
| 3584 } | 3330 } |
| 3585 return dartEntry.getValue(descriptor); | 3331 return dartEntry.getValue(descriptor); |
| 3586 } | 3332 } |
| 3587 | 3333 |
| 3588 /** | 3334 /** |
| 3589 * Given a source for a Dart file, return the data represented by the given de
scriptor that is | 3335 * Given a source for a Dart file, return the data represented by the given |
| 3590 * associated with that source, or the given default value if the source is no
t a Dart file. This | 3336 * descriptor that is associated with that source, or the given default value |
| 3591 * method assumes that the data can be produced by parsing the source if it is
not already cached. | 3337 * if the source is not a Dart file. This method assumes that the data can be |
| 3338 * produced by parsing the source if it is not already cached. |
| 3339 * |
| 3340 * Throws an [AnalysisException] if data could not be returned because the |
| 3341 * source could not be parsed. |
| 3592 * | 3342 * |
| 3593 * <b>Note:</b> This method cannot be used in an async environment. | 3343 * <b>Note:</b> This method cannot be used in an async environment. |
| 3594 * | |
| 3595 * @param source the source representing the Dart file | |
| 3596 * @param descriptor the descriptor representing the data to be returned | |
| 3597 * @param defaultValue the value to be returned if the source is not a Dart fi
le | |
| 3598 * @return the requested data about the given source | |
| 3599 * @throws AnalysisException if data could not be returned because the source
could not be parsed | |
| 3600 */ | 3344 */ |
| 3601 Object _getDartParseData2( | 3345 Object _getDartParseData2( |
| 3602 Source source, DataDescriptor descriptor, Object defaultValue) { | 3346 Source source, DataDescriptor descriptor, Object defaultValue) { |
| 3603 DartEntry dartEntry = _getReadableDartEntry(source); | 3347 DartEntry dartEntry = _getReadableDartEntry(source); |
| 3604 if (dartEntry == null) { | 3348 if (dartEntry == null) { |
| 3605 return defaultValue; | 3349 return defaultValue; |
| 3606 } | 3350 } |
| 3607 try { | 3351 try { |
| 3608 return _getDartParseData(source, dartEntry, descriptor); | 3352 return _getDartParseData(source, dartEntry, descriptor); |
| 3609 } on ObsoleteSourceAnalysisException catch (exception, stackTrace) { | 3353 } on ObsoleteSourceAnalysisException catch (exception, stackTrace) { |
| 3610 AnalysisEngine.instance.logger.logInformation( | 3354 AnalysisEngine.instance.logger.logInformation( |
| 3611 "Could not compute $descriptor", | 3355 "Could not compute $descriptor", |
| 3612 new CaughtException(exception, stackTrace)); | 3356 new CaughtException(exception, stackTrace)); |
| 3613 return defaultValue; | 3357 return defaultValue; |
| 3614 } | 3358 } |
| 3615 } | 3359 } |
| 3616 | 3360 |
| 3617 /** | 3361 /** |
| 3618 * Given a source for a Dart file and the library that contains it, return the
data represented by | 3362 * Given a source for a Dart file and the library that contains it, return the |
| 3619 * the given descriptor that is associated with that source. This method assum
es that the data can | 3363 * data represented by the given descriptor that is associated with that |
| 3620 * be produced by resolving the source in the context of the library if it is
not already cached. | 3364 * source. This method assumes that the data can be produced by resolving the |
| 3365 * source in the context of the library if it is not already cached. |
| 3366 * |
| 3367 * Throws an [AnalysisException] if data could not be returned because the |
| 3368 * source could not be resolved. |
| 3621 * | 3369 * |
| 3622 * <b>Note:</b> This method cannot be used in an async environment. | 3370 * <b>Note:</b> This method cannot be used in an async environment. |
| 3623 * | |
| 3624 * @param unitSource the source representing the Dart file | |
| 3625 * @param librarySource the source representing the library containing the Dar
t file | |
| 3626 * @param dartEntry the entry representing the Dart file | |
| 3627 * @param descriptor the descriptor representing the data to be returned | |
| 3628 * @return the requested data about the given source | |
| 3629 * @throws AnalysisException if data could not be returned because the source
could not be | |
| 3630 * resolved | |
| 3631 */ | 3371 */ |
| 3632 Object _getDartResolutionData(Source unitSource, Source librarySource, | 3372 Object _getDartResolutionData(Source unitSource, Source librarySource, |
| 3633 DartEntry dartEntry, DataDescriptor descriptor) { | 3373 DartEntry dartEntry, DataDescriptor descriptor) { |
| 3634 dartEntry = _cacheDartResolutionData( | 3374 dartEntry = _cacheDartResolutionData( |
| 3635 unitSource, librarySource, dartEntry, descriptor); | 3375 unitSource, librarySource, dartEntry, descriptor); |
| 3636 if (identical(descriptor, DartEntry.ELEMENT)) { | 3376 if (identical(descriptor, DartEntry.ELEMENT)) { |
| 3637 return dartEntry.getValue(descriptor); | 3377 return dartEntry.getValue(descriptor); |
| 3638 } else if (identical(descriptor, DartEntry.RESOLVED_UNIT)) { | 3378 } else if (identical(descriptor, DartEntry.RESOLVED_UNIT)) { |
| 3639 _accessedAst(unitSource); | 3379 _accessedAst(unitSource); |
| 3640 } | 3380 } |
| 3641 return dartEntry.getValueInLibrary(descriptor, librarySource); | 3381 return dartEntry.getValueInLibrary(descriptor, librarySource); |
| 3642 } | 3382 } |
| 3643 | 3383 |
| 3644 /** | 3384 /** |
| 3645 * Given a source for a Dart file and the library that contains it, return the
data represented by | 3385 * Given a source for a Dart file and the library that contains it, return the |
| 3646 * the given descriptor that is associated with that source, or the given defa
ult value if the | 3386 * data represented by the given descriptor that is associated with that |
| 3647 * source is not a Dart file. This method assumes that the data can be produce
d by resolving the | 3387 * source, or the given default value if the source is not a Dart file. This |
| 3648 * source in the context of the library if it is not already cached. | 3388 * method assumes that the data can be produced by resolving the source in the |
| 3389 * context of the library if it is not already cached. |
| 3390 * |
| 3391 * Throws an [AnalysisException] if data could not be returned because the |
| 3392 * source could not be resolved. |
| 3649 * | 3393 * |
| 3650 * <b>Note:</b> This method cannot be used in an async environment. | 3394 * <b>Note:</b> This method cannot be used in an async environment. |
| 3651 * | |
| 3652 * @param unitSource the source representing the Dart file | |
| 3653 * @param librarySource the source representing the library containing the Dar
t file | |
| 3654 * @param descriptor the descriptor representing the data to be returned | |
| 3655 * @param defaultValue the value to be returned if the source is not a Dart fi
le | |
| 3656 * @return the requested data about the given source | |
| 3657 * @throws AnalysisException if data could not be returned because the source
could not be | |
| 3658 * resolved | |
| 3659 */ | 3395 */ |
| 3660 Object _getDartResolutionData2(Source unitSource, Source librarySource, | 3396 Object _getDartResolutionData2(Source unitSource, Source librarySource, |
| 3661 DataDescriptor descriptor, Object defaultValue) { | 3397 DataDescriptor descriptor, Object defaultValue) { |
| 3662 DartEntry dartEntry = _getReadableDartEntry(unitSource); | 3398 DartEntry dartEntry = _getReadableDartEntry(unitSource); |
| 3663 if (dartEntry == null) { | 3399 if (dartEntry == null) { |
| 3664 return defaultValue; | 3400 return defaultValue; |
| 3665 } | 3401 } |
| 3666 try { | 3402 try { |
| 3667 return _getDartResolutionData( | 3403 return _getDartResolutionData( |
| 3668 unitSource, librarySource, dartEntry, descriptor); | 3404 unitSource, librarySource, dartEntry, descriptor); |
| 3669 } on ObsoleteSourceAnalysisException catch (exception, stackTrace) { | 3405 } on ObsoleteSourceAnalysisException catch (exception, stackTrace) { |
| 3670 AnalysisEngine.instance.logger.logInformation( | 3406 AnalysisEngine.instance.logger.logInformation( |
| 3671 "Could not compute $descriptor", | 3407 "Could not compute $descriptor", |
| 3672 new CaughtException(exception, stackTrace)); | 3408 new CaughtException(exception, stackTrace)); |
| 3673 return defaultValue; | 3409 return defaultValue; |
| 3674 } | 3410 } |
| 3675 } | 3411 } |
| 3676 | 3412 |
| 3677 /** | 3413 /** |
| 3678 * Given a source for a Dart file, return the data represented by the given de
scriptor that is | 3414 * Given a source for a Dart file, return the data represented by the given |
| 3679 * associated with that source. This method assumes that the data can be produ
ced by scanning the | 3415 * descriptor that is associated with that source. This method assumes that |
| 3680 * source if it is not already cached. | 3416 * the data can be produced by scanning the source if it is not already |
| 3417 * cached. |
| 3418 * |
| 3419 * Throws an [AnalysisException] if data could not be returned because the |
| 3420 * source could not be scanned. |
| 3681 * | 3421 * |
| 3682 * <b>Note:</b> This method cannot be used in an async environment. | 3422 * <b>Note:</b> This method cannot be used in an async environment. |
| 3683 * | |
| 3684 * @param source the source representing the Dart file | |
| 3685 * @param dartEntry the cache entry associated with the Dart file | |
| 3686 * @param descriptor the descriptor representing the data to be returned | |
| 3687 * @return the requested data about the given source | |
| 3688 * @throws AnalysisException if data could not be returned because the source
could not be scanned | |
| 3689 */ | 3423 */ |
| 3690 Object _getDartScanData( | 3424 Object _getDartScanData( |
| 3691 Source source, DartEntry dartEntry, DataDescriptor descriptor) { | 3425 Source source, DartEntry dartEntry, DataDescriptor descriptor) { |
| 3692 dartEntry = _cacheDartScanData(source, dartEntry, descriptor); | 3426 dartEntry = _cacheDartScanData(source, dartEntry, descriptor); |
| 3693 return dartEntry.getValue(descriptor); | 3427 return dartEntry.getValue(descriptor); |
| 3694 } | 3428 } |
| 3695 | 3429 |
| 3696 /** | 3430 /** |
| 3697 * Given a source for a Dart file, return the data represented by the given de
scriptor that is | 3431 * Given a source for a Dart file, return the data represented by the given |
| 3698 * associated with that source, or the given default value if the source is no
t a Dart file. This | 3432 * descriptor that is associated with that source, or the given default value |
| 3699 * method assumes that the data can be produced by scanning the source if it i
s not already | 3433 * if the source is not a Dart file. This method assumes that the data can be |
| 3700 * cached. | 3434 * produced by scanning the source if it is not already cached. |
| 3435 * |
| 3436 * Throws an [AnalysisException] if data could not be returned because the |
| 3437 * source could not be scanned. |
| 3701 * | 3438 * |
| 3702 * <b>Note:</b> This method cannot be used in an async environment. | 3439 * <b>Note:</b> This method cannot be used in an async environment. |
| 3703 * | |
| 3704 * @param source the source representing the Dart file | |
| 3705 * @param descriptor the descriptor representing the data to be returned | |
| 3706 * @param defaultValue the value to be returned if the source is not a Dart fi
le | |
| 3707 * @return the requested data about the given source | |
| 3708 * @throws AnalysisException if data could not be returned because the source
could not be scanned | |
| 3709 */ | 3440 */ |
| 3710 Object _getDartScanData2( | 3441 Object _getDartScanData2( |
| 3711 Source source, DataDescriptor descriptor, Object defaultValue) { | 3442 Source source, DataDescriptor descriptor, Object defaultValue) { |
| 3712 DartEntry dartEntry = _getReadableDartEntry(source); | 3443 DartEntry dartEntry = _getReadableDartEntry(source); |
| 3713 if (dartEntry == null) { | 3444 if (dartEntry == null) { |
| 3714 return defaultValue; | 3445 return defaultValue; |
| 3715 } | 3446 } |
| 3716 try { | 3447 try { |
| 3717 return _getDartScanData(source, dartEntry, descriptor); | 3448 return _getDartScanData(source, dartEntry, descriptor); |
| 3718 } on ObsoleteSourceAnalysisException catch (exception, stackTrace) { | 3449 } on ObsoleteSourceAnalysisException catch (exception, stackTrace) { |
| 3719 AnalysisEngine.instance.logger.logInformation( | 3450 AnalysisEngine.instance.logger.logInformation( |
| 3720 "Could not compute $descriptor", | 3451 "Could not compute $descriptor", |
| 3721 new CaughtException(exception, stackTrace)); | 3452 new CaughtException(exception, stackTrace)); |
| 3722 return defaultValue; | 3453 return defaultValue; |
| 3723 } | 3454 } |
| 3724 } | 3455 } |
| 3725 | 3456 |
| 3726 /** | 3457 /** |
| 3727 * Given a source for a Dart file and the library that contains it, return the
data represented by | 3458 * Given a source for a Dart file and the library that contains it, return the |
| 3728 * the given descriptor that is associated with that source. This method assum
es that the data can | 3459 * data represented by the given descriptor that is associated with that |
| 3729 * be produced by verifying the source within the given library if it is not a
lready cached. | 3460 * source. This method assumes that the data can be produced by verifying the |
| 3461 * source within the given library if it is not already cached. |
| 3462 * |
| 3463 * Throws an [AnalysisException] if data could not be returned because the |
| 3464 * source could not be resolved. |
| 3730 * | 3465 * |
| 3731 * <b>Note:</b> This method cannot be used in an async environment. | 3466 * <b>Note:</b> This method cannot be used in an async environment. |
| 3732 * | |
| 3733 * @param unitSource the source representing the Dart file | |
| 3734 * @param librarySource the source representing the library containing the Dar
t file | |
| 3735 * @param dartEntry the entry representing the Dart file | |
| 3736 * @param descriptor the descriptor representing the data to be returned | |
| 3737 * @return the requested data about the given source | |
| 3738 * @throws AnalysisException if data could not be returned because the source
could not be | |
| 3739 * resolved | |
| 3740 */ | 3467 */ |
| 3741 Object _getDartVerificationData(Source unitSource, Source librarySource, | 3468 Object _getDartVerificationData(Source unitSource, Source librarySource, |
| 3742 DartEntry dartEntry, DataDescriptor descriptor) { | 3469 DartEntry dartEntry, DataDescriptor descriptor) { |
| 3743 dartEntry = _cacheDartVerificationData( | 3470 dartEntry = _cacheDartVerificationData( |
| 3744 unitSource, librarySource, dartEntry, descriptor); | 3471 unitSource, librarySource, dartEntry, descriptor); |
| 3745 return dartEntry.getValueInLibrary(descriptor, librarySource); | 3472 return dartEntry.getValueInLibrary(descriptor, librarySource); |
| 3746 } | 3473 } |
| 3747 | 3474 |
| 3748 /** | 3475 /** |
| 3749 * Given a source for an HTML file, return the data represented by the given d
escriptor that is | 3476 * Given a source for an HTML file, return the data represented by the given |
| 3750 * associated with that source, or the given default value if the source is no
t an HTML file. This | 3477 * descriptor that is associated with that source, or the given default value |
| 3751 * method assumes that the data can be produced by parsing the source if it is
not already cached. | 3478 * if the source is not an HTML file. This method assumes that the data can be |
| 3479 * produced by parsing the source if it is not already cached. |
| 3480 * |
| 3481 * Throws an [AnalysisException] if data could not be returned because the |
| 3482 * source could not be parsed. |
| 3752 * | 3483 * |
| 3753 * <b>Note:</b> This method cannot be used in an async environment. | 3484 * <b>Note:</b> This method cannot be used in an async environment. |
| 3754 * | |
| 3755 * @param source the source representing the Dart file | |
| 3756 * @param descriptor the descriptor representing the data to be returned | |
| 3757 * @param defaultValue the value to be returned if the source is not an HTML f
ile | |
| 3758 * @return the requested data about the given source | |
| 3759 * @throws AnalysisException if data could not be returned because the source
could not be parsed | |
| 3760 */ | 3485 */ |
| 3761 Object _getHtmlParseData( | 3486 Object _getHtmlParseData( |
| 3762 Source source, DataDescriptor descriptor, Object defaultValue) { | 3487 Source source, DataDescriptor descriptor, Object defaultValue) { |
| 3763 HtmlEntry htmlEntry = _getReadableHtmlEntry(source); | 3488 HtmlEntry htmlEntry = _getReadableHtmlEntry(source); |
| 3764 if (htmlEntry == null) { | 3489 if (htmlEntry == null) { |
| 3765 return defaultValue; | 3490 return defaultValue; |
| 3766 } | 3491 } |
| 3767 htmlEntry = _cacheHtmlParseData(source, htmlEntry, descriptor); | 3492 htmlEntry = _cacheHtmlParseData(source, htmlEntry, descriptor); |
| 3768 if (identical(descriptor, HtmlEntry.PARSED_UNIT)) { | 3493 if (identical(descriptor, HtmlEntry.PARSED_UNIT)) { |
| 3769 _accessedAst(source); | 3494 _accessedAst(source); |
| 3770 return htmlEntry.anyParsedUnit; | 3495 return htmlEntry.anyParsedUnit; |
| 3771 } | 3496 } |
| 3772 return htmlEntry.getValue(descriptor); | 3497 return htmlEntry.getValue(descriptor); |
| 3773 } | 3498 } |
| 3774 | 3499 |
| 3775 /** | 3500 /** |
| 3776 * Given a source for an HTML file, return the data represented by the given d
escriptor that is | 3501 * Given a source for an HTML file, return the data represented by the given |
| 3777 * associated with that source, or the given default value if the source is no
t an HTML file. This | 3502 * descriptor that is associated with that source, or the given default value |
| 3778 * method assumes that the data can be produced by resolving the source if it
is not already | 3503 * if the source is not an HTML file. This method assumes that the data can be |
| 3779 * cached. | 3504 * produced by resolving the source if it is not already cached. |
| 3505 * |
| 3506 * Throws an [AnalysisException] if data could not be returned because the |
| 3507 * source could not be resolved. |
| 3780 * | 3508 * |
| 3781 * <b>Note:</b> This method cannot be used in an async environment. | 3509 * <b>Note:</b> This method cannot be used in an async environment. |
| 3782 * | |
| 3783 * @param source the source representing the HTML file | |
| 3784 * @param descriptor the descriptor representing the data to be returned | |
| 3785 * @param defaultValue the value to be returned if the source is not an HTML f
ile | |
| 3786 * @return the requested data about the given source | |
| 3787 * @throws AnalysisException if data could not be returned because the source
could not be | |
| 3788 * resolved | |
| 3789 */ | 3510 */ |
| 3790 Object _getHtmlResolutionData( | 3511 Object _getHtmlResolutionData( |
| 3791 Source source, DataDescriptor descriptor, Object defaultValue) { | 3512 Source source, DataDescriptor descriptor, Object defaultValue) { |
| 3792 HtmlEntry htmlEntry = _getReadableHtmlEntry(source); | 3513 HtmlEntry htmlEntry = _getReadableHtmlEntry(source); |
| 3793 if (htmlEntry == null) { | 3514 if (htmlEntry == null) { |
| 3794 return defaultValue; | 3515 return defaultValue; |
| 3795 } | 3516 } |
| 3796 try { | 3517 try { |
| 3797 return _getHtmlResolutionData2(source, htmlEntry, descriptor); | 3518 return _getHtmlResolutionData2(source, htmlEntry, descriptor); |
| 3798 } on ObsoleteSourceAnalysisException catch (exception, stackTrace) { | 3519 } on ObsoleteSourceAnalysisException catch (exception, stackTrace) { |
| 3799 AnalysisEngine.instance.logger.logInformation( | 3520 AnalysisEngine.instance.logger.logInformation( |
| 3800 "Could not compute $descriptor", | 3521 "Could not compute $descriptor", |
| 3801 new CaughtException(exception, stackTrace)); | 3522 new CaughtException(exception, stackTrace)); |
| 3802 return defaultValue; | 3523 return defaultValue; |
| 3803 } | 3524 } |
| 3804 } | 3525 } |
| 3805 | 3526 |
| 3806 /** | 3527 /** |
| 3807 * Given a source for an HTML file, return the data represented by the given d
escriptor that is | 3528 * Given a source for an HTML file, return the data represented by the given |
| 3808 * associated with that source. This method assumes that the data can be produ
ced by resolving the | 3529 * descriptor that is associated with that source. This method assumes that |
| 3809 * source if it is not already cached. | 3530 * the data can be produced by resolving the source if it is not already |
| 3531 * cached. |
| 3532 * |
| 3533 * Throws an [AnalysisException] if data could not be returned because the |
| 3534 * source could not be resolved. |
| 3810 * | 3535 * |
| 3811 * <b>Note:</b> This method cannot be used in an async environment. | 3536 * <b>Note:</b> This method cannot be used in an async environment. |
| 3812 * | |
| 3813 * @param source the source representing the HTML file | |
| 3814 * @param htmlEntry the entry representing the HTML file | |
| 3815 * @param descriptor the descriptor representing the data to be returned | |
| 3816 * @return the requested data about the given source | |
| 3817 * @throws AnalysisException if data could not be returned because the source
could not be | |
| 3818 * resolved | |
| 3819 */ | 3537 */ |
| 3820 Object _getHtmlResolutionData2( | 3538 Object _getHtmlResolutionData2( |
| 3821 Source source, HtmlEntry htmlEntry, DataDescriptor descriptor) { | 3539 Source source, HtmlEntry htmlEntry, DataDescriptor descriptor) { |
| 3822 htmlEntry = _cacheHtmlResolutionData(source, htmlEntry, descriptor); | 3540 htmlEntry = _cacheHtmlResolutionData(source, htmlEntry, descriptor); |
| 3823 if (identical(descriptor, HtmlEntry.RESOLVED_UNIT)) { | 3541 if (identical(descriptor, HtmlEntry.RESOLVED_UNIT)) { |
| 3824 _accessedAst(source); | 3542 _accessedAst(source); |
| 3825 } | 3543 } |
| 3826 return htmlEntry.getValue(descriptor); | 3544 return htmlEntry.getValue(descriptor); |
| 3827 } | 3545 } |
| 3828 | 3546 |
| 3829 /** | 3547 /** |
| 3830 * Look at the given source to see whether a task needs to be performed relate
d to it. Return the | 3548 * Look at the given [source] to see whether a task needs to be performed |
| 3831 * task that should be performed, or `null` if there is no more work to be don
e for the | 3549 * related to it. Return the task that should be performed, or `null` if there |
| 3832 * source. | 3550 * is no more work to be done for the source. |
| 3833 * | |
| 3834 * <b>Note:</b> This method must only be invoked while we are synchronized on
[cacheLock]. | |
| 3835 * | |
| 3836 * @param source the source to be checked | |
| 3837 * @param sourceEntry the cache entry associated with the source | |
| 3838 * @param isPriority `true` if the source is a priority source | |
| 3839 * @param hintsEnabled `true` if hints are currently enabled | |
| 3840 * @param lintsEnabled `true` if lints are currently enabled | |
| 3841 * @return the next task that needs to be performed for the given source | |
| 3842 */ | 3551 */ |
| 3843 AnalysisContextImpl_TaskData _getNextAnalysisTaskForSource(Source source, | 3552 AnalysisContextImpl_TaskData _getNextAnalysisTaskForSource(Source source, |
| 3844 SourceEntry sourceEntry, bool isPriority, bool hintsEnabled, | 3553 SourceEntry sourceEntry, bool isPriority, bool hintsEnabled, |
| 3845 bool lintsEnabled) { | 3554 bool lintsEnabled) { |
| 3846 // Refuse to generate tasks for html based files that are above 1500 KB | 3555 // Refuse to generate tasks for html based files that are above 1500 KB |
| 3847 if (_isTooBigHtmlSourceEntry(source, sourceEntry)) { | 3556 if (_isTooBigHtmlSourceEntry(source, sourceEntry)) { |
| 3848 // TODO (jwren) we still need to report an error of some kind back to the | 3557 // TODO (jwren) we still need to report an error of some kind back to the |
| 3849 // client. | 3558 // client. |
| 3850 return new AnalysisContextImpl_TaskData(null, false); | 3559 return new AnalysisContextImpl_TaskData(null, false); |
| 3851 } | 3560 } |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3968 htmlEntry.getState(HtmlEntry.RESOLVED_UNIT); | 3677 htmlEntry.getState(HtmlEntry.RESOLVED_UNIT); |
| 3969 if (resolvedUnitState == CacheState.INVALID || | 3678 if (resolvedUnitState == CacheState.INVALID || |
| 3970 (isPriority && resolvedUnitState == CacheState.FLUSHED)) { | 3679 (isPriority && resolvedUnitState == CacheState.FLUSHED)) { |
| 3971 return _createResolveHtmlTask(source, htmlEntry); | 3680 return _createResolveHtmlTask(source, htmlEntry); |
| 3972 } | 3681 } |
| 3973 } | 3682 } |
| 3974 return new AnalysisContextImpl_TaskData(null, false); | 3683 return new AnalysisContextImpl_TaskData(null, false); |
| 3975 } | 3684 } |
| 3976 | 3685 |
| 3977 /** | 3686 /** |
| 3978 * Return a change notice for the given source, creating one if one does not a
lready exist. | 3687 * Return a change notice for the given [source], creating one if one does not |
| 3979 * | 3688 * already exist. |
| 3980 * @param source the source for which changes are being reported | |
| 3981 * @return a change notice for the given source | |
| 3982 */ | 3689 */ |
| 3983 ChangeNoticeImpl _getNotice(Source source) { | 3690 ChangeNoticeImpl _getNotice(Source source) { |
| 3984 ChangeNoticeImpl notice = _pendingNotices[source]; | 3691 ChangeNoticeImpl notice = _pendingNotices[source]; |
| 3985 if (notice == null) { | 3692 if (notice == null) { |
| 3986 notice = new ChangeNoticeImpl(source); | 3693 notice = new ChangeNoticeImpl(source); |
| 3987 _pendingNotices[source] = notice; | 3694 _pendingNotices[source] = notice; |
| 3988 } | 3695 } |
| 3989 return notice; | 3696 return notice; |
| 3990 } | 3697 } |
| 3991 | 3698 |
| 3992 /** | 3699 /** |
| 3993 * Return the cache entry associated with the given source, or `null` if the s
ource is not a | 3700 * Return the cache entry associated with the given [source], or `null` if the |
| 3994 * Dart file. | 3701 * source is not a Dart file. |
| 3995 * | 3702 * |
| 3996 * @param source the source for which a cache entry is being sought | 3703 * @param source the source for which a cache entry is being sought |
| 3997 * @return the source cache entry associated with the given source | 3704 * @return the source cache entry associated with the given source |
| 3998 */ | 3705 */ |
| 3999 DartEntry _getReadableDartEntry(Source source) { | 3706 DartEntry _getReadableDartEntry(Source source) { |
| 4000 SourceEntry sourceEntry = _cache.get(source); | 3707 SourceEntry sourceEntry = _cache.get(source); |
| 4001 if (sourceEntry == null) { | 3708 if (sourceEntry == null) { |
| 4002 sourceEntry = _createSourceEntry(source, false); | 3709 sourceEntry = _createSourceEntry(source, false); |
| 4003 } | 3710 } |
| 4004 if (sourceEntry is DartEntry) { | 3711 if (sourceEntry is DartEntry) { |
| 4005 return sourceEntry; | 3712 return sourceEntry; |
| 4006 } | 3713 } |
| 4007 return null; | 3714 return null; |
| 4008 } | 3715 } |
| 4009 | 3716 |
| 4010 /** | 3717 /** |
| 4011 * Return the cache entry associated with the given source, or `null` if the s
ource is not | 3718 * Return the cache entry associated with the given [source], or `null` if the |
| 4012 * an HTML file. | 3719 * source is not an HTML file. |
| 4013 * | |
| 4014 * @param source the source for which a cache entry is being sought | |
| 4015 * @return the source cache entry associated with the given source | |
| 4016 */ | 3720 */ |
| 4017 HtmlEntry _getReadableHtmlEntry(Source source) { | 3721 HtmlEntry _getReadableHtmlEntry(Source source) { |
| 4018 SourceEntry sourceEntry = _cache.get(source); | 3722 SourceEntry sourceEntry = _cache.get(source); |
| 4019 if (sourceEntry == null) { | 3723 if (sourceEntry == null) { |
| 4020 sourceEntry = _createSourceEntry(source, false); | 3724 sourceEntry = _createSourceEntry(source, false); |
| 4021 } | 3725 } |
| 4022 if (sourceEntry is HtmlEntry) { | 3726 if (sourceEntry is HtmlEntry) { |
| 4023 return sourceEntry; | 3727 return sourceEntry; |
| 4024 } | 3728 } |
| 4025 return null; | 3729 return null; |
| 4026 } | 3730 } |
| 4027 | 3731 |
| 4028 /** | 3732 /** |
| 4029 * Return the cache entry associated with the given source, creating it if nec
essary. | 3733 * Return the cache entry associated with the given [source], creating it if |
| 4030 * | 3734 * necessary. |
| 4031 * @param source the source for which a cache entry is being sought | |
| 4032 * @return the source cache entry associated with the given source | |
| 4033 */ | 3735 */ |
| 4034 SourceEntry _getReadableSourceEntry(Source source) { | 3736 SourceEntry _getReadableSourceEntry(Source source) { |
| 4035 SourceEntry sourceEntry = _cache.get(source); | 3737 SourceEntry sourceEntry = _cache.get(source); |
| 4036 if (sourceEntry == null) { | 3738 if (sourceEntry == null) { |
| 4037 sourceEntry = _createSourceEntry(source, false); | 3739 sourceEntry = _createSourceEntry(source, false); |
| 4038 } | 3740 } |
| 4039 return sourceEntry; | 3741 return sourceEntry; |
| 4040 } | 3742 } |
| 4041 | 3743 |
| 4042 /** | 3744 /** |
| 4043 * Return a resolved compilation unit corresponding to the given element in th
e given library, or | 3745 * Return a resolved compilation unit corresponding to the given [element] in |
| 4044 * `null` if the information is not cached. | 3746 * the library defined by the given [librarySource], or `null` if the |
| 4045 * | 3747 * information is not cached. |
| 4046 * @param element the element representing the compilation unit | |
| 4047 * @param librarySource the source representing the library containing the uni
t | |
| 4048 * @return the specified resolved compilation unit | |
| 4049 */ | 3748 */ |
| 4050 TimestampedData<CompilationUnit> _getResolvedUnit( | 3749 TimestampedData<CompilationUnit> _getResolvedUnit( |
| 4051 CompilationUnitElement element, Source librarySource) { | 3750 CompilationUnitElement element, Source librarySource) { |
| 4052 SourceEntry sourceEntry = _cache.get(element.source); | 3751 SourceEntry sourceEntry = _cache.get(element.source); |
| 4053 if (sourceEntry is DartEntry) { | 3752 if (sourceEntry is DartEntry) { |
| 4054 DartEntry dartEntry = sourceEntry; | 3753 DartEntry dartEntry = sourceEntry; |
| 4055 if (dartEntry.getStateInLibrary(DartEntry.RESOLVED_UNIT, librarySource) == | 3754 if (dartEntry.getStateInLibrary(DartEntry.RESOLVED_UNIT, librarySource) == |
| 4056 CacheState.VALID) { | 3755 CacheState.VALID) { |
| 4057 return new TimestampedData<CompilationUnit>(dartEntry.modificationTime, | 3756 return new TimestampedData<CompilationUnit>(dartEntry.modificationTime, |
| 4058 dartEntry.getValueInLibrary( | 3757 dartEntry.getValueInLibrary( |
| 4059 DartEntry.RESOLVED_UNIT, librarySource)); | 3758 DartEntry.RESOLVED_UNIT, librarySource)); |
| 4060 } | 3759 } |
| 4061 } | 3760 } |
| 4062 return null; | 3761 return null; |
| 4063 } | 3762 } |
| 4064 | 3763 |
| 4065 /** | 3764 /** |
| 4066 * Return an array containing all of the sources known to this context that ha
ve the given kind. | 3765 * Return a list containing all of the sources known to this context that have |
| 4067 * | 3766 * the given [kind]. |
| 4068 * @param kind the kind of sources to be returned | |
| 4069 * @return all of the sources known to this context that have the given kind | |
| 4070 */ | 3767 */ |
| 4071 List<Source> _getSources(SourceKind kind) { | 3768 List<Source> _getSources(SourceKind kind) { |
| 4072 List<Source> sources = new List<Source>(); | 3769 List<Source> sources = new List<Source>(); |
| 4073 MapIterator<Source, SourceEntry> iterator = _cache.iterator(); | 3770 MapIterator<Source, SourceEntry> iterator = _cache.iterator(); |
| 4074 while (iterator.moveNext()) { | 3771 while (iterator.moveNext()) { |
| 4075 if (iterator.value.kind == kind) { | 3772 if (iterator.value.kind == kind) { |
| 4076 sources.add(iterator.key); | 3773 sources.add(iterator.key); |
| 4077 } | 3774 } |
| 4078 } | 3775 } |
| 4079 return sources; | 3776 return sources; |
| 4080 } | 3777 } |
| 4081 | 3778 |
| 4082 /** | 3779 /** |
| 4083 * Look at the given source to see whether a task needs to be performed relate
d to it. If so, add | 3780 * Look at the given [source] to see whether a task needs to be performed |
| 4084 * the source to the set of sources that need to be processed. This method dup
licates, and must | 3781 * related to it. If so, add the source to the set of sources that need to be |
| 4085 * therefore be kept in sync with, | 3782 * processed. This method duplicates, and must therefore be kept in sync with, |
| 4086 * [getNextAnalysisTask]. This method is intended to | 3783 * [_getNextAnalysisTaskForSource]. This method is intended to be used for |
| 4087 * be used for testing purposes only. | 3784 * testing purposes only. |
| 4088 * | |
| 4089 * <b>Note:</b> This method must only be invoked while we are synchronized on
[cacheLock]. | |
| 4090 * | |
| 4091 * @param source the source to be checked | |
| 4092 * @param sourceEntry the cache entry associated with the source | |
| 4093 * @param isPriority `true` if the source is a priority source | |
| 4094 * @param hintsEnabled `true` if hints are currently enabled | |
| 4095 * @param lintsEnabled `true` if lints are currently enabled | |
| 4096 * @param sources the set to which sources should be added | |
| 4097 */ | 3785 */ |
| 4098 void _getSourcesNeedingProcessing(Source source, SourceEntry sourceEntry, | 3786 void _getSourcesNeedingProcessing(Source source, SourceEntry sourceEntry, |
| 4099 bool isPriority, bool hintsEnabled, bool lintsEnabled, | 3787 bool isPriority, bool hintsEnabled, bool lintsEnabled, |
| 4100 HashSet<Source> sources) { | 3788 HashSet<Source> sources) { |
| 4101 if (sourceEntry is DartEntry) { | 3789 if (sourceEntry is DartEntry) { |
| 4102 DartEntry dartEntry = sourceEntry; | 3790 DartEntry dartEntry = sourceEntry; |
| 4103 CacheState scanErrorsState = dartEntry.getState(DartEntry.SCAN_ERRORS); | 3791 CacheState scanErrorsState = dartEntry.getState(DartEntry.SCAN_ERRORS); |
| 4104 if (scanErrorsState == CacheState.INVALID || | 3792 if (scanErrorsState == CacheState.INVALID || |
| 4105 (isPriority && scanErrorsState == CacheState.FLUSHED)) { | 3793 (isPriority && scanErrorsState == CacheState.FLUSHED)) { |
| 4106 sources.add(source); | 3794 sources.add(source); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4191 htmlEntry.getState(HtmlEntry.RESOLVED_UNIT); | 3879 htmlEntry.getState(HtmlEntry.RESOLVED_UNIT); |
| 4192 if (resolvedUnitState == CacheState.INVALID || | 3880 if (resolvedUnitState == CacheState.INVALID || |
| 4193 (isPriority && resolvedUnitState == CacheState.FLUSHED)) { | 3881 (isPriority && resolvedUnitState == CacheState.FLUSHED)) { |
| 4194 sources.add(source); | 3882 sources.add(source); |
| 4195 return; | 3883 return; |
| 4196 } | 3884 } |
| 4197 } | 3885 } |
| 4198 } | 3886 } |
| 4199 | 3887 |
| 4200 /** | 3888 /** |
| 4201 * Invalidate all of the resolution results computed by this context. | 3889 * Invalidate all of the resolution results computed by this context. The flag |
| 4202 * | 3890 * [invalidateUris] should be `true` if the cached results of converting URIs |
| 4203 * <b>Note:</b> This method must only be invoked while we are synchronized on
[cacheLock]. | 3891 * to source files should also be invalidated. |
| 4204 * | |
| 4205 * @param invalidateUris `true` if the cached results of converting URIs to so
urce files | |
| 4206 * should also be invalidated. | |
| 4207 */ | 3892 */ |
| 4208 void _invalidateAllLocalResolutionInformation(bool invalidateUris) { | 3893 void _invalidateAllLocalResolutionInformation(bool invalidateUris) { |
| 4209 HashMap<Source, List<Source>> oldPartMap = | 3894 HashMap<Source, List<Source>> oldPartMap = |
| 4210 new HashMap<Source, List<Source>>(); | 3895 new HashMap<Source, List<Source>>(); |
| 4211 MapIterator<Source, SourceEntry> iterator = _privatePartition.iterator(); | 3896 MapIterator<Source, SourceEntry> iterator = _privatePartition.iterator(); |
| 4212 while (iterator.moveNext()) { | 3897 while (iterator.moveNext()) { |
| 4213 Source source = iterator.key; | 3898 Source source = iterator.key; |
| 4214 SourceEntry sourceEntry = iterator.value; | 3899 SourceEntry sourceEntry = iterator.value; |
| 4215 if (sourceEntry is HtmlEntry) { | 3900 if (sourceEntry is HtmlEntry) { |
| 4216 HtmlEntry htmlEntry = sourceEntry; | 3901 HtmlEntry htmlEntry = sourceEntry; |
| 4217 htmlEntry.invalidateAllResolutionInformation(invalidateUris); | 3902 htmlEntry.invalidateAllResolutionInformation(invalidateUris); |
| 4218 iterator.value = htmlEntry; | 3903 iterator.value = htmlEntry; |
| 4219 _workManager.add(source, SourcePriority.HTML); | 3904 _workManager.add(source, SourcePriority.HTML); |
| 4220 } else if (sourceEntry is DartEntry) { | 3905 } else if (sourceEntry is DartEntry) { |
| 4221 DartEntry dartEntry = sourceEntry; | 3906 DartEntry dartEntry = sourceEntry; |
| 4222 oldPartMap[source] = dartEntry.getValue(DartEntry.INCLUDED_PARTS); | 3907 oldPartMap[source] = dartEntry.getValue(DartEntry.INCLUDED_PARTS); |
| 4223 dartEntry.invalidateAllResolutionInformation(invalidateUris); | 3908 dartEntry.invalidateAllResolutionInformation(invalidateUris); |
| 4224 iterator.value = dartEntry; | 3909 iterator.value = dartEntry; |
| 4225 _workManager.add(source, _computePriority(dartEntry)); | 3910 _workManager.add(source, _computePriority(dartEntry)); |
| 4226 } | 3911 } |
| 4227 } | 3912 } |
| 4228 _removeFromPartsUsingMap(oldPartMap); | 3913 _removeFromPartsUsingMap(oldPartMap); |
| 4229 } | 3914 } |
| 4230 | 3915 |
| 4231 /** | 3916 /** |
| 4232 * In response to a change to at least one of the compilation units in the giv
en library, | 3917 * In response to a change to at least one of the compilation units in the |
| 4233 * invalidate any results that are dependent on the result of resolving that l
ibrary. | 3918 * library defined by the given [librarySource], invalidate any results that |
| 3919 * are dependent on the result of resolving that library. |
| 4234 * | 3920 * |
| 4235 * <b>Note:</b> This method must only be invoked while we are synchronized on
[cacheLock]. | 3921 * <b>Note:</b> Any cache entries that were accessed before this method was |
| 4236 * | 3922 * invoked must be re-accessed after this method returns. |
| 4237 * <b>Note:</b> Any cache entries that were accessed before this method was in
voked must be | |
| 4238 * re-accessed after this method returns. | |
| 4239 * | |
| 4240 * @param librarySource the source of the library being invalidated | |
| 4241 */ | 3923 */ |
| 4242 void _invalidateLibraryResolution(Source librarySource) { | 3924 void _invalidateLibraryResolution(Source librarySource) { |
| 4243 // TODO(brianwilkerson) This could be optimized. There's no need to flush | 3925 // TODO(brianwilkerson) This could be optimized. There's no need to flush |
| 4244 // all of these entries if the public namespace hasn't changed, which will | 3926 // all of these entries if the public namespace hasn't changed, which will |
| 4245 // be a fairly common case. The question is whether we can afford the time | 3927 // be a fairly common case. The question is whether we can afford the time |
| 4246 // to compute the namespace to look for differences. | 3928 // to compute the namespace to look for differences. |
| 4247 DartEntry libraryEntry = _getReadableDartEntry(librarySource); | 3929 DartEntry libraryEntry = _getReadableDartEntry(librarySource); |
| 4248 if (libraryEntry != null) { | 3930 if (libraryEntry != null) { |
| 4249 List<Source> includedParts = | 3931 List<Source> includedParts = |
| 4250 libraryEntry.getValue(DartEntry.INCLUDED_PARTS); | 3932 libraryEntry.getValue(DartEntry.INCLUDED_PARTS); |
| 4251 libraryEntry.invalidateAllResolutionInformation(false); | 3933 libraryEntry.invalidateAllResolutionInformation(false); |
| 4252 _workManager.add(librarySource, SourcePriority.LIBRARY); | 3934 _workManager.add(librarySource, SourcePriority.LIBRARY); |
| 4253 for (Source partSource in includedParts) { | 3935 for (Source partSource in includedParts) { |
| 4254 SourceEntry partEntry = _cache.get(partSource); | 3936 SourceEntry partEntry = _cache.get(partSource); |
| 4255 if (partEntry is DartEntry) { | 3937 if (partEntry is DartEntry) { |
| 4256 partEntry.invalidateAllResolutionInformation(false); | 3938 partEntry.invalidateAllResolutionInformation(false); |
| 4257 } | 3939 } |
| 4258 } | 3940 } |
| 4259 } | 3941 } |
| 4260 } | 3942 } |
| 4261 | 3943 |
| 4262 /** | 3944 /** |
| 4263 * Return `true` if this library is, or depends on, dart:html. | 3945 * Return `true` if the given [library] is, or depends on, 'dart:html'. The |
| 4264 * | 3946 * [visitedLibraries] is a collection of the libraries that have been visited, |
| 4265 * @param library the library being tested | 3947 * used to prevent infinite recursion. |
| 4266 * @param visitedLibraries a collection of the libraries that have been visite
d, used to prevent | |
| 4267 * infinite recursion | |
| 4268 * @return `true` if this library is, or depends on, dart:html | |
| 4269 */ | 3948 */ |
| 4270 bool _isClient(LibraryElement library, Source htmlSource, | 3949 bool _isClient(LibraryElement library, Source htmlSource, |
| 4271 HashSet<LibraryElement> visitedLibraries) { | 3950 HashSet<LibraryElement> visitedLibraries) { |
| 4272 if (visitedLibraries.contains(library)) { | 3951 if (visitedLibraries.contains(library)) { |
| 4273 return false; | 3952 return false; |
| 4274 } | 3953 } |
| 4275 if (library.source == htmlSource) { | 3954 if (library.source == htmlSource) { |
| 4276 return true; | 3955 return true; |
| 4277 } | 3956 } |
| 4278 visitedLibraries.add(library); | 3957 visitedLibraries.add(library); |
| 4279 for (LibraryElement imported in library.importedLibraries) { | 3958 for (LibraryElement imported in library.importedLibraries) { |
| 4280 if (_isClient(imported, htmlSource, visitedLibraries)) { | 3959 if (_isClient(imported, htmlSource, visitedLibraries)) { |
| 4281 return true; | 3960 return true; |
| 4282 } | 3961 } |
| 4283 } | 3962 } |
| 4284 for (LibraryElement exported in library.exportedLibraries) { | 3963 for (LibraryElement exported in library.exportedLibraries) { |
| 4285 if (_isClient(exported, htmlSource, visitedLibraries)) { | 3964 if (_isClient(exported, htmlSource, visitedLibraries)) { |
| 4286 return true; | 3965 return true; |
| 4287 } | 3966 } |
| 4288 } | 3967 } |
| 4289 return false; | 3968 return false; |
| 4290 } | 3969 } |
| 4291 | 3970 |
| 4292 bool _isTooBigHtmlSourceEntry(Source source, SourceEntry sourceEntry) => | 3971 bool _isTooBigHtmlSourceEntry(Source source, SourceEntry sourceEntry) => |
| 4293 false; | 3972 false; |
| 4294 | 3973 |
| 4295 /** | 3974 /** |
| 4296 * Log the given debugging information. | 3975 * Log the given debugging [message]. |
| 4297 * | |
| 4298 * @param message the message to be added to the log | |
| 4299 */ | 3976 */ |
| 4300 void _logInformation(String message) { | 3977 void _logInformation(String message) { |
| 4301 AnalysisEngine.instance.logger.logInformation(message); | 3978 AnalysisEngine.instance.logger.logInformation(message); |
| 4302 } | 3979 } |
| 4303 | 3980 |
| 4304 /** | 3981 /** |
| 4305 * Notify all of the analysis listeners that a task is about to be performed. | 3982 * Notify all of the analysis listeners that a task is about to be performed. |
| 4306 * | |
| 4307 * @param taskDescription a human readable description of the task that is abo
ut to be performed | |
| 4308 */ | 3983 */ |
| 4309 void _notifyAboutToPerformTask(String taskDescription) { | 3984 void _notifyAboutToPerformTask(String taskDescription) { |
| 4310 int count = _listeners.length; | 3985 int count = _listeners.length; |
| 4311 for (int i = 0; i < count; i++) { | 3986 for (int i = 0; i < count; i++) { |
| 4312 _listeners[i].aboutToPerformTask(this, taskDescription); | 3987 _listeners[i].aboutToPerformTask(this, taskDescription); |
| 4313 } | 3988 } |
| 4314 } | 3989 } |
| 4315 | 3990 |
| 4316 /** | 3991 /** |
| 4317 * Notify all of the analysis listeners that the errors associated with the gi
ven source has been | 3992 * Notify all of the analysis listeners that the errors associated with the |
| 4318 * updated to the given errors. | 3993 * given [source] has been updated to the given [errors]. |
| 4319 * | |
| 4320 * @param source the source containing the errors that were computed | |
| 4321 * @param errors the errors that were computed | |
| 4322 * @param lineInfo the line information associated with the source | |
| 4323 */ | 3994 */ |
| 4324 void _notifyErrors( | 3995 void _notifyErrors( |
| 4325 Source source, List<AnalysisError> errors, LineInfo lineInfo) { | 3996 Source source, List<AnalysisError> errors, LineInfo lineInfo) { |
| 4326 int count = _listeners.length; | 3997 int count = _listeners.length; |
| 4327 for (int i = 0; i < count; i++) { | 3998 for (int i = 0; i < count; i++) { |
| 4328 _listeners[i].computedErrors(this, source, errors, lineInfo); | 3999 _listeners[i].computedErrors(this, source, errors, lineInfo); |
| 4329 } | 4000 } |
| 4330 } | 4001 } |
| 4331 | 4002 |
| 4332 /** | 4003 /** |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4464 // * @param unit the result of resolving the source | 4135 // * @param unit the result of resolving the source |
| 4465 // */ | 4136 // */ |
| 4466 // void _notifyResolvedHtml(Source source, ht.HtmlUnit unit) { | 4137 // void _notifyResolvedHtml(Source source, ht.HtmlUnit unit) { |
| 4467 // int count = _listeners.length; | 4138 // int count = _listeners.length; |
| 4468 // for (int i = 0; i < count; i++) { | 4139 // for (int i = 0; i < count; i++) { |
| 4469 // _listeners[i].resolvedHtml(this, source, unit); | 4140 // _listeners[i].resolvedHtml(this, source, unit); |
| 4470 // } | 4141 // } |
| 4471 // } | 4142 // } |
| 4472 | 4143 |
| 4473 /** | 4144 /** |
| 4474 * Given a cache entry and a library element, record the library element and o
ther information | 4145 * Given a [dartEntry] and a [library] element, record the library element and |
| 4475 * gleaned from the element in the cache entry. | 4146 * other information gleaned from the element in the cache entry. |
| 4476 * | |
| 4477 * @param dartCopy the cache entry in which data is to be recorded | |
| 4478 * @param library the library element used to record information | |
| 4479 * @param librarySource the source for the library used to record information | |
| 4480 * @param htmlSource the source for the HTML library | |
| 4481 */ | 4147 */ |
| 4482 void _recordElementData(DartEntry dartEntry, LibraryElement library, | 4148 void _recordElementData(DartEntry dartEntry, LibraryElement library, |
| 4483 Source librarySource, Source htmlSource) { | 4149 Source librarySource, Source htmlSource) { |
| 4484 dartEntry.setValue(DartEntry.ELEMENT, library); | 4150 dartEntry.setValue(DartEntry.ELEMENT, library); |
| 4485 dartEntry.setValue(DartEntry.IS_LAUNCHABLE, library.entryPoint != null); | 4151 dartEntry.setValue(DartEntry.IS_LAUNCHABLE, library.entryPoint != null); |
| 4486 dartEntry.setValue(DartEntry.IS_CLIENT, | 4152 dartEntry.setValue(DartEntry.IS_CLIENT, |
| 4487 _isClient(library, htmlSource, new HashSet<LibraryElement>())); | 4153 _isClient(library, htmlSource, new HashSet<LibraryElement>())); |
| 4488 } | 4154 } |
| 4489 | 4155 |
| 4490 /** | 4156 /** |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4613 } | 4279 } |
| 4614 _workManager.remove(source); | 4280 _workManager.remove(source); |
| 4615 throw new AnalysisException('<rethrow>', thrownException); | 4281 throw new AnalysisException('<rethrow>', thrownException); |
| 4616 } | 4282 } |
| 4617 sourceEntry.modificationTime = task.modificationTime; | 4283 sourceEntry.modificationTime = task.modificationTime; |
| 4618 sourceEntry.setValue(SourceEntry.CONTENT, task.content); | 4284 sourceEntry.setValue(SourceEntry.CONTENT, task.content); |
| 4619 return sourceEntry; | 4285 return sourceEntry; |
| 4620 } | 4286 } |
| 4621 | 4287 |
| 4622 /** | 4288 /** |
| 4623 * Record the results produced by performing a [IncrementalAnalysisTask]. | 4289 * Record the results produced by performing a [task] and return the cache |
| 4624 * | 4290 * entry associated with the results. |
| 4625 * @param task the task that was performed | |
| 4626 * @return an entry containing the computed results | |
| 4627 * @throws AnalysisException if the results could not be recorded | |
| 4628 */ | 4291 */ |
| 4629 DartEntry _recordIncrementalAnalysisTaskResults( | 4292 DartEntry _recordIncrementalAnalysisTaskResults( |
| 4630 IncrementalAnalysisTask task) { | 4293 IncrementalAnalysisTask task) { |
| 4631 CompilationUnit unit = task.compilationUnit; | 4294 CompilationUnit unit = task.compilationUnit; |
| 4632 if (unit != null) { | 4295 if (unit != null) { |
| 4633 ChangeNoticeImpl notice = _getNotice(task.source); | 4296 ChangeNoticeImpl notice = _getNotice(task.source); |
| 4634 notice.resolvedDartUnit = unit; | 4297 notice.resolvedDartUnit = unit; |
| 4635 _incrementalAnalysisCache = | 4298 _incrementalAnalysisCache = |
| 4636 IncrementalAnalysisCache.cacheResult(task.cache, unit); | 4299 IncrementalAnalysisCache.cacheResult(task.cache, unit); |
| 4637 } | 4300 } |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4792 dartEntry.setValue(SourceEntry.LINE_INFO, lineInfo); | 4455 dartEntry.setValue(SourceEntry.LINE_INFO, lineInfo); |
| 4793 dartEntry.setValue(DartEntry.TOKEN_STREAM, task.tokenStream); | 4456 dartEntry.setValue(DartEntry.TOKEN_STREAM, task.tokenStream); |
| 4794 dartEntry.setValue(DartEntry.SCAN_ERRORS, task.errors); | 4457 dartEntry.setValue(DartEntry.SCAN_ERRORS, task.errors); |
| 4795 _cache.storedAst(source); | 4458 _cache.storedAst(source); |
| 4796 ChangeNoticeImpl notice = _getNotice(source); | 4459 ChangeNoticeImpl notice = _getNotice(source); |
| 4797 notice.setErrors(dartEntry.allErrors, lineInfo); | 4460 notice.setErrors(dartEntry.allErrors, lineInfo); |
| 4798 return dartEntry; | 4461 return dartEntry; |
| 4799 } | 4462 } |
| 4800 | 4463 |
| 4801 /** | 4464 /** |
| 4802 * Remove the given library from the list of containing libraries for all of t
he parts referenced | 4465 * Remove the given [librarySource] from the list of containing libraries for |
| 4803 * by the given entry. | 4466 * all of the parts referenced by the given [dartEntry]. |
| 4804 * | |
| 4805 * <b>Note:</b> This method must only be invoked while we are synchronized on
[cacheLock]. | |
| 4806 * | |
| 4807 * @param librarySource the library to be removed | |
| 4808 * @param dartEntry the entry containing the list of included parts | |
| 4809 */ | 4467 */ |
| 4810 void _removeFromParts(Source librarySource, DartEntry dartEntry) { | 4468 void _removeFromParts(Source librarySource, DartEntry dartEntry) { |
| 4811 List<Source> oldParts = dartEntry.getValue(DartEntry.INCLUDED_PARTS); | 4469 List<Source> oldParts = dartEntry.getValue(DartEntry.INCLUDED_PARTS); |
| 4812 for (int i = 0; i < oldParts.length; i++) { | 4470 for (int i = 0; i < oldParts.length; i++) { |
| 4813 Source partSource = oldParts[i]; | 4471 Source partSource = oldParts[i]; |
| 4814 DartEntry partEntry = _getReadableDartEntry(partSource); | 4472 DartEntry partEntry = _getReadableDartEntry(partSource); |
| 4815 if (partEntry != null && !identical(partEntry, dartEntry)) { | 4473 if (partEntry != null && !identical(partEntry, dartEntry)) { |
| 4816 partEntry.removeContainingLibrary(librarySource); | 4474 partEntry.removeContainingLibrary(librarySource); |
| 4817 if (partEntry.containingLibraries.length == 0 && !exists(partSource)) { | 4475 if (partEntry.containingLibraries.length == 0 && !exists(partSource)) { |
| 4818 _cache.remove(partSource); | 4476 _cache.remove(partSource); |
| 4819 } | 4477 } |
| 4820 } | 4478 } |
| 4821 } | 4479 } |
| 4822 } | 4480 } |
| 4823 | 4481 |
| 4824 /** | 4482 /** |
| 4825 * Remove the given libraries that are keys in the given map from the list of
containing libraries | 4483 * Remove the given libraries that are keys in the given map from the list of |
| 4826 * for each of the parts in the corresponding value. | 4484 * containing libraries for each of the parts in the corresponding value. |
| 4827 * | |
| 4828 * <b>Note:</b> This method must only be invoked while we are synchronized on
[cacheLock]. | |
| 4829 * | |
| 4830 * @param oldPartMap the table containing the parts associated with each libra
ry | |
| 4831 */ | 4485 */ |
| 4832 void _removeFromPartsUsingMap(HashMap<Source, List<Source>> oldPartMap) { | 4486 void _removeFromPartsUsingMap(HashMap<Source, List<Source>> oldPartMap) { |
| 4833 oldPartMap.forEach((Source librarySource, List<Source> oldParts) { | 4487 oldPartMap.forEach((Source librarySource, List<Source> oldParts) { |
| 4834 for (int i = 0; i < oldParts.length; i++) { | 4488 for (int i = 0; i < oldParts.length; i++) { |
| 4835 Source partSource = oldParts[i]; | 4489 Source partSource = oldParts[i]; |
| 4836 if (partSource != librarySource) { | 4490 if (partSource != librarySource) { |
| 4837 DartEntry partEntry = _getReadableDartEntry(partSource); | 4491 DartEntry partEntry = _getReadableDartEntry(partSource); |
| 4838 if (partEntry != null) { | 4492 if (partEntry != null) { |
| 4839 partEntry.removeContainingLibrary(librarySource); | 4493 partEntry.removeContainingLibrary(librarySource); |
| 4840 if (partEntry.containingLibraries.length == 0 && | 4494 if (partEntry.containingLibraries.length == 0 && |
| 4841 !exists(partSource)) { | 4495 !exists(partSource)) { |
| 4842 _cache.remove(partSource); | 4496 _cache.remove(partSource); |
| 4843 } | 4497 } |
| 4844 } | 4498 } |
| 4845 } | 4499 } |
| 4846 } | 4500 } |
| 4847 }); | 4501 }); |
| 4848 } | 4502 } |
| 4849 | 4503 |
| 4850 /** | 4504 /** |
| 4851 * Remove the given source from the priority order if it is in the list. | 4505 * Remove the given [source] from the priority order if it is in the list. |
| 4852 * | |
| 4853 * @param source the source to be removed | |
| 4854 */ | 4506 */ |
| 4855 void _removeFromPriorityOrder(Source source) { | 4507 void _removeFromPriorityOrder(Source source) { |
| 4856 int count = _priorityOrder.length; | 4508 int count = _priorityOrder.length; |
| 4857 List<Source> newOrder = new List<Source>(); | 4509 List<Source> newOrder = new List<Source>(); |
| 4858 for (int i = 0; i < count; i++) { | 4510 for (int i = 0; i < count; i++) { |
| 4859 if (_priorityOrder[i] != source) { | 4511 if (_priorityOrder[i] != source) { |
| 4860 newOrder.add(_priorityOrder[i]); | 4512 newOrder.add(_priorityOrder[i]); |
| 4861 } | 4513 } |
| 4862 } | 4514 } |
| 4863 if (newOrder.length < count) { | 4515 if (newOrder.length < count) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 4875 } else if (!dartEntry.explicitlyAdded) { | 4527 } else if (!dartEntry.explicitlyAdded) { |
| 4876 return _generateImplicitErrors; | 4528 return _generateImplicitErrors; |
| 4877 } else { | 4529 } else { |
| 4878 return true; | 4530 return true; |
| 4879 } | 4531 } |
| 4880 } | 4532 } |
| 4881 | 4533 |
| 4882 /** | 4534 /** |
| 4883 * Create an entry for the newly added [source] and invalidate any sources | 4535 * Create an entry for the newly added [source] and invalidate any sources |
| 4884 * that referenced the source before it existed. | 4536 * that referenced the source before it existed. |
| 4885 * | |
| 4886 * <b>Note:</b> This method must only be invoked while we are synchronized on | |
| 4887 * [cacheLock]. | |
| 4888 */ | 4537 */ |
| 4889 void _sourceAvailable(Source source) { | 4538 void _sourceAvailable(Source source) { |
| 4890 SourceEntry sourceEntry = _cache.get(source); | 4539 SourceEntry sourceEntry = _cache.get(source); |
| 4891 if (sourceEntry == null) { | 4540 if (sourceEntry == null) { |
| 4892 sourceEntry = _createSourceEntry(source, true); | 4541 sourceEntry = _createSourceEntry(source, true); |
| 4893 } else { | 4542 } else { |
| 4894 _propagateInvalidation(source, sourceEntry); | 4543 _propagateInvalidation(source, sourceEntry); |
| 4895 sourceEntry = _cache.get(source); | 4544 sourceEntry = _cache.get(source); |
| 4896 } | 4545 } |
| 4897 if (sourceEntry is HtmlEntry) { | 4546 if (sourceEntry is HtmlEntry) { |
| 4898 _workManager.add(source, SourcePriority.HTML); | 4547 _workManager.add(source, SourcePriority.HTML); |
| 4899 } else if (sourceEntry is DartEntry) { | 4548 } else if (sourceEntry is DartEntry) { |
| 4900 _workManager.add(source, _computePriority(sourceEntry)); | 4549 _workManager.add(source, _computePriority(sourceEntry)); |
| 4901 } | 4550 } |
| 4902 } | 4551 } |
| 4903 | 4552 |
| 4904 /** | 4553 /** |
| 4905 * Invalidate the [source] that was changed and any sources that referenced | 4554 * Invalidate the [source] that was changed and any sources that referenced |
| 4906 * the source before it existed. | 4555 * the source before it existed. |
| 4907 * | |
| 4908 * <b>Note:</b> This method must only be invoked while we are synchronized on | |
| 4909 * [cacheLock]. | |
| 4910 */ | 4556 */ |
| 4911 void _sourceChanged(Source source) { | 4557 void _sourceChanged(Source source) { |
| 4912 SourceEntry sourceEntry = _cache.get(source); | 4558 SourceEntry sourceEntry = _cache.get(source); |
| 4913 // If the source is removed, we don't care about it. | 4559 // If the source is removed, we don't care about it. |
| 4914 if (sourceEntry == null) { | 4560 if (sourceEntry == null) { |
| 4915 return; | 4561 return; |
| 4916 } | 4562 } |
| 4917 // Check if the content of the source is the same as it was the last time. | 4563 // Check if the content of the source is the same as it was the last time. |
| 4918 String sourceContent = sourceEntry.getValue(SourceEntry.CONTENT); | 4564 String sourceContent = sourceEntry.getValue(SourceEntry.CONTENT); |
| 4919 if (sourceContent != null) { | 4565 if (sourceContent != null) { |
| 4920 sourceEntry.setState(SourceEntry.CONTENT, CacheState.FLUSHED); | 4566 sourceEntry.setState(SourceEntry.CONTENT, CacheState.FLUSHED); |
| 4921 try { | 4567 try { |
| 4922 TimestampedData<String> fileContents = getContents(source); | 4568 TimestampedData<String> fileContents = getContents(source); |
| 4923 if (fileContents.data == sourceContent) { | 4569 if (fileContents.data == sourceContent) { |
| 4924 return; | 4570 return; |
| 4925 } | 4571 } |
| 4926 } catch (e) {} | 4572 } catch (e) {} |
| 4927 } | 4573 } |
| 4928 // We have to invalidate the cache. | 4574 // We have to invalidate the cache. |
| 4929 _propagateInvalidation(source, sourceEntry); | 4575 _propagateInvalidation(source, sourceEntry); |
| 4930 } | 4576 } |
| 4931 | 4577 |
| 4932 /** | 4578 /** |
| 4933 * <b>Note:</b> This method must only be invoked while we are synchronized on
[cacheLock]. | 4579 * Record that the give [source] has been deleted. |
| 4934 * | |
| 4935 * @param source the source that has been deleted | |
| 4936 */ | 4580 */ |
| 4937 void _sourceDeleted(Source source) { | 4581 void _sourceDeleted(Source source) { |
| 4938 SourceEntry sourceEntry = _cache.get(source); | 4582 SourceEntry sourceEntry = _cache.get(source); |
| 4939 if (sourceEntry is HtmlEntry) { | 4583 if (sourceEntry is HtmlEntry) { |
| 4940 HtmlEntry htmlEntry = sourceEntry; | 4584 HtmlEntry htmlEntry = sourceEntry; |
| 4941 htmlEntry.recordContentError(new CaughtException( | 4585 htmlEntry.recordContentError(new CaughtException( |
| 4942 new AnalysisException("This source was marked as being deleted"), | 4586 new AnalysisException("This source was marked as being deleted"), |
| 4943 null)); | 4587 null)); |
| 4944 } else if (sourceEntry is DartEntry) { | 4588 } else if (sourceEntry is DartEntry) { |
| 4945 DartEntry dartEntry = sourceEntry; | 4589 DartEntry dartEntry = sourceEntry; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 4956 } | 4600 } |
| 4957 dartEntry.recordContentError(new CaughtException( | 4601 dartEntry.recordContentError(new CaughtException( |
| 4958 new AnalysisException("This source was marked as being deleted"), | 4602 new AnalysisException("This source was marked as being deleted"), |
| 4959 null)); | 4603 null)); |
| 4960 } | 4604 } |
| 4961 _workManager.remove(source); | 4605 _workManager.remove(source); |
| 4962 _removeFromPriorityOrder(source); | 4606 _removeFromPriorityOrder(source); |
| 4963 } | 4607 } |
| 4964 | 4608 |
| 4965 /** | 4609 /** |
| 4966 * <b>Note:</b> This method must only be invoked while we are synchronized on
[cacheLock]. | 4610 * Record that the given [source] has been removed. |
| 4967 * | |
| 4968 * @param source the source that has been removed | |
| 4969 */ | 4611 */ |
| 4970 void _sourceRemoved(Source source) { | 4612 void _sourceRemoved(Source source) { |
| 4971 SourceEntry sourceEntry = _cache.get(source); | 4613 SourceEntry sourceEntry = _cache.get(source); |
| 4972 if (sourceEntry is HtmlEntry) {} else if (sourceEntry is DartEntry) { | 4614 if (sourceEntry is HtmlEntry) {} else if (sourceEntry is DartEntry) { |
| 4973 HashSet<Source> libraries = new HashSet<Source>(); | 4615 HashSet<Source> libraries = new HashSet<Source>(); |
| 4974 for (Source librarySource in getLibrariesContaining(source)) { | 4616 for (Source librarySource in getLibrariesContaining(source)) { |
| 4975 libraries.add(librarySource); | 4617 libraries.add(librarySource); |
| 4976 for (Source dependentLibrary | 4618 for (Source dependentLibrary |
| 4977 in getLibrariesDependingOn(librarySource)) { | 4619 in getLibrariesDependingOn(librarySource)) { |
| 4978 libraries.add(dependentLibrary); | 4620 libraries.add(dependentLibrary); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5043 ChangeNoticeImpl notice = _getNotice(unitSource); | 4685 ChangeNoticeImpl notice = _getNotice(unitSource); |
| 5044 notice.resolvedDartUnit = oldUnit; | 4686 notice.resolvedDartUnit = oldUnit; |
| 5045 notice.setErrors(dartEntry.allErrors, lineInfo); | 4687 notice.setErrors(dartEntry.allErrors, lineInfo); |
| 5046 } | 4688 } |
| 5047 // OK | 4689 // OK |
| 5048 return true; | 4690 return true; |
| 5049 }); | 4691 }); |
| 5050 } | 4692 } |
| 5051 | 4693 |
| 5052 /** | 4694 /** |
| 5053 * Check the cache for any invalid entries (entries whose modification time do
es not match the | 4695 * Check the cache for any invalid entries (entries whose modification time |
| 5054 * modification time of the source associated with the entry). Invalid entries
will be marked as | 4696 * does not match the modification time of the source associated with the |
| 5055 * invalid so that the source will be re-analyzed. | 4697 * entry). Invalid entries will be marked as invalid so that the source will |
| 5056 * | 4698 * be re-analyzed. Return `true` if at least one entry was invalid. |
| 5057 * <b>Note:</b> This method must only be invoked while we are synchronized on
[cacheLock]. | |
| 5058 * | |
| 5059 * @return `true` if at least one entry was invalid | |
| 5060 */ | 4699 */ |
| 5061 bool _validateCacheConsistency() { | 4700 bool _validateCacheConsistency() { |
| 5062 int consistencyCheckStart = JavaSystem.nanoTime(); | 4701 int consistencyCheckStart = JavaSystem.nanoTime(); |
| 5063 List<Source> changedSources = new List<Source>(); | 4702 List<Source> changedSources = new List<Source>(); |
| 5064 List<Source> missingSources = new List<Source>(); | 4703 List<Source> missingSources = new List<Source>(); |
| 5065 MapIterator<Source, SourceEntry> iterator = _cache.iterator(); | 4704 MapIterator<Source, SourceEntry> iterator = _cache.iterator(); |
| 5066 while (iterator.moveNext()) { | 4705 while (iterator.moveNext()) { |
| 5067 Source source = iterator.key; | 4706 Source source = iterator.key; |
| 5068 SourceEntry sourceEntry = iterator.value; | 4707 SourceEntry sourceEntry = iterator.value; |
| 5069 int sourceTime = getModificationStamp(source); | 4708 int sourceTime = getModificationStamp(source); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5131 AnalysisEngine.instance.logger.logError(message); | 4770 AnalysisEngine.instance.logger.logError(message); |
| 5132 } | 4771 } |
| 5133 } | 4772 } |
| 5134 incrementalResolutionValidation_lastUnitSource = null; | 4773 incrementalResolutionValidation_lastUnitSource = null; |
| 5135 incrementalResolutionValidation_lastLibrarySource = null; | 4774 incrementalResolutionValidation_lastLibrarySource = null; |
| 5136 incrementalResolutionValidation_lastUnit = null; | 4775 incrementalResolutionValidation_lastUnit = null; |
| 5137 } | 4776 } |
| 5138 } | 4777 } |
| 5139 | 4778 |
| 5140 /** | 4779 /** |
| 5141 * An `AnalysisTaskResultRecorder` is used by an analysis context to record the | 4780 * An object used by an analysis context to record the results of a task. |
| 5142 * results of a task. | |
| 5143 */ | 4781 */ |
| 5144 class AnalysisContextImpl_AnalysisTaskResultRecorder | 4782 class AnalysisContextImpl_AnalysisTaskResultRecorder |
| 5145 implements AnalysisTaskVisitor<SourceEntry> { | 4783 implements AnalysisTaskVisitor<SourceEntry> { |
| 5146 final AnalysisContextImpl AnalysisContextImpl_this; | 4784 final AnalysisContextImpl AnalysisContextImpl_this; |
| 5147 | 4785 |
| 5148 AnalysisContextImpl_AnalysisTaskResultRecorder(this.AnalysisContextImpl_this); | 4786 AnalysisContextImpl_AnalysisTaskResultRecorder(this.AnalysisContextImpl_this); |
| 5149 | 4787 |
| 5150 @override | 4788 @override |
| 5151 DartEntry visitBuildUnitElementTask(BuildUnitElementTask task) => | 4789 DartEntry visitBuildUnitElementTask(BuildUnitElementTask task) => |
| 5152 AnalysisContextImpl_this._recordBuildUnitElementTask(task); | 4790 AnalysisContextImpl_this._recordBuildUnitElementTask(task); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5229 } | 4867 } |
| 5230 | 4868 |
| 5231 bool _astIsNeeded(DartEntry dartEntry) => | 4869 bool _astIsNeeded(DartEntry dartEntry) => |
| 5232 dartEntry.hasInvalidData(DartEntry.HINTS) || | 4870 dartEntry.hasInvalidData(DartEntry.HINTS) || |
| 5233 dartEntry.hasInvalidData(DartEntry.LINTS) || | 4871 dartEntry.hasInvalidData(DartEntry.LINTS) || |
| 5234 dartEntry.hasInvalidData(DartEntry.VERIFICATION_ERRORS) || | 4872 dartEntry.hasInvalidData(DartEntry.VERIFICATION_ERRORS) || |
| 5235 dartEntry.hasInvalidData(DartEntry.RESOLUTION_ERRORS); | 4873 dartEntry.hasInvalidData(DartEntry.RESOLUTION_ERRORS); |
| 5236 } | 4874 } |
| 5237 | 4875 |
| 5238 /** | 4876 /** |
| 5239 * Instances of the class `CycleBuilder` are used to construct a list of the lib
raries that | 4877 * An object used to construct a list of the libraries that must be resolved |
| 5240 * must be resolved together in order to resolve any one of the libraries. | 4878 * together in order to resolve any one of the libraries. |
| 5241 */ | 4879 */ |
| 5242 class AnalysisContextImpl_CycleBuilder { | 4880 class AnalysisContextImpl_CycleBuilder { |
| 5243 final AnalysisContextImpl AnalysisContextImpl_this; | 4881 final AnalysisContextImpl AnalysisContextImpl_this; |
| 5244 | 4882 |
| 5245 /** | 4883 /** |
| 5246 * A table mapping the sources of the defining compilation units of libraries
to the | 4884 * A table mapping the sources of the defining compilation units of libraries |
| 5247 * representation of the library that has the information needed to resolve th
e library. | 4885 * to the representation of the library that has the information needed to |
| 4886 * resolve the library. |
| 5248 */ | 4887 */ |
| 5249 HashMap<Source, ResolvableLibrary> _libraryMap = | 4888 HashMap<Source, ResolvableLibrary> _libraryMap = |
| 5250 new HashMap<Source, ResolvableLibrary>(); | 4889 new HashMap<Source, ResolvableLibrary>(); |
| 5251 | 4890 |
| 5252 /** | 4891 /** |
| 5253 * The dependency graph used to compute the libraries in the cycle. | 4892 * The dependency graph used to compute the libraries in the cycle. |
| 5254 */ | 4893 */ |
| 5255 DirectedGraph<ResolvableLibrary> _dependencyGraph; | 4894 DirectedGraph<ResolvableLibrary> _dependencyGraph; |
| 5256 | 4895 |
| 5257 /** | 4896 /** |
| 5258 * A list containing the libraries that are ready to be resolved. | 4897 * A list containing the libraries that are ready to be resolved. |
| 5259 */ | 4898 */ |
| 5260 List<ResolvableLibrary> _librariesInCycle; | 4899 List<ResolvableLibrary> _librariesInCycle; |
| 5261 | 4900 |
| 5262 /** | 4901 /** |
| 5263 * The analysis task that needs to be performed before the cycle of libraries
can be resolved, | 4902 * The analysis task that needs to be performed before the cycle of libraries |
| 5264 * or `null` if the libraries are ready to be resolved. | 4903 * can be resolved, or `null` if the libraries are ready to be resolved. |
| 5265 */ | 4904 */ |
| 5266 AnalysisContextImpl_TaskData _taskData; | 4905 AnalysisContextImpl_TaskData _taskData; |
| 5267 | 4906 |
| 5268 /** | 4907 /** |
| 5269 * Initialize a newly created cycle builder. | 4908 * Initialize a newly created cycle builder. |
| 5270 */ | 4909 */ |
| 5271 AnalysisContextImpl_CycleBuilder(this.AnalysisContextImpl_this) : super(); | 4910 AnalysisContextImpl_CycleBuilder(this.AnalysisContextImpl_this) : super(); |
| 5272 | 4911 |
| 5273 /** | 4912 /** |
| 5274 * Return a list containing the libraries that are ready to be resolved (assum
ing that | 4913 * Return a list containing the libraries that are ready to be resolved |
| 5275 * [getTaskData] returns `null`). | 4914 * (assuming that [getTaskData] returns `null`). |
| 5276 * | |
| 5277 * @return the libraries that are ready to be resolved | |
| 5278 */ | 4915 */ |
| 5279 List<ResolvableLibrary> get librariesInCycle => _librariesInCycle; | 4916 List<ResolvableLibrary> get librariesInCycle => _librariesInCycle; |
| 5280 | 4917 |
| 5281 /** | 4918 /** |
| 5282 * Return a representation of an analysis task that needs to be performed befo
re the cycle of | 4919 * Return a representation of an analysis task that needs to be performed |
| 5283 * libraries can be resolved, or `null` if the libraries are ready to be resol
ved. | 4920 * before the cycle of libraries can be resolved, or `null` if the libraries |
| 5284 * | 4921 * are ready to be resolved. |
| 5285 * @return the analysis task that needs to be performed before the cycle of li
braries can be | |
| 5286 * resolved | |
| 5287 */ | 4922 */ |
| 5288 AnalysisContextImpl_TaskData get taskData => _taskData; | 4923 AnalysisContextImpl_TaskData get taskData => _taskData; |
| 5289 | 4924 |
| 5290 /** | 4925 /** |
| 5291 * Compute a list of the libraries that need to be resolved together in order
to resolve the | 4926 * Compute a list of the libraries that need to be resolved together in orde |
| 5292 * given library. | 4927 * to resolve the given [librarySource]. |
| 5293 * | |
| 5294 * @param librarySource the source of the library to be resolved | |
| 5295 * @throws AnalysisException if the core library cannot be found | |
| 5296 */ | 4928 */ |
| 5297 void computeCycleContaining(Source librarySource) { | 4929 void computeCycleContaining(Source librarySource) { |
| 5298 // | 4930 // |
| 5299 // Create the object representing the library being resolved. | 4931 // Create the object representing the library being resolved. |
| 5300 // | 4932 // |
| 5301 ResolvableLibrary targetLibrary = _createLibrary(librarySource); | 4933 ResolvableLibrary targetLibrary = _createLibrary(librarySource); |
| 5302 // | 4934 // |
| 5303 // Compute the set of libraries that need to be resolved together. | 4935 // Compute the set of libraries that need to be resolved together. |
| 5304 // | 4936 // |
| 5305 _dependencyGraph = new DirectedGraph<ResolvableLibrary>(); | 4937 _dependencyGraph = new DirectedGraph<ResolvableLibrary>(); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5352 if (importedLibrary != null) { | 4984 if (importedLibrary != null) { |
| 5353 if (dependencyList != null) { | 4985 if (dependencyList != null) { |
| 5354 dependencyList.add(importedLibrary); | 4986 dependencyList.add(importedLibrary); |
| 5355 } | 4987 } |
| 5356 _dependencyGraph.addEdge(dependant, importedLibrary); | 4988 _dependencyGraph.addEdge(dependant, importedLibrary); |
| 5357 } | 4989 } |
| 5358 return true; | 4990 return true; |
| 5359 } | 4991 } |
| 5360 | 4992 |
| 5361 /** | 4993 /** |
| 5362 * Recursively traverse the libraries reachable from the given library, creati
ng instances of | 4994 * Recursively traverse the libraries reachable from the given [library], |
| 5363 * the class [Library] to represent them, and record the references in the lib
rary | 4995 * creating instances of the class [Library] to represent them, and record the |
| 5364 * objects. | 4996 * references in the library objects. |
| 5365 * | 4997 * |
| 5366 * @param library the library to be processed to find libraries that have not
yet been traversed | 4998 * Throws an [AnalysisException] if some portion of the library graph could |
| 5367 * @throws AnalysisException if some portion of the library graph could not be
traversed | 4999 * not be traversed. |
| 5368 */ | 5000 */ |
| 5369 void _computeLibraryDependencies(ResolvableLibrary library) { | 5001 void _computeLibraryDependencies(ResolvableLibrary library) { |
| 5370 Source librarySource = library.librarySource; | 5002 Source librarySource = library.librarySource; |
| 5371 DartEntry dartEntry = | 5003 DartEntry dartEntry = |
| 5372 AnalysisContextImpl_this._getReadableDartEntry(librarySource); | 5004 AnalysisContextImpl_this._getReadableDartEntry(librarySource); |
| 5373 List<Source> importedSources = | 5005 List<Source> importedSources = |
| 5374 _getSources(librarySource, dartEntry, DartEntry.IMPORTED_LIBRARIES); | 5006 _getSources(librarySource, dartEntry, DartEntry.IMPORTED_LIBRARIES); |
| 5375 if (_taskData != null) { | 5007 if (_taskData != null) { |
| 5376 return; | 5008 return; |
| 5377 } | 5009 } |
| 5378 List<Source> exportedSources = | 5010 List<Source> exportedSources = |
| 5379 _getSources(librarySource, dartEntry, DartEntry.EXPORTED_LIBRARIES); | 5011 _getSources(librarySource, dartEntry, DartEntry.EXPORTED_LIBRARIES); |
| 5380 if (_taskData != null) { | 5012 if (_taskData != null) { |
| 5381 return; | 5013 return; |
| 5382 } | 5014 } |
| 5383 _computeLibraryDependenciesFromDirectives( | 5015 _computeLibraryDependenciesFromDirectives( |
| 5384 library, importedSources, exportedSources); | 5016 library, importedSources, exportedSources); |
| 5385 } | 5017 } |
| 5386 | 5018 |
| 5387 /** | 5019 /** |
| 5388 * Recursively traverse the libraries reachable from the given library, creati
ng instances of | 5020 * Recursively traverse the libraries reachable from the given [library], |
| 5389 * the class [Library] to represent them, and record the references in the lib
rary | 5021 * creating instances of the class [Library] to represent them, and record the |
| 5390 * objects. | 5022 * references in the library objects. The [importedSources] is a list |
| 5391 * | 5023 * containing the sources that are imported into the given library. The |
| 5392 * @param library the library to be processed to find libraries that have not
yet been traversed | 5024 * [exportedSources] is a list containing the sources that are exported from |
| 5393 * @param importedSources an array containing the sources that are imported in
to the given | 5025 * the given library. |
| 5394 * library | |
| 5395 * @param exportedSources an array containing the sources that are exported fr
om the given | |
| 5396 * library | |
| 5397 */ | 5026 */ |
| 5398 void _computeLibraryDependenciesFromDirectives(ResolvableLibrary library, | 5027 void _computeLibraryDependenciesFromDirectives(ResolvableLibrary library, |
| 5399 List<Source> importedSources, List<Source> exportedSources) { | 5028 List<Source> importedSources, List<Source> exportedSources) { |
| 5400 int importCount = importedSources.length; | 5029 int importCount = importedSources.length; |
| 5401 List<ResolvableLibrary> importedLibraries = new List<ResolvableLibrary>(); | 5030 List<ResolvableLibrary> importedLibraries = new List<ResolvableLibrary>(); |
| 5402 bool explicitlyImportsCore = false; | 5031 bool explicitlyImportsCore = false; |
| 5403 bool importsAsync = false; | 5032 bool importsAsync = false; |
| 5404 for (int i = 0; i < importCount; i++) { | 5033 for (int i = 0; i < importCount; i++) { |
| 5405 Source importedSource = importedSources[i]; | 5034 Source importedSource = importedSources[i]; |
| 5406 if (importedSource == AnalysisContextImpl_this._coreLibrarySource) { | 5035 if (importedSource == AnalysisContextImpl_this._coreLibrarySource) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5443 Source exportedSource = exportedSources[i]; | 5072 Source exportedSource = exportedSources[i]; |
| 5444 if (!_addDependency(library, exportedSource, exportedLibraries)) { | 5073 if (!_addDependency(library, exportedSource, exportedLibraries)) { |
| 5445 return; | 5074 return; |
| 5446 } | 5075 } |
| 5447 } | 5076 } |
| 5448 library.exportedLibraries = exportedLibraries; | 5077 library.exportedLibraries = exportedLibraries; |
| 5449 } | 5078 } |
| 5450 } | 5079 } |
| 5451 | 5080 |
| 5452 /** | 5081 /** |
| 5453 * Gather the resolvable AST structures for each of the compilation units in e
ach of the | 5082 * Gather the resolvable AST structures for each of the compilation units in |
| 5454 * libraries in the cycle. This is done in two phases: first we ensure that we
have cached an | 5083 * each of the libraries in the cycle. This is done in two phases: first we |
| 5455 * AST structure for each compilation unit, then we gather them. We split the
work this way | 5084 * ensure that we have cached an AST structure for each compilation unit, then |
| 5456 * because getting the AST structures can change the state of the cache in suc
h a way that we | 5085 * we gather them. We split the work this way because getting the AST |
| 5457 * would have more work to do if any compilation unit didn't have a resolvable
AST structure. | 5086 * structures can change the state of the cache in such a way that we would |
| 5087 * have more work to do if any compilation unit didn't have a resolvable AST |
| 5088 * structure. |
| 5458 */ | 5089 */ |
| 5459 void _computePartsInCycle(Source librarySource) { | 5090 void _computePartsInCycle(Source librarySource) { |
| 5460 int count = _librariesInCycle.length; | 5091 int count = _librariesInCycle.length; |
| 5461 List<CycleBuilder_LibraryPair> libraryData = | 5092 List<CycleBuilder_LibraryPair> libraryData = |
| 5462 new List<CycleBuilder_LibraryPair>(); | 5093 new List<CycleBuilder_LibraryPair>(); |
| 5463 for (int i = 0; i < count; i++) { | 5094 for (int i = 0; i < count; i++) { |
| 5464 ResolvableLibrary library = _librariesInCycle[i]; | 5095 ResolvableLibrary library = _librariesInCycle[i]; |
| 5465 libraryData.add(new CycleBuilder_LibraryPair( | 5096 libraryData.add(new CycleBuilder_LibraryPair( |
| 5466 library, _ensurePartsInLibrary(library))); | 5097 library, _ensurePartsInLibrary(library))); |
| 5467 } | 5098 } |
| 5468 AnalysisContextImpl_this._neededForResolution = _gatherSources(libraryData); | 5099 AnalysisContextImpl_this._neededForResolution = _gatherSources(libraryData); |
| 5469 if (AnalysisContextImpl._TRACE_PERFORM_TASK) { | 5100 if (AnalysisContextImpl._TRACE_PERFORM_TASK) { |
| 5470 print( | 5101 print( |
| 5471 " preserve resolution data for ${AnalysisContextImpl_this._neededForR
esolution.length} sources while resolving ${librarySource.fullName}"); | 5102 " preserve resolution data for ${AnalysisContextImpl_this._neededForR
esolution.length} sources while resolving ${librarySource.fullName}"); |
| 5472 } | 5103 } |
| 5473 if (_taskData != null) { | 5104 if (_taskData != null) { |
| 5474 return; | 5105 return; |
| 5475 } | 5106 } |
| 5476 for (int i = 0; i < count; i++) { | 5107 for (int i = 0; i < count; i++) { |
| 5477 _computePartsInLibrary(libraryData[i]); | 5108 _computePartsInLibrary(libraryData[i]); |
| 5478 } | 5109 } |
| 5479 } | 5110 } |
| 5480 | 5111 |
| 5481 /** | 5112 /** |
| 5482 * Gather the resolvable compilation units for each of the compilation units i
n the specified | 5113 * Gather the resolvable compilation units for each of the compilation units |
| 5483 * library. | 5114 * in the library represented by the [libraryPair]. |
| 5484 * | |
| 5485 * @param libraryPair a holder containing both the library and a list of (sour
ce, entry) pairs | |
| 5486 * for all of the compilation units in the library | |
| 5487 */ | 5115 */ |
| 5488 void _computePartsInLibrary(CycleBuilder_LibraryPair libraryPair) { | 5116 void _computePartsInLibrary(CycleBuilder_LibraryPair libraryPair) { |
| 5489 ResolvableLibrary library = libraryPair.library; | 5117 ResolvableLibrary library = libraryPair.library; |
| 5490 List<CycleBuilder_SourceEntryPair> entryPairs = libraryPair.entryPairs; | 5118 List<CycleBuilder_SourceEntryPair> entryPairs = libraryPair.entryPairs; |
| 5491 int count = entryPairs.length; | 5119 int count = entryPairs.length; |
| 5492 List<ResolvableCompilationUnit> units = | 5120 List<ResolvableCompilationUnit> units = |
| 5493 new List<ResolvableCompilationUnit>(count); | 5121 new List<ResolvableCompilationUnit>(count); |
| 5494 for (int i = 0; i < count; i++) { | 5122 for (int i = 0; i < count; i++) { |
| 5495 CycleBuilder_SourceEntryPair entryPair = entryPairs[i]; | 5123 CycleBuilder_SourceEntryPair entryPair = entryPairs[i]; |
| 5496 Source source = entryPair.source; | 5124 Source source = entryPair.source; |
| 5497 DartEntry dartEntry = entryPair.entry; | 5125 DartEntry dartEntry = entryPair.entry; |
| 5498 units[i] = new ResolvableCompilationUnit( | 5126 units[i] = new ResolvableCompilationUnit( |
| 5499 source, dartEntry.resolvableCompilationUnit); | 5127 source, dartEntry.resolvableCompilationUnit); |
| 5500 } | 5128 } |
| 5501 library.resolvableCompilationUnits = units; | 5129 library.resolvableCompilationUnits = units; |
| 5502 } | 5130 } |
| 5503 | 5131 |
| 5504 /** | 5132 /** |
| 5505 * Create an object to represent the information about the library defined by
the compilation | 5133 * Create an object to represent the information about the library defined by |
| 5506 * unit with the given source. | 5134 * the compilation unit with the given [librarySource]. |
| 5507 * | |
| 5508 * @param librarySource the source of the library's defining compilation unit | |
| 5509 * @return the library object that was created | |
| 5510 */ | 5135 */ |
| 5511 ResolvableLibrary _createLibrary(Source librarySource) { | 5136 ResolvableLibrary _createLibrary(Source librarySource) { |
| 5512 ResolvableLibrary library = new ResolvableLibrary(librarySource); | 5137 ResolvableLibrary library = new ResolvableLibrary(librarySource); |
| 5513 SourceEntry sourceEntry = | 5138 SourceEntry sourceEntry = |
| 5514 AnalysisContextImpl_this._cache.get(librarySource); | 5139 AnalysisContextImpl_this._cache.get(librarySource); |
| 5515 if (sourceEntry is DartEntry) { | 5140 if (sourceEntry is DartEntry) { |
| 5516 LibraryElementImpl libraryElement = | 5141 LibraryElementImpl libraryElement = |
| 5517 sourceEntry.getValue(DartEntry.ELEMENT) as LibraryElementImpl; | 5142 sourceEntry.getValue(DartEntry.ELEMENT) as LibraryElementImpl; |
| 5518 if (libraryElement != null) { | 5143 if (libraryElement != null) { |
| 5519 library.libraryElement = libraryElement; | 5144 library.libraryElement = libraryElement; |
| 5520 } | 5145 } |
| 5521 } | 5146 } |
| 5522 _libraryMap[librarySource] = library; | 5147 _libraryMap[librarySource] = library; |
| 5523 return library; | 5148 return library; |
| 5524 } | 5149 } |
| 5525 | 5150 |
| 5526 /** | 5151 /** |
| 5527 * Create an object to represent the information about the library defined by
the compilation | 5152 * Create an object to represent the information about the library defined by |
| 5528 * unit with the given source. | 5153 * the compilation unit with the given [librarySource]. |
| 5529 * | |
| 5530 * @param librarySource the source of the library's defining compilation unit | |
| 5531 * @return the library object that was created | |
| 5532 */ | 5154 */ |
| 5533 ResolvableLibrary _createLibraryOrNull(Source librarySource) { | 5155 ResolvableLibrary _createLibraryOrNull(Source librarySource) { |
| 5534 ResolvableLibrary library = new ResolvableLibrary(librarySource); | 5156 ResolvableLibrary library = new ResolvableLibrary(librarySource); |
| 5535 SourceEntry sourceEntry = | 5157 SourceEntry sourceEntry = |
| 5536 AnalysisContextImpl_this._cache.get(librarySource); | 5158 AnalysisContextImpl_this._cache.get(librarySource); |
| 5537 if (sourceEntry is DartEntry) { | 5159 if (sourceEntry is DartEntry) { |
| 5538 LibraryElementImpl libraryElement = | 5160 LibraryElementImpl libraryElement = |
| 5539 sourceEntry.getValue(DartEntry.ELEMENT) as LibraryElementImpl; | 5161 sourceEntry.getValue(DartEntry.ELEMENT) as LibraryElementImpl; |
| 5540 if (libraryElement != null) { | 5162 if (libraryElement != null) { |
| 5541 library.libraryElement = libraryElement; | 5163 library.libraryElement = libraryElement; |
| 5542 } | 5164 } |
| 5543 } | 5165 } |
| 5544 _libraryMap[librarySource] = library; | 5166 _libraryMap[librarySource] = library; |
| 5545 return library; | 5167 return library; |
| 5546 } | 5168 } |
| 5547 | 5169 |
| 5548 /** | 5170 /** |
| 5549 * Ensure that the given library has an element model built for it. If another
task needs to be | 5171 * Ensure that the given [library] has an element model built for it. If |
| 5550 * executed first in order to build the element model, that task is placed in
[taskData]. | 5172 * another task needs to be executed first in order to build the element |
| 5551 * | 5173 * model, that task is placed in [taskData]. |
| 5552 * @param library the library which needs an element model. | |
| 5553 */ | 5174 */ |
| 5554 void _ensureElementModel(ResolvableLibrary library) { | 5175 void _ensureElementModel(ResolvableLibrary library) { |
| 5555 Source librarySource = library.librarySource; | 5176 Source librarySource = library.librarySource; |
| 5556 DartEntry libraryEntry = | 5177 DartEntry libraryEntry = |
| 5557 AnalysisContextImpl_this._getReadableDartEntry(librarySource); | 5178 AnalysisContextImpl_this._getReadableDartEntry(librarySource); |
| 5558 if (libraryEntry != null && | 5179 if (libraryEntry != null && |
| 5559 libraryEntry.getState(DartEntry.PARSED_UNIT) != CacheState.ERROR) { | 5180 libraryEntry.getState(DartEntry.PARSED_UNIT) != CacheState.ERROR) { |
| 5560 AnalysisContextImpl_this._workManager.addFirst( | 5181 AnalysisContextImpl_this._workManager.addFirst( |
| 5561 librarySource, SourcePriority.LIBRARY); | 5182 librarySource, SourcePriority.LIBRARY); |
| 5562 if (_taskData == null) { | 5183 if (_taskData == null) { |
| 5563 _taskData = AnalysisContextImpl_this._createResolveDartLibraryTask( | 5184 _taskData = AnalysisContextImpl_this._createResolveDartLibraryTask( |
| 5564 librarySource, libraryEntry); | 5185 librarySource, libraryEntry); |
| 5565 } | 5186 } |
| 5566 } | 5187 } |
| 5567 } | 5188 } |
| 5568 | 5189 |
| 5569 /** | 5190 /** |
| 5570 * Ensure that all of the libraries that are exported by the given library (bu
t are not | 5191 * Ensure that all of the libraries that are exported by the given [library] |
| 5571 * themselves in the cycle) have element models built for them. If another tas
k needs to be | 5192 * (but are not themselves in the cycle) have element models built for them. |
| 5572 * executed first in order to build the element model, that task is placed in
[taskData]. | 5193 * If another task needs to be executed first in order to build the element |
| 5573 * | 5194 * model, that task is placed in [taskData]. |
| 5574 * @param library the library being tested | |
| 5575 */ | 5195 */ |
| 5576 void _ensureExports( | 5196 void _ensureExports( |
| 5577 ResolvableLibrary library, HashSet<Source> visitedLibraries) { | 5197 ResolvableLibrary library, HashSet<Source> visitedLibraries) { |
| 5578 List<ResolvableLibrary> dependencies = library.exports; | 5198 List<ResolvableLibrary> dependencies = library.exports; |
| 5579 int dependencyCount = dependencies.length; | 5199 int dependencyCount = dependencies.length; |
| 5580 for (int i = 0; i < dependencyCount; i++) { | 5200 for (int i = 0; i < dependencyCount; i++) { |
| 5581 ResolvableLibrary dependency = dependencies[i]; | 5201 ResolvableLibrary dependency = dependencies[i]; |
| 5582 if (!_librariesInCycle.contains(dependency) && | 5202 if (!_librariesInCycle.contains(dependency) && |
| 5583 visitedLibraries.add(dependency.librarySource)) { | 5203 visitedLibraries.add(dependency.librarySource)) { |
| 5584 if (dependency.libraryElement == null) { | 5204 if (dependency.libraryElement == null) { |
| 5585 _ensureElementModel(dependency); | 5205 _ensureElementModel(dependency); |
| 5586 } else { | 5206 } else { |
| 5587 _ensureExports(dependency, visitedLibraries); | 5207 _ensureExports(dependency, visitedLibraries); |
| 5588 } | 5208 } |
| 5589 if (_taskData != null) { | 5209 if (_taskData != null) { |
| 5590 return; | 5210 return; |
| 5591 } | 5211 } |
| 5592 } | 5212 } |
| 5593 } | 5213 } |
| 5594 } | 5214 } |
| 5595 | 5215 |
| 5596 /** | 5216 /** |
| 5597 * Ensure that all of the libraries that are exported by the given library (bu
t are not | 5217 * Ensure that all of the libraries that are exported by the given [library] |
| 5598 * themselves in the cycle) have element models built for them. If another tas
k needs to be | 5218 * (but are not themselves in the cycle) have element models built for them. |
| 5599 * executed first in order to build the element model, that task is placed in
[taskData]. | 5219 * If another task needs to be executed first in order to build the element |
| 5600 * | 5220 * model, that task is placed in [taskData]. |
| 5601 * @param library the library being tested | |
| 5602 */ | 5221 */ |
| 5603 void _ensureImports(ResolvableLibrary library) { | 5222 void _ensureImports(ResolvableLibrary library) { |
| 5604 List<ResolvableLibrary> dependencies = library.imports; | 5223 List<ResolvableLibrary> dependencies = library.imports; |
| 5605 int dependencyCount = dependencies.length; | 5224 int dependencyCount = dependencies.length; |
| 5606 for (int i = 0; i < dependencyCount; i++) { | 5225 for (int i = 0; i < dependencyCount; i++) { |
| 5607 ResolvableLibrary dependency = dependencies[i]; | 5226 ResolvableLibrary dependency = dependencies[i]; |
| 5608 if (!_librariesInCycle.contains(dependency) && | 5227 if (!_librariesInCycle.contains(dependency) && |
| 5609 dependency.libraryElement == null) { | 5228 dependency.libraryElement == null) { |
| 5610 _ensureElementModel(dependency); | 5229 _ensureElementModel(dependency); |
| 5611 if (_taskData != null) { | 5230 if (_taskData != null) { |
| 5612 return; | 5231 return; |
| 5613 } | 5232 } |
| 5614 } | 5233 } |
| 5615 } | 5234 } |
| 5616 } | 5235 } |
| 5617 | 5236 |
| 5618 /** | 5237 /** |
| 5619 * Ensure that all of the libraries that are either imported or exported by li
braries in the | 5238 * Ensure that all of the libraries that are either imported or exported by |
| 5620 * cycle (but are not themselves in the cycle) have element models built for t
hem. | 5239 * libraries in the cycle (but are not themselves in the cycle) have element |
| 5240 * models built for them. |
| 5621 */ | 5241 */ |
| 5622 void _ensureImportsAndExports() { | 5242 void _ensureImportsAndExports() { |
| 5623 HashSet<Source> visitedLibraries = new HashSet<Source>(); | 5243 HashSet<Source> visitedLibraries = new HashSet<Source>(); |
| 5624 int libraryCount = _librariesInCycle.length; | 5244 int libraryCount = _librariesInCycle.length; |
| 5625 for (int i = 0; i < libraryCount; i++) { | 5245 for (int i = 0; i < libraryCount; i++) { |
| 5626 ResolvableLibrary library = _librariesInCycle[i]; | 5246 ResolvableLibrary library = _librariesInCycle[i]; |
| 5627 _ensureImports(library); | 5247 _ensureImports(library); |
| 5628 if (_taskData != null) { | 5248 if (_taskData != null) { |
| 5629 return; | 5249 return; |
| 5630 } | 5250 } |
| 5631 _ensureExports(library, visitedLibraries); | 5251 _ensureExports(library, visitedLibraries); |
| 5632 if (_taskData != null) { | 5252 if (_taskData != null) { |
| 5633 return; | 5253 return; |
| 5634 } | 5254 } |
| 5635 } | 5255 } |
| 5636 } | 5256 } |
| 5637 | 5257 |
| 5638 /** | 5258 /** |
| 5639 * Ensure that there is a resolvable compilation unit available for all of the
compilation units | 5259 * Ensure that there is a resolvable compilation unit available for all of the |
| 5640 * in the given library. | 5260 * compilation units in the given [library]. |
| 5641 * | |
| 5642 * @param library the library for which resolvable compilation units must be a
vailable | |
| 5643 * @return a list of (source, entry) pairs for all of the compilation units in
the library | |
| 5644 */ | 5261 */ |
| 5645 List<CycleBuilder_SourceEntryPair> _ensurePartsInLibrary( | 5262 List<CycleBuilder_SourceEntryPair> _ensurePartsInLibrary( |
| 5646 ResolvableLibrary library) { | 5263 ResolvableLibrary library) { |
| 5647 List<CycleBuilder_SourceEntryPair> pairs = | 5264 List<CycleBuilder_SourceEntryPair> pairs = |
| 5648 new List<CycleBuilder_SourceEntryPair>(); | 5265 new List<CycleBuilder_SourceEntryPair>(); |
| 5649 Source librarySource = library.librarySource; | 5266 Source librarySource = library.librarySource; |
| 5650 DartEntry libraryEntry = | 5267 DartEntry libraryEntry = |
| 5651 AnalysisContextImpl_this._getReadableDartEntry(librarySource); | 5268 AnalysisContextImpl_this._getReadableDartEntry(librarySource); |
| 5652 if (libraryEntry == null) { | 5269 if (libraryEntry == null) { |
| 5653 throw new AnalysisException( | 5270 throw new AnalysisException( |
| (...skipping 21 matching lines...) Expand all Loading... |
| 5675 if (partEntry != null && | 5292 if (partEntry != null && |
| 5676 partEntry.getState(DartEntry.PARSED_UNIT) != CacheState.ERROR) { | 5293 partEntry.getState(DartEntry.PARSED_UNIT) != CacheState.ERROR) { |
| 5677 _ensureResolvableCompilationUnit(partSource, partEntry); | 5294 _ensureResolvableCompilationUnit(partSource, partEntry); |
| 5678 pairs.add(new CycleBuilder_SourceEntryPair(partSource, partEntry)); | 5295 pairs.add(new CycleBuilder_SourceEntryPair(partSource, partEntry)); |
| 5679 } | 5296 } |
| 5680 } | 5297 } |
| 5681 return pairs; | 5298 return pairs; |
| 5682 } | 5299 } |
| 5683 | 5300 |
| 5684 /** | 5301 /** |
| 5685 * Ensure that there is a resolvable compilation unit available for the given
source. | 5302 * Ensure that there is a resolvable compilation unit available for the given |
| 5686 * | 5303 * [source]. |
| 5687 * @param source the source for which a resolvable compilation unit must be av
ailable | |
| 5688 * @param dartEntry the entry associated with the source | |
| 5689 */ | 5304 */ |
| 5690 void _ensureResolvableCompilationUnit(Source source, DartEntry dartEntry) { | 5305 void _ensureResolvableCompilationUnit(Source source, DartEntry dartEntry) { |
| 5691 // The entry will be null if the source represents a non-Dart file. | 5306 // The entry will be null if the source represents a non-Dart file. |
| 5692 if (dartEntry != null && !dartEntry.hasResolvableCompilationUnit) { | 5307 if (dartEntry != null && !dartEntry.hasResolvableCompilationUnit) { |
| 5693 if (_taskData == null) { | 5308 if (_taskData == null) { |
| 5694 _taskData = | 5309 _taskData = |
| 5695 AnalysisContextImpl_this._createParseDartTask(source, dartEntry); | 5310 AnalysisContextImpl_this._createParseDartTask(source, dartEntry); |
| 5696 } | 5311 } |
| 5697 } | 5312 } |
| 5698 } | 5313 } |
| 5699 | 5314 |
| 5700 HashSet<Source> _gatherSources(List<CycleBuilder_LibraryPair> libraryData) { | 5315 HashSet<Source> _gatherSources(List<CycleBuilder_LibraryPair> libraryData) { |
| 5701 int libraryCount = libraryData.length; | 5316 int libraryCount = libraryData.length; |
| 5702 HashSet<Source> sources = new HashSet<Source>(); | 5317 HashSet<Source> sources = new HashSet<Source>(); |
| 5703 for (int i = 0; i < libraryCount; i++) { | 5318 for (int i = 0; i < libraryCount; i++) { |
| 5704 List<CycleBuilder_SourceEntryPair> entryPairs = libraryData[i].entryPairs; | 5319 List<CycleBuilder_SourceEntryPair> entryPairs = libraryData[i].entryPairs; |
| 5705 int entryCount = entryPairs.length; | 5320 int entryCount = entryPairs.length; |
| 5706 for (int j = 0; j < entryCount; j++) { | 5321 for (int j = 0; j < entryCount; j++) { |
| 5707 sources.add(entryPairs[j].source); | 5322 sources.add(entryPairs[j].source); |
| 5708 } | 5323 } |
| 5709 } | 5324 } |
| 5710 return sources; | 5325 return sources; |
| 5711 } | 5326 } |
| 5712 | 5327 |
| 5713 /** | 5328 /** |
| 5714 * Return the sources described by the given descriptor. | 5329 * Return the sources described by the given [descriptor]. |
| 5715 * | |
| 5716 * @param source the source with which the sources are associated | |
| 5717 * @param dartEntry the entry corresponding to the source | |
| 5718 * @param descriptor the descriptor indicating which sources are to be returne
d | |
| 5719 * @return the sources described by the given descriptor | |
| 5720 */ | 5330 */ |
| 5721 List<Source> _getSources(Source source, DartEntry dartEntry, | 5331 List<Source> _getSources(Source source, DartEntry dartEntry, |
| 5722 DataDescriptor<List<Source>> descriptor) { | 5332 DataDescriptor<List<Source>> descriptor) { |
| 5723 if (dartEntry == null) { | 5333 if (dartEntry == null) { |
| 5724 return Source.EMPTY_ARRAY; | 5334 return Source.EMPTY_ARRAY; |
| 5725 } | 5335 } |
| 5726 CacheState exportState = dartEntry.getState(descriptor); | 5336 CacheState exportState = dartEntry.getState(descriptor); |
| 5727 if (exportState == CacheState.ERROR) { | 5337 if (exportState == CacheState.ERROR) { |
| 5728 return Source.EMPTY_ARRAY; | 5338 return Source.EMPTY_ARRAY; |
| 5729 } else if (exportState != CacheState.VALID) { | 5339 } else if (exportState != CacheState.VALID) { |
| 5730 if (_taskData == null) { | 5340 if (_taskData == null) { |
| 5731 _taskData = | 5341 _taskData = |
| 5732 AnalysisContextImpl_this._createParseDartTask(source, dartEntry); | 5342 AnalysisContextImpl_this._createParseDartTask(source, dartEntry); |
| 5733 } | 5343 } |
| 5734 return Source.EMPTY_ARRAY; | 5344 return Source.EMPTY_ARRAY; |
| 5735 } | 5345 } |
| 5736 return dartEntry.getValue(descriptor); | 5346 return dartEntry.getValue(descriptor); |
| 5737 } | 5347 } |
| 5738 } | 5348 } |
| 5739 | 5349 |
| 5740 /** | 5350 /** |
| 5741 * Instances of the class `TaskData` represent information about the next task t
o be | 5351 * Information about the next task to be performed. Each data has an implicit |
| 5742 * performed. Each data has an implicit associated source: the source that might
need to be | 5352 * associated source: the source that might need to be analyzed. There are |
| 5743 * analyzed. There are essentially three states that can be represented: | 5353 * essentially three states that can be represented: |
| 5354 * |
| 5744 * * If [getTask] returns a non-`null` value, then that is the task that should | 5355 * * If [getTask] returns a non-`null` value, then that is the task that should |
| 5745 * be executed to further analyze the associated source. | 5356 * be executed to further analyze the associated source. |
| 5746 * * Otherwise, if [isBlocked] returns `true`, then there is no work that can be | 5357 * * Otherwise, if [isBlocked] returns `true`, then there is no work that can be |
| 5747 * done, but analysis for the associated source is not complete. | 5358 * done, but analysis for the associated source is not complete. |
| 5748 * * Otherwise, [getDependentSource] should return a source that needs to be ana
lyzed | 5359 * * Otherwise, [getDependentSource] should return a source that needs to be |
| 5749 * before the analysis of the associated source can be completed. | 5360 * analyzed before the analysis of the associated source can be completed. |
| 5750 */ | 5361 */ |
| 5751 class AnalysisContextImpl_TaskData { | 5362 class AnalysisContextImpl_TaskData { |
| 5752 /** | 5363 /** |
| 5753 * The task that is to be performed. | 5364 * The task that is to be performed. |
| 5754 */ | 5365 */ |
| 5755 final AnalysisTask task; | 5366 final AnalysisTask task; |
| 5756 | 5367 |
| 5757 /** | 5368 /** |
| 5758 * A flag indicating whether the associated source is blocked waiting for its
contents to be | 5369 * A flag indicating whether the associated source is blocked waiting for its |
| 5759 * loaded. | 5370 * contents to be loaded. |
| 5760 */ | 5371 */ |
| 5761 final bool _blocked; | 5372 final bool _blocked; |
| 5762 | 5373 |
| 5763 /** | 5374 /** |
| 5764 * Initialize a newly created data holder. | 5375 * Initialize a newly created data holder. |
| 5765 * | |
| 5766 * @param task the task that is to be performed | |
| 5767 * @param blocked `true` if the associated source is blocked waiting for its c
ontents to | |
| 5768 * be loaded | |
| 5769 */ | 5376 */ |
| 5770 AnalysisContextImpl_TaskData(this.task, this._blocked); | 5377 AnalysisContextImpl_TaskData(this.task, this._blocked); |
| 5771 | 5378 |
| 5772 /** | 5379 /** |
| 5773 * Return `true` if the associated source is blocked waiting for its contents
to be | 5380 * Return `true` if the associated source is blocked waiting for its contents |
| 5774 * loaded. | 5381 * to be loaded. |
| 5775 * | |
| 5776 * @return `true` if the associated source is blocked waiting for its contents
to be | |
| 5777 * loaded | |
| 5778 */ | 5382 */ |
| 5779 bool get isBlocked => _blocked; | 5383 bool get isBlocked => _blocked; |
| 5780 | 5384 |
| 5781 @override | 5385 @override |
| 5782 String toString() { | 5386 String toString() { |
| 5783 if (task == null) { | 5387 if (task == null) { |
| 5784 return "blocked: $_blocked"; | 5388 return "blocked: $_blocked"; |
| 5785 } | 5389 } |
| 5786 return task.toString(); | 5390 return task.toString(); |
| 5787 } | 5391 } |
| 5788 } | 5392 } |
| 5789 | 5393 |
| 5790 /** | 5394 /** |
| 5791 * The interface `AnalysisContextStatistics` defines access to statistics about
a single | 5395 * Statistics and information about a single [AnalysisContext]. |
| 5792 * [AnalysisContext]. | |
| 5793 */ | 5396 */ |
| 5794 abstract class AnalysisContextStatistics { | 5397 abstract class AnalysisContextStatistics { |
| 5795 /** | 5398 /** |
| 5796 * Return the statistics for each kind of cached data. | 5399 * Return the statistics for each kind of cached data. |
| 5797 */ | 5400 */ |
| 5798 List<AnalysisContextStatistics_CacheRow> get cacheRows; | 5401 List<AnalysisContextStatistics_CacheRow> get cacheRows; |
| 5799 | 5402 |
| 5800 /** | 5403 /** |
| 5801 * Return the exceptions that caused some entries to have a state of [CacheSta
te.ERROR]. | 5404 * Return the exceptions that caused some entries to have a state of |
| 5405 * [CacheState.ERROR]. |
| 5802 */ | 5406 */ |
| 5803 List<CaughtException> get exceptions; | 5407 List<CaughtException> get exceptions; |
| 5804 | 5408 |
| 5805 /** | 5409 /** |
| 5806 * Return information about each of the partitions in the cache. | 5410 * Return information about each of the partitions in the cache. |
| 5807 */ | 5411 */ |
| 5808 List<AnalysisContextStatistics_PartitionData> get partitionData; | 5412 List<AnalysisContextStatistics_PartitionData> get partitionData; |
| 5809 | 5413 |
| 5810 /** | 5414 /** |
| 5811 * Return an array containing all of the sources in the cache. | 5415 * Return a list containing all of the sources in the cache. |
| 5812 */ | 5416 */ |
| 5813 List<Source> get sources; | 5417 List<Source> get sources; |
| 5814 } | 5418 } |
| 5815 | 5419 |
| 5816 /** | 5420 /** |
| 5817 * Information about single piece of data in the cache. | 5421 * Information about single piece of data in the cache. |
| 5818 */ | 5422 */ |
| 5819 abstract class AnalysisContextStatistics_CacheRow { | 5423 abstract class AnalysisContextStatistics_CacheRow { |
| 5820 /** | 5424 /** |
| 5821 * List of possible states which can be queried. | 5425 * List of possible states which can be queried. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5862 * Return the number of entries whose state is [state]. | 5466 * Return the number of entries whose state is [state]. |
| 5863 */ | 5467 */ |
| 5864 int getCount(CacheState state); | 5468 int getCount(CacheState state); |
| 5865 } | 5469 } |
| 5866 | 5470 |
| 5867 /** | 5471 /** |
| 5868 * Information about a single partition in the cache. | 5472 * Information about a single partition in the cache. |
| 5869 */ | 5473 */ |
| 5870 abstract class AnalysisContextStatistics_PartitionData { | 5474 abstract class AnalysisContextStatistics_PartitionData { |
| 5871 /** | 5475 /** |
| 5872 * Return the number of entries in the partition that have an AST structure in
one state or | 5476 * Return the number of entries in the partition that have an AST structure in |
| 5873 * another. | 5477 * one state or another. |
| 5874 */ | 5478 */ |
| 5875 int get astCount; | 5479 int get astCount; |
| 5876 | 5480 |
| 5877 /** | 5481 /** |
| 5878 * Return the total number of entries in the partition. | 5482 * Return the total number of entries in the partition. |
| 5879 */ | 5483 */ |
| 5880 int get totalCount; | 5484 int get totalCount; |
| 5881 } | 5485 } |
| 5882 | 5486 |
| 5883 /** | 5487 /** |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5990 implements AnalysisContextStatistics_PartitionData { | 5594 implements AnalysisContextStatistics_PartitionData { |
| 5991 final int astCount; | 5595 final int astCount; |
| 5992 | 5596 |
| 5993 final int totalCount; | 5597 final int totalCount; |
| 5994 | 5598 |
| 5995 AnalysisContextStatisticsImpl_PartitionDataImpl( | 5599 AnalysisContextStatisticsImpl_PartitionDataImpl( |
| 5996 this.astCount, this.totalCount); | 5600 this.astCount, this.totalCount); |
| 5997 } | 5601 } |
| 5998 | 5602 |
| 5999 /** | 5603 /** |
| 6000 * Instances of the class `AnalysisDelta` indicate changes to the types of analy
sis that | 5604 * A representation of changes to the types of analysis that should be |
| 6001 * should be performed. | 5605 * performed. |
| 6002 */ | 5606 */ |
| 6003 class AnalysisDelta { | 5607 class AnalysisDelta { |
| 6004 /** | 5608 /** |
| 6005 * A mapping from source to what type of analysis should be performed on that
source. | 5609 * A mapping from source to what type of analysis should be performed on that |
| 5610 * source. |
| 6006 */ | 5611 */ |
| 6007 HashMap<Source, AnalysisLevel> _analysisMap = | 5612 HashMap<Source, AnalysisLevel> _analysisMap = |
| 6008 new HashMap<Source, AnalysisLevel>(); | 5613 new HashMap<Source, AnalysisLevel>(); |
| 6009 | 5614 |
| 6010 /** | 5615 /** |
| 6011 * Return a collection of the sources that have been added. This is equivalent
to calling | 5616 * Return a collection of the sources that have been added. This is equivalent |
| 6012 * [getAnalysisLevels] and collecting all sources that do not have an analysis
level of | 5617 * to calling [getAnalysisLevels] and collecting all sources that do not have |
| 6013 * [AnalysisLevel.NONE]. | 5618 * an analysis level of [AnalysisLevel.NONE]. |
| 6014 * | |
| 6015 * @return a collection of the sources | |
| 6016 */ | 5619 */ |
| 6017 List<Source> get addedSources { | 5620 List<Source> get addedSources { |
| 6018 List<Source> result = new List<Source>(); | 5621 List<Source> result = new List<Source>(); |
| 6019 _analysisMap.forEach((Source source, AnalysisLevel level) { | 5622 _analysisMap.forEach((Source source, AnalysisLevel level) { |
| 6020 if (level != AnalysisLevel.NONE) { | 5623 if (level != AnalysisLevel.NONE) { |
| 6021 result.add(source); | 5624 result.add(source); |
| 6022 } | 5625 } |
| 6023 }); | 5626 }); |
| 6024 return result; | 5627 return result; |
| 6025 } | 5628 } |
| 6026 | 5629 |
| 6027 /** | 5630 /** |
| 6028 * Return a mapping of sources to the level of analysis that should be perform
ed. | 5631 * Return a mapping of sources to the level of analysis that should be |
| 6029 * | 5632 * performed. |
| 6030 * @return the analysis map | |
| 6031 */ | 5633 */ |
| 6032 Map<Source, AnalysisLevel> get analysisLevels => _analysisMap; | 5634 Map<Source, AnalysisLevel> get analysisLevels => _analysisMap; |
| 6033 | 5635 |
| 6034 /** | 5636 /** |
| 6035 * Record that the specified source should be analyzed at the specified level. | 5637 * Record that the given [source] should be analyzed at the given [level]. |
| 6036 * | |
| 6037 * @param source the source | |
| 6038 * @param level the level at which the given source should be analyzed | |
| 6039 */ | 5638 */ |
| 6040 void setAnalysisLevel(Source source, AnalysisLevel level) { | 5639 void setAnalysisLevel(Source source, AnalysisLevel level) { |
| 6041 _analysisMap[source] = level; | 5640 _analysisMap[source] = level; |
| 6042 } | 5641 } |
| 6043 | 5642 |
| 6044 @override | 5643 @override |
| 6045 String toString() { | 5644 String toString() { |
| 6046 StringBuffer buffer = new StringBuffer(); | 5645 StringBuffer buffer = new StringBuffer(); |
| 6047 bool needsSeparator = _appendSources(buffer, false, AnalysisLevel.ALL); | 5646 bool needsSeparator = _appendSources(buffer, false, AnalysisLevel.ALL); |
| 6048 needsSeparator = | 5647 needsSeparator = |
| 6049 _appendSources(buffer, needsSeparator, AnalysisLevel.RESOLVED); | 5648 _appendSources(buffer, needsSeparator, AnalysisLevel.RESOLVED); |
| 6050 _appendSources(buffer, needsSeparator, AnalysisLevel.NONE); | 5649 _appendSources(buffer, needsSeparator, AnalysisLevel.NONE); |
| 6051 return buffer.toString(); | 5650 return buffer.toString(); |
| 6052 } | 5651 } |
| 6053 | 5652 |
| 6054 /** | 5653 /** |
| 6055 * Appendto the given [builder] all sources with the given analysis [level], | 5654 * Appendto the given [buffer] all sources with the given analysis [level], |
| 6056 * prefixed with a label and a separator if [needsSeparator] is `true`. | 5655 * prefixed with a label and a separator if [needsSeparator] is `true`. |
| 6057 */ | 5656 */ |
| 6058 bool _appendSources( | 5657 bool _appendSources( |
| 6059 StringBuffer buffer, bool needsSeparator, AnalysisLevel level) { | 5658 StringBuffer buffer, bool needsSeparator, AnalysisLevel level) { |
| 6060 bool first = true; | 5659 bool first = true; |
| 6061 _analysisMap.forEach((Source source, AnalysisLevel sourceLevel) { | 5660 _analysisMap.forEach((Source source, AnalysisLevel sourceLevel) { |
| 6062 if (sourceLevel == level) { | 5661 if (sourceLevel == level) { |
| 6063 if (first) { | 5662 if (first) { |
| 6064 first = false; | 5663 first = false; |
| 6065 if (needsSeparator) { | 5664 if (needsSeparator) { |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6204 if (fileName == null) { | 5803 if (fileName == null) { |
| 6205 return false; | 5804 return false; |
| 6206 } | 5805 } |
| 6207 String extension = FileNameUtilities.getExtension(fileName); | 5806 String extension = FileNameUtilities.getExtension(fileName); |
| 6208 return javaStringEqualsIgnoreCase(extension, SUFFIX_HTML) || | 5807 return javaStringEqualsIgnoreCase(extension, SUFFIX_HTML) || |
| 6209 javaStringEqualsIgnoreCase(extension, SUFFIX_HTM); | 5808 javaStringEqualsIgnoreCase(extension, SUFFIX_HTM); |
| 6210 } | 5809 } |
| 6211 } | 5810 } |
| 6212 | 5811 |
| 6213 /** | 5812 /** |
| 6214 * The interface `AnalysisErrorInfo` contains the analysis errors and line infor
mation for the | 5813 * The analysis errors and line information for the errors. |
| 6215 * errors. | |
| 6216 */ | 5814 */ |
| 6217 abstract class AnalysisErrorInfo { | 5815 abstract class AnalysisErrorInfo { |
| 6218 /** | 5816 /** |
| 6219 * Return the errors that as a result of the analysis, or `null` if there were
no errors. | 5817 * Return the errors that as a result of the analysis, or `null` if there were |
| 6220 * | 5818 * no errors. |
| 6221 * @return the errors as a result of the analysis | |
| 6222 */ | 5819 */ |
| 6223 List<AnalysisError> get errors; | 5820 List<AnalysisError> get errors; |
| 6224 | 5821 |
| 6225 /** | 5822 /** |
| 6226 * Return the line information associated with the errors, or `null` if there
were no | 5823 * Return the line information associated with the errors, or `null` if there |
| 6227 * errors. | 5824 * were no errors. |
| 6228 * | |
| 6229 * @return the line information associated with the errors | |
| 6230 */ | 5825 */ |
| 6231 LineInfo get lineInfo; | 5826 LineInfo get lineInfo; |
| 6232 } | 5827 } |
| 6233 | 5828 |
| 6234 /** | 5829 /** |
| 6235 * Instances of the class `AnalysisErrorInfoImpl` represent the analysis errors
and line info | 5830 * The analysis errors and line info associated with a source. |
| 6236 * associated with a source. | |
| 6237 */ | 5831 */ |
| 6238 class AnalysisErrorInfoImpl implements AnalysisErrorInfo { | 5832 class AnalysisErrorInfoImpl implements AnalysisErrorInfo { |
| 6239 /** | 5833 /** |
| 6240 * The analysis errors associated with a source, or `null` if there are no err
ors. | 5834 * The analysis errors associated with a source, or `null` if there are no |
| 5835 * errors. |
| 6241 */ | 5836 */ |
| 6242 final List<AnalysisError> errors; | 5837 final List<AnalysisError> errors; |
| 6243 | 5838 |
| 6244 /** | 5839 /** |
| 6245 * The line information associated with the errors, or `null` if there are no
errors. | 5840 * The line information associated with the errors, or `null` if there are no |
| 5841 * errors. |
| 6246 */ | 5842 */ |
| 6247 final LineInfo lineInfo; | 5843 final LineInfo lineInfo; |
| 6248 | 5844 |
| 6249 /** | 5845 /** |
| 6250 * Initialize an newly created error info with the errors and line information | 5846 * Initialize an newly created error info with the given [errors] and |
| 6251 * | 5847 * [lineInfo]. |
| 6252 * @param errors the errors as a result of analysis | |
| 6253 * @param lineinfo the line info for the errors | |
| 6254 */ | 5848 */ |
| 6255 AnalysisErrorInfoImpl(this.errors, this.lineInfo); | 5849 AnalysisErrorInfoImpl(this.errors, this.lineInfo); |
| 6256 } | 5850 } |
| 6257 | 5851 |
| 6258 /** | 5852 /** |
| 6259 * The enumeration `AnalysisLevel` encodes the different levels at which a sourc
e can be | 5853 * The levels at which a source can be analyzed. |
| 6260 * analyzed. | |
| 6261 */ | 5854 */ |
| 6262 class AnalysisLevel extends Enum<AnalysisLevel> { | 5855 class AnalysisLevel extends Enum<AnalysisLevel> { |
| 6263 /** | 5856 /** |
| 6264 * Indicates a source should be fully analyzed. | 5857 * Indicates a source should be fully analyzed. |
| 6265 */ | 5858 */ |
| 6266 static const AnalysisLevel ALL = const AnalysisLevel('ALL', 0); | 5859 static const AnalysisLevel ALL = const AnalysisLevel('ALL', 0); |
| 6267 | 5860 |
| 6268 /** | 5861 /** |
| 6269 * Indicates a source should be resolved and that errors, warnings and hints a
re needed. | 5862 * Indicates a source should be resolved and that errors, warnings and hints a
re needed. |
| 6270 */ | 5863 */ |
| 6271 static const AnalysisLevel ERRORS = const AnalysisLevel('ERRORS', 1); | 5864 static const AnalysisLevel ERRORS = const AnalysisLevel('ERRORS', 1); |
| 6272 | 5865 |
| 6273 /** | 5866 /** |
| 6274 * Indicates a source should be resolved, but that errors, warnings and hints
are not needed. | 5867 * Indicates a source should be resolved, but that errors, warnings and hints
are not needed. |
| 6275 */ | 5868 */ |
| 6276 static const AnalysisLevel RESOLVED = const AnalysisLevel('RESOLVED', 2); | 5869 static const AnalysisLevel RESOLVED = const AnalysisLevel('RESOLVED', 2); |
| 6277 | 5870 |
| 6278 /** | 5871 /** |
| 6279 * Indicates a source is not of interest to the client. | 5872 * Indicates a source is not of interest to the client. |
| 6280 */ | 5873 */ |
| 6281 static const AnalysisLevel NONE = const AnalysisLevel('NONE', 3); | 5874 static const AnalysisLevel NONE = const AnalysisLevel('NONE', 3); |
| 6282 | 5875 |
| 6283 static const List<AnalysisLevel> values = const [ALL, ERRORS, RESOLVED, NONE]; | 5876 static const List<AnalysisLevel> values = const [ALL, ERRORS, RESOLVED, NONE]; |
| 6284 | 5877 |
| 6285 const AnalysisLevel(String name, int ordinal) : super(name, ordinal); | 5878 const AnalysisLevel(String name, int ordinal) : super(name, ordinal); |
| 6286 } | 5879 } |
| 6287 | 5880 |
| 6288 /** | 5881 /** |
| 6289 * The interface `AnalysisListener` defines the behavior of objects that are lis
tening for | 5882 * An object that is listening for results being produced by an analysis |
| 6290 * results being produced by an analysis context. | 5883 * context. |
| 6291 */ | 5884 */ |
| 6292 abstract class AnalysisListener { | 5885 abstract class AnalysisListener { |
| 6293 /** | 5886 /** |
| 6294 * Reports that a task is about to be performed by the given context. | 5887 * Reports that a task, described by the given [taskDescription] is about to |
| 6295 * | 5888 * be performed by the given [context]. |
| 6296 * @param context the context in which the task is to be performed | |
| 6297 * @param taskDescription a human readable description of the task that is abo
ut to be performed | |
| 6298 */ | 5889 */ |
| 6299 void aboutToPerformTask(AnalysisContext context, String taskDescription); | 5890 void aboutToPerformTask(AnalysisContext context, String taskDescription); |
| 6300 | 5891 |
| 6301 /** | 5892 /** |
| 6302 * Reports that the errors associated with the given source in the given conte
xt has been updated | 5893 * Reports that the [errors] associated with the given [source] in the given |
| 6303 * to the given errors. | 5894 * [context] has been updated to the given errors. The [lineInfo] is the line |
| 6304 * | 5895 * information associated with the source. |
| 6305 * @param context the context in which the new list of errors was produced | |
| 6306 * @param source the source containing the errors that were computed | |
| 6307 * @param errors the errors that were computed | |
| 6308 * @param lineInfo the line information associated with the source | |
| 6309 */ | 5896 */ |
| 6310 void computedErrors(AnalysisContext context, Source source, | 5897 void computedErrors(AnalysisContext context, Source source, |
| 6311 List<AnalysisError> errors, LineInfo lineInfo); | 5898 List<AnalysisError> errors, LineInfo lineInfo); |
| 6312 | 5899 |
| 6313 /** | 5900 /** |
| 6314 * Reports that the given source is no longer included in the set of sources t
hat are being | 5901 * Reports that the given [source] is no longer included in the set of sources |
| 6315 * analyzed by the given analysis context. | 5902 * that are being analyzed by the given analysis [context]. |
| 6316 * | |
| 6317 * @param context the context in which the source is being analyzed | |
| 6318 * @param source the source that is no longer being analyzed | |
| 6319 */ | 5903 */ |
| 6320 void excludedSource(AnalysisContext context, Source source); | 5904 void excludedSource(AnalysisContext context, Source source); |
| 6321 | 5905 |
| 6322 /** | 5906 /** |
| 6323 * Reports that the given source is now included in the set of sources that ar
e being analyzed by | 5907 * Reports that the given [source] is now included in the set of sources that |
| 6324 * the given analysis context. | 5908 * are being analyzed by the given analysis [context]. |
| 6325 * | |
| 6326 * @param context the context in which the source is being analyzed | |
| 6327 * @param source the source that is now being analyzed | |
| 6328 */ | 5909 */ |
| 6329 void includedSource(AnalysisContext context, Source source); | 5910 void includedSource(AnalysisContext context, Source source); |
| 6330 | 5911 |
| 6331 /** | 5912 /** |
| 6332 * Reports that the given Dart source was parsed in the given context. | 5913 * Reports that the given Dart [source] was parsed in the given [context], |
| 6333 * | 5914 * producing the given [unit]. |
| 6334 * @param context the context in which the source was parsed | |
| 6335 * @param source the source that was parsed | |
| 6336 * @param unit the result of parsing the source in the given context | |
| 6337 */ | 5915 */ |
| 6338 void parsedDart(AnalysisContext context, Source source, CompilationUnit unit); | 5916 void parsedDart(AnalysisContext context, Source source, CompilationUnit unit); |
| 6339 | 5917 |
| 6340 /** | 5918 /** |
| 6341 * Reports that the given HTML source was parsed in the given context. | 5919 * Reports that the given HTML [source] was parsed in the given [context]. |
| 6342 * | |
| 6343 * @param context the context in which the source was parsed | |
| 6344 * @param source the source that was parsed | |
| 6345 * @param unit the result of parsing the source in the given context | |
| 6346 */ | 5920 */ |
| 6347 void parsedHtml(AnalysisContext context, Source source, ht.HtmlUnit unit); | 5921 void parsedHtml(AnalysisContext context, Source source, ht.HtmlUnit unit); |
| 6348 | 5922 |
| 6349 /** | 5923 /** |
| 6350 * Reports that the given Dart source was resolved in the given context. | 5924 * Reports that the given Dart [source] was resolved in the given [context]. |
| 6351 * | |
| 6352 * @param context the context in which the source was resolved | |
| 6353 * @param source the source that was resolved | |
| 6354 * @param unit the result of resolving the source in the given context | |
| 6355 */ | 5925 */ |
| 6356 void resolvedDart( | 5926 void resolvedDart( |
| 6357 AnalysisContext context, Source source, CompilationUnit unit); | 5927 AnalysisContext context, Source source, CompilationUnit unit); |
| 6358 | 5928 |
| 6359 /** | 5929 /** |
| 6360 * Reports that the given HTML source was resolved in the given context. | 5930 * Reports that the given HTML [source] was resolved in the given [context]. |
| 6361 * | |
| 6362 * @param context the context in which the source was resolved | |
| 6363 * @param source the source that was resolved | |
| 6364 * @param unit the result of resolving the source in the given context | |
| 6365 */ | 5931 */ |
| 6366 void resolvedHtml(AnalysisContext context, Source source, ht.HtmlUnit unit); | 5932 void resolvedHtml(AnalysisContext context, Source source, ht.HtmlUnit unit); |
| 6367 } | 5933 } |
| 6368 | 5934 |
| 6369 /** | 5935 /** |
| 6370 * Futures returned by [AnalysisContext] for pending analysis results will | 5936 * Futures returned by [AnalysisContext] for pending analysis results will |
| 6371 * complete with this error if it is determined that analysis results will | 5937 * complete with this error if it is determined that analysis results will |
| 6372 * never become available (e.g. because the requested source is not subject to | 5938 * never become available (e.g. because the requested source is not subject to |
| 6373 * analysis, or because the requested source is a part file which is not a part | 5939 * analysis, or because the requested source is a part file which is not a part |
| 6374 * of any known library). | 5940 * of any known library). |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6660 static bool _analyzeAllFunctionBodies(Source _) => true; | 6226 static bool _analyzeAllFunctionBodies(Source _) => true; |
| 6661 | 6227 |
| 6662 /** | 6228 /** |
| 6663 * Predicate used for [analyzeFunctionBodiesPredicate] when | 6229 * Predicate used for [analyzeFunctionBodiesPredicate] when |
| 6664 * [analyzeFunctionBodies] is set to `false`. | 6230 * [analyzeFunctionBodies] is set to `false`. |
| 6665 */ | 6231 */ |
| 6666 static bool _analyzeNoFunctionBodies(Source _) => false; | 6232 static bool _analyzeNoFunctionBodies(Source _) => false; |
| 6667 } | 6233 } |
| 6668 | 6234 |
| 6669 /** | 6235 /** |
| 6670 * Instances of the class `AnalysisResult` | 6236 * |
| 6671 */ | 6237 */ |
| 6672 class AnalysisResult { | 6238 class AnalysisResult { |
| 6673 /** | 6239 /** |
| 6674 * The change notices associated with this result, or `null` if there were no
changes and | 6240 * The change notices associated with this result, or `null` if there were no |
| 6675 * there is no more work to be done. | 6241 * changes and there is no more work to be done. |
| 6676 */ | 6242 */ |
| 6677 final List<ChangeNotice> _notices; | 6243 final List<ChangeNotice> _notices; |
| 6678 | 6244 |
| 6679 /** | 6245 /** |
| 6680 * The number of milliseconds required to determine which task was to be perfo
rmed. | 6246 * The number of milliseconds required to determine which task was to be |
| 6247 * performed. |
| 6681 */ | 6248 */ |
| 6682 final int getTime; | 6249 final int getTime; |
| 6683 | 6250 |
| 6684 /** | 6251 /** |
| 6685 * The name of the class of the task that was performed. | 6252 * The name of the class of the task that was performed. |
| 6686 */ | 6253 */ |
| 6687 final String taskClassName; | 6254 final String taskClassName; |
| 6688 | 6255 |
| 6689 /** | 6256 /** |
| 6690 * The number of milliseconds required to perform the task. | 6257 * The number of milliseconds required to perform the task. |
| 6691 */ | 6258 */ |
| 6692 final int performTime; | 6259 final int performTime; |
| 6693 | 6260 |
| 6694 /** | 6261 /** |
| 6695 * Initialize a newly created analysis result to have the given values. | 6262 * Initialize a newly created analysis result to have the given values. The |
| 6696 * | 6263 * [notices] is the change notices associated with this result. The [getTime] |
| 6697 * @param notices the change notices associated with this result | 6264 * is the number of milliseconds required to determine which task was to be |
| 6698 * @param getTime the number of milliseconds required to determine which task
was to be performed | 6265 * performed. The [taskClassName] is the name of the class of the task that |
| 6699 * @param taskClassName the name of the class of the task that was performed | 6266 * was performed. The [performTime] is the number of milliseconds required to |
| 6700 * @param performTime the number of milliseconds required to perform the task | 6267 * perform the task. |
| 6701 */ | 6268 */ |
| 6702 AnalysisResult( | 6269 AnalysisResult( |
| 6703 this._notices, this.getTime, this.taskClassName, this.performTime); | 6270 this._notices, this.getTime, this.taskClassName, this.performTime); |
| 6704 | 6271 |
| 6705 /** | 6272 /** |
| 6706 * Return the change notices associated with this result, or `null` if there w
ere no changes | 6273 * Return the change notices associated with this result, or `null` if there |
| 6707 * and there is no more work to be done. | 6274 * were no changes and there is no more work to be done. |
| 6708 * | |
| 6709 * @return the change notices associated with this result | |
| 6710 */ | 6275 */ |
| 6711 List<ChangeNotice> get changeNotices => _notices; | 6276 List<ChangeNotice> get changeNotices => _notices; |
| 6712 | 6277 |
| 6713 /** | 6278 /** |
| 6714 * Return `true` if there is more to be performed after the task that was perf
ormed. | 6279 * Return `true` if there is more to be performed after the task that was |
| 6715 * | 6280 * performed. |
| 6716 * @return `true` if there is more to be performed after the task that was per
formed | |
| 6717 */ | 6281 */ |
| 6718 bool get hasMoreWork => _notices != null; | 6282 bool get hasMoreWork => _notices != null; |
| 6719 } | 6283 } |
| 6720 | 6284 |
| 6721 /** | 6285 /** |
| 6722 * The abstract class `AnalysisTask` defines the behavior of objects used to per
form an | 6286 * An analysis task. |
| 6723 * analysis task. | |
| 6724 */ | 6287 */ |
| 6725 abstract class AnalysisTask { | 6288 abstract class AnalysisTask { |
| 6726 /** | 6289 /** |
| 6727 * The context in which the task is to be performed. | 6290 * The context in which the task is to be performed. |
| 6728 */ | 6291 */ |
| 6729 final InternalAnalysisContext context; | 6292 final InternalAnalysisContext context; |
| 6730 | 6293 |
| 6731 /** | 6294 /** |
| 6732 * The exception that was thrown while performing this task, or `null` if the
task completed | 6295 * The exception that was thrown while performing this task, or `null` if the |
| 6733 * successfully. | 6296 * task completed successfully. |
| 6734 */ | 6297 */ |
| 6735 CaughtException _thrownException; | 6298 CaughtException _thrownException; |
| 6736 | 6299 |
| 6737 /** | 6300 /** |
| 6738 * Initialize a newly created task to perform analysis within the given contex
t. | 6301 * Initialize a newly created task to perform analysis within the given |
| 6739 * | 6302 * [context]. |
| 6740 * @param context the context in which the task is to be performed | |
| 6741 */ | 6303 */ |
| 6742 AnalysisTask(this.context); | 6304 AnalysisTask(this.context); |
| 6743 | 6305 |
| 6744 /** | 6306 /** |
| 6745 * Return the exception that was thrown while performing this task, or `null`
if the task | 6307 * Return the exception that was thrown while performing this task, or `null` |
| 6746 * completed successfully. | 6308 * if the task completed successfully. |
| 6747 * | |
| 6748 * @return the exception that was thrown while performing this task | |
| 6749 */ | 6309 */ |
| 6750 CaughtException get exception => _thrownException; | 6310 CaughtException get exception => _thrownException; |
| 6751 | 6311 |
| 6752 /** | 6312 /** |
| 6753 * Return a textual description of this task. | 6313 * Return a textual description of this task. |
| 6754 * | |
| 6755 * @return a textual description of this task | |
| 6756 */ | 6314 */ |
| 6757 String get taskDescription; | 6315 String get taskDescription; |
| 6758 | 6316 |
| 6759 /** | 6317 /** |
| 6760 * Use the given visitor to visit this task. | 6318 * Use the given [visitor] to visit this task. Throws an [AnalysisException] |
| 6761 * | 6319 * if the visitor throws the exception. |
| 6762 * @param visitor the visitor that should be used to visit this task | |
| 6763 * @return the value returned by the visitor | |
| 6764 * @throws AnalysisException if the visitor throws the exception | |
| 6765 */ | 6320 */ |
| 6766 accept(AnalysisTaskVisitor visitor); | 6321 accept(AnalysisTaskVisitor visitor); |
| 6767 | 6322 |
| 6768 /** | 6323 /** |
| 6769 * Perform this analysis task, protected by an exception handler. | 6324 * Perform this analysis task, protected by an exception handler. Throws an |
| 6770 * | 6325 * [AnalysisException] if an exception occurs while performing the task. |
| 6771 * @throws AnalysisException if an exception occurs while performing the task | |
| 6772 */ | 6326 */ |
| 6773 void internalPerform(); | 6327 void internalPerform(); |
| 6774 | 6328 |
| 6775 /** | 6329 /** |
| 6776 * Perform this analysis task and use the given visitor to visit this task aft
er it has completed. | 6330 * Perform this analysis task and use the given [visitor] to visit this task |
| 6777 * | 6331 * after it has completed. Throws an [AnalysisException] if the visitor throws |
| 6778 * @param visitor the visitor used to visit this task after it has completed | 6332 * the exception. |
| 6779 * @return the value returned by the visitor | |
| 6780 * @throws AnalysisException if the visitor throws the exception | |
| 6781 */ | 6333 */ |
| 6782 Object perform(AnalysisTaskVisitor visitor) { | 6334 Object perform(AnalysisTaskVisitor visitor) { |
| 6783 try { | 6335 try { |
| 6784 _safelyPerform(); | 6336 _safelyPerform(); |
| 6785 } on AnalysisException catch (exception, stackTrace) { | 6337 } on AnalysisException catch (exception, stackTrace) { |
| 6786 _thrownException = new CaughtException(exception, stackTrace); | 6338 _thrownException = new CaughtException(exception, stackTrace); |
| 6787 AnalysisEngine.instance.logger.logInformation( | 6339 AnalysisEngine.instance.logger.logInformation( |
| 6788 "Task failed: $taskDescription", | 6340 "Task failed: $taskDescription", |
| 6789 new CaughtException(exception, stackTrace)); | 6341 new CaughtException(exception, stackTrace)); |
| 6790 } | 6342 } |
| 6791 return PerformanceStatistics.analysisTaskVisitor | 6343 return PerformanceStatistics.analysisTaskVisitor |
| 6792 .makeCurrentWhile(() => accept(visitor)); | 6344 .makeCurrentWhile(() => accept(visitor)); |
| 6793 } | 6345 } |
| 6794 | 6346 |
| 6795 @override | 6347 @override |
| 6796 String toString() => taskDescription; | 6348 String toString() => taskDescription; |
| 6797 | 6349 |
| 6798 /** | 6350 /** |
| 6799 * Perform this analysis task, ensuring that all exceptions are wrapped in an | 6351 * Perform this analysis task, ensuring that all exceptions are wrapped in an |
| 6800 * [AnalysisException]. | 6352 * [AnalysisException]. Throws an [AnalysisException] if any exception occurs |
| 6801 * | 6353 * while performing the task |
| 6802 * @throws AnalysisException if any exception occurs while performing the task | |
| 6803 */ | 6354 */ |
| 6804 void _safelyPerform() { | 6355 void _safelyPerform() { |
| 6805 try { | 6356 try { |
| 6806 String contextName = context.name; | 6357 String contextName = context.name; |
| 6807 if (contextName == null) { | 6358 if (contextName == null) { |
| 6808 contextName = 'unnamed'; | 6359 contextName = 'unnamed'; |
| 6809 } | 6360 } |
| 6810 AnalysisEngine.instance.instrumentationService.logAnalysisTask( | 6361 AnalysisEngine.instance.instrumentationService.logAnalysisTask( |
| 6811 contextName, taskDescription); | 6362 contextName, taskDescription); |
| 6812 internalPerform(); | 6363 internalPerform(); |
| 6813 } on AnalysisException { | 6364 } on AnalysisException { |
| 6814 rethrow; | 6365 rethrow; |
| 6815 } catch (exception, stackTrace) { | 6366 } catch (exception, stackTrace) { |
| 6816 throw new AnalysisException( | 6367 throw new AnalysisException( |
| 6817 exception.toString(), new CaughtException(exception, stackTrace)); | 6368 exception.toString(), new CaughtException(exception, stackTrace)); |
| 6818 } | 6369 } |
| 6819 } | 6370 } |
| 6820 } | 6371 } |
| 6821 | 6372 |
| 6822 /** | 6373 /** |
| 6823 * An `AnalysisTaskVisitor` visits tasks. While tasks are not structured in any | 6374 * An object used to visit tasks. While tasks are not structured in any |
| 6824 * interesting way, this class provides the ability to dispatch to an | 6375 * interesting way, this class provides the ability to dispatch to an |
| 6825 * appropriate method. | 6376 * appropriate method. |
| 6826 */ | 6377 */ |
| 6827 abstract class AnalysisTaskVisitor<E> { | 6378 abstract class AnalysisTaskVisitor<E> { |
| 6828 /** | 6379 /** |
| 6829 * Visit the given [task], returning the result of the visit. This method will | 6380 * Visit the given [task], returning the result of the visit. This method will |
| 6830 * throw an AnalysisException if the visitor throws an exception. | 6381 * throw an AnalysisException if the visitor throws an exception. |
| 6831 */ | 6382 */ |
| 6832 E visitBuildUnitElementTask(BuildUnitElementTask task); | 6383 E visitBuildUnitElementTask(BuildUnitElementTask task); |
| 6833 | 6384 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6925 * Initialize a newly created result holder to represent the value of data | 6476 * Initialize a newly created result holder to represent the value of data |
| 6926 * described by the given [descriptor]. | 6477 * described by the given [descriptor]. |
| 6927 */ | 6478 */ |
| 6928 CachedResult(DataDescriptor descriptor) { | 6479 CachedResult(DataDescriptor descriptor) { |
| 6929 state = CacheState.INVALID; | 6480 state = CacheState.INVALID; |
| 6930 value = descriptor.defaultValue; | 6481 value = descriptor.defaultValue; |
| 6931 } | 6482 } |
| 6932 } | 6483 } |
| 6933 | 6484 |
| 6934 /** | 6485 /** |
| 6935 * Instances of the class `CachePartition` implement a single partition in an LR
U cache of | 6486 * A single partition in an LRU cache of information related to analysis. |
| 6936 * information related to analysis. | |
| 6937 */ | 6487 */ |
| 6938 abstract class CachePartition { | 6488 abstract class CachePartition { |
| 6939 /** | 6489 /** |
| 6940 * The context that owns this partition. Multiple contexts can reference a par
tition, but only one | 6490 * The context that owns this partition. Multiple contexts can reference a |
| 6941 * context can own it. | 6491 * partition, but only one context can own it. |
| 6942 */ | 6492 */ |
| 6943 final InternalAnalysisContext context; | 6493 final InternalAnalysisContext context; |
| 6944 | 6494 |
| 6945 /** | 6495 /** |
| 6946 * The maximum number of sources for which AST structures should be kept in th
e cache. | 6496 * The maximum number of sources for which AST structures should be kept in |
| 6497 * the cache. |
| 6947 */ | 6498 */ |
| 6948 int _maxCacheSize = 0; | 6499 int _maxCacheSize = 0; |
| 6949 | 6500 |
| 6950 /** | 6501 /** |
| 6951 * The policy used to determine which pieces of data to remove from the cache. | 6502 * The policy used to determine which pieces of data to remove from the cache. |
| 6952 */ | 6503 */ |
| 6953 final CacheRetentionPolicy _retentionPolicy; | 6504 final CacheRetentionPolicy _retentionPolicy; |
| 6954 | 6505 |
| 6955 /** | 6506 /** |
| 6956 * A table mapping the sources belonging to this partition to the information
known about those | 6507 * A table mapping the sources belonging to this partition to the information |
| 6957 * sources. | 6508 * known about those sources. |
| 6958 */ | 6509 */ |
| 6959 HashMap<Source, SourceEntry> _sourceMap = new HashMap<Source, SourceEntry>(); | 6510 HashMap<Source, SourceEntry> _sourceMap = new HashMap<Source, SourceEntry>(); |
| 6960 | 6511 |
| 6961 /** | 6512 /** |
| 6962 * A list containing the most recently accessed sources with the most recently
used at the end of | 6513 * A list containing the most recently accessed sources with the most recently |
| 6963 * the list. When more sources are added than the maximum allowed then the lea
st recently used | 6514 * used at the end of the list. When more sources are added than the maximum |
| 6964 * source will be removed and will have it's cached AST structure flushed. | 6515 * allowed then the least recently used source will be removed and will have |
| 6516 * it's cached AST structure flushed. |
| 6965 */ | 6517 */ |
| 6966 List<Source> _recentlyUsed; | 6518 List<Source> _recentlyUsed; |
| 6967 | 6519 |
| 6968 /** | 6520 /** |
| 6969 * Initialize a newly created cache to maintain at most the given number of AS
T structures in the | 6521 * Initialize a newly created cache to maintain at most [maxCacheSize] AST |
| 6970 * cache. | 6522 * structures in the cache. The cache is owned by the give [context], and the |
| 6971 * | 6523 * [retentionPolicy] will be used to determine which pieces of data to remove |
| 6972 * @param context the context that owns this partition | 6524 * from the cache. |
| 6973 * @param maxCacheSize the maximum number of sources for which AST structures
should be kept in | |
| 6974 * the cache | |
| 6975 * @param retentionPolicy the policy used to determine which pieces of data to
remove from the | |
| 6976 * cache | |
| 6977 */ | 6525 */ |
| 6978 CachePartition(this.context, int maxCacheSize, this._retentionPolicy) { | 6526 CachePartition(this.context, int maxCacheSize, this._retentionPolicy) { |
| 6979 this._maxCacheSize = maxCacheSize; | 6527 this._maxCacheSize = maxCacheSize; |
| 6980 _recentlyUsed = new List<Source>(); | 6528 _recentlyUsed = new List<Source>(); |
| 6981 } | 6529 } |
| 6982 | 6530 |
| 6983 /** | 6531 /** |
| 6984 * Return the number of entries in this partition that have an AST associated
with them. | 6532 * Return the number of entries in this partition that have an AST associated |
| 6985 * | 6533 * with them. |
| 6986 * @return the number of entries in this partition that have an AST associated
with them | |
| 6987 */ | 6534 */ |
| 6988 int get astSize { | 6535 int get astSize { |
| 6989 int astSize = 0; | 6536 int astSize = 0; |
| 6990 int count = _recentlyUsed.length; | 6537 int count = _recentlyUsed.length; |
| 6991 for (int i = 0; i < count; i++) { | 6538 for (int i = 0; i < count; i++) { |
| 6992 Source source = _recentlyUsed[i]; | 6539 Source source = _recentlyUsed[i]; |
| 6993 SourceEntry sourceEntry = _sourceMap[source]; | 6540 SourceEntry sourceEntry = _sourceMap[source]; |
| 6994 if (sourceEntry is DartEntry) { | 6541 if (sourceEntry is DartEntry) { |
| 6995 if (sourceEntry.anyParsedCompilationUnit != null) { | 6542 if (sourceEntry.anyParsedCompilationUnit != null) { |
| 6996 astSize++; | 6543 astSize++; |
| 6997 } | 6544 } |
| 6998 } else if (sourceEntry is HtmlEntry) { | 6545 } else if (sourceEntry is HtmlEntry) { |
| 6999 if (sourceEntry.anyParsedUnit != null) { | 6546 if (sourceEntry.anyParsedUnit != null) { |
| 7000 astSize++; | 6547 astSize++; |
| 7001 } | 6548 } |
| 7002 } | 6549 } |
| 7003 } | 6550 } |
| 7004 return astSize; | 6551 return astSize; |
| 7005 } | 6552 } |
| 7006 | 6553 |
| 7007 /** | 6554 /** |
| 7008 * Return a table mapping the sources known to the context to the information
known about the | 6555 * Return a table mapping the sources known to the context to the information |
| 7009 * source. | 6556 * known about the source. |
| 7010 * | 6557 * |
| 7011 * <b>Note:</b> This method is only visible for use by [AnalysisCache] and sho
uld not be | 6558 * <b>Note:</b> This method is only visible for use by [AnalysisCache] and |
| 7012 * used for any other purpose. | 6559 * should not be used for any other purpose. |
| 7013 * | |
| 7014 * @return a table mapping the sources known to the context to the information
known about the | |
| 7015 * source | |
| 7016 */ | 6560 */ |
| 7017 Map<Source, SourceEntry> get map => _sourceMap; | 6561 Map<Source, SourceEntry> get map => _sourceMap; |
| 7018 | 6562 |
| 7019 /** | 6563 /** |
| 7020 * Set the maximum size of the cache to the given size. | 6564 * Set the maximum size of the cache to the given [size]. |
| 7021 * | |
| 7022 * @param size the maximum number of sources for which AST structures should b
e kept in the cache | |
| 7023 */ | 6565 */ |
| 7024 void set maxCacheSize(int size) { | 6566 void set maxCacheSize(int size) { |
| 7025 _maxCacheSize = size; | 6567 _maxCacheSize = size; |
| 7026 while (_recentlyUsed.length > _maxCacheSize) { | 6568 while (_recentlyUsed.length > _maxCacheSize) { |
| 7027 if (!_flushAstFromCache()) { | 6569 if (!_flushAstFromCache()) { |
| 7028 break; | 6570 break; |
| 7029 } | 6571 } |
| 7030 } | 6572 } |
| 7031 } | 6573 } |
| 7032 | 6574 |
| 7033 /** | 6575 /** |
| 7034 * Record that the AST associated with the given source was just read from the
cache. | 6576 * Record that the AST associated with the given source was just read from the |
| 7035 * | 6577 * cache. |
| 7036 * @param source the source whose AST was accessed | |
| 7037 */ | 6578 */ |
| 7038 void accessedAst(Source source) { | 6579 void accessedAst(Source source) { |
| 7039 if (_recentlyUsed.remove(source)) { | 6580 if (_recentlyUsed.remove(source)) { |
| 7040 _recentlyUsed.add(source); | 6581 _recentlyUsed.add(source); |
| 7041 return; | 6582 return; |
| 7042 } | 6583 } |
| 7043 while (_recentlyUsed.length >= _maxCacheSize) { | 6584 while (_recentlyUsed.length >= _maxCacheSize) { |
| 7044 if (!_flushAstFromCache()) { | 6585 if (!_flushAstFromCache()) { |
| 7045 break; | 6586 break; |
| 7046 } | 6587 } |
| 7047 } | 6588 } |
| 7048 _recentlyUsed.add(source); | 6589 _recentlyUsed.add(source); |
| 7049 } | 6590 } |
| 7050 | 6591 |
| 7051 /** | 6592 /** |
| 7052 * Return `true` if the given source is contained in this partition. | 6593 * Return `true` if the given [source] is contained in this partition. |
| 7053 * | |
| 7054 * @param source the source being tested | |
| 7055 * @return `true` if the source is contained in this partition | |
| 7056 */ | 6594 */ |
| 7057 bool contains(Source source); | 6595 bool contains(Source source); |
| 7058 | 6596 |
| 7059 /** | 6597 /** |
| 7060 * Return the entry associated with the given source. | 6598 * Return the entry associated with the given [source]. |
| 7061 * | |
| 7062 * @param source the source whose entry is to be returned | |
| 7063 * @return the entry associated with the given source | |
| 7064 */ | 6599 */ |
| 7065 SourceEntry get(Source source) => _sourceMap[source]; | 6600 SourceEntry get(Source source) => _sourceMap[source]; |
| 7066 | 6601 |
| 7067 /** | 6602 /** |
| 7068 * Return an iterator returning all of the map entries mapping sources to cach
e entries. | 6603 * Return an iterator returning all of the map entries mapping sources to |
| 7069 * | 6604 * cache entries. |
| 7070 * @return an iterator returning all of the map entries mapping sources to cac
he entries | |
| 7071 */ | 6605 */ |
| 7072 MapIterator<Source, SourceEntry> iterator() => | 6606 MapIterator<Source, SourceEntry> iterator() => |
| 7073 new SingleMapIterator<Source, SourceEntry>(_sourceMap); | 6607 new SingleMapIterator<Source, SourceEntry>(_sourceMap); |
| 7074 | 6608 |
| 7075 /** | 6609 /** |
| 7076 * Associate the given entry with the given source. | 6610 * Associate the given [entry] with the given [source]. |
| 7077 * | |
| 7078 * @param source the source with which the entry is to be associated | |
| 7079 * @param entry the entry to be associated with the source | |
| 7080 */ | 6611 */ |
| 7081 void put(Source source, SourceEntry entry) { | 6612 void put(Source source, SourceEntry entry) { |
| 7082 entry.fixExceptionState(); | 6613 entry.fixExceptionState(); |
| 7083 _sourceMap[source] = entry; | 6614 _sourceMap[source] = entry; |
| 7084 } | 6615 } |
| 7085 | 6616 |
| 7086 /** | 6617 /** |
| 7087 * Remove all information related to the given source from this cache. | 6618 * Remove all information related to the given [source] from this cache. |
| 7088 * | |
| 7089 * @param source the source to be removed | |
| 7090 */ | 6619 */ |
| 7091 void remove(Source source) { | 6620 void remove(Source source) { |
| 7092 _recentlyUsed.remove(source); | 6621 _recentlyUsed.remove(source); |
| 7093 _sourceMap.remove(source); | 6622 _sourceMap.remove(source); |
| 7094 } | 6623 } |
| 7095 | 6624 |
| 7096 /** | 6625 /** |
| 7097 * Record that the AST associated with the given source was just removed from
the cache. | 6626 * Record that the AST associated with the given [source] was just removed |
| 7098 * | 6627 * from the cache. |
| 7099 * @param source the source whose AST was removed | |
| 7100 */ | 6628 */ |
| 7101 void removedAst(Source source) { | 6629 void removedAst(Source source) { |
| 7102 _recentlyUsed.remove(source); | 6630 _recentlyUsed.remove(source); |
| 7103 } | 6631 } |
| 7104 | 6632 |
| 7105 /** | 6633 /** |
| 7106 * Return the number of sources that are mapped to cache entries. | 6634 * Return the number of sources that are mapped to cache entries. |
| 7107 * | |
| 7108 * @return the number of sources that are mapped to cache entries | |
| 7109 */ | 6635 */ |
| 7110 int size() => _sourceMap.length; | 6636 int size() => _sourceMap.length; |
| 7111 | 6637 |
| 7112 /** | 6638 /** |
| 7113 * Record that the AST associated with the given source was just stored to the
cache. | 6639 * Record that the AST associated with the given [source] was just stored to |
| 7114 * | 6640 * the cache. |
| 7115 * @param source the source whose AST was stored | |
| 7116 */ | 6641 */ |
| 7117 void storedAst(Source source) { | 6642 void storedAst(Source source) { |
| 7118 if (_recentlyUsed.contains(source)) { | 6643 if (_recentlyUsed.contains(source)) { |
| 7119 return; | 6644 return; |
| 7120 } | 6645 } |
| 7121 while (_recentlyUsed.length >= _maxCacheSize) { | 6646 while (_recentlyUsed.length >= _maxCacheSize) { |
| 7122 if (!_flushAstFromCache()) { | 6647 if (!_flushAstFromCache()) { |
| 7123 break; | 6648 break; |
| 7124 } | 6649 } |
| 7125 } | 6650 } |
| 7126 _recentlyUsed.add(source); | 6651 _recentlyUsed.add(source); |
| 7127 } | 6652 } |
| 7128 | 6653 |
| 7129 /** | 6654 /** |
| 7130 * Attempt to flush one AST structure from the cache. | 6655 * Attempt to flush one AST structure from the cache. Return `true` if a |
| 7131 * | 6656 * structure was flushed. |
| 7132 * @return `true` if a structure was flushed | |
| 7133 */ | 6657 */ |
| 7134 bool _flushAstFromCache() { | 6658 bool _flushAstFromCache() { |
| 7135 Source removedSource = _removeAstToFlush(); | 6659 Source removedSource = _removeAstToFlush(); |
| 7136 if (removedSource == null) { | 6660 if (removedSource == null) { |
| 7137 return false; | 6661 return false; |
| 7138 } | 6662 } |
| 7139 SourceEntry sourceEntry = _sourceMap[removedSource]; | 6663 SourceEntry sourceEntry = _sourceMap[removedSource]; |
| 7140 if (sourceEntry is HtmlEntry) { | 6664 if (sourceEntry is HtmlEntry) { |
| 7141 HtmlEntry htmlEntry = sourceEntry; | 6665 HtmlEntry htmlEntry = sourceEntry; |
| 7142 htmlEntry.flushAstStructures(); | 6666 htmlEntry.flushAstStructures(); |
| 7143 } else if (sourceEntry is DartEntry) { | 6667 } else if (sourceEntry is DartEntry) { |
| 7144 DartEntry dartEntry = sourceEntry; | 6668 DartEntry dartEntry = sourceEntry; |
| 7145 dartEntry.flushAstStructures(); | 6669 dartEntry.flushAstStructures(); |
| 7146 } | 6670 } |
| 7147 return true; | 6671 return true; |
| 7148 } | 6672 } |
| 7149 | 6673 |
| 7150 /** | 6674 /** |
| 7151 * Remove and return one source from the list of recently used sources whose A
ST structure can be | 6675 * Remove and return one source from the list of recently used sources whose |
| 7152 * flushed from the cache. The source that will be returned will be the source
that has been | 6676 * AST structure can be flushed from the cache. The source that will be |
| 7153 * unreferenced for the longest period of time but that is not a priority for
analysis. | 6677 * returned will be the source that has been unreferenced for the longest |
| 7154 * | 6678 * period of time but that is not a priority for analysis. |
| 7155 * @return the source that was removed | |
| 7156 */ | 6679 */ |
| 7157 Source _removeAstToFlush() { | 6680 Source _removeAstToFlush() { |
| 7158 int sourceToRemove = -1; | 6681 int sourceToRemove = -1; |
| 7159 for (int i = 0; i < _recentlyUsed.length; i++) { | 6682 for (int i = 0; i < _recentlyUsed.length; i++) { |
| 7160 Source source = _recentlyUsed[i]; | 6683 Source source = _recentlyUsed[i]; |
| 7161 RetentionPriority priority = | 6684 RetentionPriority priority = |
| 7162 _retentionPolicy.getAstPriority(source, _sourceMap[source]); | 6685 _retentionPolicy.getAstPriority(source, _sourceMap[source]); |
| 7163 if (priority == RetentionPriority.LOW) { | 6686 if (priority == RetentionPriority.LOW) { |
| 7164 return _recentlyUsed.removeAt(i); | 6687 return _recentlyUsed.removeAt(i); |
| 7165 } else if (priority == RetentionPriority.MEDIUM && sourceToRemove < 0) { | 6688 } else if (priority == RetentionPriority.MEDIUM && sourceToRemove < 0) { |
| 7166 sourceToRemove = i; | 6689 sourceToRemove = i; |
| 7167 } | 6690 } |
| 7168 } | 6691 } |
| 7169 if (sourceToRemove < 0) { | 6692 if (sourceToRemove < 0) { |
| 7170 // This happens if the retention policy returns a priority of HIGH for all | 6693 // This happens if the retention policy returns a priority of HIGH for all |
| 7171 // of the sources that have been recently used. This is the case, for | 6694 // of the sources that have been recently used. This is the case, for |
| 7172 // example, when the list of priority sources is bigger than the current | 6695 // example, when the list of priority sources is bigger than the current |
| 7173 // cache size. | 6696 // cache size. |
| 7174 return null; | 6697 return null; |
| 7175 } | 6698 } |
| 7176 return _recentlyUsed.removeAt(sourceToRemove); | 6699 return _recentlyUsed.removeAt(sourceToRemove); |
| 7177 } | 6700 } |
| 7178 } | 6701 } |
| 7179 | 6702 |
| 7180 /** | 6703 /** |
| 7181 * Instances of the class `CacheRetentionPolicy` define the behavior of objects
that determine | 6704 * An object used to determine how important it is for data to be retained in |
| 7182 * how important it is for data to be retained in the analysis cache. | 6705 * the analysis cache. |
| 7183 */ | 6706 */ |
| 7184 abstract class CacheRetentionPolicy { | 6707 abstract class CacheRetentionPolicy { |
| 7185 /** | 6708 /** |
| 7186 * Return the priority of retaining the AST structure for the given source. | 6709 * Return the priority of retaining the AST structure for the given [source]. |
| 7187 * | |
| 7188 * @param source the source whose AST structure is being considered for remova
l | |
| 7189 * @param sourceEntry the entry representing the source | |
| 7190 * @return the priority of retaining the AST structure for the given source | |
| 7191 */ | 6710 */ |
| 7192 RetentionPriority getAstPriority(Source source, SourceEntry sourceEntry); | 6711 RetentionPriority getAstPriority(Source source, SourceEntry sourceEntry); |
| 7193 } | 6712 } |
| 7194 | 6713 |
| 7195 /** | 6714 /** |
| 7196 * The possible states of cached data. | 6715 * The possible states of cached data. |
| 7197 */ | 6716 */ |
| 7198 class CacheState extends Enum<CacheState> { | 6717 class CacheState extends Enum<CacheState> { |
| 7199 /** | 6718 /** |
| 7200 * The data is not in the cache and the last time an attempt was made to | 6719 * The data is not in the cache and the last time an attempt was made to |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7356 AnalysisEngine.instance.logger.logInformation("No line info: $source", | 6875 AnalysisEngine.instance.logger.logInformation("No line info: $source", |
| 7357 new CaughtException(new AnalysisException(), null)); | 6876 new CaughtException(new AnalysisException(), null)); |
| 7358 } | 6877 } |
| 7359 } | 6878 } |
| 7360 | 6879 |
| 7361 @override | 6880 @override |
| 7362 String toString() => "Changes for ${source.fullName}"; | 6881 String toString() => "Changes for ${source.fullName}"; |
| 7363 } | 6882 } |
| 7364 | 6883 |
| 7365 /** | 6884 /** |
| 7366 * Instances of the class `ChangeSet` indicate which sources have been added, ch
anged, | 6885 * An indication of which sources have been added, changed, removed, or deleted. |
| 7367 * removed, or deleted. In the case of a changed source, there are multiple ways
of indicating the | 6886 * In the case of a changed source, there are multiple ways of indicating the |
| 7368 * nature of the change. | 6887 * nature of the change. |
| 7369 * | 6888 * |
| 7370 * No source should be added to the change set more than once, either with the s
ame or a different | 6889 * No source should be added to the change set more than once, either with the |
| 7371 * kind of change. It does not make sense, for example, for a source to be both
added and removed, | 6890 * same or a different kind of change. It does not make sense, for example, for |
| 7372 * and it is redundant for a source to be marked as changed in its entirety and
changed in some | 6891 * a source to be both added and removed, and it is redundant for a source to be |
| 7373 * specific range. | 6892 * marked as changed in its entirety and changed in some specific range. |
| 7374 */ | 6893 */ |
| 7375 class ChangeSet { | 6894 class ChangeSet { |
| 7376 /** | 6895 /** |
| 7377 * A list containing the sources that have been added. | 6896 * A list containing the sources that have been added. |
| 7378 */ | 6897 */ |
| 7379 final List<Source> addedSources = new List<Source>(); | 6898 final List<Source> addedSources = new List<Source>(); |
| 7380 | 6899 |
| 7381 /** | 6900 /** |
| 7382 * A list containing the sources that have been changed. | 6901 * A list containing the sources that have been changed. |
| 7383 */ | 6902 */ |
| 7384 final List<Source> changedSources = new List<Source>(); | 6903 final List<Source> changedSources = new List<Source>(); |
| 7385 | 6904 |
| 7386 /** | 6905 /** |
| 7387 * A table mapping the sources whose content has been changed to the current c
ontent of those | 6906 * A table mapping the sources whose content has been changed to the current |
| 7388 * sources. | 6907 * content of those sources. |
| 7389 */ | 6908 */ |
| 7390 HashMap<Source, String> _changedContent = new HashMap<Source, String>(); | 6909 HashMap<Source, String> _changedContent = new HashMap<Source, String>(); |
| 7391 | 6910 |
| 7392 /** | 6911 /** |
| 7393 * A table mapping the sources whose content has been changed within a single
range to the current | 6912 * A table mapping the sources whose content has been changed within a single |
| 7394 * content of those sources and information about the affected range. | 6913 * range to the current content of those sources and information about the |
| 6914 * affected range. |
| 7395 */ | 6915 */ |
| 7396 final HashMap<Source, ChangeSet_ContentChange> changedRanges = | 6916 final HashMap<Source, ChangeSet_ContentChange> changedRanges = |
| 7397 new HashMap<Source, ChangeSet_ContentChange>(); | 6917 new HashMap<Source, ChangeSet_ContentChange>(); |
| 7398 | 6918 |
| 7399 /** | 6919 /** |
| 7400 * A list containing the sources that have been removed. | 6920 * A list containing the sources that have been removed. |
| 7401 */ | 6921 */ |
| 7402 final List<Source> removedSources = new List<Source>(); | 6922 final List<Source> removedSources = new List<Source>(); |
| 7403 | 6923 |
| 7404 /** | 6924 /** |
| 7405 * A list containing the source containers specifying additional sources that
have been removed. | 6925 * A list containing the source containers specifying additional sources that |
| 6926 * have been removed. |
| 7406 */ | 6927 */ |
| 7407 final List<SourceContainer> removedContainers = new List<SourceContainer>(); | 6928 final List<SourceContainer> removedContainers = new List<SourceContainer>(); |
| 7408 | 6929 |
| 7409 /** | 6930 /** |
| 7410 * A list containing the sources that have been deleted. | 6931 * A list containing the sources that have been deleted. |
| 7411 */ | 6932 */ |
| 7412 final List<Source> deletedSources = new List<Source>(); | 6933 final List<Source> deletedSources = new List<Source>(); |
| 7413 | 6934 |
| 7414 /** | 6935 /** |
| 7415 * Return a table mapping the sources whose content has been changed to the cu
rrent content of | 6936 * Return a table mapping the sources whose content has been changed to the |
| 7416 * those sources. | 6937 * current content of those sources. |
| 7417 * | |
| 7418 * @return a table mapping the sources whose content has been changed to the c
urrent content of | |
| 7419 * those sources | |
| 7420 */ | 6938 */ |
| 7421 Map<Source, String> get changedContents => _changedContent; | 6939 Map<Source, String> get changedContents => _changedContent; |
| 7422 | 6940 |
| 7423 /** | 6941 /** |
| 7424 * Return `true` if this change set does not contain any changes. | 6942 * Return `true` if this change set does not contain any changes. |
| 7425 * | |
| 7426 * @return `true` if this change set does not contain any changes | |
| 7427 */ | 6943 */ |
| 7428 bool get isEmpty => addedSources.isEmpty && | 6944 bool get isEmpty => addedSources.isEmpty && |
| 7429 changedSources.isEmpty && | 6945 changedSources.isEmpty && |
| 7430 _changedContent.isEmpty && | 6946 _changedContent.isEmpty && |
| 7431 changedRanges.isEmpty && | 6947 changedRanges.isEmpty && |
| 7432 removedSources.isEmpty && | 6948 removedSources.isEmpty && |
| 7433 removedContainers.isEmpty && | 6949 removedContainers.isEmpty && |
| 7434 deletedSources.isEmpty; | 6950 deletedSources.isEmpty; |
| 7435 | 6951 |
| 7436 /** | 6952 /** |
| 7437 * Record that the specified source has been added and that its content is the
default contents of | 6953 * Record that the specified [source] has been added and that its content is |
| 7438 * the source. | 6954 * the default contents of the source. |
| 7439 * | |
| 7440 * @param source the source that was added | |
| 7441 */ | 6955 */ |
| 7442 void addedSource(Source source) { | 6956 void addedSource(Source source) { |
| 7443 addedSources.add(source); | 6957 addedSources.add(source); |
| 7444 } | 6958 } |
| 7445 | 6959 |
| 7446 /** | 6960 /** |
| 7447 * Record that the specified source has been changed and that its content is t
he given contents. | 6961 * Record that the specified [source] has been changed and that its content is |
| 7448 * | 6962 * the given [contents]. |
| 7449 * @param source the source that was changed | |
| 7450 * @param contents the new contents of the source, or `null` if the default co
ntents of the | |
| 7451 * source are to be used | |
| 7452 */ | 6963 */ |
| 7453 void changedContent(Source source, String contents) { | 6964 void changedContent(Source source, String contents) { |
| 7454 _changedContent[source] = contents; | 6965 _changedContent[source] = contents; |
| 7455 } | 6966 } |
| 7456 | 6967 |
| 7457 /** | 6968 /** |
| 7458 * Record that the specified source has been changed and that its content is t
he given contents. | 6969 * Record that the specified [source] has been changed and that its content is |
| 7459 * | 6970 * the given [contents]. The [offset] is the offset into the current contents. |
| 7460 * @param source the source that was changed | 6971 * The [oldLength] is the number of characters in the original contents that |
| 7461 * @param contents the new contents of the source | 6972 * were replaced. The [newLength] is the number of characters in the |
| 7462 * @param offset the offset into the current contents | 6973 * replacement text. |
| 7463 * @param oldLength the number of characters in the original contents that wer
e replaced | |
| 7464 * @param newLength the number of characters in the replacement text | |
| 7465 */ | 6974 */ |
| 7466 void changedRange(Source source, String contents, int offset, int oldLength, | 6975 void changedRange(Source source, String contents, int offset, int oldLength, |
| 7467 int newLength) { | 6976 int newLength) { |
| 7468 changedRanges[source] = | 6977 changedRanges[source] = |
| 7469 new ChangeSet_ContentChange(contents, offset, oldLength, newLength); | 6978 new ChangeSet_ContentChange(contents, offset, oldLength, newLength); |
| 7470 } | 6979 } |
| 7471 | 6980 |
| 7472 /** | 6981 /** |
| 7473 * Record that the specified source has been changed. If the content of the so
urce was previously | 6982 * Record that the specified [source] has been changed. If the content of the |
| 7474 * overridden, this has no effect (the content remains overridden). To cancel
(or change) the | 6983 * source was previously overridden, this has no effect (the content remains |
| 7475 * override, use [changedContent] instead. | 6984 * overridden). To cancel (or change) the override, use [changedContent] |
| 7476 * | 6985 * instead. |
| 7477 * @param source the source that was changed | |
| 7478 */ | 6986 */ |
| 7479 void changedSource(Source source) { | 6987 void changedSource(Source source) { |
| 7480 changedSources.add(source); | 6988 changedSources.add(source); |
| 7481 } | 6989 } |
| 7482 | 6990 |
| 7483 /** | 6991 /** |
| 7484 * Record that the specified source has been deleted. | 6992 * Record that the specified [source] has been deleted. |
| 7485 * | |
| 7486 * @param source the source that was deleted | |
| 7487 */ | 6993 */ |
| 7488 void deletedSource(Source source) { | 6994 void deletedSource(Source source) { |
| 7489 deletedSources.add(source); | 6995 deletedSources.add(source); |
| 7490 } | 6996 } |
| 7491 | 6997 |
| 7492 /** | 6998 /** |
| 7493 * Record that the specified source container has been removed. | 6999 * Record that the specified source [container] has been removed. |
| 7494 * | |
| 7495 * @param container the source container that was removed | |
| 7496 */ | 7000 */ |
| 7497 void removedContainer(SourceContainer container) { | 7001 void removedContainer(SourceContainer container) { |
| 7498 if (container != null) { | 7002 if (container != null) { |
| 7499 removedContainers.add(container); | 7003 removedContainers.add(container); |
| 7500 } | 7004 } |
| 7501 } | 7005 } |
| 7502 | 7006 |
| 7503 /** | 7007 /** |
| 7504 * Record that the specified source has been removed. | 7008 * Record that the specified [source] has been removed. |
| 7505 * | |
| 7506 * @param source the source that was removed | |
| 7507 */ | 7009 */ |
| 7508 void removedSource(Source source) { | 7010 void removedSource(Source source) { |
| 7509 if (source != null) { | 7011 if (source != null) { |
| 7510 removedSources.add(source); | 7012 removedSources.add(source); |
| 7511 } | 7013 } |
| 7512 } | 7014 } |
| 7513 | 7015 |
| 7514 @override | 7016 @override |
| 7515 String toString() { | 7017 String toString() { |
| 7516 StringBuffer buffer = new StringBuffer(); | 7018 StringBuffer buffer = new StringBuffer(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 7538 } else { | 7040 } else { |
| 7539 buffer.write(", and more from "); | 7041 buffer.write(", and more from "); |
| 7540 buffer.write(count); | 7042 buffer.write(count); |
| 7541 buffer.write(" containers"); | 7043 buffer.write(" containers"); |
| 7542 } | 7044 } |
| 7543 } | 7045 } |
| 7544 return buffer.toString(); | 7046 return buffer.toString(); |
| 7545 } | 7047 } |
| 7546 | 7048 |
| 7547 /** | 7049 /** |
| 7548 * Append the given sources to the given builder, prefixed with the given labe
l and possibly a | 7050 * Append the given [sources] to the given [buffer], prefixed with the given |
| 7549 * separator. | 7051 * [label] and a separator if [needsSeparator] is `true`. Return `true` if |
| 7550 * | 7052 * future lists of sources will need a separator. |
| 7551 * @param builder the builder to which the sources are to be appended | |
| 7552 * @param sources the sources to be appended | |
| 7553 * @param needsSeparator `true` if a separator is needed before the label | |
| 7554 * @param label the label used to prefix the sources | |
| 7555 * @return `true` if future lists of sources will need a separator | |
| 7556 */ | 7053 */ |
| 7557 bool _appendSources(StringBuffer buffer, List<Source> sources, | 7054 bool _appendSources(StringBuffer buffer, List<Source> sources, |
| 7558 bool needsSeparator, String label) { | 7055 bool needsSeparator, String label) { |
| 7559 if (sources.isEmpty) { | 7056 if (sources.isEmpty) { |
| 7560 return needsSeparator; | 7057 return needsSeparator; |
| 7561 } | 7058 } |
| 7562 if (needsSeparator) { | 7059 if (needsSeparator) { |
| 7563 buffer.write("; "); | 7060 buffer.write("; "); |
| 7564 } | 7061 } |
| 7565 buffer.write(label); | 7062 buffer.write(label); |
| 7566 String prefix = " "; | 7063 String prefix = " "; |
| 7567 for (Source source in sources) { | 7064 for (Source source in sources) { |
| 7568 buffer.write(prefix); | 7065 buffer.write(prefix); |
| 7569 buffer.write(source.fullName); | 7066 buffer.write(source.fullName); |
| 7570 prefix = ", "; | 7067 prefix = ", "; |
| 7571 } | 7068 } |
| 7572 return true; | 7069 return true; |
| 7573 } | 7070 } |
| 7574 | 7071 |
| 7575 /** | 7072 /** |
| 7576 * Append the given sources to the given builder, prefixed with the given labe
l and possibly a | 7073 * Append the given [sources] to the given [builder], prefixed with the given |
| 7577 * separator. | 7074 * [label] and a separator if [needsSeparator] is `true`. Return `true` if |
| 7578 * | 7075 * future lists of sources will need a separator. |
| 7579 * @param builder the builder to which the sources are to be appended | |
| 7580 * @param sources the sources to be appended | |
| 7581 * @param needsSeparator `true` if a separator is needed before the label | |
| 7582 * @param label the label used to prefix the sources | |
| 7583 * @return `true` if future lists of sources will need a separator | |
| 7584 */ | 7076 */ |
| 7585 bool _appendSources2(StringBuffer buffer, HashMap<Source, dynamic> sources, | 7077 bool _appendSources2(StringBuffer buffer, HashMap<Source, dynamic> sources, |
| 7586 bool needsSeparator, String label) { | 7078 bool needsSeparator, String label) { |
| 7587 if (sources.isEmpty) { | 7079 if (sources.isEmpty) { |
| 7588 return needsSeparator; | 7080 return needsSeparator; |
| 7589 } | 7081 } |
| 7590 if (needsSeparator) { | 7082 if (needsSeparator) { |
| 7591 buffer.write("; "); | 7083 buffer.write("; "); |
| 7592 } | 7084 } |
| 7593 buffer.write(label); | 7085 buffer.write(label); |
| 7594 String prefix = " "; | 7086 String prefix = " "; |
| 7595 for (Source source in sources.keys.toSet()) { | 7087 for (Source source in sources.keys.toSet()) { |
| 7596 buffer.write(prefix); | 7088 buffer.write(prefix); |
| 7597 buffer.write(source.fullName); | 7089 buffer.write(source.fullName); |
| 7598 prefix = ", "; | 7090 prefix = ", "; |
| 7599 } | 7091 } |
| 7600 return true; | 7092 return true; |
| 7601 } | 7093 } |
| 7602 } | 7094 } |
| 7603 | 7095 |
| 7604 /** | 7096 /** |
| 7605 * Instances of the class `ContentChange` represent a change to the content of a
source. | 7097 * A change to the content of a source. |
| 7606 */ | 7098 */ |
| 7607 class ChangeSet_ContentChange { | 7099 class ChangeSet_ContentChange { |
| 7608 /** | 7100 /** |
| 7609 * The new contents of the source. | 7101 * The new contents of the source. |
| 7610 */ | 7102 */ |
| 7611 final String contents; | 7103 final String contents; |
| 7612 | 7104 |
| 7613 /** | 7105 /** |
| 7614 * The offset into the current contents. | 7106 * The offset into the current contents. |
| 7615 */ | 7107 */ |
| 7616 final int offset; | 7108 final int offset; |
| 7617 | 7109 |
| 7618 /** | 7110 /** |
| 7619 * The number of characters in the original contents that were replaced | 7111 * The number of characters in the original contents that were replaced |
| 7620 */ | 7112 */ |
| 7621 final int oldLength; | 7113 final int oldLength; |
| 7622 | 7114 |
| 7623 /** | 7115 /** |
| 7624 * The number of characters in the replacement text. | 7116 * The number of characters in the replacement text. |
| 7625 */ | 7117 */ |
| 7626 final int newLength; | 7118 final int newLength; |
| 7627 | 7119 |
| 7628 /** | 7120 /** |
| 7629 * Initialize a newly created change object to represent a change to the conte
nt of a source. | 7121 * Initialize a newly created change object to represent a change to the |
| 7630 * | 7122 * content of a source. The [contents] is the new contents of the source. The |
| 7631 * @param contents the new contents of the source | 7123 * [offse] ist the offset into the current contents. The [oldLength] is the |
| 7632 * @param offset the offset into the current contents | 7124 * number of characters in the original contents that were replaced. The |
| 7633 * @param oldLength the number of characters in the original contents that wer
e replaced | 7125 * [newLength] is the number of characters in the replacement text. |
| 7634 * @param newLength the number of characters in the replacement text | |
| 7635 */ | 7126 */ |
| 7636 ChangeSet_ContentChange( | 7127 ChangeSet_ContentChange( |
| 7637 this.contents, this.offset, this.oldLength, this.newLength); | 7128 this.contents, this.offset, this.oldLength, this.newLength); |
| 7638 } | 7129 } |
| 7639 | 7130 |
| 7640 /** | 7131 /** |
| 7641 * Instances of the class `LibraryPair` hold a library and a list of the (source
, entry) | 7132 * A pair containing a library and a list of the (source, entry) pairs for |
| 7642 * pairs for compilation units in the library. | 7133 * compilation units in the library. |
| 7643 */ | 7134 */ |
| 7644 class CycleBuilder_LibraryPair { | 7135 class CycleBuilder_LibraryPair { |
| 7645 /** | 7136 /** |
| 7646 * The library containing the compilation units. | 7137 * The library containing the compilation units. |
| 7647 */ | 7138 */ |
| 7648 ResolvableLibrary library; | 7139 ResolvableLibrary library; |
| 7649 | 7140 |
| 7650 /** | 7141 /** |
| 7651 * The (source, entry) pairs representing the compilation units in the library
. | 7142 * The (source, entry) pairs representing the compilation units in the |
| 7143 * library. |
| 7652 */ | 7144 */ |
| 7653 List<CycleBuilder_SourceEntryPair> entryPairs; | 7145 List<CycleBuilder_SourceEntryPair> entryPairs; |
| 7654 | 7146 |
| 7655 /** | 7147 /** |
| 7656 * Initialize a newly created pair. | 7148 * Initialize a newly created pair from the given [library] and [entryPairs]. |
| 7657 * | |
| 7658 * @param library the library containing the compilation units | |
| 7659 * @param entryPairs the (source, entry) pairs representing the compilation un
its in the | |
| 7660 * library | |
| 7661 */ | 7149 */ |
| 7662 CycleBuilder_LibraryPair(ResolvableLibrary library, | 7150 CycleBuilder_LibraryPair(ResolvableLibrary library, |
| 7663 List<CycleBuilder_SourceEntryPair> entryPairs) { | 7151 List<CycleBuilder_SourceEntryPair> entryPairs) { |
| 7664 this.library = library; | 7152 this.library = library; |
| 7665 this.entryPairs = entryPairs; | 7153 this.entryPairs = entryPairs; |
| 7666 } | 7154 } |
| 7667 } | 7155 } |
| 7668 | 7156 |
| 7669 /** | 7157 /** |
| 7670 * Instances of the class `SourceEntryPair` hold a source and the cache entry as
sociated | 7158 * A pair containing a source and the cache entry associated with that source. |
| 7671 * with that source. They are used to reduce the number of times an entry must b
e looked up in | 7159 * They are used to reduce the number of times an entry must be looked up in the |
| 7672 * the [cache]. | 7160 * [cache]. |
| 7673 */ | 7161 */ |
| 7674 class CycleBuilder_SourceEntryPair { | 7162 class CycleBuilder_SourceEntryPair { |
| 7675 /** | 7163 /** |
| 7676 * The source associated with the entry. | 7164 * The source associated with the entry. |
| 7677 */ | 7165 */ |
| 7678 Source source; | 7166 Source source; |
| 7679 | 7167 |
| 7680 /** | 7168 /** |
| 7681 * The entry associated with the source. | 7169 * The entry associated with the source. |
| 7682 */ | 7170 */ |
| 7683 DartEntry entry; | 7171 DartEntry entry; |
| 7684 | 7172 |
| 7685 /** | 7173 /** |
| 7686 * Initialize a newly created pair. | 7174 * Initialize a newly created pair from the given [source] and [entry]. |
| 7687 * | |
| 7688 * @param source the source associated with the entry | |
| 7689 * @param entry the entry associated with the source | |
| 7690 */ | 7175 */ |
| 7691 CycleBuilder_SourceEntryPair(Source source, DartEntry entry) { | 7176 CycleBuilder_SourceEntryPair(Source source, DartEntry entry) { |
| 7692 this.source = source; | 7177 this.source = source; |
| 7693 this.entry = entry; | 7178 this.entry = entry; |
| 7694 } | 7179 } |
| 7695 } | 7180 } |
| 7696 | 7181 |
| 7697 /** | 7182 /** |
| 7698 * A `DartEntry` maintains the information cached by an analysis context about | 7183 * The information cached by an analysis context about an individual Dart file. |
| 7699 * an individual Dart file. | |
| 7700 */ | 7184 */ |
| 7701 class DartEntry extends SourceEntry { | 7185 class DartEntry extends SourceEntry { |
| 7702 /** | 7186 /** |
| 7703 * The data descriptor representing the element model representing a single | 7187 * The data descriptor representing the element model representing a single |
| 7704 * compilation unit. This model is incomplete and should not be used except as | 7188 * compilation unit. This model is incomplete and should not be used except as |
| 7705 * input to another task. | 7189 * input to another task. |
| 7706 */ | 7190 */ |
| 7707 static final DataDescriptor<List<AnalysisError>> BUILT_ELEMENT = | 7191 static final DataDescriptor<List<AnalysisError>> BUILT_ELEMENT = |
| 7708 new DataDescriptor<List<AnalysisError>>("DartEntry.BUILT_ELEMENT"); | 7192 new DataDescriptor<List<AnalysisError>>("DartEntry.BUILT_ELEMENT"); |
| 7709 | 7193 |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7886 state = state._nextState; | 7370 state = state._nextState; |
| 7887 } | 7371 } |
| 7888 if (errors.length == 0) { | 7372 if (errors.length == 0) { |
| 7889 return AnalysisError.NO_ERRORS; | 7373 return AnalysisError.NO_ERRORS; |
| 7890 } | 7374 } |
| 7891 return errors; | 7375 return errors; |
| 7892 } | 7376 } |
| 7893 | 7377 |
| 7894 /** | 7378 /** |
| 7895 * Return a valid parsed compilation unit, either an unresolved AST structure | 7379 * Return a valid parsed compilation unit, either an unresolved AST structure |
| 7896 * or the result of resolving the AST structure in the context of some library
, | 7380 * or the result of resolving the AST structure in the context of some |
| 7897 * or `null` if there is no parsed compilation unit available. | 7381 * library, or `null` if there is no parsed compilation unit available. |
| 7898 */ | 7382 */ |
| 7899 CompilationUnit get anyParsedCompilationUnit { | 7383 CompilationUnit get anyParsedCompilationUnit { |
| 7900 if (getState(PARSED_UNIT) == CacheState.VALID) { | 7384 if (getState(PARSED_UNIT) == CacheState.VALID) { |
| 7901 return getValue(PARSED_UNIT); | 7385 return getValue(PARSED_UNIT); |
| 7902 } | 7386 } |
| 7903 ResolutionState state = _resolutionState; | 7387 ResolutionState state = _resolutionState; |
| 7904 while (state != null) { | 7388 while (state != null) { |
| 7905 if (state.getState(BUILT_UNIT) == CacheState.VALID) { | 7389 if (state.getState(BUILT_UNIT) == CacheState.VALID) { |
| 7906 return state.getValue(BUILT_UNIT); | 7390 return state.getValue(BUILT_UNIT); |
| 7907 } | 7391 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 7926 return null; | 7410 return null; |
| 7927 } | 7411 } |
| 7928 | 7412 |
| 7929 /** | 7413 /** |
| 7930 * The libraries that are known to contain this part. | 7414 * The libraries that are known to contain this part. |
| 7931 */ | 7415 */ |
| 7932 List<Source> get containingLibraries => _containingLibraries; | 7416 List<Source> get containingLibraries => _containingLibraries; |
| 7933 | 7417 |
| 7934 /** | 7418 /** |
| 7935 * Set the list of libraries that contain this compilation unit to contain | 7419 * Set the list of libraries that contain this compilation unit to contain |
| 7936 * only the given source. This method should only be invoked on entries that | 7420 * only the given [librarySource]. This method should only be invoked on |
| 7937 * represent a library. | 7421 * entries that represent a library. |
| 7938 * | |
| 7939 * @param librarySource the source of the single library that the list should
contain | |
| 7940 */ | 7422 */ |
| 7941 void set containingLibrary(Source librarySource) { | 7423 void set containingLibrary(Source librarySource) { |
| 7942 _containingLibraries.clear(); | 7424 _containingLibraries.clear(); |
| 7943 _containingLibraries.add(librarySource); | 7425 _containingLibraries.add(librarySource); |
| 7944 } | 7426 } |
| 7945 | 7427 |
| 7946 @override | 7428 @override |
| 7947 List<DataDescriptor> get descriptors { | 7429 List<DataDescriptor> get descriptors { |
| 7948 List<DataDescriptor> result = super.descriptors; | 7430 List<DataDescriptor> result = super.descriptors; |
| 7949 result.addAll(<DataDescriptor>[ | 7431 result.addAll(<DataDescriptor>[ |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8205 | 7687 |
| 8206 @override | 7688 @override |
| 8207 void recordContentError(CaughtException exception) { | 7689 void recordContentError(CaughtException exception) { |
| 8208 super.recordContentError(exception); | 7690 super.recordContentError(exception); |
| 8209 recordScanError(exception); | 7691 recordScanError(exception); |
| 8210 } | 7692 } |
| 8211 | 7693 |
| 8212 /** | 7694 /** |
| 8213 * Record that an error occurred while attempting to generate hints for the | 7695 * Record that an error occurred while attempting to generate hints for the |
| 8214 * source represented by this entry. This will set the state of all | 7696 * source represented by this entry. This will set the state of all |
| 8215 * verification information as being in error. | 7697 * verification information as being in error. The [librarySource] is the |
| 8216 * | 7698 * source of the library in which hints were being generated. The [exception] |
| 8217 * @param librarySource the source of the library in which hints were being ge
nerated | 7699 * is the exception that shows where the error occurred. |
| 8218 * @param exception the exception that shows where the error occurred | |
| 8219 */ | 7700 */ |
| 8220 void recordHintErrorInLibrary( | 7701 void recordHintErrorInLibrary( |
| 8221 Source librarySource, CaughtException exception) { | 7702 Source librarySource, CaughtException exception) { |
| 8222 this.exception = exception; | 7703 this.exception = exception; |
| 8223 ResolutionState state = _getOrCreateResolutionState(librarySource); | 7704 ResolutionState state = _getOrCreateResolutionState(librarySource); |
| 8224 state.recordHintError(); | 7705 state.recordHintError(); |
| 8225 } | 7706 } |
| 8226 | 7707 |
| 8227 /** | 7708 /** |
| 8228 * Record that an error occurred while attempting to generate lints for the | 7709 * Record that an error occurred while attempting to generate lints for the |
| 8229 * source represented by this entry. This will set the state of all | 7710 * source represented by this entry. This will set the state of all |
| 8230 * verification information as being in error. | 7711 * verification information as being in error. The [librarySource] is the |
| 8231 * | 7712 * source of the library in which lints were being generated. The [exception] |
| 8232 * @param librarySource the source of the library in which lints were being ge
nerated | 7713 * is the exception that shows where the error occurred. |
| 8233 * @param exception the exception that shows where the error occurred | |
| 8234 */ | 7714 */ |
| 8235 void recordLintErrorInLibrary( | 7715 void recordLintErrorInLibrary( |
| 8236 Source librarySource, CaughtException exception) { | 7716 Source librarySource, CaughtException exception) { |
| 8237 this.exception = exception; | 7717 this.exception = exception; |
| 8238 ResolutionState state = _getOrCreateResolutionState(librarySource); | 7718 ResolutionState state = _getOrCreateResolutionState(librarySource); |
| 8239 state.recordLintError(); | 7719 state.recordLintError(); |
| 8240 } | 7720 } |
| 8241 | 7721 |
| 8242 /** | 7722 /** |
| 8243 * Record that an [exception] occurred while attempting to scan or parse the | 7723 * Record that an [exception] occurred while attempting to scan or parse the |
| 8244 * entry represented by this entry. This will set the state of all information
, | 7724 * entry represented by this entry. This will set the state of all information
, |
| 8245 * including any resolution-based information, as being in error. | 7725 * including any resolution-based information, as being in error. |
| 8246 */ | 7726 */ |
| 8247 void recordParseError(CaughtException exception) { | 7727 void recordParseError(CaughtException exception) { |
| 8248 setState(SOURCE_KIND, CacheState.ERROR); | 7728 setState(SOURCE_KIND, CacheState.ERROR); |
| 8249 setState(PARSE_ERRORS, CacheState.ERROR); | 7729 setState(PARSE_ERRORS, CacheState.ERROR); |
| 8250 setState(PARSED_UNIT, CacheState.ERROR); | 7730 setState(PARSED_UNIT, CacheState.ERROR); |
| 8251 setState(EXPORTED_LIBRARIES, CacheState.ERROR); | 7731 setState(EXPORTED_LIBRARIES, CacheState.ERROR); |
| 8252 setState(IMPORTED_LIBRARIES, CacheState.ERROR); | 7732 setState(IMPORTED_LIBRARIES, CacheState.ERROR); |
| 8253 setState(INCLUDED_PARTS, CacheState.ERROR); | 7733 setState(INCLUDED_PARTS, CacheState.ERROR); |
| 8254 recordResolutionError(exception); | 7734 recordResolutionError(exception); |
| 8255 } | 7735 } |
| 8256 | 7736 |
| 8257 /** | 7737 /** |
| 8258 * Record that an [exception] occurred while attempting to resolve the source | 7738 * Record that an [exception] occurred while attempting to resolve the source |
| 8259 * represented by this entry. This will set the state of all resolution-based | 7739 * represented by this entry. This will set the state of all resolution-based |
| 8260 * information as being in error, but will not change the state of any parse | 7740 * information as being in error, but will not change the state of any parse |
| 8261 * results. | 7741 * results. |
| 8262 * | |
| 8263 * @param exception the exception that shows where the error occurred | |
| 8264 */ | 7742 */ |
| 8265 void recordResolutionError(CaughtException exception) { | 7743 void recordResolutionError(CaughtException exception) { |
| 8266 this.exception = exception; | 7744 this.exception = exception; |
| 8267 setState(ELEMENT, CacheState.ERROR); | 7745 setState(ELEMENT, CacheState.ERROR); |
| 8268 setState(IS_CLIENT, CacheState.ERROR); | 7746 setState(IS_CLIENT, CacheState.ERROR); |
| 8269 setState(IS_LAUNCHABLE, CacheState.ERROR); | 7747 setState(IS_LAUNCHABLE, CacheState.ERROR); |
| 8270 setState(PUBLIC_NAMESPACE, CacheState.ERROR); | 7748 setState(PUBLIC_NAMESPACE, CacheState.ERROR); |
| 8271 _resolutionState.recordResolutionErrorsInAllLibraries(); | 7749 _resolutionState.recordResolutionErrorsInAllLibraries(); |
| 8272 } | 7750 } |
| 8273 | 7751 |
| 8274 /** | 7752 /** |
| 8275 * Record that an error occurred while attempting to resolve the source repres
ented by this entry. | 7753 * Record that an error occurred while attempting to resolve the source |
| 8276 * This will set the state of all resolution-based information as being in err
or, but will not | 7754 * represented by this entry. This will set the state of all resolution-based |
| 8277 * change the state of any parse results. | 7755 * information as being in error, but will not change the state of any parse |
| 8278 * | 7756 * results. The [librarySource] is the source of the library in which |
| 8279 * @param librarySource the source of the library in which resolution was bein
g performed | 7757 * resolution was being performed. The [exception] is the exception that shows |
| 8280 * @param exception the exception that shows where the error occurred | 7758 * where the error occurred. |
| 8281 */ | 7759 */ |
| 8282 void recordResolutionErrorInLibrary( | 7760 void recordResolutionErrorInLibrary( |
| 8283 Source librarySource, CaughtException exception) { | 7761 Source librarySource, CaughtException exception) { |
| 8284 this.exception = exception; | 7762 this.exception = exception; |
| 8285 setState(ELEMENT, CacheState.ERROR); | 7763 setState(ELEMENT, CacheState.ERROR); |
| 8286 setState(IS_CLIENT, CacheState.ERROR); | 7764 setState(IS_CLIENT, CacheState.ERROR); |
| 8287 setState(IS_LAUNCHABLE, CacheState.ERROR); | 7765 setState(IS_LAUNCHABLE, CacheState.ERROR); |
| 8288 setState(PUBLIC_NAMESPACE, CacheState.ERROR); | 7766 setState(PUBLIC_NAMESPACE, CacheState.ERROR); |
| 8289 ResolutionState state = _getOrCreateResolutionState(librarySource); | 7767 ResolutionState state = _getOrCreateResolutionState(librarySource); |
| 8290 state.recordResolutionError(); | 7768 state.recordResolutionError(); |
| 8291 } | 7769 } |
| 8292 | 7770 |
| 8293 /** | 7771 /** |
| 8294 * Record that an [exception] occurred while attempting to scan or parse the | 7772 * Record that an [exception] occurred while attempting to scan or parse the |
| 8295 * entry represented by this entry. This will set the state of all information
, | 7773 * entry represented by this entry. This will set the state of all |
| 8296 * including any resolution-based information, as being in error. | 7774 * information, including any resolution-based information, as being in error. |
| 8297 */ | 7775 */ |
| 8298 @override | 7776 @override |
| 8299 void recordScanError(CaughtException exception) { | 7777 void recordScanError(CaughtException exception) { |
| 8300 super.recordScanError(exception); | 7778 super.recordScanError(exception); |
| 8301 setState(SCAN_ERRORS, CacheState.ERROR); | 7779 setState(SCAN_ERRORS, CacheState.ERROR); |
| 8302 setState(TOKEN_STREAM, CacheState.ERROR); | 7780 setState(TOKEN_STREAM, CacheState.ERROR); |
| 8303 recordParseError(exception); | 7781 recordParseError(exception); |
| 8304 } | 7782 } |
| 8305 | 7783 |
| 8306 /** | 7784 /** |
| 8307 * Record that an [exception] occurred while attempting to generate errors and | 7785 * Record that an [exception] occurred while attempting to generate errors and |
| 8308 * warnings for the source represented by this entry. This will set the state | 7786 * warnings for the source represented by this entry. This will set the state |
| 8309 * of all verification information as being in error. | 7787 * of all verification information as being in error. The [librarySource] is |
| 8310 * | 7788 * the source of the library in which verification was being performed. The |
| 8311 * @param librarySource the source of the library in which verification was be
ing performed | 7789 * [exception] is the exception that shows where the error occurred. |
| 8312 * @param exception the exception that shows where the error occurred | |
| 8313 */ | 7790 */ |
| 8314 void recordVerificationErrorInLibrary( | 7791 void recordVerificationErrorInLibrary( |
| 8315 Source librarySource, CaughtException exception) { | 7792 Source librarySource, CaughtException exception) { |
| 8316 this.exception = exception; | 7793 this.exception = exception; |
| 8317 ResolutionState state = _getOrCreateResolutionState(librarySource); | 7794 ResolutionState state = _getOrCreateResolutionState(librarySource); |
| 8318 state.recordVerificationError(); | 7795 state.recordVerificationError(); |
| 8319 } | 7796 } |
| 8320 | 7797 |
| 8321 /** | 7798 /** |
| 8322 * Remove the given [library] from the list of libraries that contain this | 7799 * Remove the given [library] from the list of libraries that contain this |
| 8323 * part. This method should only be invoked on entries that represent a part. | 7800 * part. This method should only be invoked on entries that represent a part. |
| 8324 * | |
| 8325 * @param librarySource the source of the library to be removed | |
| 8326 */ | 7801 */ |
| 8327 void removeContainingLibrary(Source library) { | 7802 void removeContainingLibrary(Source library) { |
| 8328 _containingLibraries.remove(library); | 7803 _containingLibraries.remove(library); |
| 8329 } | 7804 } |
| 8330 | 7805 |
| 8331 /** | 7806 /** |
| 8332 * Remove any resolution information associated with this compilation unit | 7807 * Remove any resolution information associated with this compilation unit |
| 8333 * being part of the given [library], presumably because it is no longer part | 7808 * being part of the given [library], presumably because it is no longer part |
| 8334 * of the library. | 7809 * of the library. |
| 8335 */ | 7810 */ |
| (...skipping 14 matching lines...) Expand all Loading... |
| 8350 break; | 7825 break; |
| 8351 } | 7826 } |
| 8352 priorState = state; | 7827 priorState = state; |
| 8353 state = state._nextState; | 7828 state = state._nextState; |
| 8354 } | 7829 } |
| 8355 } | 7830 } |
| 8356 } | 7831 } |
| 8357 } | 7832 } |
| 8358 | 7833 |
| 8359 /** | 7834 /** |
| 8360 * Set the state of the data represented by the given descriptor in the contex
t of the given | 7835 * Set the state of the data represented by the given [descriptor] in the |
| 8361 * library to the given state. | 7836 * context of the given [library] to the given [state]. |
| 8362 * | |
| 8363 * @param descriptor the descriptor representing the data whose state is to be
set | |
| 8364 * @param librarySource the source of the defining compilation unit of the lib
rary that is the | |
| 8365 * context for the data | |
| 8366 * @param cacheState the new state of the data represented by the given descri
ptor | |
| 8367 */ | 7837 */ |
| 8368 void setStateInLibrary( | 7838 void setStateInLibrary( |
| 8369 DataDescriptor descriptor, Source librarySource, CacheState cacheState) { | 7839 DataDescriptor descriptor, Source library, CacheState state) { |
| 8370 if (!_isValidLibraryDescriptor(descriptor)) { | 7840 if (!_isValidLibraryDescriptor(descriptor)) { |
| 8371 throw new ArgumentError("Invalid descriptor: $descriptor"); | 7841 throw new ArgumentError("Invalid descriptor: $descriptor"); |
| 8372 } | 7842 } |
| 8373 ResolutionState state = _getOrCreateResolutionState(librarySource); | 7843 ResolutionState resolutionState = _getOrCreateResolutionState(library); |
| 8374 state.setState(descriptor, cacheState); | 7844 resolutionState.setState(descriptor, state); |
| 8375 } | 7845 } |
| 8376 | 7846 |
| 8377 /** | 7847 /** |
| 8378 * Set the value of the data represented by the given descriptor in the contex
t of the given | 7848 * Set the value of the data represented by the given [descriptor] in the |
| 8379 * library to the given value, and set the state of that data to [CacheState.V
ALID]. | 7849 * context of the given [library] to the given [value], and set the state of |
| 8380 * | 7850 * that data to [CacheState.VALID]. |
| 8381 * @param descriptor the descriptor representing which data is to have its val
ue set | |
| 8382 * @param librarySource the source of the defining compilation unit of the lib
rary that is the | |
| 8383 * context for the data | |
| 8384 * @param value the new value of the data represented by the given descriptor
and library | |
| 8385 */ | 7851 */ |
| 8386 void setValueInLibrary( | 7852 void setValueInLibrary( |
| 8387 DataDescriptor descriptor, Source librarySource, Object value) { | 7853 DataDescriptor descriptor, Source library, Object value) { |
| 8388 if (!_isValidLibraryDescriptor(descriptor)) { | 7854 if (!_isValidLibraryDescriptor(descriptor)) { |
| 8389 throw new ArgumentError("Invalid descriptor: $descriptor"); | 7855 throw new ArgumentError("Invalid descriptor: $descriptor"); |
| 8390 } | 7856 } |
| 8391 ResolutionState state = _getOrCreateResolutionState(librarySource); | 7857 ResolutionState state = _getOrCreateResolutionState(library); |
| 8392 state.setValue(descriptor, value); | 7858 state.setValue(descriptor, value); |
| 8393 } | 7859 } |
| 8394 | 7860 |
| 8395 /** | 7861 /** |
| 8396 * Invalidate all of the resolution information associated with the compilatio
n unit. | 7862 * Invalidate all of the resolution information associated with the |
| 8397 * | 7863 * compilation unit. The flag [invalidateUris] should be `true` if the cached |
| 8398 * @param invalidateUris true if the cached results of converting URIs to sour
ce files should also | 7864 * results of converting URIs to source files should also be invalidated. |
| 8399 * be invalidated. | |
| 8400 */ | 7865 */ |
| 8401 void _discardCachedResolutionInformation(bool invalidateUris) { | 7866 void _discardCachedResolutionInformation(bool invalidateUris) { |
| 8402 setState(ELEMENT, CacheState.INVALID); | 7867 setState(ELEMENT, CacheState.INVALID); |
| 8403 setState(IS_CLIENT, CacheState.INVALID); | 7868 setState(IS_CLIENT, CacheState.INVALID); |
| 8404 setState(IS_LAUNCHABLE, CacheState.INVALID); | 7869 setState(IS_LAUNCHABLE, CacheState.INVALID); |
| 8405 setState(PUBLIC_NAMESPACE, CacheState.INVALID); | 7870 setState(PUBLIC_NAMESPACE, CacheState.INVALID); |
| 8406 _resolutionState.invalidateAllResolutionInformation(); | 7871 _resolutionState.invalidateAllResolutionInformation(); |
| 8407 if (invalidateUris) { | 7872 if (invalidateUris) { |
| 8408 setState(EXPORTED_LIBRARIES, CacheState.INVALID); | 7873 setState(EXPORTED_LIBRARIES, CacheState.INVALID); |
| 8409 setState(IMPORTED_LIBRARIES, CacheState.INVALID); | 7874 setState(IMPORTED_LIBRARIES, CacheState.INVALID); |
| 8410 setState(INCLUDED_PARTS, CacheState.INVALID); | 7875 setState(INCLUDED_PARTS, CacheState.INVALID); |
| 8411 } | 7876 } |
| 8412 } | 7877 } |
| 8413 | 7878 |
| 8414 /** | 7879 /** |
| 8415 * Return a resolution state for the specified library, creating one as necess
ary. | 7880 * Return a resolution state for the specified [library], creating one as |
| 8416 * | 7881 * necessary. |
| 8417 * @param librarySource the library source (not `null`) | |
| 8418 * @return the resolution state (not `null`) | |
| 8419 */ | 7882 */ |
| 8420 ResolutionState _getOrCreateResolutionState(Source librarySource) { | 7883 ResolutionState _getOrCreateResolutionState(Source library) { |
| 8421 ResolutionState state = _resolutionState; | 7884 ResolutionState state = _resolutionState; |
| 8422 if (state._librarySource == null) { | 7885 if (state._librarySource == null) { |
| 8423 state._librarySource = librarySource; | 7886 state._librarySource = library; |
| 8424 return state; | 7887 return state; |
| 8425 } | 7888 } |
| 8426 while (state._librarySource != librarySource) { | 7889 while (state._librarySource != library) { |
| 8427 if (state._nextState == null) { | 7890 if (state._nextState == null) { |
| 8428 ResolutionState newState = new ResolutionState(); | 7891 ResolutionState newState = new ResolutionState(); |
| 8429 newState._librarySource = librarySource; | 7892 newState._librarySource = library; |
| 8430 state._nextState = newState; | 7893 state._nextState = newState; |
| 8431 return newState; | 7894 return newState; |
| 8432 } | 7895 } |
| 8433 state = state._nextState; | 7896 state = state._nextState; |
| 8434 } | 7897 } |
| 8435 return state; | 7898 return state; |
| 8436 } | 7899 } |
| 8437 | 7900 |
| 8438 @override | 7901 @override |
| 8439 bool _isValidDescriptor(DataDescriptor descriptor) { | 7902 bool _isValidDescriptor(DataDescriptor descriptor) { |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8573 _writeStateOn(buffer, "includedParts", INCLUDED_PARTS); | 8036 _writeStateOn(buffer, "includedParts", INCLUDED_PARTS); |
| 8574 _writeStateOn(buffer, "element", ELEMENT); | 8037 _writeStateOn(buffer, "element", ELEMENT); |
| 8575 _writeStateOn(buffer, "publicNamespace", PUBLIC_NAMESPACE); | 8038 _writeStateOn(buffer, "publicNamespace", PUBLIC_NAMESPACE); |
| 8576 _writeStateOn(buffer, "clientServer", IS_CLIENT); | 8039 _writeStateOn(buffer, "clientServer", IS_CLIENT); |
| 8577 _writeStateOn(buffer, "launchable", IS_LAUNCHABLE); | 8040 _writeStateOn(buffer, "launchable", IS_LAUNCHABLE); |
| 8578 _resolutionState._writeOn(buffer); | 8041 _resolutionState._writeOn(buffer); |
| 8579 } | 8042 } |
| 8580 } | 8043 } |
| 8581 | 8044 |
| 8582 /** | 8045 /** |
| 8583 * Instances of the class `DataDescriptor` are immutable constants representing
data that can | 8046 * An immutable constant representing data that can be stored in the cache. |
| 8584 * be stored in the cache. | |
| 8585 */ | 8047 */ |
| 8586 class DataDescriptor<E> { | 8048 class DataDescriptor<E> { |
| 8587 /** | 8049 /** |
| 8588 * The next artificial hash code. | 8050 * The next artificial hash code. |
| 8589 */ | 8051 */ |
| 8590 static int _NEXT_HASH_CODE = 0; | 8052 static int _NEXT_HASH_CODE = 0; |
| 8591 | 8053 |
| 8592 /** | 8054 /** |
| 8593 * The artifitial hash code for this object. | 8055 * The artifitial hash code for this object. |
| 8594 */ | 8056 */ |
| (...skipping 16 matching lines...) Expand all Loading... |
| 8611 DataDescriptor(this._name, [this.defaultValue = null]); | 8073 DataDescriptor(this._name, [this.defaultValue = null]); |
| 8612 | 8074 |
| 8613 @override | 8075 @override |
| 8614 int get hashCode => _hashCode; | 8076 int get hashCode => _hashCode; |
| 8615 | 8077 |
| 8616 @override | 8078 @override |
| 8617 String toString() => _name; | 8079 String toString() => _name; |
| 8618 } | 8080 } |
| 8619 | 8081 |
| 8620 /** | 8082 /** |
| 8621 * Instances of the class `DefaultRetentionPolicy` implement a retention policy
that will keep | 8083 * A retention policy that will keep AST's in the cache if there is analysis |
| 8622 * AST's in the cache if there is analysis information that needs to be computed
for a source, where | 8084 * information that needs to be computed for a source, where the computation is |
| 8623 * the computation is dependent on having the AST. | 8085 * dependent on having the AST. |
| 8624 */ | 8086 */ |
| 8625 class DefaultRetentionPolicy implements CacheRetentionPolicy { | 8087 class DefaultRetentionPolicy implements CacheRetentionPolicy { |
| 8626 /** | 8088 /** |
| 8627 * An instance of this class that can be shared. | 8089 * An instance of this class that can be shared. |
| 8628 */ | 8090 */ |
| 8629 static DefaultRetentionPolicy POLICY = new DefaultRetentionPolicy(); | 8091 static DefaultRetentionPolicy POLICY = new DefaultRetentionPolicy(); |
| 8630 | 8092 |
| 8631 /** | 8093 /** |
| 8632 * Return `true` if there is analysis information in the given entry that need
s to be | 8094 * Return `true` if there is analysis information in the given [dartEntry] |
| 8633 * computed, where the computation is dependent on having the AST. | 8095 * that needs to be computed, where the computation is dependent on having the |
| 8634 * | 8096 * AST. |
| 8635 * @param dartEntry the entry being tested | |
| 8636 * @return `true` if there is analysis information that needs to be computed f
rom the AST | |
| 8637 */ | 8097 */ |
| 8638 bool astIsNeeded(DartEntry dartEntry) => | 8098 bool astIsNeeded(DartEntry dartEntry) => |
| 8639 dartEntry.hasInvalidData(DartEntry.HINTS) || | 8099 dartEntry.hasInvalidData(DartEntry.HINTS) || |
| 8640 dartEntry.hasInvalidData(DartEntry.LINTS) || | 8100 dartEntry.hasInvalidData(DartEntry.LINTS) || |
| 8641 dartEntry.hasInvalidData(DartEntry.VERIFICATION_ERRORS) || | 8101 dartEntry.hasInvalidData(DartEntry.VERIFICATION_ERRORS) || |
| 8642 dartEntry.hasInvalidData(DartEntry.RESOLUTION_ERRORS); | 8102 dartEntry.hasInvalidData(DartEntry.RESOLUTION_ERRORS); |
| 8643 | 8103 |
| 8644 @override | 8104 @override |
| 8645 RetentionPriority getAstPriority(Source source, SourceEntry sourceEntry) { | 8105 RetentionPriority getAstPriority(Source source, SourceEntry sourceEntry) { |
| 8646 if (sourceEntry is DartEntry) { | 8106 if (sourceEntry is DartEntry) { |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8784 CompileTimeErrorCode.URI_DOES_NOT_EXIST, [directive.uriContent])); | 8244 CompileTimeErrorCode.URI_DOES_NOT_EXIST, [directive.uriContent])); |
| 8785 } | 8245 } |
| 8786 } | 8246 } |
| 8787 | 8247 |
| 8788 /** | 8248 /** |
| 8789 * Instances of the class `GenerateDartHintsTask` generate hints for a single Da
rt library. | 8249 * Instances of the class `GenerateDartHintsTask` generate hints for a single Da
rt library. |
| 8790 */ | 8250 */ |
| 8791 class GenerateDartHintsTask extends AnalysisTask { | 8251 class GenerateDartHintsTask extends AnalysisTask { |
| 8792 /** | 8252 /** |
| 8793 * The compilation units that comprise the library, with the defining compilat
ion unit appearing | 8253 * The compilation units that comprise the library, with the defining compilat
ion unit appearing |
| 8794 * first in the array. | 8254 * first in the list. |
| 8795 */ | 8255 */ |
| 8796 final List<TimestampedData<CompilationUnit>> _units; | 8256 final List<TimestampedData<CompilationUnit>> _units; |
| 8797 | 8257 |
| 8798 /** | 8258 /** |
| 8799 * The element model for the library being analyzed. | 8259 * The element model for the library being analyzed. |
| 8800 */ | 8260 */ |
| 8801 final LibraryElement libraryElement; | 8261 final LibraryElement libraryElement; |
| 8802 | 8262 |
| 8803 /** | 8263 /** |
| 8804 * A table mapping the sources that were analyzed to the hints that were | 8264 * A table mapping the sources that were analyzed to the hints that were |
| 8805 * generated for the sources. | 8265 * generated for the sources. |
| 8806 */ | 8266 */ |
| 8807 HashMap<Source, List<AnalysisError>> _hintMap; | 8267 HashMap<Source, List<AnalysisError>> _hintMap; |
| 8808 | 8268 |
| 8809 /** | 8269 /** |
| 8810 * Initialize a newly created task to perform analysis within the given contex
t. | 8270 * Initialize a newly created task to perform analysis within the given contex
t. |
| 8811 * | 8271 * |
| 8812 * @param context the context in which the task is to be performed | 8272 * @param context the context in which the task is to be performed |
| 8813 * @param units the compilation units that comprise the library, with the defi
ning compilation | 8273 * @param units the compilation units that comprise the library, with the defi
ning compilation |
| 8814 * unit appearing first in the array | 8274 * unit appearing first in the list |
| 8815 * @param libraryElement the element model for the library being analyzed | 8275 * @param libraryElement the element model for the library being analyzed |
| 8816 */ | 8276 */ |
| 8817 GenerateDartHintsTask( | 8277 GenerateDartHintsTask( |
| 8818 InternalAnalysisContext context, this._units, this.libraryElement) | 8278 InternalAnalysisContext context, this._units, this.libraryElement) |
| 8819 : super(context); | 8279 : super(context); |
| 8820 | 8280 |
| 8821 /** | 8281 /** |
| 8822 * Return a table mapping the sources that were analyzed to the hints that wer
e generated for the | 8282 * Return a table mapping the sources that were analyzed to the hints that wer
e generated for the |
| 8823 * sources, or `null` if the task has not been performed or if the analysis di
d not complete | 8283 * sources, or `null` if the task has not been performed or if the analysis di
d not complete |
| 8824 * normally. | 8284 * normally. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8867 Source source = _units[i].data.element.source; | 8327 Source source = _units[i].data.element.source; |
| 8868 _hintMap[source] = errorListener.getErrorsForSource(source); | 8328 _hintMap[source] = errorListener.getErrorsForSource(source); |
| 8869 } | 8329 } |
| 8870 } | 8330 } |
| 8871 } | 8331 } |
| 8872 | 8332 |
| 8873 /// Generates lint feedback for a single Dart library. | 8333 /// Generates lint feedback for a single Dart library. |
| 8874 class GenerateDartLintsTask extends AnalysisTask { | 8334 class GenerateDartLintsTask extends AnalysisTask { |
| 8875 | 8335 |
| 8876 ///The compilation units that comprise the library, with the defining | 8336 ///The compilation units that comprise the library, with the defining |
| 8877 ///compilation unit appearing first in the array. | 8337 ///compilation unit appearing first in the list. |
| 8878 final List<TimestampedData<CompilationUnit>> _units; | 8338 final List<TimestampedData<CompilationUnit>> _units; |
| 8879 | 8339 |
| 8880 /// The element model for the library being analyzed. | 8340 /// The element model for the library being analyzed. |
| 8881 final LibraryElement libraryElement; | 8341 final LibraryElement libraryElement; |
| 8882 | 8342 |
| 8883 /// A mapping of analyzed sources to their associated lint warnings. | 8343 /// A mapping of analyzed sources to their associated lint warnings. |
| 8884 /// May be [null] if the task has not been performed or if analysis did not | 8344 /// May be [null] if the task has not been performed or if analysis did not |
| 8885 /// complete normally. | 8345 /// complete normally. |
| 8886 HashMap<Source, List<AnalysisError>> lintMap; | 8346 HashMap<Source, List<AnalysisError>> lintMap; |
| 8887 | 8347 |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9007 } catch (exception, stackTrace) { | 8467 } catch (exception, stackTrace) { |
| 9008 errors.add(new AnalysisError.con1( | 8468 errors.add(new AnalysisError.con1( |
| 9009 source, ScannerErrorCode.UNABLE_GET_CONTENT, [exception])); | 8469 source, ScannerErrorCode.UNABLE_GET_CONTENT, [exception])); |
| 9010 throw new AnalysisException("Could not get contents of $source", | 8470 throw new AnalysisException("Could not get contents of $source", |
| 9011 new CaughtException(exception, stackTrace)); | 8471 new CaughtException(exception, stackTrace)); |
| 9012 } | 8472 } |
| 9013 } | 8473 } |
| 9014 } | 8474 } |
| 9015 | 8475 |
| 9016 /** | 8476 /** |
| 9017 * An `HtmlEntry` maintains the information cached by an analysis context about | 8477 * The information cached by an analysis context about an individual HTML file. |
| 9018 * an individual HTML file. | |
| 9019 */ | 8478 */ |
| 9020 class HtmlEntry extends SourceEntry { | 8479 class HtmlEntry extends SourceEntry { |
| 9021 /** | 8480 /** |
| 9022 * The data descriptor representing the HTML element. | 8481 * The data descriptor representing the HTML element. |
| 9023 */ | 8482 */ |
| 9024 static final DataDescriptor<HtmlElement> ELEMENT = | 8483 static final DataDescriptor<HtmlElement> ELEMENT = |
| 9025 new DataDescriptor<HtmlElement>("HtmlEntry.ELEMENT"); | 8484 new DataDescriptor<HtmlElement>("HtmlEntry.ELEMENT"); |
| 9026 | 8485 |
| 9027 /** | 8486 /** |
| 9028 * The data descriptor representing the hints resulting from auditing the | 8487 * The data descriptor representing the hints resulting from auditing the |
| (...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9517 IncrementalResolver resolver = new IncrementalResolver( | 8976 IncrementalResolver resolver = new IncrementalResolver( |
| 9518 element, cache.offset, cache.oldLength, cache.newLength); | 8977 element, cache.offset, cache.oldLength, cache.newLength); |
| 9519 resolver.resolve(parser.updatedNode); | 8978 resolver.resolve(parser.updatedNode); |
| 9520 } | 8979 } |
| 9521 } | 8980 } |
| 9522 } | 8981 } |
| 9523 } | 8982 } |
| 9524 } | 8983 } |
| 9525 | 8984 |
| 9526 /** | 8985 /** |
| 9527 * The interface `InternalAnalysisContext` defines additional behavior for an an
alysis context | 8986 * Additional behavior for an analysis context that is required by internal |
| 9528 * that is required by internal users of the context. | 8987 * users of the context. |
| 9529 */ | 8988 */ |
| 9530 abstract class InternalAnalysisContext implements AnalysisContext { | 8989 abstract class InternalAnalysisContext implements AnalysisContext { |
| 9531 /** | 8990 /** |
| 9532 * Allow the client to supply its own content cache. This will take the | 8991 * Allow the client to supply its own content cache. This will take the |
| 9533 * place of the content cache created by default, allowing clients to share | 8992 * place of the content cache created by default, allowing clients to share |
| 9534 * the content cache between contexts. | 8993 * the content cache between contexts. |
| 9535 */ | 8994 */ |
| 9536 set contentCache(ContentCache value); | 8995 set contentCache(ContentCache value); |
| 9537 | 8996 |
| 9538 /** | 8997 /** |
| 9539 * Return an array containing all of the sources that have been marked as prio
rity sources. | 8998 * Return a list containing all of the sources that have been marked as |
| 9540 * Clients must not modify the returned array. | 8999 * priority sources. Clients must not modify the returned list. |
| 9541 * | |
| 9542 * @return the sources that have been marked as priority sources | |
| 9543 */ | 9000 */ |
| 9544 List<Source> get prioritySources; | 9001 List<Source> get prioritySources; |
| 9545 | 9002 |
| 9546 /** A factory to override how [ResolverVisitor] is created. */ | 9003 /** |
| 9004 * A factory to override how [ResolverVisitor] is created. |
| 9005 */ |
| 9547 ResolverVisitorFactory get resolverVisitorFactory; | 9006 ResolverVisitorFactory get resolverVisitorFactory; |
| 9548 | 9007 |
| 9549 /** | 9008 /** |
| 9550 * Returns a statistics about this context. | 9009 * Returns a statistics about this context. |
| 9551 */ | 9010 */ |
| 9552 AnalysisContextStatistics get statistics; | 9011 AnalysisContextStatistics get statistics; |
| 9553 | 9012 |
| 9554 /** | 9013 /** |
| 9555 * Sets the [TypeProvider] for this context. | 9014 * Sets the [TypeProvider] for this context. |
| 9556 */ | 9015 */ |
| 9557 void set typeProvider(TypeProvider typeProvider); | 9016 void set typeProvider(TypeProvider typeProvider); |
| 9558 | 9017 |
| 9559 /** A factory to override how [TypeResolverVisitor] is created. */ | 9018 /** |
| 9019 * A factory to override how [TypeResolverVisitor] is created. |
| 9020 */ |
| 9560 TypeResolverVisitorFactory get typeResolverVisitorFactory; | 9021 TypeResolverVisitorFactory get typeResolverVisitorFactory; |
| 9561 | 9022 |
| 9562 /** | 9023 /** |
| 9563 * Add the given source with the given information to this context. | 9024 * Add the given [source] with the given [information] to this context. |
| 9564 * | |
| 9565 * @param source the source to be added | |
| 9566 * @param info the information about the source | |
| 9567 */ | 9025 */ |
| 9568 void addSourceInfo(Source source, SourceEntry info); | 9026 void addSourceInfo(Source source, SourceEntry information); |
| 9569 | 9027 |
| 9570 /** | 9028 /** |
| 9571 * Return an array containing the sources of the libraries that are exported b
y the library with | 9029 * Return a list containing the sources of the libraries that are exported by |
| 9572 * the given source. The array will be empty if the given source is invalid, i
f the given source | 9030 * the library with the given [source]. The list will be empty if the given |
| 9573 * does not represent a library, or if the library does not export any other l
ibraries. | 9031 * source is invalid, if the given source does not represent a library, or if |
| 9032 * the library does not export any other libraries. |
| 9574 * | 9033 * |
| 9575 * @param source the source representing the library whose exports are to be r
eturned | 9034 * Throws an [AnalysisException] if the exported libraries could not be |
| 9576 * @return the sources of the libraries that are exported by the given library | 9035 * computed. |
| 9577 * @throws AnalysisException if the exported libraries could not be computed | |
| 9578 */ | 9036 */ |
| 9579 List<Source> computeExportedLibraries(Source source); | 9037 List<Source> computeExportedLibraries(Source source); |
| 9580 | 9038 |
| 9581 /** | 9039 /** |
| 9582 * Return an array containing the sources of the libraries that are imported b
y the library with | 9040 * Return a list containing the sources of the libraries that are imported by |
| 9583 * the given source. The array will be empty if the given source is invalid, i
f the given source | 9041 * the library with the given [source]. The list will be empty if the given |
| 9584 * does not represent a library, or if the library does not import any other l
ibraries. | 9042 * source is invalid, if the given source does not represent a library, or if |
| 9043 * the library does not import any other libraries. |
| 9585 * | 9044 * |
| 9586 * @param source the source representing the library whose imports are to be r
eturned | 9045 * Throws an [AnalysisException] if the imported libraries could not be |
| 9587 * @return the sources of the libraries that are imported by the given library | 9046 * computed. |
| 9588 * @throws AnalysisException if the imported libraries could not be computed | |
| 9589 */ | 9047 */ |
| 9590 List<Source> computeImportedLibraries(Source source); | 9048 List<Source> computeImportedLibraries(Source source); |
| 9591 | 9049 |
| 9592 /** | 9050 /** |
| 9593 * Return an AST structure corresponding to the given source, but ensure that
the structure has | 9051 * Return an AST structure corresponding to the given [source], but ensure |
| 9594 * not already been resolved and will not be resolved by any other threads or
in any other | 9052 * that the structure has not already been resolved and will not be resolved |
| 9595 * library. | 9053 * by any other threads or in any other library. |
| 9054 * |
| 9055 * Throws an [AnalysisException] if the analysis could not be performed. |
| 9596 * | 9056 * |
| 9597 * <b>Note:</b> This method cannot be used in an async environment | 9057 * <b>Note:</b> This method cannot be used in an async environment |
| 9598 * | |
| 9599 * @param source the compilation unit for which an AST structure should be ret
urned | |
| 9600 * @return the AST structure representing the content of the source | |
| 9601 * @throws AnalysisException if the analysis could not be performed | |
| 9602 */ | 9058 */ |
| 9603 CompilationUnit computeResolvableCompilationUnit(Source source); | 9059 CompilationUnit computeResolvableCompilationUnit(Source source); |
| 9604 | 9060 |
| 9605 /** | 9061 /** |
| 9606 * Return all the resolved [CompilationUnit]s for the given [source] if not | 9062 * Return all the resolved [CompilationUnit]s for the given [source] if not |
| 9607 * flushed, otherwise return `null` and ensures that the [CompilationUnit]s | 9063 * flushed, otherwise return `null` and ensures that the [CompilationUnit]s |
| 9608 * will be eventually returned to the client from [performAnalysisTask]. | 9064 * will be eventually returned to the client from [performAnalysisTask]. |
| 9609 */ | 9065 */ |
| 9610 List<CompilationUnit> ensureResolvedDartUnits(Source source); | 9066 List<CompilationUnit> ensureResolvedDartUnits(Source source); |
| 9611 | 9067 |
| 9612 /** | 9068 /** |
| 9613 * Return context that owns the given source. | 9069 * Return context that owns the given [source]. |
| 9614 * | |
| 9615 * @param source the source whose context is to be returned | |
| 9616 * @return the context that owns the partition that contains the source | |
| 9617 */ | 9070 */ |
| 9618 InternalAnalysisContext getContextFor(Source source); | 9071 InternalAnalysisContext getContextFor(Source source); |
| 9619 | 9072 |
| 9620 /** | 9073 /** |
| 9621 * Return a namespace containing mappings for all of the public names defined
by the given | 9074 * Return a namespace containing mappings for all of the public names defined |
| 9622 * library. | 9075 * by the given [library]. |
| 9623 * | |
| 9624 * @param library the library whose public namespace is to be returned | |
| 9625 * @return the public namespace of the given library | |
| 9626 */ | 9076 */ |
| 9627 Namespace getPublicNamespace(LibraryElement library); | 9077 Namespace getPublicNamespace(LibraryElement library); |
| 9628 | 9078 |
| 9629 /** | 9079 /** |
| 9630 * Respond to a change which has been made to the given [source] file. | 9080 * Respond to a change which has been made to the given [source] file. |
| 9631 * [originalContents] is the former contents of the file, and [newContents] | 9081 * [originalContents] is the former contents of the file, and [newContents] |
| 9632 * is the updated contents. If [notify] is true, a source changed event is | 9082 * is the updated contents. If [notify] is true, a source changed event is |
| 9633 * triggered. | 9083 * triggered. |
| 9634 * | 9084 * |
| 9635 * Normally it should not be necessary for clients to call this function, | 9085 * Normally it should not be necessary for clients to call this function, |
| 9636 * since it will be automatically invoked in response to a call to | 9086 * since it will be automatically invoked in response to a call to |
| 9637 * [applyChanges] or [setContents]. However, if this analysis context is | 9087 * [applyChanges] or [setContents]. However, if this analysis context is |
| 9638 * sharing its content cache with other contexts, then the client must | 9088 * sharing its content cache with other contexts, then the client must |
| 9639 * manually update the content cache and call this function for each context. | 9089 * manually update the content cache and call this function for each context. |
| 9640 * | 9090 * |
| 9641 * Return `true` if the change was significant to this context (i.e. [source] | 9091 * Return `true` if the change was significant to this context (i.e. [source] |
| 9642 * is either implicitly or explicitly analyzed by this context, and a change | 9092 * is either implicitly or explicitly analyzed by this context, and a change |
| 9643 * actually occurred). | 9093 * actually occurred). |
| 9644 */ | 9094 */ |
| 9645 bool handleContentsChanged( | 9095 bool handleContentsChanged( |
| 9646 Source source, String originalContents, String newContents, bool notify); | 9096 Source source, String originalContents, String newContents, bool notify); |
| 9647 | 9097 |
| 9648 /** | 9098 /** |
| 9649 * Given a table mapping the source for the libraries represented by the corre
sponding elements to | 9099 * Given an [elementMap] mapping the source for the libraries represented by |
| 9650 * the elements representing the libraries, record those mappings. | 9100 * the corresponding elements to the elements representing the libraries, |
| 9651 * | 9101 * record those mappings. |
| 9652 * @param elementMap a table mapping the source for the libraries represented
by the elements to | |
| 9653 * the elements representing the libraries | |
| 9654 */ | 9102 */ |
| 9655 void recordLibraryElements(Map<Source, LibraryElement> elementMap); | 9103 void recordLibraryElements(Map<Source, LibraryElement> elementMap); |
| 9656 | 9104 |
| 9657 /** | 9105 /** |
| 9658 * Call the given callback function for eache cache item in the context. | 9106 * Call the given callback function for eache cache item in the context. |
| 9659 */ | 9107 */ |
| 9660 void visitCacheItems(void callback(Source source, SourceEntry dartEntry, | 9108 void visitCacheItems(void callback(Source source, SourceEntry dartEntry, |
| 9661 DataDescriptor rowDesc, CacheState state)); | 9109 DataDescriptor rowDesc, CacheState state)); |
| 9662 } | 9110 } |
| 9663 | 9111 |
| 9664 /** | 9112 /** |
| 9665 * A `Logger` is an object that can be used to receive information about errors | 9113 * An object that can be used to receive information about errors within the |
| 9666 * within the analysis engine. Implementations usually write this information to | 9114 * analysis engine. Implementations usually write this information to a file, |
| 9667 * a file, but can also record the information for later use (such as during | 9115 * but can also record the information for later use (such as during testing) or |
| 9668 * testing) or even ignore the information. | 9116 * even ignore the information. |
| 9669 */ | 9117 */ |
| 9670 abstract class Logger { | 9118 abstract class Logger { |
| 9671 /** | 9119 /** |
| 9672 * A logger that ignores all logging. | 9120 * A logger that ignores all logging. |
| 9673 */ | 9121 */ |
| 9674 static final Logger NULL = new NullLogger(); | 9122 static final Logger NULL = new NullLogger(); |
| 9675 | 9123 |
| 9676 /** | 9124 /** |
| 9677 * Log the given message as an error. The [message] is expected to be an | 9125 * Log the given message as an error. The [message] is expected to be an |
| 9678 * explanation of why the error occurred or what it means. The [exception] is | 9126 * explanation of why the error occurred or what it means. The [exception] is |
| 9679 * expected to be the reason for the error. At least one argument must be | 9127 * expected to be the reason for the error. At least one argument must be |
| 9680 * provided. | 9128 * provided. |
| 9681 */ | 9129 */ |
| 9682 void logError(String message, [CaughtException exception]); | 9130 void logError(String message, [CaughtException exception]); |
| 9683 | 9131 |
| 9684 /** | 9132 /** |
| 9685 * Log the given exception as one representing an error. | 9133 * Log the given [exception] as one representing an error. The [message] is an |
| 9686 * | 9134 * explanation of why the error occurred or what it means. |
| 9687 * @param message an explanation of why the error occurred or what it means | |
| 9688 * @param exception the exception being logged | |
| 9689 */ | 9135 */ |
| 9690 @deprecated | 9136 @deprecated |
| 9691 void logError2(String message, Object exception); | 9137 void logError2(String message, Object exception); |
| 9692 | 9138 |
| 9693 /** | 9139 /** |
| 9694 * Log the given informational message. The [message] is expected to be an | 9140 * Log the given informational message. The [message] is expected to be an |
| 9695 * explanation of why the error occurred or what it means. The [exception] is | 9141 * explanation of why the error occurred or what it means. The [exception] is |
| 9696 * expected to be the reason for the error. | 9142 * expected to be the reason for the error. |
| 9697 */ | 9143 */ |
| 9698 void logInformation(String message, [CaughtException exception]); | 9144 void logInformation(String message, [CaughtException exception]); |
| 9699 | 9145 |
| 9700 /** | 9146 /** |
| 9701 * Log the given exception as one representing an informational message. | 9147 * Log the given [exception] as one representing an informational message. The |
| 9702 * | 9148 * [message] is an explanation of why the error occurred or what it means. |
| 9703 * @param message an explanation of why the error occurred or what it means | |
| 9704 * @param exception the exception being logged | |
| 9705 */ | 9149 */ |
| 9706 @deprecated | 9150 @deprecated |
| 9707 void logInformation2(String message, Object exception); | 9151 void logInformation2(String message, Object exception); |
| 9708 } | 9152 } |
| 9709 | 9153 |
| 9710 /** | 9154 /** |
| 9711 * An implementation of [Logger] that does nothing. | 9155 * An implementation of [Logger] that does nothing. |
| 9712 */ | 9156 */ |
| 9713 class NullLogger implements Logger { | 9157 class NullLogger implements Logger { |
| 9714 @override | 9158 @override |
| 9715 void logError(String message, [CaughtException exception]) {} | 9159 void logError(String message, [CaughtException exception]) {} |
| 9716 | 9160 |
| 9717 @override | 9161 @override |
| 9718 void logError2(String message, Object exception) {} | 9162 void logError2(String message, Object exception) {} |
| 9719 | 9163 |
| 9720 @override | 9164 @override |
| 9721 void logInformation(String message, [CaughtException exception]) {} | 9165 void logInformation(String message, [CaughtException exception]) {} |
| 9722 | 9166 |
| 9723 @override | 9167 @override |
| 9724 void logInformation2(String message, Object exception) {} | 9168 void logInformation2(String message, Object exception) {} |
| 9725 } | 9169 } |
| 9726 | 9170 |
| 9727 /** | 9171 /** |
| 9728 * Instances of the class `ObsoleteSourceAnalysisException` represent an analysi
s attempt that | 9172 * An exception created when an analysis attempt fails because a source was |
| 9729 * failed because a source was deleted between the time the analysis started and
the time the | 9173 * deleted between the time the analysis started and the time the results of the |
| 9730 * results of the analysis were ready to be recorded. | 9174 * analysis were ready to be recorded. |
| 9731 */ | 9175 */ |
| 9732 class ObsoleteSourceAnalysisException extends AnalysisException { | 9176 class ObsoleteSourceAnalysisException extends AnalysisException { |
| 9733 /** | 9177 /** |
| 9734 * The source that was removed while it was being analyzed. | 9178 * The source that was removed while it was being analyzed. |
| 9735 */ | 9179 */ |
| 9736 Source _source; | 9180 Source _source; |
| 9737 | 9181 |
| 9738 /** | 9182 /** |
| 9739 * Initialize a newly created exception to represent the removal of the given
source. | 9183 * Initialize a newly created exception to represent the removal of the given |
| 9740 * | 9184 * [source]. |
| 9741 * @param source the source that was removed while it was being analyzed | |
| 9742 */ | 9185 */ |
| 9743 ObsoleteSourceAnalysisException(Source source) : super( | 9186 ObsoleteSourceAnalysisException(Source source) : super( |
| 9744 "The source '${source.fullName}' was removed while it was being analyz
ed") { | 9187 "The source '${source.fullName}' was removed while it was being analyz
ed") { |
| 9745 this._source = source; | 9188 this._source = source; |
| 9746 } | 9189 } |
| 9747 | 9190 |
| 9748 /** | 9191 /** |
| 9749 * Return the source that was removed while it was being analyzed. | 9192 * Return the source that was removed while it was being analyzed. |
| 9750 * | |
| 9751 * @return the source that was removed | |
| 9752 */ | 9193 */ |
| 9753 Source get source => _source; | 9194 Source get source => _source; |
| 9754 } | 9195 } |
| 9755 | 9196 |
| 9756 /** | 9197 /** |
| 9757 * Instances of the class `ParseDartTask` parse a specific source as a Dart file
. | 9198 * Instances of the class `ParseDartTask` parse a specific source as a Dart file
. |
| 9758 */ | 9199 */ |
| 9759 class ParseDartTask extends AnalysisTask { | 9200 class ParseDartTask extends AnalysisTask { |
| 9760 /** | 9201 /** |
| 9761 * The source to be parsed. | 9202 * The source to be parsed. |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9821 | 9262 |
| 9822 /** | 9263 /** |
| 9823 * Return the compilation unit that was produced by parsing the source, or `nu
ll` if the | 9264 * Return the compilation unit that was produced by parsing the source, or `nu
ll` if the |
| 9824 * task has not yet been performed or if an exception occurred. | 9265 * task has not yet been performed or if an exception occurred. |
| 9825 * | 9266 * |
| 9826 * @return the compilation unit that was produced by parsing the source | 9267 * @return the compilation unit that was produced by parsing the source |
| 9827 */ | 9268 */ |
| 9828 CompilationUnit get compilationUnit => _unit; | 9269 CompilationUnit get compilationUnit => _unit; |
| 9829 | 9270 |
| 9830 /** | 9271 /** |
| 9831 * Return the errors that were produced by scanning and parsing the source, or
an empty array if | 9272 * Return the errors that were produced by scanning and parsing the source, or
an empty list if |
| 9832 * the task has not yet been performed or if an exception occurred. | 9273 * the task has not yet been performed or if an exception occurred. |
| 9833 * | 9274 * |
| 9834 * @return the errors that were produced by scanning and parsing the source | 9275 * @return the errors that were produced by scanning and parsing the source |
| 9835 */ | 9276 */ |
| 9836 List<AnalysisError> get errors => _errors; | 9277 List<AnalysisError> get errors => _errors; |
| 9837 | 9278 |
| 9838 /** | 9279 /** |
| 9839 * Return an array containing the sources referenced by 'export' directives, o
r an empty array if | 9280 * Return a list containing the sources referenced by 'export' directives, or
an empty list if |
| 9840 * the task has not yet been performed or if an exception occurred. | 9281 * the task has not yet been performed or if an exception occurred. |
| 9841 * | 9282 * |
| 9842 * @return an array containing the sources referenced by 'export' directives | 9283 * @return an list containing the sources referenced by 'export' directives |
| 9843 */ | 9284 */ |
| 9844 List<Source> get exportedSources => _toArray(_exportedSources); | 9285 List<Source> get exportedSources => _toArray(_exportedSources); |
| 9845 | 9286 |
| 9846 /** | 9287 /** |
| 9847 * Return `true` if the source contains any directive other than a 'part of' d
irective, or | 9288 * Return `true` if the source contains any directive other than a 'part of' d
irective, or |
| 9848 * `false` if the task has not yet been performed or if an exception occurred. | 9289 * `false` if the task has not yet been performed or if an exception occurred. |
| 9849 * | 9290 * |
| 9850 * @return `true` if the source contains any directive other than a 'part of'
directive | 9291 * @return `true` if the source contains any directive other than a 'part of'
directive |
| 9851 */ | 9292 */ |
| 9852 bool get hasNonPartOfDirective => _containsNonPartOfDirective; | 9293 bool get hasNonPartOfDirective => _containsNonPartOfDirective; |
| 9853 | 9294 |
| 9854 /** | 9295 /** |
| 9855 * Return `true` if the source contains a 'part of' directive, or `false` if t
he task | 9296 * Return `true` if the source contains a 'part of' directive, or `false` if t
he task |
| 9856 * has not yet been performed or if an exception occurred. | 9297 * has not yet been performed or if an exception occurred. |
| 9857 * | 9298 * |
| 9858 * @return `true` if the source contains a 'part of' directive | 9299 * @return `true` if the source contains a 'part of' directive |
| 9859 */ | 9300 */ |
| 9860 bool get hasPartOfDirective => _containsPartOfDirective; | 9301 bool get hasPartOfDirective => _containsPartOfDirective; |
| 9861 | 9302 |
| 9862 /** | 9303 /** |
| 9863 * Return an array containing the sources referenced by 'import' directives, o
r an empty array if | 9304 * Return a list containing the sources referenced by 'import' directives, or
an empty list if |
| 9864 * the task has not yet been performed or if an exception occurred. | 9305 * the task has not yet been performed or if an exception occurred. |
| 9865 * | 9306 * |
| 9866 * @return an array containing the sources referenced by 'import' directives | 9307 * @return a list containing the sources referenced by 'import' directives |
| 9867 */ | 9308 */ |
| 9868 List<Source> get importedSources => _toArray(_importedSources); | 9309 List<Source> get importedSources => _toArray(_importedSources); |
| 9869 | 9310 |
| 9870 /** | 9311 /** |
| 9871 * Return an array containing the sources referenced by 'part' directives, or
an empty array if | 9312 * Return a list containing the sources referenced by 'part' directives, or an
empty list if |
| 9872 * the task has not yet been performed or if an exception occurred. | 9313 * the task has not yet been performed or if an exception occurred. |
| 9873 * | 9314 * |
| 9874 * @return an array containing the sources referenced by 'part' directives | 9315 * @return a list containing the sources referenced by 'part' directives |
| 9875 */ | 9316 */ |
| 9876 List<Source> get includedSources => _toArray(_includedSources); | 9317 List<Source> get includedSources => _toArray(_includedSources); |
| 9877 | 9318 |
| 9878 @override | 9319 @override |
| 9879 String get taskDescription { | 9320 String get taskDescription { |
| 9880 if (source == null) { | 9321 if (source == null) { |
| 9881 return "parse as dart null source"; | 9322 return "parse as dart null source"; |
| 9882 } | 9323 } |
| 9883 return "parse as dart ${source.fullName}"; | 9324 return "parse as dart ${source.fullName}"; |
| 9884 } | 9325 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9923 } | 9364 } |
| 9924 } | 9365 } |
| 9925 } | 9366 } |
| 9926 } | 9367 } |
| 9927 } | 9368 } |
| 9928 _errors = errorListener.getErrorsForSource(source); | 9369 _errors = errorListener.getErrorsForSource(source); |
| 9929 }); | 9370 }); |
| 9930 } | 9371 } |
| 9931 | 9372 |
| 9932 /** | 9373 /** |
| 9933 * Efficiently convert the given set of sources to an array. | 9374 * Efficiently convert the given set of [sources] to a list. |
| 9934 * | |
| 9935 * @param sources the set to be converted | |
| 9936 * @return an array containing all of the sources in the given set | |
| 9937 */ | 9375 */ |
| 9938 List<Source> _toArray(HashSet<Source> sources) { | 9376 List<Source> _toArray(HashSet<Source> sources) { |
| 9939 int size = sources.length; | 9377 int size = sources.length; |
| 9940 if (size == 0) { | 9378 if (size == 0) { |
| 9941 return Source.EMPTY_ARRAY; | 9379 return Source.EMPTY_ARRAY; |
| 9942 } | 9380 } |
| 9943 return new List.from(sources); | 9381 return new List.from(sources); |
| 9944 } | 9382 } |
| 9945 | 9383 |
| 9946 /** | 9384 /** |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10022 * The HTML unit that was produced by parsing the source. | 9460 * The HTML unit that was produced by parsing the source. |
| 10023 */ | 9461 */ |
| 10024 ht.HtmlUnit _unit; | 9462 ht.HtmlUnit _unit; |
| 10025 | 9463 |
| 10026 /** | 9464 /** |
| 10027 * The errors that were produced by scanning and parsing the source. | 9465 * The errors that were produced by scanning and parsing the source. |
| 10028 */ | 9466 */ |
| 10029 List<AnalysisError> _errors = AnalysisError.NO_ERRORS; | 9467 List<AnalysisError> _errors = AnalysisError.NO_ERRORS; |
| 10030 | 9468 |
| 10031 /** | 9469 /** |
| 10032 * An array containing the sources of the libraries that are referenced within
the HTML. | 9470 * A list containing the sources of the libraries that are referenced within t
he HTML. |
| 10033 */ | 9471 */ |
| 10034 List<Source> _referencedLibraries = Source.EMPTY_ARRAY; | 9472 List<Source> _referencedLibraries = Source.EMPTY_ARRAY; |
| 10035 | 9473 |
| 10036 /** | 9474 /** |
| 10037 * Initialize a newly created task to perform analysis within the given contex
t. | 9475 * Initialize a newly created task to perform analysis within the given contex
t. |
| 10038 * | 9476 * |
| 10039 * @param context the context in which the task is to be performed | 9477 * @param context the context in which the task is to be performed |
| 10040 * @param source the source to be parsed | 9478 * @param source the source to be parsed |
| 10041 * @param content the contents of the source | 9479 * @param content the contents of the source |
| 10042 */ | 9480 */ |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10074 | 9512 |
| 10075 /** | 9513 /** |
| 10076 * Return the line information that was produced, or `null` if the task has no
t yet been | 9514 * Return the line information that was produced, or `null` if the task has no
t yet been |
| 10077 * performed or if an exception occurred. | 9515 * performed or if an exception occurred. |
| 10078 * | 9516 * |
| 10079 * @return the line information that was produced | 9517 * @return the line information that was produced |
| 10080 */ | 9518 */ |
| 10081 LineInfo get lineInfo => _lineInfo; | 9519 LineInfo get lineInfo => _lineInfo; |
| 10082 | 9520 |
| 10083 /** | 9521 /** |
| 10084 * Return an array containing the sources of the libraries that are referenced
within the HTML. | 9522 * Return a list containing the sources of the libraries that are referenced w
ithin the HTML. |
| 10085 * | 9523 * |
| 10086 * @return the sources of the libraries that are referenced within the HTML | 9524 * @return the sources of the libraries that are referenced within the HTML |
| 10087 */ | 9525 */ |
| 10088 List<Source> get referencedLibraries => _referencedLibraries; | 9526 List<Source> get referencedLibraries => _referencedLibraries; |
| 10089 | 9527 |
| 10090 @override | 9528 @override |
| 10091 String get taskDescription { | 9529 String get taskDescription { |
| 10092 if (source == null) { | 9530 if (source == null) { |
| 10093 return "parse as html null source"; | 9531 return "parse as html null source"; |
| 10094 } | 9532 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10162 } | 9600 } |
| 10163 } on FormatException { | 9601 } on FormatException { |
| 10164 // ignored - invalid URI reported during resolution phase | 9602 // ignored - invalid URI reported during resolution phase |
| 10165 } | 9603 } |
| 10166 } | 9604 } |
| 10167 return super.visitHtmlScriptTagNode(node); | 9605 return super.visitHtmlScriptTagNode(node); |
| 10168 } | 9606 } |
| 10169 } | 9607 } |
| 10170 | 9608 |
| 10171 /** | 9609 /** |
| 10172 * Instances of the class `PartitionManager` manage the partitions that can be s
hared between | 9610 * An object that manages the partitions that can be shared between analysis |
| 10173 * analysis contexts. | 9611 * contexts. |
| 10174 */ | 9612 */ |
| 10175 class PartitionManager { | 9613 class PartitionManager { |
| 10176 /** | 9614 /** |
| 10177 * The default cache size for a Dart SDK partition. | 9615 * The default cache size for a Dart SDK partition. |
| 10178 */ | 9616 */ |
| 10179 static int _DEFAULT_SDK_CACHE_SIZE = 256; | 9617 static int _DEFAULT_SDK_CACHE_SIZE = 256; |
| 10180 | 9618 |
| 10181 /** | 9619 /** |
| 10182 * A table mapping SDK's to the partitions used for those SDK's. | 9620 * A table mapping SDK's to the partitions used for those SDK's. |
| 10183 */ | 9621 */ |
| 10184 HashMap<DartSdk, SdkCachePartition> _sdkPartitions = | 9622 HashMap<DartSdk, SdkCachePartition> _sdkPartitions = |
| 10185 new HashMap<DartSdk, SdkCachePartition>(); | 9623 new HashMap<DartSdk, SdkCachePartition>(); |
| 10186 | 9624 |
| 10187 /** | 9625 /** |
| 10188 * Clear any cached data being maintained by this manager. | 9626 * Clear any cached data being maintained by this manager. |
| 10189 */ | 9627 */ |
| 10190 void clearCache() { | 9628 void clearCache() { |
| 10191 _sdkPartitions.clear(); | 9629 _sdkPartitions.clear(); |
| 10192 } | 9630 } |
| 10193 | 9631 |
| 10194 /** | 9632 /** |
| 10195 * Return the partition being used for the given SDK, creating the partition | 9633 * Return the partition being used for the given [sdk], creating the partition |
| 10196 * if necessary. | 9634 * if necessary. |
| 10197 * | |
| 10198 * [sdk] - the SDK for which a partition is being requested. | |
| 10199 */ | 9635 */ |
| 10200 SdkCachePartition forSdk(DartSdk sdk) { | 9636 SdkCachePartition forSdk(DartSdk sdk) { |
| 10201 // Call sdk.context now, because when it creates a new | 9637 // Call sdk.context now, because when it creates a new |
| 10202 // InternalAnalysisContext instance, it calls forSdk() again, so creates an | 9638 // InternalAnalysisContext instance, it calls forSdk() again, so creates an |
| 10203 // SdkCachePartition instance. | 9639 // SdkCachePartition instance. |
| 10204 // So, if we initialize context after "partition == null", we end up | 9640 // So, if we initialize context after "partition == null", we end up |
| 10205 // with two SdkCachePartition instances. | 9641 // with two SdkCachePartition instances. |
| 10206 InternalAnalysisContext sdkContext = sdk.context; | 9642 InternalAnalysisContext sdkContext = sdk.context; |
| 10207 // Check cache for an existing partition. | 9643 // Check cache for an existing partition. |
| 10208 SdkCachePartition partition = _sdkPartitions[sdk]; | 9644 SdkCachePartition partition = _sdkPartitions[sdk]; |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10359 | 9795 |
| 10360 /** | 9796 /** |
| 10361 * The [PerformanceTag] for time spent during otherwise not accounted parts | 9797 * The [PerformanceTag] for time spent during otherwise not accounted parts |
| 10362 * incremental of analysis. | 9798 * incremental of analysis. |
| 10363 */ | 9799 */ |
| 10364 static PerformanceTag incrementalAnalysis = | 9800 static PerformanceTag incrementalAnalysis = |
| 10365 new PerformanceTag('incrementalAnalysis'); | 9801 new PerformanceTag('incrementalAnalysis'); |
| 10366 } | 9802 } |
| 10367 | 9803 |
| 10368 /** | 9804 /** |
| 10369 * Instances of the class `RecordingErrorListener` implement an error listener t
hat will | 9805 * An error listener that will record the errors that are reported to it in a |
| 10370 * record the errors that are reported to it in a way that is appropriate for ca
ching those errors | 9806 * way that is appropriate for caching those errors within an analysis context. |
| 10371 * within an analysis context. | |
| 10372 */ | 9807 */ |
| 10373 class RecordingErrorListener implements AnalysisErrorListener { | 9808 class RecordingErrorListener implements AnalysisErrorListener { |
| 10374 /** | 9809 /** |
| 10375 * A HashMap of lists containing the errors that were collected, keyed by each
[Source]. | 9810 * A map of sets containing the errors that were collected, keyed by each |
| 9811 * source. |
| 10376 */ | 9812 */ |
| 10377 Map<Source, HashSet<AnalysisError>> _errors = | 9813 Map<Source, HashSet<AnalysisError>> _errors = |
| 10378 new HashMap<Source, HashSet<AnalysisError>>(); | 9814 new HashMap<Source, HashSet<AnalysisError>>(); |
| 10379 | 9815 |
| 10380 /** | 9816 /** |
| 10381 * Answer the errors collected by the listener. | 9817 * Return the errors collected by the listener. |
| 10382 * | |
| 10383 * @return an array of errors (not `null`, contains no `null`s) | |
| 10384 */ | 9818 */ |
| 10385 List<AnalysisError> get errors { | 9819 List<AnalysisError> get errors { |
| 10386 int numEntries = _errors.length; | 9820 int numEntries = _errors.length; |
| 10387 if (numEntries == 0) { | 9821 if (numEntries == 0) { |
| 10388 return AnalysisError.NO_ERRORS; | 9822 return AnalysisError.NO_ERRORS; |
| 10389 } | 9823 } |
| 10390 List<AnalysisError> resultList = new List<AnalysisError>(); | 9824 List<AnalysisError> resultList = new List<AnalysisError>(); |
| 10391 for (HashSet<AnalysisError> errors in _errors.values) { | 9825 for (HashSet<AnalysisError> errors in _errors.values) { |
| 10392 resultList.addAll(errors); | 9826 resultList.addAll(errors); |
| 10393 } | 9827 } |
| 10394 return resultList; | 9828 return resultList; |
| 10395 } | 9829 } |
| 10396 | 9830 |
| 10397 /** | 9831 /** |
| 10398 * Add all of the errors recorded by the given listener to this listener. | 9832 * Add all of the errors recorded by the given [listener] to this listener. |
| 10399 * | |
| 10400 * @param listener the listener that has recorded the errors to be added | |
| 10401 */ | 9833 */ |
| 10402 void addAll(RecordingErrorListener listener) { | 9834 void addAll(RecordingErrorListener listener) { |
| 10403 for (AnalysisError error in listener.errors) { | 9835 for (AnalysisError error in listener.errors) { |
| 10404 onError(error); | 9836 onError(error); |
| 10405 } | 9837 } |
| 10406 } | 9838 } |
| 10407 | 9839 |
| 10408 /** | 9840 /** |
| 10409 * Answer the errors collected by the listener for some passed [Source]. | 9841 * Return the errors collected by the listener for the given [source]. |
| 10410 * | |
| 10411 * @param source some [Source] for which the caller wants the set of [Analysis
Error]s | |
| 10412 * collected by this listener | |
| 10413 * @return the errors collected by the listener for the passed [Source] | |
| 10414 */ | 9842 */ |
| 10415 List<AnalysisError> getErrorsForSource(Source source) { | 9843 List<AnalysisError> getErrorsForSource(Source source) { |
| 10416 HashSet<AnalysisError> errorsForSource = _errors[source]; | 9844 HashSet<AnalysisError> errorsForSource = _errors[source]; |
| 10417 if (errorsForSource == null) { | 9845 if (errorsForSource == null) { |
| 10418 return AnalysisError.NO_ERRORS; | 9846 return AnalysisError.NO_ERRORS; |
| 10419 } else { | 9847 } else { |
| 10420 return new List.from(errorsForSource); | 9848 return new List.from(errorsForSource); |
| 10421 } | 9849 } |
| 10422 } | 9850 } |
| 10423 | 9851 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10465 CompilationUnit script = node.script; | 9893 CompilationUnit script = node.script; |
| 10466 if (script != null) { | 9894 if (script != null) { |
| 10467 GenerateDartErrorsTask.validateDirectives(ResolveHtmlTask_this.context, | 9895 GenerateDartErrorsTask.validateDirectives(ResolveHtmlTask_this.context, |
| 10468 ResolveHtmlTask_this.source, script, errorListener); | 9896 ResolveHtmlTask_this.source, script, errorListener); |
| 10469 } | 9897 } |
| 10470 return null; | 9898 return null; |
| 10471 } | 9899 } |
| 10472 } | 9900 } |
| 10473 | 9901 |
| 10474 /** | 9902 /** |
| 10475 * A `ResolutionEraser` removes any resolution information from an AST | 9903 * An visitor that removes any resolution information from an AST structure when |
| 10476 * structure when used to visit that structure. | 9904 * used to visit that structure. |
| 10477 */ | 9905 */ |
| 10478 class ResolutionEraser extends GeneralizingAstVisitor<Object> { | 9906 class ResolutionEraser extends GeneralizingAstVisitor<Object> { |
| 10479 @override | 9907 @override |
| 10480 Object visitAssignmentExpression(AssignmentExpression node) { | 9908 Object visitAssignmentExpression(AssignmentExpression node) { |
| 10481 node.staticElement = null; | 9909 node.staticElement = null; |
| 10482 node.propagatedElement = null; | 9910 node.propagatedElement = null; |
| 10483 return super.visitAssignmentExpression(node); | 9911 return super.visitAssignmentExpression(node); |
| 10484 } | 9912 } |
| 10485 | 9913 |
| 10486 @override | 9914 @override |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10595 | 10023 |
| 10596 /** | 10024 /** |
| 10597 * Remove any resolution information from the given AST structure. | 10025 * Remove any resolution information from the given AST structure. |
| 10598 */ | 10026 */ |
| 10599 static void erase(AstNode node) { | 10027 static void erase(AstNode node) { |
| 10600 node.accept(new ResolutionEraser()); | 10028 node.accept(new ResolutionEraser()); |
| 10601 } | 10029 } |
| 10602 } | 10030 } |
| 10603 | 10031 |
| 10604 /** | 10032 /** |
| 10605 * A `ResolutionState` maintains the information produced by resolving a | 10033 * The information produced by resolving a compilation unit as part of a |
| 10606 * compilation unit as part of a specific library. | 10034 * specific library. |
| 10607 */ | 10035 */ |
| 10608 class ResolutionState { | 10036 class ResolutionState { |
| 10609 /** | 10037 /** |
| 10610 * The next resolution state or `null` if none. | 10038 * The next resolution state or `null` if none. |
| 10611 */ | 10039 */ |
| 10612 ResolutionState _nextState; | 10040 ResolutionState _nextState; |
| 10613 | 10041 |
| 10614 /** | 10042 /** |
| 10615 * The source for the defining compilation unit of the library that contains t
his unit. If this | 10043 * The source for the defining compilation unit of the library that contains |
| 10616 * unit is the defining compilation unit for it's library, then this will be t
he source for this | 10044 * this unit. If this unit is the defining compilation unit for it's library, |
| 10617 * unit. | 10045 * then this will be the source for this unit. |
| 10618 */ | 10046 */ |
| 10619 Source _librarySource; | 10047 Source _librarySource; |
| 10620 | 10048 |
| 10621 /** | 10049 /** |
| 10622 * A table mapping descriptors to the cached results for those descriptors. | 10050 * A table mapping descriptors to the cached results for those descriptors. |
| 10623 * If there is no entry for a given descriptor then the state is implicitly | 10051 * If there is no entry for a given descriptor then the state is implicitly |
| 10624 * [CacheState.INVALID] and the value is implicitly the default value. | 10052 * [CacheState.INVALID] and the value is implicitly the default value. |
| 10625 */ | 10053 */ |
| 10626 Map<DataDescriptor, CachedResult> resultMap = | 10054 Map<DataDescriptor, CachedResult> resultMap = |
| 10627 new HashMap<DataDescriptor, CachedResult>(); | 10055 new HashMap<DataDescriptor, CachedResult>(); |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10788 */ | 10216 */ |
| 10789 void _flush(DataDescriptor descriptor) { | 10217 void _flush(DataDescriptor descriptor) { |
| 10790 CachedResult result = resultMap[descriptor]; | 10218 CachedResult result = resultMap[descriptor]; |
| 10791 if (result != null && result.state == CacheState.VALID) { | 10219 if (result != null && result.state == CacheState.VALID) { |
| 10792 result.state = CacheState.FLUSHED; | 10220 result.state = CacheState.FLUSHED; |
| 10793 result.value = descriptor.defaultValue; | 10221 result.value = descriptor.defaultValue; |
| 10794 } | 10222 } |
| 10795 } | 10223 } |
| 10796 | 10224 |
| 10797 /** | 10225 /** |
| 10798 * Write a textual representation of the difference between the old entry and
this entry to the | 10226 * Write a textual representation of the difference between the old entry and |
| 10799 * given string builder. | 10227 * this entry to the given string [buffer]. A separator will be written before |
| 10800 * | 10228 * the first difference if [needsSeparator] is `true`. The [oldEntry] is the |
| 10801 * @param builder the string builder to which the difference is to be written | 10229 * entry that was replaced by this entry. Return `true` is a separator is |
| 10802 * @param oldEntry the entry that was replaced by this entry | 10230 * needed before writing any subsequent differences. |
| 10803 * @return `true` if some difference was written | |
| 10804 */ | 10231 */ |
| 10805 bool _writeDiffOn( | 10232 bool _writeDiffOn( |
| 10806 StringBuffer buffer, bool needsSeparator, DartEntry oldEntry) { | 10233 StringBuffer buffer, bool needsSeparator, DartEntry oldEntry) { |
| 10807 needsSeparator = _writeStateDiffOn(buffer, needsSeparator, "resolvedUnit", | 10234 needsSeparator = _writeStateDiffOn(buffer, needsSeparator, "resolvedUnit", |
| 10808 DartEntry.RESOLVED_UNIT, oldEntry); | 10235 DartEntry.RESOLVED_UNIT, oldEntry); |
| 10809 needsSeparator = _writeStateDiffOn(buffer, needsSeparator, | 10236 needsSeparator = _writeStateDiffOn(buffer, needsSeparator, |
| 10810 "resolutionErrors", DartEntry.RESOLUTION_ERRORS, oldEntry); | 10237 "resolutionErrors", DartEntry.RESOLUTION_ERRORS, oldEntry); |
| 10811 needsSeparator = _writeStateDiffOn(buffer, needsSeparator, | 10238 needsSeparator = _writeStateDiffOn(buffer, needsSeparator, |
| 10812 "verificationErrors", DartEntry.VERIFICATION_ERRORS, oldEntry); | 10239 "verificationErrors", DartEntry.VERIFICATION_ERRORS, oldEntry); |
| 10813 needsSeparator = _writeStateDiffOn( | 10240 needsSeparator = _writeStateDiffOn( |
| 10814 buffer, needsSeparator, "hints", DartEntry.HINTS, oldEntry); | 10241 buffer, needsSeparator, "hints", DartEntry.HINTS, oldEntry); |
| 10815 needsSeparator = _writeStateDiffOn( | 10242 needsSeparator = _writeStateDiffOn( |
| 10816 buffer, needsSeparator, "lints", DartEntry.LINTS, oldEntry); | 10243 buffer, needsSeparator, "lints", DartEntry.LINTS, oldEntry); |
| 10817 return needsSeparator; | 10244 return needsSeparator; |
| 10818 } | 10245 } |
| 10819 | 10246 |
| 10820 /** | 10247 /** |
| 10821 * Write a textual representation of this state to the given builder. The resu
lt will only be | 10248 * Write a textual representation of this state to the given [buffer]. The |
| 10822 * used for debugging purposes. | 10249 * result will only be used for debugging purposes. |
| 10823 * | |
| 10824 * @param builder the builder to which the text should be written | |
| 10825 */ | 10250 */ |
| 10826 void _writeOn(StringBuffer buffer) { | 10251 void _writeOn(StringBuffer buffer) { |
| 10827 if (_librarySource != null) { | 10252 if (_librarySource != null) { |
| 10828 _writeStateOn(buffer, "builtElement", DartEntry.BUILT_ELEMENT); | 10253 _writeStateOn(buffer, "builtElement", DartEntry.BUILT_ELEMENT); |
| 10829 _writeStateOn(buffer, "builtUnit", DartEntry.BUILT_UNIT); | 10254 _writeStateOn(buffer, "builtUnit", DartEntry.BUILT_UNIT); |
| 10830 _writeStateOn(buffer, "resolvedUnit", DartEntry.RESOLVED_UNIT); | 10255 _writeStateOn(buffer, "resolvedUnit", DartEntry.RESOLVED_UNIT); |
| 10831 _writeStateOn(buffer, "resolutionErrors", DartEntry.RESOLUTION_ERRORS); | 10256 _writeStateOn(buffer, "resolutionErrors", DartEntry.RESOLUTION_ERRORS); |
| 10832 _writeStateOn( | 10257 _writeStateOn( |
| 10833 buffer, "verificationErrors", DartEntry.VERIFICATION_ERRORS); | 10258 buffer, "verificationErrors", DartEntry.VERIFICATION_ERRORS); |
| 10834 _writeStateOn(buffer, "hints", DartEntry.HINTS); | 10259 _writeStateOn(buffer, "hints", DartEntry.HINTS); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10871 StringBuffer buffer, String label, DataDescriptor descriptor) { | 10296 StringBuffer buffer, String label, DataDescriptor descriptor) { |
| 10872 CachedResult result = resultMap[descriptor]; | 10297 CachedResult result = resultMap[descriptor]; |
| 10873 buffer.write("; "); | 10298 buffer.write("; "); |
| 10874 buffer.write(label); | 10299 buffer.write(label); |
| 10875 buffer.write(" = "); | 10300 buffer.write(" = "); |
| 10876 buffer.write(result == null ? CacheState.INVALID : result.state); | 10301 buffer.write(result == null ? CacheState.INVALID : result.state); |
| 10877 } | 10302 } |
| 10878 } | 10303 } |
| 10879 | 10304 |
| 10880 /** | 10305 /** |
| 10881 * A `ResolvableCompilationUnit` is a compilation unit that is not referenced by | 10306 * A compilation unit that is not referenced by any other objects. It is used by |
| 10882 * any other objects. It is used by the [LibraryResolver] to resolve a library. | 10307 * the [LibraryResolver] to resolve a library. |
| 10883 */ | 10308 */ |
| 10884 class ResolvableCompilationUnit { | 10309 class ResolvableCompilationUnit { |
| 10885 /** | 10310 /** |
| 10886 * The source of the compilation unit. | 10311 * The source of the compilation unit. |
| 10887 */ | 10312 */ |
| 10888 final Source source; | 10313 final Source source; |
| 10889 | 10314 |
| 10890 /** | 10315 /** |
| 10891 * The compilation unit. | 10316 * The compilation unit. |
| 10892 */ | 10317 */ |
| 10893 final CompilationUnit compilationUnit; | 10318 final CompilationUnit compilationUnit; |
| 10894 | 10319 |
| 10895 /** | 10320 /** |
| 10896 * Initialize a newly created holder to hold the given values. | 10321 * Initialize a newly created holder to hold the given [source] and |
| 10897 * | 10322 * [compilationUnit]. |
| 10898 * @param source the source of the compilation unit | |
| 10899 * @param unit the AST that was created from the source | |
| 10900 */ | 10323 */ |
| 10901 ResolvableCompilationUnit(this.source, this.compilationUnit); | 10324 ResolvableCompilationUnit(this.source, this.compilationUnit); |
| 10902 } | 10325 } |
| 10903 | 10326 |
| 10904 /** | 10327 /** |
| 10905 * Instances of the class `ResolveDartLibraryTask` resolve a specific Dart libra
ry. | 10328 * Instances of the class `ResolveDartLibraryTask` resolve a specific Dart libra
ry. |
| 10906 */ | 10329 */ |
| 10907 class ResolveDartLibraryCycleTask extends AnalysisTask { | 10330 class ResolveDartLibraryCycleTask extends AnalysisTask { |
| 10908 /** | 10331 /** |
| 10909 * The source representing the file whose compilation unit is to be returned.
TODO(brianwilkerson) | 10332 * The source representing the file whose compilation unit is to be returned.
TODO(brianwilkerson) |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11236 // | 10659 // |
| 11237 _resolutionErrors = errorListener.getErrorsForSource(source); | 10660 _resolutionErrors = errorListener.getErrorsForSource(source); |
| 11238 // | 10661 // |
| 11239 // Remember the resolved unit. | 10662 // Remember the resolved unit. |
| 11240 // | 10663 // |
| 11241 _resolvedUnit = _unit; | 10664 _resolvedUnit = _unit; |
| 11242 } | 10665 } |
| 11243 } | 10666 } |
| 11244 | 10667 |
| 11245 /** | 10668 /** |
| 11246 * The enumerated type `RetentionPriority` represents the priority of data in th
e cache in | 10669 * The priority of data in the cache in terms of the desirability of retaining |
| 11247 * terms of the desirability of retaining some specified data about a specified
source. | 10670 * some specified data about a specified source. |
| 11248 */ | 10671 */ |
| 11249 class RetentionPriority extends Enum<RetentionPriority> { | 10672 class RetentionPriority extends Enum<RetentionPriority> { |
| 11250 /** | 10673 /** |
| 11251 * A priority indicating that a given piece of data can be removed from the ca
che without | 10674 * A priority indicating that a given piece of data can be removed from the |
| 11252 * reservation. | 10675 * cache without reservation. |
| 11253 */ | 10676 */ |
| 11254 static const RetentionPriority LOW = const RetentionPriority('LOW', 0); | 10677 static const RetentionPriority LOW = const RetentionPriority('LOW', 0); |
| 11255 | 10678 |
| 11256 /** | 10679 /** |
| 11257 * A priority indicating that a given piece of data should not be removed from
the cache unless | 10680 * A priority indicating that a given piece of data should not be removed from |
| 11258 * there are no sources for which the corresponding data has a lower priority.
Currently used for | 10681 * the cache unless there are no sources for which the corresponding data has |
| 11259 * data that is needed in order to finish some outstanding analysis task. | 10682 * a lower priority. Currently used for data that is needed in order to finish |
| 10683 * some outstanding analysis task. |
| 11260 */ | 10684 */ |
| 11261 static const RetentionPriority MEDIUM = const RetentionPriority('MEDIUM', 1); | 10685 static const RetentionPriority MEDIUM = const RetentionPriority('MEDIUM', 1); |
| 11262 | 10686 |
| 11263 /** | 10687 /** |
| 11264 * A priority indicating that a given piece of data should not be removed from
the cache. | 10688 * A priority indicating that a given piece of data should not be removed from |
| 11265 * Currently used for data related to a priority source. | 10689 * the cache. Currently used for data related to a priority source. |
| 11266 */ | 10690 */ |
| 11267 static const RetentionPriority HIGH = const RetentionPriority('HIGH', 2); | 10691 static const RetentionPriority HIGH = const RetentionPriority('HIGH', 2); |
| 11268 | 10692 |
| 11269 static const List<RetentionPriority> values = const [LOW, MEDIUM, HIGH]; | 10693 static const List<RetentionPriority> values = const [LOW, MEDIUM, HIGH]; |
| 11270 | 10694 |
| 11271 const RetentionPriority(String name, int ordinal) : super(name, ordinal); | 10695 const RetentionPriority(String name, int ordinal) : super(name, ordinal); |
| 11272 } | 10696 } |
| 11273 | 10697 |
| 11274 /** | 10698 /** |
| 11275 * Instances of the class `ScanDartTask` scan a specific source as a Dart file. | 10699 * Instances of the class `ScanDartTask` scan a specific source as a Dart file. |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11358 _errors = errorListener.getErrorsForSource(source); | 10782 _errors = errorListener.getErrorsForSource(source); |
| 11359 } catch (exception, stackTrace) { | 10783 } catch (exception, stackTrace) { |
| 11360 throw new AnalysisException( | 10784 throw new AnalysisException( |
| 11361 "Exception", new CaughtException(exception, stackTrace)); | 10785 "Exception", new CaughtException(exception, stackTrace)); |
| 11362 } | 10786 } |
| 11363 }); | 10787 }); |
| 11364 } | 10788 } |
| 11365 } | 10789 } |
| 11366 | 10790 |
| 11367 /** | 10791 /** |
| 11368 * Instances of the class `SdkAnalysisContext` implement an [AnalysisContext] th
at only | 10792 * An [AnalysisContext] that only contains sources for a Dart SDK. |
| 11369 * contains sources for a Dart SDK. | |
| 11370 */ | 10793 */ |
| 11371 class SdkAnalysisContext extends AnalysisContextImpl { | 10794 class SdkAnalysisContext extends AnalysisContextImpl { |
| 11372 @override | 10795 @override |
| 11373 AnalysisCache createCacheFromSourceFactory(SourceFactory factory) { | 10796 AnalysisCache createCacheFromSourceFactory(SourceFactory factory) { |
| 11374 if (factory == null) { | 10797 if (factory == null) { |
| 11375 return super.createCacheFromSourceFactory(factory); | 10798 return super.createCacheFromSourceFactory(factory); |
| 11376 } | 10799 } |
| 11377 DartSdk sdk = factory.dartSdk; | 10800 DartSdk sdk = factory.dartSdk; |
| 11378 if (sdk == null) { | 10801 if (sdk == null) { |
| 11379 throw new IllegalArgumentException( | 10802 throw new IllegalArgumentException( |
| 11380 "The source factory for an SDK analysis context must have a DartUriRes
olver"); | 10803 "The source factory for an SDK analysis context must have a DartUriRes
olver"); |
| 11381 } | 10804 } |
| 11382 return new AnalysisCache( | 10805 return new AnalysisCache( |
| 11383 <CachePartition>[AnalysisEngine.instance.partitionManager.forSdk(sdk)]); | 10806 <CachePartition>[AnalysisEngine.instance.partitionManager.forSdk(sdk)]); |
| 11384 } | 10807 } |
| 11385 } | 10808 } |
| 11386 | 10809 |
| 11387 /** | 10810 /** |
| 11388 * Instances of the class `SdkCachePartition` implement a cache partition that c
ontains all of | 10811 * A cache partition that contains all of the sources in the SDK. |
| 11389 * the sources in the SDK. | |
| 11390 */ | 10812 */ |
| 11391 class SdkCachePartition extends CachePartition { | 10813 class SdkCachePartition extends CachePartition { |
| 11392 /** | 10814 /** |
| 11393 * Initialize a newly created partition. | 10815 * Initialize a newly created partition. The [context] is the context that |
| 11394 * | 10816 * owns this partition. The [maxCacheSize] is the maximum number of sources |
| 11395 * @param context the context that owns this partition | 10817 * for which AST structures should be kept in the cache. |
| 11396 * @param maxCacheSize the maximum number of sources for which AST structures
should be kept in | |
| 11397 * the cache | |
| 11398 */ | 10818 */ |
| 11399 SdkCachePartition(InternalAnalysisContext context, int maxCacheSize) | 10819 SdkCachePartition(InternalAnalysisContext context, int maxCacheSize) |
| 11400 : super(context, maxCacheSize, DefaultRetentionPolicy.POLICY); | 10820 : super(context, maxCacheSize, DefaultRetentionPolicy.POLICY); |
| 11401 | 10821 |
| 11402 @override | 10822 @override |
| 11403 bool contains(Source source) => source.isInSystemLibrary; | 10823 bool contains(Source source) => source.isInSystemLibrary; |
| 11404 } | 10824 } |
| 11405 | 10825 |
| 11406 /** | 10826 /** |
| 11407 * A `SourceEntry` maintains the information cached by an analysis context about | 10827 * The information cached by an analysis context about an individual source, no |
| 11408 * an individual source, no matter what kind of source it is. | 10828 * matter what kind of source it is. |
| 11409 */ | 10829 */ |
| 11410 abstract class SourceEntry { | 10830 abstract class SourceEntry { |
| 11411 /** | 10831 /** |
| 11412 * The data descriptor representing the contents of the source. | 10832 * The data descriptor representing the contents of the source. |
| 11413 */ | 10833 */ |
| 11414 static final DataDescriptor<String> CONTENT = | 10834 static final DataDescriptor<String> CONTENT = |
| 11415 new DataDescriptor<String>("SourceEntry.CONTENT"); | 10835 new DataDescriptor<String>("SourceEntry.CONTENT"); |
| 11416 | 10836 |
| 11417 /** | 10837 /** |
| 11418 * The data descriptor representing the errors resulting from reading the | 10838 * The data descriptor representing the errors resulting from reading the |
| (...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11799 */ | 11219 */ |
| 11800 static void countTransition(DataDescriptor descriptor, CachedResult result) { | 11220 static void countTransition(DataDescriptor descriptor, CachedResult result) { |
| 11801 Map<CacheState, int> countMap = transitionMap.putIfAbsent( | 11221 Map<CacheState, int> countMap = transitionMap.putIfAbsent( |
| 11802 descriptor, () => new HashMap<CacheState, int>()); | 11222 descriptor, () => new HashMap<CacheState, int>()); |
| 11803 int count = countMap[result.state]; | 11223 int count = countMap[result.state]; |
| 11804 countMap[result.state] = count == null ? 1 : count + 1; | 11224 countMap[result.state] = count == null ? 1 : count + 1; |
| 11805 } | 11225 } |
| 11806 } | 11226 } |
| 11807 | 11227 |
| 11808 /** | 11228 /** |
| 11809 * The enumerated type `Priority` defines the priority levels used to return sou
rces in an | 11229 * The priority levels used to return sources in an optimal order. A smaller |
| 11810 * optimal order. A smaller ordinal value equates to a higher priority. | 11230 * ordinal value equates to a higher priority. |
| 11811 */ | 11231 */ |
| 11812 class SourcePriority extends Enum<SourcePriority> { | 11232 class SourcePriority extends Enum<SourcePriority> { |
| 11813 /** | 11233 /** |
| 11814 * Used for a Dart source that is known to be a part contained in a library th
at was recently | 11234 * Used for a Dart source that is known to be a part contained in a library |
| 11815 * resolved. These parts are given a higher priority because there is a high p
robability that | 11235 * that was recently resolved. These parts are given a higher priority because |
| 11816 * their AST structure is still in the cache and therefore would not need to b
e re-created. | 11236 * there is a high probability that their AST structure is still in the cache |
| 11237 * and therefore would not need to be re-created. |
| 11817 */ | 11238 */ |
| 11818 static const SourcePriority PRIORITY_PART = | 11239 static const SourcePriority PRIORITY_PART = |
| 11819 const SourcePriority('PRIORITY_PART', 0); | 11240 const SourcePriority('PRIORITY_PART', 0); |
| 11820 | 11241 |
| 11821 /** | 11242 /** |
| 11822 * Used for a Dart source that is known to be a library. | 11243 * Used for a Dart source that is known to be a library. |
| 11823 */ | 11244 */ |
| 11824 static const SourcePriority LIBRARY = const SourcePriority('LIBRARY', 1); | 11245 static const SourcePriority LIBRARY = const SourcePriority('LIBRARY', 1); |
| 11825 | 11246 |
| 11826 /** | 11247 /** |
| 11827 * Used for a Dart source whose kind is unknown. | 11248 * Used for a Dart source whose kind is unknown. |
| 11828 */ | 11249 */ |
| 11829 static const SourcePriority UNKNOWN = const SourcePriority('UNKNOWN', 2); | 11250 static const SourcePriority UNKNOWN = const SourcePriority('UNKNOWN', 2); |
| 11830 | 11251 |
| 11831 /** | 11252 /** |
| 11832 * Used for a Dart source that is known to be a part but whose library has not
yet been resolved. | 11253 * Used for a Dart source that is known to be a part but whose library has not |
| 11254 * yet been resolved. |
| 11833 */ | 11255 */ |
| 11834 static const SourcePriority NORMAL_PART = | 11256 static const SourcePriority NORMAL_PART = |
| 11835 const SourcePriority('NORMAL_PART', 3); | 11257 const SourcePriority('NORMAL_PART', 3); |
| 11836 | 11258 |
| 11837 /** | 11259 /** |
| 11838 * Used for an HTML source. | 11260 * Used for an HTML source. |
| 11839 */ | 11261 */ |
| 11840 static const SourcePriority HTML = const SourcePriority('HTML', 4); | 11262 static const SourcePriority HTML = const SourcePriority('HTML', 4); |
| 11841 | 11263 |
| 11842 static const List<SourcePriority> values = const [ | 11264 static const List<SourcePriority> values = const [ |
| 11843 PRIORITY_PART, | 11265 PRIORITY_PART, |
| 11844 LIBRARY, | 11266 LIBRARY, |
| 11845 UNKNOWN, | 11267 UNKNOWN, |
| 11846 NORMAL_PART, | 11268 NORMAL_PART, |
| 11847 HTML | 11269 HTML |
| 11848 ]; | 11270 ]; |
| 11849 | 11271 |
| 11850 const SourcePriority(String name, int ordinal) : super(name, ordinal); | 11272 const SourcePriority(String name, int ordinal) : super(name, ordinal); |
| 11851 } | 11273 } |
| 11852 | 11274 |
| 11853 /** | 11275 /** |
| 11854 * [SourcesChangedEvent] indicates which sources have been added, removed, | 11276 * [SourcesChangedEvent] indicates which sources have been added, removed, |
| 11855 * or whose contents have changed. | 11277 * or whose contents have changed. |
| 11856 */ | 11278 */ |
| 11857 class SourcesChangedEvent { | 11279 class SourcesChangedEvent { |
| 11858 | |
| 11859 /** | 11280 /** |
| 11860 * The internal representation of what has changed. | 11281 * The internal representation of what has changed. Clients should not access |
| 11861 * Clients should not access this field directly. | 11282 * this field directly. |
| 11862 */ | 11283 */ |
| 11863 final ChangeSet _changeSet; | 11284 final ChangeSet _changeSet; |
| 11864 | 11285 |
| 11865 /** | 11286 /** |
| 11866 * Construct an instance representing the given changes. | 11287 * Construct an instance representing the given changes. |
| 11867 */ | 11288 */ |
| 11868 SourcesChangedEvent(ChangeSet changeSet) : _changeSet = changeSet; | 11289 SourcesChangedEvent(ChangeSet changeSet) : _changeSet = changeSet; |
| 11869 | 11290 |
| 11870 /** | 11291 /** |
| 11871 * Construct an instance representing a source content change. | 11292 * Construct an instance representing a source content change. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11904 /** | 11325 /** |
| 11905 * Return `true` if any sources were removed or deleted. | 11326 * Return `true` if any sources were removed or deleted. |
| 11906 */ | 11327 */ |
| 11907 bool get wereSourcesRemovedOrDeleted => | 11328 bool get wereSourcesRemovedOrDeleted => |
| 11908 _changeSet.removedSources.length > 0 || | 11329 _changeSet.removedSources.length > 0 || |
| 11909 _changeSet.removedContainers.length > 0 || | 11330 _changeSet.removedContainers.length > 0 || |
| 11910 _changeSet.deletedSources.length > 0; | 11331 _changeSet.deletedSources.length > 0; |
| 11911 } | 11332 } |
| 11912 | 11333 |
| 11913 /** | 11334 /** |
| 11914 * Instances of the class `TimestampedData` represent analysis data for which we
have a | 11335 * Analysis data for which we have a modification time. |
| 11915 * modification time. | |
| 11916 */ | 11336 */ |
| 11917 class TimestampedData<E> { | 11337 class TimestampedData<E> { |
| 11918 /** | 11338 /** |
| 11919 * The modification time of the source from which the data was created. | 11339 * The modification time of the source from which the data was created. |
| 11920 */ | 11340 */ |
| 11921 final int modificationTime; | 11341 final int modificationTime; |
| 11922 | 11342 |
| 11923 /** | 11343 /** |
| 11924 * The data that was created from the source. | 11344 * The data that was created from the source. |
| 11925 */ | 11345 */ |
| 11926 final E data; | 11346 final E data; |
| 11927 | 11347 |
| 11928 /** | 11348 /** |
| 11929 * Initialize a newly created holder to hold the given values. | 11349 * Initialize a newly created holder to associate the given [data] with the |
| 11930 * | 11350 * given [modificationTime]. |
| 11931 * @param modificationTime the modification time of the source from which the
data was created | |
| 11932 * @param unit the data that was created from the source | |
| 11933 */ | 11351 */ |
| 11934 TimestampedData(this.modificationTime, this.data); | 11352 TimestampedData(this.modificationTime, this.data); |
| 11935 } | 11353 } |
| 11936 | 11354 |
| 11937 /** | 11355 /** |
| 11938 * Instances of the class `UniversalCachePartition` implement a cache partition
that contains | 11356 * A cache partition that contains all sources not contained in other |
| 11939 * all sources not contained in other partitions. | 11357 * partitions. |
| 11940 */ | 11358 */ |
| 11941 class UniversalCachePartition extends CachePartition { | 11359 class UniversalCachePartition extends CachePartition { |
| 11942 /** | 11360 /** |
| 11943 * Initialize a newly created partition. | 11361 * Initialize a newly created partition. The [context] is the context that |
| 11944 * | 11362 * owns this partition. The [maxCacheSize] is the maximum number of sources |
| 11945 * @param context the context that owns this partition | 11363 * for which AST structures should be kept in the cache. The [retentionPolicy] |
| 11946 * @param maxCacheSize the maximum number of sources for which AST structures
should be kept in | 11364 * is the policy used to determine which pieces of data to remove from the |
| 11947 * the cache | 11365 * cache. |
| 11948 * @param retentionPolicy the policy used to determine which pieces of data to
remove from the | |
| 11949 * cache | |
| 11950 */ | 11366 */ |
| 11951 UniversalCachePartition(InternalAnalysisContext context, int maxCacheSize, | 11367 UniversalCachePartition(InternalAnalysisContext context, int maxCacheSize, |
| 11952 CacheRetentionPolicy retentionPolicy) | 11368 CacheRetentionPolicy retentionPolicy) |
| 11953 : super(context, maxCacheSize, retentionPolicy); | 11369 : super(context, maxCacheSize, retentionPolicy); |
| 11954 | 11370 |
| 11955 @override | 11371 @override |
| 11956 bool contains(Source source) => true; | 11372 bool contains(Source source) => true; |
| 11957 } | 11373 } |
| 11958 | 11374 |
| 11959 /** | 11375 /** |
| (...skipping 25 matching lines...) Expand all Loading... |
| 11985 @override | 11401 @override |
| 11986 accept(AnalysisTaskVisitor visitor) => null; | 11402 accept(AnalysisTaskVisitor visitor) => null; |
| 11987 | 11403 |
| 11988 @override | 11404 @override |
| 11989 void internalPerform() { | 11405 void internalPerform() { |
| 11990 // There is no work to be done. | 11406 // There is no work to be done. |
| 11991 } | 11407 } |
| 11992 } | 11408 } |
| 11993 | 11409 |
| 11994 /** | 11410 /** |
| 11995 * Instances of the class `WorkManager` manage a list of sources that need to ha
ve analysis | 11411 * An object that manages a list of sources that need to have analysis work |
| 11996 * work performed on them. | 11412 * performed on them. |
| 11997 */ | 11413 */ |
| 11998 class WorkManager { | 11414 class WorkManager { |
| 11999 /** | 11415 /** |
| 12000 * An array containing the various queues is priority order. | 11416 * A list containing the various queues is priority order. |
| 12001 */ | 11417 */ |
| 12002 List<List<Source>> _workQueues; | 11418 List<List<Source>> _workQueues; |
| 12003 | 11419 |
| 12004 /** | 11420 /** |
| 12005 * Initialize a newly created manager to have no work queued up. | 11421 * Initialize a newly created manager to have no work queued up. |
| 12006 */ | 11422 */ |
| 12007 WorkManager() { | 11423 WorkManager() { |
| 12008 int queueCount = SourcePriority.values.length; | 11424 int queueCount = SourcePriority.values.length; |
| 12009 _workQueues = new List<List>(queueCount); | 11425 _workQueues = new List<List>(queueCount); |
| 12010 for (int i = 0; i < queueCount; i++) { | 11426 for (int i = 0; i < queueCount; i++) { |
| 12011 _workQueues[i] = new List<Source>(); | 11427 _workQueues[i] = new List<Source>(); |
| 12012 } | 11428 } |
| 12013 } | 11429 } |
| 12014 | 11430 |
| 12015 /** | 11431 /** |
| 12016 * Record that the given source needs to be analyzed. The priority level is us
ed to control when | 11432 * Record that the given [source] needs to be analyzed. The [priority] level |
| 12017 * the source will be analyzed with respect to other sources. If the source wa
s previously added | 11433 * is used to control when the source will be analyzed with respect to other |
| 12018 * then it's priority is updated. If it was previously added with the same pri
ority then it's | 11434 * sources. If the source was previously added then it's priority is updated. |
| 12019 * position in the queue is unchanged. | 11435 * If it was previously added with the same priority then it's position in the |
| 12020 * | 11436 * queue is unchanged. |
| 12021 * @param source the source that needs to be analyzed | |
| 12022 * @param priority the priority level of the source | |
| 12023 */ | 11437 */ |
| 12024 void add(Source source, SourcePriority priority) { | 11438 void add(Source source, SourcePriority priority) { |
| 12025 int queueCount = _workQueues.length; | 11439 int queueCount = _workQueues.length; |
| 12026 int ordinal = priority.ordinal; | 11440 int ordinal = priority.ordinal; |
| 12027 for (int i = 0; i < queueCount; i++) { | 11441 for (int i = 0; i < queueCount; i++) { |
| 12028 List<Source> queue = _workQueues[i]; | 11442 List<Source> queue = _workQueues[i]; |
| 12029 if (i == ordinal) { | 11443 if (i == ordinal) { |
| 12030 if (!queue.contains(source)) { | 11444 if (!queue.contains(source)) { |
| 12031 queue.add(source); | 11445 queue.add(source); |
| 12032 } | 11446 } |
| 12033 } else { | 11447 } else { |
| 12034 queue.remove(source); | 11448 queue.remove(source); |
| 12035 } | 11449 } |
| 12036 } | 11450 } |
| 12037 } | 11451 } |
| 12038 | 11452 |
| 12039 /** | 11453 /** |
| 12040 * Record that the given source needs to be analyzed. The priority level is us
ed to control when | 11454 * Record that the given [source] needs to be analyzed. The [priority] level |
| 12041 * the source will be analyzed with respect to other sources. If the source wa
s previously added | 11455 * is used to control when the source will be analyzed with respect to other |
| 12042 * then it's priority is updated. In either case, it will be analyzed before o
ther sources of the | 11456 * sources. If the source was previously added then it's priority is updated. |
| 12043 * same priority. | 11457 * In either case, it will be analyzed before other sources of the same |
| 12044 * | 11458 * priority. |
| 12045 * @param source the source that needs to be analyzed | |
| 12046 * @param priority the priority level of the source | |
| 12047 */ | 11459 */ |
| 12048 void addFirst(Source source, SourcePriority priority) { | 11460 void addFirst(Source source, SourcePriority priority) { |
| 12049 int queueCount = _workQueues.length; | 11461 int queueCount = _workQueues.length; |
| 12050 int ordinal = priority.ordinal; | 11462 int ordinal = priority.ordinal; |
| 12051 for (int i = 0; i < queueCount; i++) { | 11463 for (int i = 0; i < queueCount; i++) { |
| 12052 List<Source> queue = _workQueues[i]; | 11464 List<Source> queue = _workQueues[i]; |
| 12053 if (i == ordinal) { | 11465 if (i == ordinal) { |
| 12054 queue.remove(source); | 11466 queue.remove(source); |
| 12055 queue.insert(0, source); | 11467 queue.insert(0, source); |
| 12056 } else { | 11468 } else { |
| 12057 queue.remove(source); | 11469 queue.remove(source); |
| 12058 } | 11470 } |
| 12059 } | 11471 } |
| 12060 } | 11472 } |
| 12061 | 11473 |
| 12062 /** | 11474 /** |
| 12063 * Return an iterator that can be used to access the sources to be analyzed in
the order in which | 11475 * Return an iterator that can be used to access the sources to be analyzed in |
| 12064 * they should be analyzed. | 11476 * the order in which they should be analyzed. |
| 12065 * | 11477 * |
| 12066 * <b>Note:</b> As with other iterators, no sources can be added or removed fr
om this work manager | 11478 * <b>Note:</b> As with other iterators, no sources can be added or removed |
| 12067 * while the iterator is being used. Unlike some implementations, however, the
iterator will not | 11479 * from this work manager while the iterator is being used. Unlike some |
| 12068 * detect when this requirement has been violated; it might work correctly, it
might return the | 11480 * implementations, however, the iterator will not detect when this |
| 11481 * requirement has been violated; it might work correctly, it might return the |
| 12069 * wrong source, or it might throw an exception. | 11482 * wrong source, or it might throw an exception. |
| 12070 * | |
| 12071 * @return an iterator that can be used to access the next source to be analyz
ed | |
| 12072 */ | 11483 */ |
| 12073 WorkManager_WorkIterator iterator() => new WorkManager_WorkIterator(this); | 11484 WorkManager_WorkIterator iterator() => new WorkManager_WorkIterator(this); |
| 12074 | 11485 |
| 12075 /** | 11486 /** |
| 12076 * Record that the given source is fully analyzed. | 11487 * Record that the given source is fully analyzed. |
| 12077 * | |
| 12078 * @param source the source that is fully analyzed | |
| 12079 */ | 11488 */ |
| 12080 void remove(Source source) { | 11489 void remove(Source source) { |
| 12081 int queueCount = _workQueues.length; | 11490 int queueCount = _workQueues.length; |
| 12082 for (int i = 0; i < queueCount; i++) { | 11491 for (int i = 0; i < queueCount; i++) { |
| 12083 _workQueues[i].remove(source); | 11492 _workQueues[i].remove(source); |
| 12084 } | 11493 } |
| 12085 } | 11494 } |
| 12086 | 11495 |
| 12087 @override | 11496 @override |
| 12088 String toString() { | 11497 String toString() { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 12106 buffer.write(queue[j].fullName); | 11515 buffer.write(queue[j].fullName); |
| 12107 } | 11516 } |
| 12108 needsSeparator = true; | 11517 needsSeparator = true; |
| 12109 } | 11518 } |
| 12110 } | 11519 } |
| 12111 return buffer.toString(); | 11520 return buffer.toString(); |
| 12112 } | 11521 } |
| 12113 } | 11522 } |
| 12114 | 11523 |
| 12115 /** | 11524 /** |
| 12116 * Instances of the class `WorkIterator` implement an iterator that returns the
sources in a | 11525 * An iterator that returns the sources in a work manager in the order in which |
| 12117 * work manager in the order in which they are to be analyzed. | 11526 * they are to be analyzed. |
| 12118 */ | 11527 */ |
| 12119 class WorkManager_WorkIterator { | 11528 class WorkManager_WorkIterator { |
| 12120 final WorkManager _manager; | 11529 final WorkManager _manager; |
| 12121 | 11530 |
| 12122 /** | 11531 /** |
| 12123 * The index of the work queue through which we are currently iterating. | 11532 * The index of the work queue through which we are currently iterating. |
| 12124 */ | 11533 */ |
| 12125 int _queueIndex = 0; | 11534 int _queueIndex = 0; |
| 12126 | 11535 |
| 12127 /** | 11536 /** |
| 12128 * The index of the next element of the work queue to be returned. | 11537 * The index of the next element of the work queue to be returned. |
| 12129 */ | 11538 */ |
| 12130 int _index = -1; | 11539 int _index = -1; |
| 12131 | 11540 |
| 12132 /** | 11541 /** |
| 12133 * Initialize a newly created iterator to be ready to return the first element
in the iteration. | 11542 * Initialize a newly created iterator to be ready to return the first element |
| 11543 * in the iteration. |
| 12134 */ | 11544 */ |
| 12135 WorkManager_WorkIterator(this._manager) { | 11545 WorkManager_WorkIterator(this._manager) { |
| 12136 _advance(); | 11546 _advance(); |
| 12137 } | 11547 } |
| 12138 | 11548 |
| 12139 /** | 11549 /** |
| 12140 * Return `true` if there is another [Source] available for processing. | 11550 * Return `true` if there is another [Source] available for processing. |
| 12141 * | |
| 12142 * @return `true` if there is another [Source] available for processing | |
| 12143 */ | 11551 */ |
| 12144 bool get hasNext => _queueIndex < _manager._workQueues.length; | 11552 bool get hasNext => _queueIndex < _manager._workQueues.length; |
| 12145 | 11553 |
| 12146 /** | 11554 /** |
| 12147 * Return the next [Source] available for processing and advance so that the r
eturned | 11555 * Return the next [Source] available for processing and advance so that the |
| 12148 * source will not be returned again. | 11556 * returned source will not be returned again. |
| 12149 * | |
| 12150 * @return the next [Source] available for processing | |
| 12151 */ | 11557 */ |
| 12152 Source next() { | 11558 Source next() { |
| 12153 if (!hasNext) { | 11559 if (!hasNext) { |
| 12154 throw new NoSuchElementException(); | 11560 throw new NoSuchElementException(); |
| 12155 } | 11561 } |
| 12156 Source source = _manager._workQueues[_queueIndex][_index]; | 11562 Source source = _manager._workQueues[_queueIndex][_index]; |
| 12157 _advance(); | 11563 _advance(); |
| 12158 return source; | 11564 return source; |
| 12159 } | 11565 } |
| 12160 | 11566 |
| 12161 /** | 11567 /** |
| 12162 * Increment the [index] and [queueIndex] so that they are either indicating t
he | 11568 * Increment the [index] and [queueIndex] so that they are either indicating |
| 12163 * next source to be returned or are indicating that there are no more sources
to be returned. | 11569 * the next source to be returned or are indicating that there are no more |
| 11570 * sources to be returned. |
| 12164 */ | 11571 */ |
| 12165 void _advance() { | 11572 void _advance() { |
| 12166 _index++; | 11573 _index++; |
| 12167 if (_index >= _manager._workQueues[_queueIndex].length) { | 11574 if (_index >= _manager._workQueues[_queueIndex].length) { |
| 12168 _index = 0; | 11575 _index = 0; |
| 12169 _queueIndex++; | 11576 _queueIndex++; |
| 12170 while (_queueIndex < _manager._workQueues.length && | 11577 while (_queueIndex < _manager._workQueues.length && |
| 12171 _manager._workQueues[_queueIndex].isEmpty) { | 11578 _manager._workQueues[_queueIndex].isEmpty) { |
| 12172 _queueIndex++; | 11579 _queueIndex++; |
| 12173 } | 11580 } |
| 12174 } | 11581 } |
| 12175 } | 11582 } |
| 12176 } | 11583 } |
| 12177 | 11584 |
| 12178 /** | 11585 /** |
| 12179 * Helper class used to create futures for AnalysisContextImpl. Using a helper | 11586 * A helper class used to create futures for AnalysisContextImpl. Using a helper |
| 12180 * class allows us to preserve the generic parameter T. | 11587 * class allows us to preserve the generic parameter T. |
| 12181 */ | 11588 */ |
| 12182 class _AnalysisFutureHelper<T> { | 11589 class _AnalysisFutureHelper<T> { |
| 12183 final AnalysisContextImpl _context; | 11590 final AnalysisContextImpl _context; |
| 12184 | 11591 |
| 12185 _AnalysisFutureHelper(this._context); | 11592 _AnalysisFutureHelper(this._context); |
| 12186 | 11593 |
| 12187 /** | 11594 /** |
| 12188 * Return a future that will be completed with the result of calling | 11595 * Return a future that will be completed with the result of calling |
| 12189 * [computeValue]. If [computeValue] returns non-null, the future will be | 11596 * [computeValue]. If [computeValue] returns non-null, the future will be |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12232 visitElement(Element element) { | 11639 visitElement(Element element) { |
| 12233 if (element.id == _id) { | 11640 if (element.id == _id) { |
| 12234 result = element; | 11641 result = element; |
| 12235 throw new _ElementByIdFinderException(); | 11642 throw new _ElementByIdFinderException(); |
| 12236 } | 11643 } |
| 12237 super.visitElement(element); | 11644 super.visitElement(element); |
| 12238 } | 11645 } |
| 12239 } | 11646 } |
| 12240 | 11647 |
| 12241 class _ElementByIdFinderException {} | 11648 class _ElementByIdFinderException {} |
| OLD | NEW |