| OLD | NEW |
| 1 // This code was auto-generated, is not intended to be edited, and is subject to | 1 // This code was auto-generated, is not intended to be edited, and is subject to |
| 2 // significant change. Please see the README file for more information. | 2 // significant change. Please see the README file for more information. |
| 3 | 3 |
| 4 library engine; | 4 library engine; |
| 5 | 5 |
| 6 import 'java_core.dart'; | 6 import 'java_core.dart'; |
| 7 import 'java_engine.dart'; | 7 import 'java_engine.dart'; |
| 8 import 'dart:collection' show HasNextIterator; | 8 import 'dart:collection' show HasNextIterator; |
| 9 import 'error.dart'; | 9 import 'error.dart'; |
| 10 import 'source.dart'; | 10 import 'source.dart'; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 * @param logger the logger that should receive information about errors withi
n the analysis | 90 * @param logger the logger that should receive information about errors withi
n the analysis |
| 91 * engine | 91 * engine |
| 92 */ | 92 */ |
| 93 void set logger(Logger logger2) { | 93 void set logger(Logger logger2) { |
| 94 this._logger = logger2 == null ? Logger.NULL : logger2; | 94 this._logger = logger2 == null ? Logger.NULL : logger2; |
| 95 } | 95 } |
| 96 } | 96 } |
| 97 /** | 97 /** |
| 98 * The interface {@code AnalysisContext} defines the behavior of objects that re
present a context in | 98 * The interface {@code AnalysisContext} defines the behavior of objects that re
present a context in |
| 99 * which analysis can be performed. The context includes such information as the
version of the SDK | 99 * which analysis can be performed. The context includes such information as the
version of the SDK |
| 100 * being analyzed against as well as the package-root used to resolve 'package:'
URI's. (The latter | 100 * being analyzed against as well as the package-root used to resolve 'package:'
URI's. (Both of |
| 101 * is included indirectly through the {@link SourceFactory source factory}.) | 101 * which are known indirectly through the {@link SourceFactory source factory}.) |
| 102 * <p> |
| 103 * They also represent the state of a given analysis, which includes knowing whi
ch sources have been |
| 104 * included in the analysis (either directly or indirectly) and the results of t
he analysis. Some |
| 105 * analysis results are cached in order to allow the context to balance between
memory usage and |
| 106 * performance. TODO(brianwilkerson) Decide how this is reflected in the API: a
getFoo() and |
| 107 * getOrComputeFoo() pair of methods, or a single getFoo(boolean). |
| 102 * <p> | 108 * <p> |
| 103 * Analysis engine allows for having more than one context. This can be used, fo
r example, to | 109 * Analysis engine allows for having more than one context. This can be used, fo
r example, to |
| 104 * perform one analysis based on the state of files on disk and a separate analy
sis based on the | 110 * perform one analysis based on the state of files on disk and a separate analy
sis based on the |
| 105 * state of those files in open editors. It can also be used to perform an analy
sis based on a | 111 * state of those files in open editors. It can also be used to perform an analy
sis based on a |
| 106 * proposed future state, such as the state after a refactoring. | 112 * proposed future state, such as the state after a refactoring. |
| 107 */ | 113 */ |
| 108 abstract class AnalysisContext { | 114 abstract class AnalysisContext { |
| 109 /** | 115 /** |
| 110 * Respond to the given set of changes by removing any cached information that
might now be | 116 * Apply the changes specified by the given change set to this context. Any an
alysis results that |
| 111 * out-of-date. The result indicates what operations need to be performed as a
result of this | 117 * have been invalidated by these changes will be removed. |
| 112 * change without actually performing those operations. | 118 * @param changeSet a description of the changes that are to be applied |
| 113 * @param changeSet a description of the changes that have occurred | |
| 114 * @return a result (not {@code null}) indicating operations to be performed | |
| 115 */ | 119 */ |
| 116 ChangeResult changed(ChangeSet changeSet); | 120 void applyChanges(ChangeSet changeSet); |
| 117 /** | 121 /** |
| 118 * Clear any cached information that is dependent on resolution. This method s
hould be invoked if | 122 * Clear any cached information that is dependent on resolution. This method s
hould be invoked if |
| 119 * the assumptions used by resolution have changed but the contents of the fil
e have not changed. | 123 * the assumptions used by resolution have changed but the contents of the fil
e have not changed. |
| 120 * Use {@link #sourceChanged(Source)} and {@link #sourcesDeleted(SourceContain
er)} to indicate | 124 * Use {@link #sourceChanged(Source)} and {@link #sourcesDeleted(SourceContain
er)} to indicate |
| 121 * when the contents of a file or files have changed. | 125 * when the contents of a file or files have changed. |
| 122 */ | 126 */ |
| 123 void clearResolution(); | 127 void clearResolution(); |
| 124 /** | 128 /** |
| 125 * Call this method when this context is no longer going to be used. At this p
oint, the receiver | 129 * Call this method when this context is no longer going to be used. At this p
oint, the receiver |
| 126 * may choose to push some of its information back into the global cache for c
onsumption by | 130 * may choose to push some of its information back into the global cache for c
onsumption by |
| 127 * another context for performance. | 131 * another context for performance. |
| 128 */ | 132 */ |
| 129 void discard(); | 133 void discard(); |
| 130 /** | 134 /** |
| 131 * Create a new context in which analysis can be performed. Any sources in the
specified directory | 135 * Create a new context in which analysis can be performed. Any sources in the
specified container |
| 132 * in the receiver will be removed from the receiver and added to the newly cr
eated context. | 136 * will be removed from this context and added to the newly created context. |
| 133 * @param directory the directory (not {@code null}) containing sources that s
hould be removed | 137 * @param container the container containing sources that should be removed fr
om this context and |
| 134 * from the receiver and added to the returned context | 138 * added to the returned context |
| 135 * @return the analysis context that was created (not {@code null}) | 139 * @return the analysis context that was created |
| 136 */ | 140 */ |
| 137 AnalysisContext extractAnalysisContext(SourceContainer container); | 141 AnalysisContext extractContext(SourceContainer container); |
| 138 /** | 142 /** |
| 139 * Return the element referenced by the given location. | 143 * Return the element referenced by the given location. |
| 140 * @param location the reference describing the element to be returned | 144 * @param location the reference describing the element to be returned |
| 141 * @return the element referenced by the given location | 145 * @return the element referenced by the given location |
| 142 */ | 146 */ |
| 143 Element getElement(ElementLocation location); | 147 Element getElement(ElementLocation location); |
| 144 /** | 148 /** |
| 145 * Return an array containing all of the errors associated with the given sour
ce. | 149 * Return an array containing all of the errors associated with the given sour
ce. The array will |
| 150 * be empty if the source is not known to this context or if there are no erro
rs in the source. |
| 146 * @param source the source whose errors are to be returned | 151 * @param source the source whose errors are to be returned |
| 147 * @return all of the errors associated with the given source | 152 * @return all of the errors associated with the given source |
| 148 * @throws AnalysisException if the errors could not be determined because the
analysis could not | 153 * @throws AnalysisException if the errors could not be determined because the
analysis could not |
| 149 * be performed | 154 * be performed |
| 150 */ | 155 */ |
| 151 List<AnalysisError> getErrors(Source source); | 156 List<AnalysisError> getErrors(Source source); |
| 152 /** | 157 /** |
| 153 * Parse and build an element model for the HTML file defined by the given sou
rce. | 158 * Return the element model corresponding to the HTML file defined by the give
n source. |
| 154 * @param source the source defining the HTML file whose element model is to b
e returned | 159 * @param source the source defining the HTML file whose element model is to b
e returned |
| 155 * @return the element model corresponding to the HTML file defined by the giv
en source | 160 * @return the element model corresponding to the HTML file defined by the giv
en source |
| 156 */ | 161 */ |
| 157 HtmlElement getHtmlElement(Source source); | 162 HtmlElement getHtmlElement(Source source); |
| 158 /** | 163 /** |
| 164 * Return an array containing all of the sources known to this context that re
present HTML files. |
| 165 * @return the sources known to this context that represent HTML files |
| 166 */ |
| 167 List<Source> get htmlSources; |
| 168 /** |
| 159 * Return the kind of the given source if it is already known, or {@code null}
if the kind is not | 169 * Return the kind of the given source if it is already known, or {@code null}
if the kind is not |
| 160 * already known. | 170 * already known. |
| 161 * @param source the source whose kind is to be returned | 171 * @param source the source whose kind is to be returned |
| 162 * @return the kind of the given source | 172 * @return the kind of the given source |
| 163 * @see #getOrComputeKindOf(Source) | 173 * @see #getOrComputeKindOf(Source) |
| 164 */ | 174 */ |
| 165 SourceKind getKnownKindOf(Source source); | 175 SourceKind getKnownKindOf(Source source); |
| 166 /** | 176 /** |
| 177 * Return an array containing all of the sources known to this context that re
present the defining |
| 178 * compilation unit of a library that can be run within a browser. The sources
that are returned |
| 179 * represent libraries that have a 'main' method and are either referenced by
an HTML file or |
| 180 * import, directly or indirectly, a client-only library. |
| 181 * @return the sources known to this context that represent the defining compi
lation unit of a |
| 182 * library that can be run within a browser |
| 183 */ |
| 184 List<Source> get launchableClientLibrarySources; |
| 185 /** |
| 186 * Return an array containing all of the sources known to this context that re
present the defining |
| 187 * compilation unit of a library that can be run outside of a browser. |
| 188 * @return the sources known to this context that represent the defining compi
lation unit of a |
| 189 * library that can be run outside of a browser |
| 190 */ |
| 191 List<Source> get launchableServerLibrarySources; |
| 192 /** |
| 167 * Return the sources for the defining compilation units of any libraries of w
hich the given | 193 * Return the sources for the defining compilation units of any libraries of w
hich the given |
| 168 * source is a part. The array will normally contain a single library because
most Dart sources | 194 * source is a part. The array will normally contain a single library because
most Dart sources |
| 169 * are only included in a single library, but it is possible to have a part th
at is contained in | 195 * are only included in a single library, but it is possible to have a part th
at is contained in |
| 170 * multiple identically named libraries. If the source represents the defining
compilation unit of | 196 * multiple identically named libraries. If the source represents the defining
compilation unit of |
| 171 * a library, then the returned array will contain the given source as its onl
y element. If the | 197 * a library, then the returned array will contain the given source as its onl
y element. If the |
| 172 * source does not represent a Dart source or is not known to this context, th
e returned array | 198 * source does not represent a Dart source or is not known to this context, th
e returned array |
| 173 * will be empty. | 199 * will be empty. |
| 174 * @param source the source contained in the returned libraries | 200 * @param source the source contained in the returned libraries |
| 175 * @return the sources for the libraries containing the given source | 201 * @return the sources for the libraries containing the given source |
| 176 */ | 202 */ |
| 177 List<Source> getLibrariesContaining(Source source); | 203 List<Source> getLibrariesContaining(Source source); |
| 178 /** | 204 /** |
| 179 * Return the element model corresponding to the library defined by the given
source. If the | 205 * Return the element model corresponding to the library defined by the given
source. If the |
| 180 * element model does not yet exist it will be created. The process of creatin
g an element model | 206 * element model does not yet exist it will be created. The process of creatin
g an element model |
| 181 * for a library can long-running, depending on the size of the library and th
e number of | 207 * for a library can long-running, depending on the size of the library and th
e number of |
| 182 * libraries that are imported into it that also need to have a model built fo
r them. | 208 * libraries that are imported into it that also need to have a model built fo
r them. |
| 183 * @param source the source defining the library whose element model is to be
returned | 209 * @param source the source defining the library whose element model is to be
returned |
| 184 * @return the element model corresponding to the library defined by the given
source or{@code null} if the element model could not be determined because the
analysis could | 210 * @return the element model corresponding to the library defined by the given
source or{@code null} if the element model could not be determined because the
analysis could |
| 185 * not be performed | 211 * not be performed |
| 186 */ | 212 */ |
| 187 LibraryElement getLibraryElement(Source source); | 213 LibraryElement getLibraryElement(Source source); |
| 188 /** | 214 /** |
| 189 * Return the element model corresponding to the library defined by the given
source, or{@code null} if the element model does not yet exist. | 215 * Return the element model corresponding to the library defined by the given
source, or{@code null} if the element model does not currently exist or if the a
nalysis could not be |
| 216 * performed. |
| 190 * @param source the source defining the library whose element model is to be
returned | 217 * @param source the source defining the library whose element model is to be
returned |
| 191 * @return the element model corresponding to the library defined by the given
source | 218 * @return the element model corresponding to the library defined by the given
source |
| 192 */ | 219 */ |
| 193 LibraryElement getLibraryElementOrNull(Source source); | 220 LibraryElement getLibraryElementOrNull(Source source); |
| 194 /** | 221 /** |
| 222 * Return an array containing all of the sources known to this context that re
present the defining |
| 223 * compilation unit of a library. |
| 224 * @return the sources known to this context that represent the defining compi
lation unit of a |
| 225 * library |
| 226 */ |
| 227 List<Source> get librarySources; |
| 228 /** |
| 195 * Return the kind of the given source, computing it's kind if it is not alrea
dy known. | 229 * Return the kind of the given source, computing it's kind if it is not alrea
dy known. |
| 196 * @param source the source whose kind is to be returned | 230 * @param source the source whose kind is to be returned |
| 197 * @return the kind of the given source | 231 * @return the kind of the given source |
| 198 * @see #getKnownKindOf(Source) | 232 * @see #getKnownKindOf(Source) |
| 199 */ | 233 */ |
| 200 SourceKind getOrComputeKindOf(Source source); | 234 SourceKind getOrComputeKindOf(Source source); |
| 201 /** | 235 /** |
| 202 * Return an array containing all of the parsing errors associated with the gi
ven source. | |
| 203 * @param source the source whose errors are to be returned | |
| 204 * @return all of the parsing errors associated with the given source | |
| 205 * @throws AnalysisException if the errors could not be determined because the
analysis could not | |
| 206 * be performed | |
| 207 */ | |
| 208 List<AnalysisError> getParsingErrors(Source source); | |
| 209 /** | |
| 210 * Return an array containing all of the resolution errors associated with the
given source. | |
| 211 * @param source the source whose errors are to be returned | |
| 212 * @return all of the resolution errors associated with the given source | |
| 213 * @throws AnalysisException if the errors could not be determined because the
analysis could not | |
| 214 * be performed | |
| 215 */ | |
| 216 List<AnalysisError> getResolutionErrors(Source source); | |
| 217 /** | |
| 218 * Return the source factory used to create the sources that can be analyzed i
n this context. | 236 * Return the source factory used to create the sources that can be analyzed i
n this context. |
| 219 * @return the source factory used to create the sources that can be analyzed
in this context | 237 * @return the source factory used to create the sources that can be analyzed
in this context |
| 220 */ | 238 */ |
| 221 SourceFactory get sourceFactory; | 239 SourceFactory get sourceFactory; |
| 222 /** | 240 /** |
| 223 * Add the sources contained in the specified context to the receiver's collec
tion of sources. | 241 * Add the sources contained in the specified context to this context's collec
tion of sources. |
| 224 * This method is called when an existing context's pubspec has been removed,
and the contained | 242 * This method is called when an existing context's pubspec has been removed,
and the contained |
| 225 * sources should be reanalyzed as part of the receiver. | 243 * sources should be reanalyzed as part of this context. |
| 226 * @param context the context being merged (not {@code null}) | 244 * @param context the context being merged |
| 227 */ | 245 */ |
| 228 void mergeAnalysisContext(AnalysisContext context); | 246 void mergeContext(AnalysisContext context); |
| 229 /** | 247 /** |
| 230 * Parse a single source to produce an AST structure. The resulting AST struct
ure may or may not | 248 * Parse a single source to produce an AST structure. The resulting AST struct
ure may or may not |
| 231 * be resolved, and may have a slightly different structure depending upon whe
ther it is resolved. | 249 * be resolved, and may have a slightly different structure depending upon whe
ther it is resolved. |
| 232 * @param source the source to be parsed | 250 * @param source the source to be parsed |
| 233 * @return the AST structure representing the content of the source | 251 * @return the AST structure representing the content of the source |
| 234 * @throws AnalysisException if the analysis could not be performed | 252 * @throws AnalysisException if the analysis could not be performed |
| 235 */ | 253 */ |
| 236 CompilationUnit parse(Source source); | 254 CompilationUnit parse(Source source); |
| 237 /** | 255 /** |
| 238 * Parse a single HTML source to produce an AST structure. The resulting HTML
AST structure may or | 256 * Parse a single HTML source to produce an AST structure. The resulting HTML
AST structure may or |
| 239 * may not be resolved, and may have a slightly different structure depending
upon whether it is | 257 * may not be resolved, and may have a slightly different structure depending
upon whether it is |
| 240 * resolved. | 258 * resolved. |
| 241 * @param source the HTML source to be parsed | 259 * @param source the HTML source to be parsed |
| 242 * @return the parse result (not {@code null}) | 260 * @return the parse result (not {@code null}) |
| 243 * @throws AnalysisException if the analysis could not be performed | 261 * @throws AnalysisException if the analysis could not be performed |
| 244 */ | 262 */ |
| 245 HtmlParseResult parseHtml(Source source); | 263 HtmlParseResult parseHtml(Source source); |
| 246 /** | 264 /** |
| 265 * Perform the next unit of work required to keep the analysis results up-to-d
ate and return |
| 266 * information about the consequent changes to the analysis results. If there
were no results the |
| 267 * returned array will be empty. This method can be long running. |
| 268 * @return an array containing notices of changes to the analysis results |
| 269 */ |
| 270 List<ChangeNotice> performAnalysisTask(); |
| 271 /** |
| 247 * Parse and resolve a single source within the given context to produce a ful
ly resolved AST. | 272 * Parse and resolve a single source within the given context to produce a ful
ly resolved AST. |
| 248 * @param source the source to be parsed and resolved | 273 * @param source the source to be parsed and resolved |
| 249 * @param library the library defining the context in which the source file is
to be resolved | 274 * @param library the library defining the context in which the source file is
to be resolved |
| 250 * @return the result of resolving the AST structure representing the content
of the source | 275 * @return the result of resolving the AST structure representing the content
of the source |
| 251 * @throws AnalysisException if the analysis could not be performed | 276 * @throws AnalysisException if the analysis could not be performed |
| 252 */ | 277 */ |
| 253 CompilationUnit resolve(Source source, LibraryElement library); | 278 CompilationUnit resolve(Source source, LibraryElement library); |
| 254 /** | 279 /** |
| 255 * Scan a single source to produce a token stream. | |
| 256 * @param source the source to be scanned | |
| 257 * @param errorListener the listener to which errors should be reported | |
| 258 * @return the head of the token stream representing the content of the source | |
| 259 * @throws AnalysisException if the analysis could not be performed | |
| 260 */ | |
| 261 Token scan(Source source, AnalysisErrorListener errorListener); | |
| 262 /** | |
| 263 * Scan a single source to produce an HTML token stream. | |
| 264 * @param source the source to be scanned | |
| 265 * @return the scan result (not {@code null}) | |
| 266 * @throws AnalysisException if the analysis could not be performed | |
| 267 */ | |
| 268 HtmlScanResult scanHtml(Source source); | |
| 269 /** | |
| 270 * Set the source factory used to create the sources that can be analyzed in t
his context to the | 280 * Set the source factory used to create the sources that can be analyzed in t
his context to the |
| 271 * given source factory. | 281 * given source factory. Clients can safely assume that all analysis results h
ave been |
| 272 * @param sourceFactory the source factory used to create the sources that can
be analyzed in this | 282 * invalidated. |
| 283 * @param factory the source factory used to create the sources that can be an
alyzed in this |
| 273 * context | 284 * context |
| 274 */ | 285 */ |
| 275 void set sourceFactory(SourceFactory sourceFactory4); | 286 void set sourceFactory(SourceFactory factory); |
| 276 /** | 287 /** |
| 277 * Given a collection of sources with content that has changed, return an {@li
nk Iterable}identifying the sources that need to be resolved. | 288 * Given a collection of sources with content that has changed, return an {@li
nk Iterable}identifying the sources that need to be resolved. |
| 278 * @param changedSources an array of sources (not {@code null}, contains no {@
code null}s) | 289 * @param changedSources an array of sources (not {@code null}, contains no {@
code null}s) |
| 279 * @return An iterable returning the sources to be resolved | 290 * @return An iterable returning the sources to be resolved |
| 280 */ | 291 */ |
| 281 Iterable<Source> sourcesToResolve(List<Source> changedSources); | 292 Iterable<Source> sourcesToResolve(List<Source> changedSources); |
| 282 } | 293 } |
| 283 /** | 294 /** |
| 284 * Instances of the class {@code AnalysisException} represent an exception that
occurred during the | 295 * Instances of the class {@code AnalysisException} represent an exception that
occurred during the |
| 285 * analysis of one or more sources. | 296 * analysis of one or more sources. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 * Initialize a newly created exception to have the given cause. | 328 * Initialize a newly created exception to have the given cause. |
| 318 * @param cause the underlying exception that caused this exception | 329 * @param cause the underlying exception that caused this exception |
| 319 */ | 330 */ |
| 320 AnalysisException.con3(Exception cause) : super.withCause(cause) { | 331 AnalysisException.con3(Exception cause) : super.withCause(cause) { |
| 321 _jtd_constructor_126_impl(cause); | 332 _jtd_constructor_126_impl(cause); |
| 322 } | 333 } |
| 323 _jtd_constructor_126_impl(Exception cause) { | 334 _jtd_constructor_126_impl(Exception cause) { |
| 324 } | 335 } |
| 325 } | 336 } |
| 326 /** | 337 /** |
| 327 * Instances of {@code ChangeResult} are returned by {@link AnalysisContext#chan
ged(ChangeSet)} to | 338 * Instances of the class {@code ChangeNotice} represent a change to the analysi
s results associated |
| 328 * indicate what operations need to be performed as a result of the change. | 339 * with a given source. |
| 329 * @coverage dart.engine | |
| 330 */ | 340 */ |
| 331 class ChangeResult { | 341 class ChangeNotice { |
| 342 /** |
| 343 * The source for which the result is being reported. |
| 344 */ |
| 345 Source _source; |
| 346 /** |
| 347 * The fully resolved AST that changed as a result of the analysis, or {@code
null} if the AST was |
| 348 * not changed. |
| 349 */ |
| 350 CompilationUnit _compilationUnit; |
| 351 /** |
| 352 * The errors that changed as a result of the analysis, or {@code null} if err
ors were not |
| 353 * changed. |
| 354 */ |
| 355 List<AnalysisError> _errors; |
| 356 /** |
| 357 * The line information associated with the source, or {@code null} if errors
were not changed. |
| 358 */ |
| 359 LineInfo _lineInfo; |
| 360 /** |
| 361 * An empty array of change notices. |
| 362 */ |
| 363 static List<ChangeNotice> EMPTY_ARRAY = new List<ChangeNotice>(0); |
| 364 /** |
| 365 * Initialize a newly created result representing the fact that the errors ass
ociated with a |
| 366 * source have changed. |
| 367 * @param source the source for which the result is being reported |
| 368 * @param errors the errors that changed as a result of the analysis |
| 369 * @param the line information associated with the source |
| 370 */ |
| 371 ChangeNotice.con1(Source source2, List<AnalysisError> errors2, LineInfo lineIn
fo3) { |
| 372 _jtd_constructor_127_impl(source2, errors2, lineInfo3); |
| 373 } |
| 374 _jtd_constructor_127_impl(Source source2, List<AnalysisError> errors2, LineInf
o lineInfo3) { |
| 375 this._source = source2; |
| 376 this._errors = errors2; |
| 377 this._lineInfo = lineInfo3; |
| 378 } |
| 379 /** |
| 380 * Initialize a newly created result representing the fact that the resolution
of a source has |
| 381 * changed. |
| 382 * @param source the source for which the result is being reported |
| 383 * @param compilationUnit the fully resolved AST produced as a result of the a
nalysis |
| 384 */ |
| 385 ChangeNotice.con2(Source source3, CompilationUnit compilationUnit9) { |
| 386 _jtd_constructor_128_impl(source3, compilationUnit9); |
| 387 } |
| 388 _jtd_constructor_128_impl(Source source3, CompilationUnit compilationUnit9) { |
| 389 this._source = source3; |
| 390 this._compilationUnit = compilationUnit9; |
| 391 } |
| 392 /** |
| 393 * Return the fully resolved AST that changed as a result of the analysis, or
{@code null} if the |
| 394 * AST was not changed. |
| 395 * @return the fully resolved AST that changed as a result of the analysis |
| 396 */ |
| 397 CompilationUnit get compilationUnit => _compilationUnit; |
| 398 /** |
| 399 * Return the errors that changed as a result of the analysis, or {@code null}
if errors were not |
| 400 * changed. |
| 401 * @return the errors that changed as a result of the analysis |
| 402 */ |
| 403 List<AnalysisError> get errors => _errors; |
| 404 /** |
| 405 * Return the line information associated with the source, or {@code null} if
errors were not |
| 406 * changed. |
| 407 * @return the line information associated with the source |
| 408 */ |
| 409 LineInfo get lineInfo => _lineInfo; |
| 410 /** |
| 411 * Return the source for which the result is being reported. |
| 412 * @return the source for which the result is being reported |
| 413 */ |
| 414 Source get source => _source; |
| 332 } | 415 } |
| 333 /** | 416 /** |
| 334 * Instances of the class {@code ChangeSet} indicate what sources have been adde
d, changed, or | 417 * Instances of the class {@code ChangeSet} indicate what sources have been adde
d, changed, or |
| 335 * removed. | 418 * removed. |
| 336 * @coverage dart.engine | 419 * @coverage dart.engine |
| 337 */ | 420 */ |
| 338 class ChangeSet { | 421 class ChangeSet { |
| 339 /** | 422 /** |
| 340 * A table mapping the sources that have been added to their contents. | 423 * A table mapping the sources that have been added to their contents. |
| 341 */ | 424 */ |
| (...skipping 19 matching lines...) Expand all Loading... |
| 361 * Record that the specified source has been added and that it's content is th
e default contents | 444 * Record that the specified source has been added and that it's content is th
e default contents |
| 362 * of the source. | 445 * of the source. |
| 363 * @param source the source that was added | 446 * @param source the source that was added |
| 364 */ | 447 */ |
| 365 void added(Source source) { | 448 void added(Source source) { |
| 366 added2(source, null); | 449 added2(source, null); |
| 367 } | 450 } |
| 368 /** | 451 /** |
| 369 * Record that the specified source has been added and that it has the given c
ontent. If the | 452 * Record that the specified source has been added and that it has the given c
ontent. If the |
| 370 * content is non-{@code null}, this has the effect of overriding the default
contents of the | 453 * content is non-{@code null}, this has the effect of overriding the default
contents of the |
| 371 * source. If the contents are {@code null}, any previous the override is remo
ved so that the | 454 * source. If the contents are {@code null}, any previous override is removed
so that the default |
| 372 * default contents will be used. | 455 * contents will be used. |
| 373 * @param source the source that was added | 456 * @param source the source that was added |
| 374 * @param content the content of the new source | 457 * @param content the content of the new source |
| 375 */ | 458 */ |
| 376 void added2(Source source, String content) { | 459 void added2(Source source, String content) { |
| 377 if (source != null) { | 460 if (source != null) { |
| 378 _added3[source] = content; | 461 _added3[source] = content; |
| 379 } | 462 } |
| 380 } | 463 } |
| 381 /** | 464 /** |
| 382 * Record that the specified source has been changed and that it's content is
the default contents | 465 * Record that the specified source has been changed and that it's content is
the default contents |
| 383 * of the source. | 466 * of the source. |
| 384 * @param source the source that was changed | 467 * @param source the source that was changed |
| 385 */ | 468 */ |
| 386 void changed(Source source) { | 469 void changed(Source source) { |
| 387 changed2(source, null); | 470 changed2(source, null); |
| 388 } | 471 } |
| 389 /** | 472 /** |
| 390 * Record that the specified source has been changed and that it now has the g
iven content. If the | 473 * Record that the specified source has been changed and that it now has the g
iven content. If the |
| 391 * content is non-{@code null}, this has the effect of overriding the default
contents of the | 474 * content is non-{@code null}, this has the effect of overriding the default
contents of the |
| 392 * source. If the contents are {@code null}, any previous the override is remo
ved so that the | 475 * source. If the contents are {@code null}, any previous override is removed
so that the default |
| 393 * default contents will be used. | 476 * contents will be used. |
| 394 * @param source the source that was changed | 477 * @param source the source that was changed |
| 395 * @param content the new content of the source | 478 * @param content the new content of the source |
| 396 */ | 479 */ |
| 397 void changed2(Source source, String content) { | 480 void changed2(Source source, String content) { |
| 398 if (source != null) { | 481 if (source != null) { |
| 399 _changed3[source] = content; | 482 _changed3[source] = content; |
| 400 } | 483 } |
| 401 } | 484 } |
| 402 /** | 485 /** |
| 403 * Return a table mapping the sources that have been added to their contents. | 486 * Return a table mapping the sources that have been added to their contents. |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 /** | 558 /** |
| 476 * A cache mapping sources (of the defining compilation units of libraries) to
the public | 559 * A cache mapping sources (of the defining compilation units of libraries) to
the public |
| 477 * namespace for that library. | 560 * namespace for that library. |
| 478 */ | 561 */ |
| 479 Map<Source, Namespace> _publicNamespaceCache = new Map<Source, Namespace>(); | 562 Map<Source, Namespace> _publicNamespaceCache = new Map<Source, Namespace>(); |
| 480 /** | 563 /** |
| 481 * The object used to synchronize access to all of the caches. | 564 * The object used to synchronize access to all of the caches. |
| 482 */ | 565 */ |
| 483 Object _cacheLock = new Object(); | 566 Object _cacheLock = new Object(); |
| 484 /** | 567 /** |
| 485 * The suffix used by sources that contain Dart. | |
| 486 */ | |
| 487 static String _DART_SUFFIX = ".dart"; | |
| 488 /** | |
| 489 * The suffix used by sources that contain HTML. | |
| 490 */ | |
| 491 static String _HTML_SUFFIX = ".html"; | |
| 492 /** | |
| 493 * Initialize a newly created analysis context. | 568 * Initialize a newly created analysis context. |
| 494 */ | 569 */ |
| 495 AnalysisContextImpl() : super() { | 570 AnalysisContextImpl() : super() { |
| 496 } | 571 } |
| 497 ChangeResult changed(ChangeSet changeSet) { | 572 void applyChanges(ChangeSet changeSet) { |
| 498 if (changeSet.isEmpty()) { | 573 if (changeSet.isEmpty()) { |
| 499 return new ChangeResult(); | 574 return; |
| 500 } | 575 } |
| 501 { | 576 { |
| 577 List<Source> addedSources = new List<Source>(); |
| 502 for (MapEntry<Source, String> entry in getMapEntrySet(changeSet.addedWithC
ontent)) { | 578 for (MapEntry<Source, String> entry in getMapEntrySet(changeSet.addedWithC
ontent)) { |
| 503 _sourceFactory.setContents(entry.getKey(), entry.getValue()); | 579 Source source = entry.getKey(); |
| 580 _sourceFactory.setContents(source, entry.getValue()); |
| 581 addedSources.add(source); |
| 504 } | 582 } |
| 583 List<Source> changedSources = new List<Source>(); |
| 505 for (MapEntry<Source, String> entry in getMapEntrySet(changeSet.changedWit
hContent)) { | 584 for (MapEntry<Source, String> entry in getMapEntrySet(changeSet.changedWit
hContent)) { |
| 506 _sourceFactory.setContents(entry.getKey(), entry.getValue()); | 585 Source source = entry.getKey(); |
| 586 _sourceFactory.setContents(source, entry.getValue()); |
| 587 changedSources.add(source); |
| 507 } | 588 } |
| 508 for (Source source in changeSet.addedWithContent.keys.toSet()) { | 589 List<Source> removedSources = new List<Source>.from(changeSet.removed); |
| 590 for (SourceContainer container in changeSet.removedContainers) { |
| 591 addSourcesInContainer(removedSources, container); |
| 592 } |
| 593 for (Source source in addedSources) { |
| 509 sourceAvailable(source); | 594 sourceAvailable(source); |
| 510 } | 595 } |
| 511 for (Source source in changeSet.changedWithContent.keys.toSet()) { | 596 for (Source source in changedSources) { |
| 512 sourceChanged(source); | 597 sourceChanged(source); |
| 513 } | 598 } |
| 514 for (Source source in changeSet.removed) { | 599 for (Source source in removedSources) { |
| 515 sourceDeleted(source); | 600 sourceRemoved(source); |
| 516 } | |
| 517 for (SourceContainer container in changeSet.removedContainers) { | |
| 518 sourcesDeleted(container); | |
| 519 } | 601 } |
| 520 } | 602 } |
| 521 return new ChangeResult(); | |
| 522 } | 603 } |
| 523 void clearResolution() { | 604 void clearResolution() { |
| 524 { | 605 { |
| 525 _parseCache.clear(); | 606 _parseCache.clear(); |
| 526 _htmlParseCache.clear(); | 607 _htmlParseCache.clear(); |
| 527 _libraryElementCache.clear(); | 608 _libraryElementCache.clear(); |
| 528 _publicNamespaceCache.clear(); | 609 _publicNamespaceCache.clear(); |
| 529 } | 610 } |
| 530 } | 611 } |
| 531 void discard() { | 612 void discard() { |
| 532 { | 613 { |
| 533 _sourceMap.clear(); | 614 _sourceMap.clear(); |
| 534 _parseCache.clear(); | 615 _parseCache.clear(); |
| 535 _htmlParseCache.clear(); | 616 _htmlParseCache.clear(); |
| 536 _libraryElementCache.clear(); | 617 _libraryElementCache.clear(); |
| 537 _publicNamespaceCache.clear(); | 618 _publicNamespaceCache.clear(); |
| 538 } | 619 } |
| 539 } | 620 } |
| 540 AnalysisContext extractAnalysisContext(SourceContainer container) { | 621 AnalysisContext extractContext(SourceContainer container) { |
| 541 AnalysisContextImpl newContext = AnalysisEngine.instance.createAnalysisConte
xt() as AnalysisContextImpl; | 622 AnalysisContextImpl newContext = AnalysisEngine.instance.createAnalysisConte
xt() as AnalysisContextImpl; |
| 542 List<Source> sourcesToRemove = new List<Source>(); | 623 List<Source> sourcesToRemove = new List<Source>(); |
| 543 { | 624 { |
| 544 for (MapEntry<Source, SourceInfo> entry in getMapEntrySet(_sourceMap)) { | 625 for (MapEntry<Source, SourceInfo> entry in getMapEntrySet(_sourceMap)) { |
| 545 Source source = entry.getKey(); | 626 Source source = entry.getKey(); |
| 546 if (container.contains(source)) { | 627 if (container.contains(source)) { |
| 547 sourcesToRemove.add(source); | 628 sourcesToRemove.add(source); |
| 548 newContext._sourceMap[source] = new SourceInfo.con2(entry.getValue()); | 629 newContext._sourceMap[source] = new SourceInfo.con2(entry.getValue()); |
| 549 } | 630 } |
| 550 } | 631 } |
| 551 } | 632 } |
| 552 return newContext; | 633 return newContext; |
| 553 } | 634 } |
| 554 Element getElement(ElementLocation location) { | 635 Element getElement(ElementLocation location) { |
| 555 throw new UnsupportedOperationException(); | 636 throw new UnsupportedOperationException(); |
| 556 } | 637 } |
| 557 List<AnalysisError> getErrors(Source source) { | 638 List<AnalysisError> getErrors(Source source) { |
| 558 throw new UnsupportedOperationException(); | 639 throw new UnsupportedOperationException(); |
| 559 } | 640 } |
| 560 HtmlElement getHtmlElement(Source source) { | 641 HtmlElement getHtmlElement(Source source) { |
| 642 if (!AnalysisEngine.isHtmlFileName(source.shortName)) { |
| 643 return null; |
| 644 } |
| 561 throw new UnsupportedOperationException(); | 645 throw new UnsupportedOperationException(); |
| 562 } | 646 } |
| 647 List<Source> get htmlSources => getSources(SourceKind.HTML); |
| 563 SourceKind getKnownKindOf(Source source) { | 648 SourceKind getKnownKindOf(Source source) { |
| 564 if (source.fullName.endsWith(_HTML_SUFFIX)) { | 649 String name = source.shortName; |
| 650 if (AnalysisEngine.isHtmlFileName(name)) { |
| 565 return SourceKind.HTML; | 651 return SourceKind.HTML; |
| 566 } | 652 } |
| 567 if (!source.fullName.endsWith(_DART_SUFFIX)) { | 653 if (!AnalysisEngine.isDartFileName(name)) { |
| 568 return SourceKind.UNKNOWN; | 654 return SourceKind.UNKNOWN; |
| 569 } | 655 } |
| 570 { | 656 { |
| 571 if (_libraryElementCache.containsKey(source)) { | 657 if (_libraryElementCache.containsKey(source)) { |
| 572 return SourceKind.LIBRARY; | 658 return SourceKind.LIBRARY; |
| 573 } | 659 } |
| 574 CompilationUnit unit = _parseCache[source]; | 660 CompilationUnit unit = _parseCache[source]; |
| 575 if (unit != null && hasPartOfDirective(unit)) { | 661 if (unit != null && hasPartOfDirective(unit)) { |
| 576 return SourceKind.PART; | 662 return SourceKind.PART; |
| 577 } | 663 } |
| 578 } | 664 } |
| 579 return null; | 665 return null; |
| 580 } | 666 } |
| 667 List<Source> get launchableClientLibrarySources => librarySources; |
| 668 List<Source> get launchableServerLibrarySources => librarySources; |
| 581 List<Source> getLibrariesContaining(Source source) { | 669 List<Source> getLibrariesContaining(Source source) { |
| 582 { | 670 { |
| 583 SourceInfo info = _sourceMap[source]; | 671 SourceInfo info = _sourceMap[source]; |
| 584 if (info == null) { | 672 if (info == null) { |
| 585 return Source.EMPTY_ARRAY; | 673 return Source.EMPTY_ARRAY; |
| 586 } | 674 } |
| 587 return info.librarySources; | 675 return info.librarySources; |
| 588 } | 676 } |
| 589 } | 677 } |
| 590 LibraryElement getLibraryElement(Source source) { | 678 LibraryElement getLibraryElement(Source source) { |
| 679 if (!AnalysisEngine.isDartFileName(source.shortName)) { |
| 680 return null; |
| 681 } |
| 591 { | 682 { |
| 592 LibraryElement element = _libraryElementCache[source]; | 683 LibraryElement element = _libraryElementCache[source]; |
| 593 if (element == null) { | 684 if (element == null) { |
| 594 if (getOrComputeKindOf(source) != SourceKind.LIBRARY) { | 685 if (getOrComputeKindOf(source) != SourceKind.LIBRARY) { |
| 595 return null; | 686 return null; |
| 596 } | 687 } |
| 597 LibraryResolver resolver = new LibraryResolver.con1(this); | 688 LibraryResolver resolver = new LibraryResolver.con1(this); |
| 598 try { | 689 try { |
| 599 element = resolver.resolveLibrary(source, true); | 690 element = resolver.resolveLibrary(source, true); |
| 600 if (element != null) { | 691 if (element != null) { |
| 601 _libraryElementCache[source] = element; | 692 _libraryElementCache[source] = element; |
| 602 } | 693 } |
| 603 } on AnalysisException catch (exception) { | 694 } on AnalysisException catch (exception) { |
| 604 AnalysisEngine.instance.logger.logError2("Could not resolve the librar
y ${source.fullName}", exception); | 695 AnalysisEngine.instance.logger.logError2("Could not resolve the librar
y ${source.fullName}", exception); |
| 605 } | 696 } |
| 606 } | 697 } |
| 607 return element; | 698 return element; |
| 608 } | 699 } |
| 609 } | 700 } |
| 610 /** | 701 /** |
| 611 * Return the element model corresponding to the library defined by the given
source, or{@code null} if the element model does not yet exist. | 702 * Return the element model corresponding to the library defined by the given
source, or{@code null} if the element model does not yet exist. |
| 612 * @param source the source defining the library whose element model is to be
returned | 703 * @param source the source defining the library whose element model is to be
returned |
| 613 * @return the element model corresponding to the library defined by the given
source | 704 * @return the element model corresponding to the library defined by the given
source |
| 614 */ | 705 */ |
| 615 LibraryElement getLibraryElementOrNull(Source source) { | 706 LibraryElement getLibraryElementOrNull(Source source) { |
| 616 { | 707 { |
| 617 return _libraryElementCache[source]; | 708 return _libraryElementCache[source]; |
| 618 } | 709 } |
| 619 } | 710 } |
| 711 List<Source> get librarySources => getSources(SourceKind.LIBRARY); |
| 620 SourceKind getOrComputeKindOf(Source source) { | 712 SourceKind getOrComputeKindOf(Source source) { |
| 621 SourceKind kind = getKnownKindOf(source); | 713 SourceKind kind = getKnownKindOf(source); |
| 622 if (kind != null) { | 714 if (kind != null) { |
| 623 return kind; | 715 return kind; |
| 624 } | 716 } |
| 625 try { | 717 return computeKindOf(source); |
| 626 if (hasPartOfDirective(parse(source))) { | |
| 627 return SourceKind.PART; | |
| 628 } | |
| 629 } on AnalysisException catch (exception) { | |
| 630 return SourceKind.UNKNOWN; | |
| 631 } | |
| 632 return SourceKind.LIBRARY; | |
| 633 } | |
| 634 List<AnalysisError> getParsingErrors(Source source) { | |
| 635 throw new UnsupportedOperationException(); | |
| 636 } | 718 } |
| 637 /** | 719 /** |
| 638 * Return a namespace containing mappings for all of the public names defined
by the given | 720 * Return a namespace containing mappings for all of the public names defined
by the given |
| 639 * library. | 721 * library. |
| 640 * @param library the library whose public namespace is to be returned | 722 * @param library the library whose public namespace is to be returned |
| 641 * @return the public namespace of the given library | 723 * @return the public namespace of the given library |
| 642 */ | 724 */ |
| 643 Namespace getPublicNamespace(LibraryElement library) { | 725 Namespace getPublicNamespace(LibraryElement library) { |
| 644 Source source8 = library.definingCompilationUnit.source; | 726 Source source10 = library.definingCompilationUnit.source; |
| 645 { | 727 { |
| 646 Namespace namespace = _publicNamespaceCache[source8]; | 728 Namespace namespace = _publicNamespaceCache[source10]; |
| 647 if (namespace == null) { | 729 if (namespace == null) { |
| 648 NamespaceBuilder builder = new NamespaceBuilder(); | 730 NamespaceBuilder builder = new NamespaceBuilder(); |
| 649 namespace = builder.createPublicNamespace(library); | 731 namespace = builder.createPublicNamespace(library); |
| 650 _publicNamespaceCache[source8] = namespace; | 732 _publicNamespaceCache[source10] = namespace; |
| 651 } | 733 } |
| 652 return namespace; | 734 return namespace; |
| 653 } | 735 } |
| 654 } | 736 } |
| 655 /** | 737 /** |
| 656 * Return a namespace containing mappings for all of the public names defined
by the library | 738 * Return a namespace containing mappings for all of the public names defined
by the library |
| 657 * defined by the given source. | 739 * defined by the given source. |
| 658 * @param source the source defining the library whose public namespace is to
be returned | 740 * @param source the source defining the library whose public namespace is to
be returned |
| 659 * @return the public namespace corresponding to the library defined by the gi
ven source | 741 * @return the public namespace corresponding to the library defined by the gi
ven source |
| 660 */ | 742 */ |
| 661 Namespace getPublicNamespace2(Source source) { | 743 Namespace getPublicNamespace2(Source source) { |
| 662 { | 744 { |
| 663 Namespace namespace = _publicNamespaceCache[source]; | 745 Namespace namespace = _publicNamespaceCache[source]; |
| 664 if (namespace == null) { | 746 if (namespace == null) { |
| 665 LibraryElement library = getLibraryElement(source); | 747 LibraryElement library = getLibraryElement(source); |
| 666 if (library == null) { | 748 if (library == null) { |
| 667 return null; | 749 return null; |
| 668 } | 750 } |
| 669 NamespaceBuilder builder = new NamespaceBuilder(); | 751 NamespaceBuilder builder = new NamespaceBuilder(); |
| 670 namespace = builder.createPublicNamespace(library); | 752 namespace = builder.createPublicNamespace(library); |
| 671 _publicNamespaceCache[source] = namespace; | 753 _publicNamespaceCache[source] = namespace; |
| 672 } | 754 } |
| 673 return namespace; | 755 return namespace; |
| 674 } | 756 } |
| 675 } | 757 } |
| 676 List<AnalysisError> getResolutionErrors(Source source) { | |
| 677 throw new UnsupportedOperationException(); | |
| 678 } | |
| 679 SourceFactory get sourceFactory => _sourceFactory; | 758 SourceFactory get sourceFactory => _sourceFactory; |
| 680 void mergeAnalysisContext(AnalysisContext context) { | 759 void mergeContext(AnalysisContext context) { |
| 681 { | 760 { |
| 682 for (MapEntry<Source, SourceInfo> entry in getMapEntrySet(((context as Ana
lysisContextImpl))._sourceMap)) { | 761 for (MapEntry<Source, SourceInfo> entry in getMapEntrySet(((context as Ana
lysisContextImpl))._sourceMap)) { |
| 683 Source newSource = entry.getKey(); | 762 Source newSource = entry.getKey(); |
| 684 SourceInfo existingInfo = _sourceMap[newSource]; | 763 SourceInfo existingInfo = _sourceMap[newSource]; |
| 685 if (existingInfo == null) { | 764 if (existingInfo == null) { |
| 686 _sourceMap[newSource] = new SourceInfo.con2(entry.getValue()); | 765 _sourceMap[newSource] = new SourceInfo.con2(entry.getValue()); |
| 687 } else { | 766 } else { |
| 688 } | 767 } |
| 689 } | 768 } |
| 690 } | 769 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 720 HtmlParseResult parseHtml(Source source) { | 799 HtmlParseResult parseHtml(Source source) { |
| 721 { | 800 { |
| 722 HtmlParseResult result = _htmlParseCache[source]; | 801 HtmlParseResult result = _htmlParseCache[source]; |
| 723 if (result == null) { | 802 if (result == null) { |
| 724 result = new HtmlParser(source).parse(scanHtml(source)); | 803 result = new HtmlParser(source).parse(scanHtml(source)); |
| 725 _htmlParseCache[source] = result; | 804 _htmlParseCache[source] = result; |
| 726 } | 805 } |
| 727 return result; | 806 return result; |
| 728 } | 807 } |
| 729 } | 808 } |
| 809 List<ChangeNotice> performAnalysisTask() => ChangeNotice.EMPTY_ARRAY; |
| 730 /** | 810 /** |
| 731 * Given a table mapping the source for the libraries represented by the corre
sponding elements to | 811 * Given a table mapping the source for the libraries represented by the corre
sponding elements to |
| 732 * the elements representing the libraries, record those mappings. | 812 * the elements representing the libraries, record those mappings. |
| 733 * @param elementMap a table mapping the source for the libraries represented
by the elements to | 813 * @param elementMap a table mapping the source for the libraries represented
by the elements to |
| 734 * the elements representing the libraries | 814 * the elements representing the libraries |
| 735 */ | 815 */ |
| 736 void recordLibraryElements(Map<Source, LibraryElement> elementMap) { | 816 void recordLibraryElements(Map<Source, LibraryElement> elementMap) { |
| 737 { | 817 { |
| 738 javaMapPutAll(_libraryElementCache, elementMap); | 818 javaMapPutAll(_libraryElementCache, elementMap); |
| 739 } | 819 } |
| 740 } | 820 } |
| 741 CompilationUnit resolve(Source source, LibraryElement library) => parse(source
); | 821 CompilationUnit resolve(Source source, LibraryElement library) => parse(source
); |
| 742 Token scan(Source source, AnalysisErrorListener errorListener) { | 822 void set sourceFactory(SourceFactory factory) { |
| 743 AnalysisContextImpl_ScanResult result = internalScan(source, errorListener); | 823 if (identical(_sourceFactory, factory)) { |
| 744 return result._token; | 824 return; |
| 745 } | 825 } else if (factory.context != null) { |
| 746 HtmlScanResult scanHtml(Source source) { | 826 throw new IllegalStateException("Source factories cannot be shared between
contexts"); |
| 747 HtmlScanner scanner = new HtmlScanner(source); | 827 } else if (_sourceFactory != null) { |
| 748 try { | 828 _sourceFactory.context = null; |
| 749 source.getContents(scanner); | |
| 750 } on JavaException catch (exception) { | |
| 751 throw new AnalysisException.con3(exception); | |
| 752 } | 829 } |
| 753 return scanner.result; | 830 factory.context = this; |
| 754 } | 831 _sourceFactory = factory; |
| 755 void set sourceFactory(SourceFactory sourceFactory2) { | |
| 756 this._sourceFactory = sourceFactory2; | |
| 757 } | 832 } |
| 758 Iterable<Source> sourcesToResolve(List<Source> changedSources) { | 833 Iterable<Source> sourcesToResolve(List<Source> changedSources) { |
| 759 List<Source> librarySources = new List<Source>(); | 834 List<Source> librarySources = new List<Source>(); |
| 760 for (Source source in changedSources) { | 835 for (Source source in changedSources) { |
| 761 if (identical(getOrComputeKindOf(source), SourceKind.LIBRARY)) { | 836 if (identical(getOrComputeKindOf(source), SourceKind.LIBRARY)) { |
| 762 librarySources.add(source); | 837 librarySources.add(source); |
| 763 } | 838 } |
| 764 } | 839 } |
| 765 return librarySources; | 840 return librarySources; |
| 766 } | 841 } |
| 767 /** | 842 /** |
| 843 * Add all of the sources contained in the given source container to the given
list of sources. |
| 844 * <p> |
| 845 * Note: This method must only be invoked while we are synchronized on {@link
#cacheLock}. |
| 846 * @param sources the list to which sources are to be added |
| 847 * @param container the source container containing the sources to be added to
the list |
| 848 */ |
| 849 void addSourcesInContainer(List<Source> sources, SourceContainer container) { |
| 850 for (Source source in _sourceMap.keys.toSet()) { |
| 851 if (container.contains(source)) { |
| 852 sources.add(source); |
| 853 } |
| 854 } |
| 855 } |
| 856 SourceKind computeKindOf(Source source) { |
| 857 try { |
| 858 if (hasPartOfDirective(parse(source))) { |
| 859 return SourceKind.PART; |
| 860 } |
| 861 } on AnalysisException catch (exception) { |
| 862 return SourceKind.UNKNOWN; |
| 863 } |
| 864 return SourceKind.LIBRARY; |
| 865 } |
| 866 /** |
| 867 * Return an array containing all of the sources known to this context that ha
ve the given kind. |
| 868 * @param kind the kind of sources to be returned |
| 869 * @return all of the sources known to this context that have the given kind |
| 870 */ |
| 871 List<Source> getSources(SourceKind kind5) { |
| 872 List<Source> sources = new List<Source>(); |
| 873 { |
| 874 for (MapEntry<Source, SourceInfo> entry in getMapEntrySet(_sourceMap)) { |
| 875 if (identical(entry.getValue().kind, kind5)) { |
| 876 sources.add(entry.getKey()); |
| 877 } |
| 878 } |
| 879 } |
| 880 return new List.from(sources); |
| 881 } |
| 882 /** |
| 768 * Return {@code true} if the given compilation unit has a part-of directive. | 883 * Return {@code true} if the given compilation unit has a part-of directive. |
| 769 * @param unit the compilation unit being tested | 884 * @param unit the compilation unit being tested |
| 770 * @return {@code true} if the compilation unit has a part-of directive | 885 * @return {@code true} if the compilation unit has a part-of directive |
| 771 */ | 886 */ |
| 772 bool hasPartOfDirective(CompilationUnit unit) { | 887 bool hasPartOfDirective(CompilationUnit unit) { |
| 773 for (Directive directive in unit.directives) { | 888 for (Directive directive in unit.directives) { |
| 774 if (directive is PartOfDirective) { | 889 if (directive is PartOfDirective) { |
| 775 return true; | 890 return true; |
| 776 } | 891 } |
| 777 } | 892 } |
| 778 return false; | 893 return false; |
| 779 } | 894 } |
| 780 AnalysisContextImpl_ScanResult internalScan(Source source, AnalysisErrorListen
er errorListener) { | 895 AnalysisContextImpl_ScanResult internalScan(Source source, AnalysisErrorListen
er errorListener) { |
| 781 AnalysisContextImpl_ScanResult result = new AnalysisContextImpl_ScanResult()
; | 896 AnalysisContextImpl_ScanResult result = new AnalysisContextImpl_ScanResult()
; |
| 782 Source_ContentReceiver receiver = new Source_ContentReceiver_3(source, error
Listener, result); | 897 Source_ContentReceiver receiver = new Source_ContentReceiver_3(source, error
Listener, result); |
| 783 try { | 898 try { |
| 784 source.getContents(receiver); | 899 source.getContents(receiver); |
| 785 } on JavaException catch (exception) { | 900 } on JavaException catch (exception) { |
| 786 throw new AnalysisException.con3(exception); | 901 throw new AnalysisException.con3(exception); |
| 787 } | 902 } |
| 788 return result; | 903 return result; |
| 789 } | 904 } |
| 905 HtmlScanResult scanHtml(Source source) { |
| 906 HtmlScanner scanner = new HtmlScanner(source); |
| 907 try { |
| 908 source.getContents(scanner); |
| 909 } on JavaException catch (exception) { |
| 910 throw new AnalysisException.con3(exception); |
| 911 } |
| 912 return scanner.result; |
| 913 } |
| 790 /** | 914 /** |
| 791 * Note: This method must only be invoked while we are synchronized on {@link
#cacheLock}. | 915 * Note: This method must only be invoked while we are synchronized on {@link
#cacheLock}. |
| 792 * @param source the source that has been added | 916 * @param source the source that has been added |
| 793 */ | 917 */ |
| 794 void sourceAvailable(Source source) { | 918 void sourceAvailable(Source source) { |
| 795 SourceInfo existingInfo = _sourceMap[source]; | 919 SourceInfo existingInfo = _sourceMap[source]; |
| 796 if (existingInfo == null) { | 920 if (existingInfo == null) { |
| 797 _sourceMap[source] = new SourceInfo.con1(source, getOrComputeKindOf(source
)); | 921 SourceKind kind = computeKindOf(source); |
| 922 _sourceMap[source] = new SourceInfo.con1(source, kind); |
| 798 } | 923 } |
| 799 } | 924 } |
| 800 /** | 925 /** |
| 801 * Note: This method must only be invoked while we are synchronized on {@link
#cacheLock}. | 926 * Note: This method must only be invoked while we are synchronized on {@link
#cacheLock}. |
| 802 * @param source the source that has been changed | 927 * @param source the source that has been changed |
| 803 */ | 928 */ |
| 804 void sourceChanged(Source source) { | 929 void sourceChanged(Source source) { |
| 805 SourceInfo info = _sourceMap[source]; | 930 SourceInfo info = _sourceMap[source]; |
| 806 if (info == null) { | 931 if (info == null) { |
| 807 return; | 932 return; |
| 808 } | 933 } |
| 809 _parseCache.remove(source); | 934 _parseCache.remove(source); |
| 810 _htmlParseCache.remove(source); | 935 _htmlParseCache.remove(source); |
| 811 _libraryElementCache.remove(source); | 936 _libraryElementCache.remove(source); |
| 812 _publicNamespaceCache.remove(source); | 937 _publicNamespaceCache.remove(source); |
| 938 SourceKind oldKind = info.kind; |
| 939 SourceKind newKind = computeKindOf(source); |
| 940 if (newKind != oldKind) { |
| 941 info.kind = newKind; |
| 942 } |
| 813 for (Source librarySource in info.librarySources) { | 943 for (Source librarySource in info.librarySources) { |
| 814 _libraryElementCache.remove(librarySource); | 944 _libraryElementCache.remove(librarySource); |
| 815 _publicNamespaceCache.remove(librarySource); | 945 _publicNamespaceCache.remove(librarySource); |
| 816 } | 946 } |
| 817 } | 947 } |
| 818 /** | 948 /** |
| 819 * Note: This method must only be invoked while we are synchronized on {@link
#cacheLock}. | 949 * Note: This method must only be invoked while we are synchronized on {@link
#cacheLock}. |
| 820 * @param source the source that has been deleted | 950 * @param source the source that has been deleted |
| 821 */ | 951 */ |
| 822 void sourceDeleted(Source source) { | 952 void sourceRemoved(Source source) { |
| 953 SourceInfo info = _sourceMap[source]; |
| 954 if (info == null) { |
| 955 return; |
| 956 } |
| 957 _parseCache.remove(source); |
| 958 _libraryElementCache.remove(source); |
| 959 _publicNamespaceCache.remove(source); |
| 960 for (Source librarySource in info.librarySources) { |
| 961 _libraryElementCache.remove(librarySource); |
| 962 _publicNamespaceCache.remove(librarySource); |
| 963 } |
| 823 _sourceMap.remove(source); | 964 _sourceMap.remove(source); |
| 824 sourceChanged(source); | |
| 825 } | |
| 826 /** | |
| 827 * Note: This method must only be invoked while we are synchronized on {@link
#cacheLock}. | |
| 828 * @param container the source container specifying the sources that have been
deleted | |
| 829 */ | |
| 830 void sourcesDeleted(SourceContainer container) { | |
| 831 List<Source> sourcesToRemove = new List<Source>(); | |
| 832 for (Source source in _sourceMap.keys.toSet()) { | |
| 833 if (container.contains(source)) { | |
| 834 sourcesToRemove.add(source); | |
| 835 } | |
| 836 } | |
| 837 } | 965 } |
| 838 } | 966 } |
| 839 /** | 967 /** |
| 840 * Instances of the class {@code ScanResult} represent the results of scanning a
source. | 968 * Instances of the class {@code ScanResult} represent the results of scanning a
source. |
| 841 */ | 969 */ |
| 842 class AnalysisContextImpl_ScanResult { | 970 class AnalysisContextImpl_ScanResult { |
| 843 /** | 971 /** |
| 844 * The first token in the token stream. | 972 * The first token in the token stream. |
| 845 */ | 973 */ |
| 846 Token _token; | 974 Token _token; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 904 */ | 1032 */ |
| 905 List<AnalysisError> getErrors2(Source source) { | 1033 List<AnalysisError> getErrors2(Source source) { |
| 906 List<AnalysisError> errorsForSource = _errors[source]; | 1034 List<AnalysisError> errorsForSource = _errors[source]; |
| 907 if (errorsForSource == null) { | 1035 if (errorsForSource == null) { |
| 908 return AnalysisError.NO_ERRORS; | 1036 return AnalysisError.NO_ERRORS; |
| 909 } else { | 1037 } else { |
| 910 return new List.from(errorsForSource); | 1038 return new List.from(errorsForSource); |
| 911 } | 1039 } |
| 912 } | 1040 } |
| 913 void onError(AnalysisError event) { | 1041 void onError(AnalysisError event) { |
| 914 Source source9 = event.source; | 1042 Source source11 = event.source; |
| 915 List<AnalysisError> errorsForSource = _errors[source9]; | 1043 List<AnalysisError> errorsForSource = _errors[source11]; |
| 916 if (_errors[source9] == null) { | 1044 if (_errors[source11] == null) { |
| 917 errorsForSource = new List<AnalysisError>(); | 1045 errorsForSource = new List<AnalysisError>(); |
| 918 _errors[source9] = errorsForSource; | 1046 _errors[source11] = errorsForSource; |
| 919 } | 1047 } |
| 920 errorsForSource.add(event); | 1048 errorsForSource.add(event); |
| 921 } | 1049 } |
| 922 } | 1050 } |
| 923 /** | 1051 /** |
| 924 * Instances of the class {@code SourceInfo} maintain the information known by a
n analysis context | 1052 * Instances of the class {@code SourceInfo} maintain the information known by a
n analysis context |
| 925 * about an individual source. | 1053 * about an individual source. |
| 926 * @coverage dart.engine | 1054 * @coverage dart.engine |
| 927 */ | 1055 */ |
| 928 class SourceInfo { | 1056 class SourceInfo { |
| 929 /** | 1057 /** |
| 930 * The kind of the source. | 1058 * The kind of the source. |
| 931 */ | 1059 */ |
| 932 SourceKind _kind; | 1060 SourceKind _kind; |
| 933 /** | 1061 /** |
| 934 * The sources for the defining compilation units for the libraries containing
the source, or{@code null} if the libraries containing the source are not yet k
nown. | 1062 * The sources for the defining compilation units for the libraries containing
the source, or{@code null} if the libraries containing the source are not yet k
nown. |
| 935 */ | 1063 */ |
| 936 List<Source> _librarySources = null; | 1064 List<Source> _librarySources = null; |
| 937 SourceInfo.con1(Source source, SourceKind kind3) { | 1065 SourceInfo.con1(Source source, SourceKind kind3) { |
| 938 _jtd_constructor_161_impl(source, kind3); | 1066 _jtd_constructor_163_impl(source, kind3); |
| 939 } | 1067 } |
| 940 _jtd_constructor_161_impl(Source source, SourceKind kind3) { | 1068 _jtd_constructor_163_impl(Source source, SourceKind kind3) { |
| 941 this._kind = kind3; | 1069 this._kind = kind3; |
| 942 } | 1070 } |
| 943 /** | 1071 /** |
| 944 * Initialize a newly created information holder to hold the same information
as the given holder. | 1072 * Initialize a newly created information holder to hold the same information
as the given holder. |
| 945 * @param info the information holder used to initialize this holder | 1073 * @param info the information holder used to initialize this holder |
| 946 */ | 1074 */ |
| 947 SourceInfo.con2(SourceInfo info) { | 1075 SourceInfo.con2(SourceInfo info) { |
| 948 _jtd_constructor_162_impl(info); | 1076 _jtd_constructor_164_impl(info); |
| 949 } | 1077 } |
| 950 _jtd_constructor_162_impl(SourceInfo info) { | 1078 _jtd_constructor_164_impl(SourceInfo info) { |
| 951 _kind = info._kind; | 1079 _kind = info._kind; |
| 952 _librarySources = new List<Source>.from(info._librarySources); | 1080 _librarySources = new List<Source>.from(info._librarySources); |
| 953 } | 1081 } |
| 954 /** | 1082 /** |
| 955 * Add the given source to the list of sources for the defining compilation un
its for the | 1083 * Add the given source to the list of sources for the defining compilation un
its for the |
| 956 * libraries containing this source. | 1084 * libraries containing this source. |
| 957 * @param source the source to be added to the list | 1085 * @param source the source to be added to the list |
| 958 */ | 1086 */ |
| 959 void addLibrarySource(Source source) { | 1087 void addLibrarySource(Source source) { |
| 960 if (_librarySources == null) { | 1088 if (_librarySources == null) { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1042 } | 1170 } |
| 1043 void logError2(String message, Exception exception) { | 1171 void logError2(String message, Exception exception) { |
| 1044 } | 1172 } |
| 1045 void logError3(Exception exception) { | 1173 void logError3(Exception exception) { |
| 1046 } | 1174 } |
| 1047 void logInformation(String message) { | 1175 void logInformation(String message) { |
| 1048 } | 1176 } |
| 1049 void logInformation2(String message, Exception exception) { | 1177 void logInformation2(String message, Exception exception) { |
| 1050 } | 1178 } |
| 1051 } | 1179 } |
| OLD | NEW |