Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(204)

Side by Side Diff: pkg/analyzer_experimental/lib/src/generated/engine.dart

Issue 12803014: New Analysis Engine translation. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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';
11 import 'scanner.dart' show Token, CharBufferScanner, StringScanner; 11 import 'scanner.dart' show Token, CharBufferScanner, StringScanner;
12 import 'ast.dart' show CompilationUnit, Directive, PartOfDirective; 12 import 'ast.dart' show CompilationUnit, Directive, PartOfDirective;
13 import 'parser.dart' show Parser; 13 import 'parser.dart' show Parser;
14 import 'element.dart'; 14 import 'element.dart';
15 import 'resolver.dart' show Namespace, NamespaceBuilder, LibraryResolver; 15 import 'resolver.dart' show Namespace, NamespaceBuilder, LibraryResolver, HtmlUn itBuilder;
16 import 'html.dart' show HtmlScanner, HtmlScanResult, HtmlParser, HtmlParseResult ; 16 import 'html.dart' show XmlTagNode, XmlAttributeNode, SimpleXmlVisitor, HtmlScan ner, HtmlScanResult, HtmlParser, HtmlParseResult, HtmlUnit;
17 17
18 /** 18 /**
19 * The unique instance of the class {@code AnalysisEngine} serves as the entry p oint for the 19 * The unique instance of the class {@code AnalysisEngine} serves as the entry p oint for the
20 * functionality provided by the analysis engine. 20 * functionality provided by the analysis engine.
21 * @coverage dart.engine 21 * @coverage dart.engine
22 */ 22 */
23 class AnalysisEngine { 23 class AnalysisEngine {
24 /** 24 /**
25 * The suffix used for Dart source files. 25 * The suffix used for Dart source files.
26 */ 26 */
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 * given logger. 89 * given logger.
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 a single analysis can be performed and incrementally maintained. The co ntext includes such
100 * being analyzed against as well as the package-root used to resolve 'package:' URI's. (Both of 100 * information as the version of the SDK being analyzed against as well as the p ackage-root used to
101 * which are known indirectly through the {@link SourceFactory source factory}.) 101 * resolve 'package:' URI's. (Both of which are known indirectly through the {@l ink SourceFactorysource factory}.)
102 * <p> 102 * <p>
103 * They also represent the state of a given analysis, which includes knowing whi ch sources have been 103 * An analysis context also represents the state of the analysis, which includes knowing which
104 * included in the analysis (either directly or indirectly) and the results of t he analysis. Some 104 * sources have been included in the analysis (either directly or indirectly) an d the results of the
105 * analysis results are cached in order to allow the context to balance between memory usage and 105 * analysis. Sources must be added and removed from the context using the method {@link #applyChanges(ChangeSet)}, which is also used to notify the context when sources have been
106 * performance. TODO(brianwilkerson) Decide how this is reflected in the API: a getFoo() and 106 * modified and, consequently, previously known results might have been invalida ted.
107 * getOrComputeFoo() pair of methods, or a single getFoo(boolean). 107 * <p>
108 * There are two ways to access the results of the analysis. The most common is to use one of the
109 * 'get' methods to access the results. The 'get' methods have the advantage tha t they will always
110 * return quickly, but have the disadvantage that if the results are not current ly available they
111 * will return either nothing or in some cases an incomplete result. The second way to access
112 * results is by using one of the 'compute' methods. The 'compute' methods will always attempt to
113 * compute the requested results but might block the caller for a significant pe riod of time.
114 * <p>
115 * When results have been invalidated, have never been computed (as is the case for newly added
116 * sources), or have been removed from the cache, they are <b>not</b> automatica lly recreated. They
117 * will only be recreated if one of the 'compute' methods is invoked.
118 * <p>
119 * However, this is not always acceptable. Some clients need to keep the analysi s results
120 * up-to-date. For such clients there is a mechanism that allows them to increme ntally perform
121 * needed analysis and get notified of the consequent changes to the analysis re sults. This
122 * mechanism is realized by the method {@link #performAnalysisTask()}.
108 * <p> 123 * <p>
109 * Analysis engine allows for having more than one context. This can be used, fo r example, to 124 * Analysis engine allows for having more than one context. This can be used, fo r example, to
110 * perform one analysis based on the state of files on disk and a separate analy sis based on the 125 * perform one analysis based on the state of files on disk and a separate analy sis based on the
111 * state of those files in open editors. It can also be used to perform an analy sis based on a 126 * state of those files in open editors. It can also be used to perform an analy sis based on a
112 * proposed future state, such as the state after a refactoring. 127 * proposed future state, such as the state after a refactoring.
113 */ 128 */
114 abstract class AnalysisContext { 129 abstract class AnalysisContext {
115 /** 130 /**
116 * Apply the changes specified by the given change set to this context. Any an alysis results that 131 * Apply the changes specified by the given change set to this context. Any an alysis results that
117 * have been invalidated by these changes will be removed. 132 * have been invalidated by these changes will be removed.
118 * @param changeSet a description of the changes that are to be applied 133 * @param changeSet a description of the changes that are to be applied
119 */ 134 */
120 void applyChanges(ChangeSet changeSet); 135 void applyChanges(ChangeSet changeSet);
121 /** 136 /**
137 * Return an array containing all of the errors associated with the given sour ce. If the errors
138 * are not already known then the source will be analyzed in order to determin e the errors
139 * associated with it.
140 * @param source the source whose errors are to be returned
141 * @return all of the errors associated with the given source
142 * @throws AnalysisException if the errors could not be determined because the analysis could not
143 * be performed
144 * @see #getErrors(Source)
145 */
146 List<AnalysisError> computeErrors(Source source);
147 /**
148 * Return the element model corresponding to the HTML file defined by the give n source. If the
149 * element model does not yet exist it will be created. The process of creatin g an element model
150 * for an HTML file can long-running, depending on the size of the file and th e number of
151 * libraries that are defined in it (via script tags) that also need to have a model built for
152 * them.
153 * @param source the source defining the HTML file whose element model is to b e returned
154 * @return the element model corresponding to the HTML file defined by the giv en source
155 * @throws AnalysisException if the element model could not be determined beca use the analysis
156 * could not be performed
157 * @see #getHtmlElement(Source)
158 */
159 HtmlElement computeHtmlElement(Source source);
160 /**
161 * Return the kind of the given source, computing it's kind if it is not alrea dy known. Return{@link SourceKind#UNKNOWN} if the source is not contained in thi s context.
162 * @param source the source whose kind is to be returned
163 * @return the kind of the given source
164 * @see #getKindOf(Source)
165 */
166 SourceKind computeKindOf(Source source);
167 /**
168 * Return the element model corresponding to the library defined by the given source. If the
169 * element model does not yet exist it will be created. The process of creatin g an element model
170 * for a library can long-running, depending on the size of the library and th e number of
171 * libraries that are imported into it that also need to have a model built fo r them.
172 * @param source the source defining the library whose element model is to be returned
173 * @return the element model corresponding to the library defined by the given source
174 * @throws AnalysisException if the element model could not be determined beca use the analysis
175 * could not be performed
176 * @see #getLibraryElement(Source)
177 */
178 LibraryElement computeLibraryElement(Source source);
179 /**
180 * Return the line information for the given source, or {@code null} if the so urce is not of a
181 * recognized kind (neither a Dart nor HTML file). If the line information was not previously
182 * known it will be created. The line information is used to map offsets from the beginning of the
183 * source to line and column pairs.
184 * @param source the source whose line information is to be returned
185 * @return the line information for the given source
186 * @throws AnalysisException if the line information could not be determined b ecause the analysis
187 * could not be performed
188 * @see #getLineInfo(Source)
189 */
190 LineInfo computeLineInfo(Source source);
191 /**
122 * Create a new context in which analysis can be performed. Any sources in the specified container 192 * Create a new context in which analysis can be performed. Any sources in the specified container
123 * will be removed from this context and added to the newly created context. 193 * will be removed from this context and added to the newly created context.
124 * @param container the container containing sources that should be removed fr om this context and 194 * @param container the container containing sources that should be removed fr om this context and
125 * added to the returned context 195 * added to the returned context
126 * @return the analysis context that was created 196 * @return the analysis context that was created
127 */ 197 */
128 AnalysisContext extractContext(SourceContainer container); 198 AnalysisContext extractContext(SourceContainer container);
129 /** 199 /**
130 * Return the element referenced by the given location. 200 * Return the element referenced by the given location, or {@code null} if the element is not
201 * immediately available or if there is no element with the given location. Th e latter condition
202 * can occur, for example, if the location describes an element from a differe nt context or if the
203 * element has been removed from this context as a result of some change since it was originally
204 * obtained.
131 * @param location the reference describing the element to be returned 205 * @param location the reference describing the element to be returned
132 * @return the element referenced by the given location 206 * @return the element referenced by the given location
133 */ 207 */
134 Element getElement(ElementLocation location); 208 Element getElement(ElementLocation location);
135 /** 209 /**
136 * Return an array containing all of the errors associated with the given sour ce. The array will 210 * Return an array containing all of the errors associated with the given sour ce. The array will
137 * be empty if the source is not known to this context or if there are no erro rs in the source. 211 * be empty if the source is not known to this context or if there are no erro rs in the source.
212 * The errors contained in the array can be incomplete.
138 * @param source the source whose errors are to be returned 213 * @param source the source whose errors are to be returned
139 * @return all of the errors associated with the given source 214 * @return all of the errors associated with the given source
140 * @throws AnalysisException if the errors could not be determined because the analysis could not 215 * @see #computeErrors(Source)
141 * be performed
142 */ 216 */
143 List<AnalysisError> getErrors(Source source); 217 List<AnalysisError> getErrors(Source source);
144 /** 218 /**
145 * Return the element model corresponding to the HTML file defined by the give n source. 219 * Return the element model corresponding to the HTML file defined by the give n source, or{@code null} if the source does not represent an HTML file, the elem ent representing the file
220 * has not yet been created, or the analysis of the HTML file failed for some reason.
146 * @param source the source defining the HTML file whose element model is to b e returned 221 * @param source the source defining the HTML file whose element model is to b e returned
147 * @return the element model corresponding to the HTML file defined by the giv en source 222 * @return the element model corresponding to the HTML file defined by the giv en source
223 * @see #computeHtmlElement(Source)
148 */ 224 */
149 HtmlElement getHtmlElement(Source source); 225 HtmlElement getHtmlElement(Source source);
150 /** 226 /**
227 * Return the sources for the HTML files that reference the given compilation unit. If the source
228 * does not represent a Dart source or is not known to this context, the retur ned array will be
229 * empty. The contents of the array can be incomplete.
230 * @param source the source referenced by the returned HTML files
231 * @return the sources for the HTML files that reference the given compilation unit
232 */
233 List<Source> getHtmlFilesReferencing(Source source);
234 /**
151 * Return an array containing all of the sources known to this context that re present HTML files. 235 * Return an array containing all of the sources known to this context that re present HTML files.
236 * The contents of the array can be incomplete.
152 * @return the sources known to this context that represent HTML files 237 * @return the sources known to this context that represent HTML files
153 */ 238 */
154 List<Source> get htmlSources; 239 List<Source> get htmlSources;
155 /** 240 /**
156 * Return the kind of the given source if it is already known, or {@code null} if the kind is not 241 * Return the kind of the given source, or {@code null} if the kind is not kno wn to this context.
157 * already known.
158 * @param source the source whose kind is to be returned 242 * @param source the source whose kind is to be returned
159 * @return the kind of the given source 243 * @return the kind of the given source
160 * @see #getOrComputeKindOf(Source) 244 * @see #computeKindOf(Source)
161 */ 245 */
162 SourceKind getKnownKindOf(Source source); 246 SourceKind getKindOf(Source source);
163 /** 247 /**
164 * Return an array containing all of the sources known to this context that re present the defining 248 * Return an array containing all of the sources known to this context that re present the defining
165 * compilation unit of a library that can be run within a browser. The sources that are returned 249 * compilation unit of a library that can be run within a browser. The sources that are returned
166 * represent libraries that have a 'main' method and are either referenced by an HTML file or 250 * represent libraries that have a 'main' method and are either referenced by an HTML file or
167 * import, directly or indirectly, a client-only library. 251 * import, directly or indirectly, a client-only library. The contents of the array can be
252 * incomplete.
168 * @return the sources known to this context that represent the defining compi lation unit of a 253 * @return the sources known to this context that represent the defining compi lation unit of a
169 * library that can be run within a browser 254 * library that can be run within a browser
170 */ 255 */
171 List<Source> get launchableClientLibrarySources; 256 List<Source> get launchableClientLibrarySources;
172 /** 257 /**
173 * Return an array containing all of the sources known to this context that re present the defining 258 * Return an array containing all of the sources known to this context that re present the defining
174 * compilation unit of a library that can be run outside of a browser. 259 * compilation unit of a library that can be run outside of a browser. The con tents of the array
260 * can be incomplete.
175 * @return the sources known to this context that represent the defining compi lation unit of a 261 * @return the sources known to this context that represent the defining compi lation unit of a
176 * library that can be run outside of a browser 262 * library that can be run outside of a browser
177 */ 263 */
178 List<Source> get launchableServerLibrarySources; 264 List<Source> get launchableServerLibrarySources;
179 /** 265 /**
180 * Return the sources for the defining compilation units of any libraries of w hich the given 266 * Return the sources for the defining compilation units of any libraries of w hich the given
181 * source is a part. The array will normally contain a single library because most Dart sources 267 * source is a part. The array will normally contain a single library because most Dart sources
182 * are only included in a single library, but it is possible to have a part th at is contained in 268 * are only included in a single library, but it is possible to have a part th at is contained in
183 * multiple identically named libraries. If the source represents the defining compilation unit of 269 * multiple identically named libraries. If the source represents the defining compilation unit of
184 * a library, then the returned array will contain the given source as its onl y element. If the 270 * a library, then the returned array will contain the given source as its onl y element. If the
185 * source does not represent a Dart source or is not known to this context, th e returned array 271 * source does not represent a Dart source or is not known to this context, th e returned array
186 * will be empty. 272 * will be empty. The contents of the array can be incomplete.
187 * @param source the source contained in the returned libraries 273 * @param source the source contained in the returned libraries
188 * @return the sources for the libraries containing the given source 274 * @return the sources for the libraries containing the given source
189 */ 275 */
190 List<Source> getLibrariesContaining(Source source); 276 List<Source> getLibrariesContaining(Source source);
191 /** 277 /**
192 * Return the element model corresponding to the library defined by the given source. If the 278 * 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 l ibrary cannot be analyzed
193 * element model does not yet exist it will be created. The process of creatin g an element model 279 * for some reason.
194 * for a library can long-running, depending on the size of the library and th e number of
195 * libraries that are imported into it that also need to have a model built fo r them.
196 * @param source the source defining the library whose element model is to be returned 280 * @param source the source defining the library whose element model is to be returned
197 * @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 281 * @return the element model corresponding to the library defined by the given source
198 * not be performed
199 */ 282 */
200 LibraryElement getLibraryElement(Source source); 283 LibraryElement getLibraryElement(Source source);
201 /** 284 /**
202 * 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
203 * performed.
204 * @param source the source defining the library whose element model is to be returned
205 * @return the element model corresponding to the library defined by the given source
206 */
207 LibraryElement getLibraryElementOrNull(Source source);
208 /**
209 * Return an array containing all of the sources known to this context that re present the defining 285 * Return an array containing all of the sources known to this context that re present the defining
210 * compilation unit of a library. 286 * compilation unit of a library. The contents of the array can be incomplete.
211 * @return the sources known to this context that represent the defining compi lation unit of a 287 * @return the sources known to this context that represent the defining compi lation unit of a
212 * library 288 * library
213 */ 289 */
214 List<Source> get librarySources; 290 List<Source> get librarySources;
215 /** 291 /**
216 * Return the kind of the given source, computing it's kind if it is not alrea dy known. 292 * Return the line information for the given source, or {@code null} if the li ne information is
217 * @param source the source whose kind is to be returned 293 * not known. The line information is used to map offsets from the beginning o f the source to line
218 * @return the kind of the given source 294 * and column pairs.
219 * @see #getKnownKindOf(Source) 295 * @param source the source whose line information is to be returned
296 * @return the line information for the given source
297 * @see #computeLineInfo(Source)
220 */ 298 */
221 SourceKind getOrComputeKindOf(Source source); 299 LineInfo getLineInfo(Source source);
222 /** 300 /**
223 * Return the source factory used to create the sources that can be analyzed i n this context. 301 * Return the source factory used to create the sources that can be analyzed i n this context.
224 * @return the source factory used to create the sources that can be analyzed in this context 302 * @return the source factory used to create the sources that can be analyzed in this context
225 */ 303 */
226 SourceFactory get sourceFactory; 304 SourceFactory get sourceFactory;
227 /** 305 /**
306 * Return {@code true} if the given source is known to be the defining compila tion unit of a
307 * library that can be run on a client (references 'dart:html', either directl y or indirectly).
308 * <p>
309 * <b>Note:</b> In addition to the expected case of returning {@code false} if the source is known
310 * to be a library that cannot be run on a client, this method will also retur n {@code false} if
311 * the source is not known to be a library or if we do not know whether it can be run on a client.
312 * @param librarySource the source being tested
313 * @return {@code true} if the given source is known to be a library that can be run on a client
314 */
315 bool isClientLibrary(Source librarySource);
316 /**
317 * Return {@code true} if the given source is known to be the defining compila tion unit of a
318 * library that can be run on the server (does not reference 'dart:html', eith er directly or
319 * indirectly).
320 * <p>
321 * <b>Note:</b> In addition to the expected case of returning {@code false} if the source is known
322 * to be a library that cannot be run on the server, this method will also ret urn {@code false} if
323 * the source is not known to be a library or if we do not know whether it can be run on the
324 * server.
325 * @param librarySource the source being tested
326 * @return {@code true} if the given source is known to be a library that can be run on the server
327 */
328 bool isServerLibrary(Source librarySource);
329 /**
228 * Add the sources contained in the specified context to this context's collec tion of sources. 330 * Add the sources contained in the specified context to this context's collec tion of sources.
229 * This method is called when an existing context's pubspec has been removed, and the contained 331 * This method is called when an existing context's pubspec has been removed, and the contained
230 * sources should be reanalyzed as part of this context. 332 * sources should be reanalyzed as part of this context.
231 * @param context the context being merged 333 * @param context the context being merged
232 */ 334 */
233 void mergeContext(AnalysisContext context); 335 void mergeContext(AnalysisContext context);
234 /** 336 /**
235 * Parse a single source to produce an AST structure. The resulting AST struct ure may or may not 337 * Parse a single source to produce an AST structure. The resulting AST struct ure may or may not
236 * be resolved, and may have a slightly different structure depending upon whe ther it is resolved. 338 * be resolved, and may have a slightly different structure depending upon whe ther it is resolved.
237 * @param source the source to be parsed 339 * @param source the source to be parsed
238 * @return the AST structure representing the content of the source 340 * @return the AST structure representing the content of the source
239 * @throws AnalysisException if the analysis could not be performed 341 * @throws AnalysisException if the analysis could not be performed
240 */ 342 */
241 CompilationUnit parse(Source source); 343 CompilationUnit parseCompilationUnit(Source source);
242 /** 344 /**
243 * Parse a single HTML source to produce an AST structure. The resulting HTML AST structure may or 345 * Parse a single HTML source to produce an AST structure. The resulting HTML AST structure may or
244 * may not be resolved, and may have a slightly different structure depending upon whether it is 346 * may not be resolved, and may have a slightly different structure depending upon whether it is
245 * resolved. 347 * resolved.
246 * @param source the HTML source to be parsed 348 * @param source the HTML source to be parsed
247 * @return the parse result (not {@code null}) 349 * @return the parse result (not {@code null})
248 * @throws AnalysisException if the analysis could not be performed 350 * @throws AnalysisException if the analysis could not be performed
249 */ 351 */
250 HtmlParseResult parseHtml(Source source); 352 HtmlUnit parseHtmlUnit(Source source);
251 /** 353 /**
252 * Perform the next unit of work required to keep the analysis results up-to-d ate and return 354 * Perform the next unit of work required to keep the analysis results up-to-d ate and return
253 * information about the consequent changes to the analysis results. If there were no results the 355 * information about the consequent changes to the analysis results. If there were no results the
254 * returned array will be empty. This method can be long running. 356 * returned array will be empty. If there are no more units of work required, then this method
357 * returns {@code null}. This method can be long running.
255 * @return an array containing notices of changes to the analysis results 358 * @return an array containing notices of changes to the analysis results
256 */ 359 */
257 List<ChangeNotice> performAnalysisTask(); 360 List<ChangeNotice> performAnalysisTask();
258 /** 361 /**
259 * Parse and resolve a single source within the given context to produce a ful ly resolved AST. 362 * Parse and resolve a single source within the given context to produce a ful ly resolved AST.
260 * @param source the source to be parsed and resolved 363 * @param unitSource the source to be parsed and resolved
261 * @param library the library defining the context in which the source file is to be resolved 364 * @param library the library containing the source to be resolved
365 * @return the result of resolving the AST structure representing the content of the source in the
366 * context of the given library
367 * @throws AnalysisException if the analysis could not be performed
368 */
369 CompilationUnit resolveCompilationUnit(Source unitSource, LibraryElement libra ry);
370 /**
371 * Parse and resolve a single source within the given context to produce a ful ly resolved AST.
372 * @param unitSource the source to be parsed and resolved
373 * @param librarySource the source of the defining compilation unit of the lib rary containing the
374 * source to be resolved
375 * @return the result of resolving the AST structure representing the content of the source in the
376 * context of the given library
377 * @throws AnalysisException if the analysis could not be performed
378 */
379 CompilationUnit resolveCompilationUnit2(Source unitSource, Source librarySourc e);
380 /**
381 * Parse and resolve a single source within the given context to produce a ful ly resolved AST.
382 * @param htmlSource the source to be parsed and resolved
262 * @return the result of resolving the AST structure representing the content of the source 383 * @return the result of resolving the AST structure representing the content of the source
263 * @throws AnalysisException if the analysis could not be performed 384 * @throws AnalysisException if the analysis could not be performed
264 */ 385 */
265 CompilationUnit resolve(Source source, LibraryElement library); 386 HtmlUnit resolveHtmlUnit(Source htmlSource);
387 /**
388 * Set the contents of the given source to the given contents and mark the sou rce as having
389 * changed. This has the effect of overriding the default contents of the sour ce. If the contents
390 * are {@code null} the override is removed so that the default contents will be returned.
391 * @param source the source whose contents are being overridden
392 * @param contents the new contents of the source
393 */
394 void setContents(Source source, String contents);
266 /** 395 /**
267 * Set the source factory used to create the sources that can be analyzed in t his context to the 396 * Set the source factory used to create the sources that can be analyzed in t his context to the
268 * given source factory. Clients can safely assume that all analysis results h ave been 397 * given source factory. Clients can safely assume that all analysis results h ave been
269 * invalidated. 398 * invalidated.
270 * @param factory the source factory used to create the sources that can be an alyzed in this 399 * @param factory the source factory used to create the sources that can be an alyzed in this
271 * context 400 * context
272 */ 401 */
273 void set sourceFactory(SourceFactory factory); 402 void set sourceFactory(SourceFactory factory);
274 /** 403 /**
275 * Given a collection of sources with content that has changed, return an {@li nk Iterable}identifying the sources that need to be resolved. 404 * Given a collection of sources with content that has changed, return an {@li nk Iterable}identifying the sources that need to be resolved.
276 * @param changedSources an array of sources (not {@code null}, contains no {@ code null}s) 405 * @param changedSources an array of sources (not {@code null}, contains no {@ code null}s)
277 * @return An iterable returning the sources to be resolved 406 * @return An iterable returning the sources to be resolved
278 */ 407 */
279 Iterable<Source> sourcesToResolve(List<Source> changedSources); 408 Iterable<Source> sourcesToResolve(List<Source> changedSources);
280 } 409 }
281 /** 410 /**
282 * Instances of the class {@code AnalysisException} represent an exception that occurred during the 411 * Instances of the class {@code AnalysisException} represent an exception that occurred during the
283 * analysis of one or more sources. 412 * analysis of one or more sources.
284 * @coverage dart.engine 413 * @coverage dart.engine
285 */ 414 */
286 class AnalysisException extends JavaException { 415 class AnalysisException extends JavaException {
287 /** 416 /**
288 * Initialize a newly created exception. 417 * Initialize a newly created exception.
289 */ 418 */
290 AnalysisException() : super() { 419 AnalysisException() : super() {
291 _jtd_constructor_123_impl(); 420 _jtd_constructor_124_impl();
292 } 421 }
293 _jtd_constructor_123_impl() { 422 _jtd_constructor_124_impl() {
294 } 423 }
295 /** 424 /**
296 * Initialize a newly created exception to have the given message. 425 * Initialize a newly created exception to have the given message.
297 * @param message the message associated with the exception 426 * @param message the message associated with the exception
298 */ 427 */
299 AnalysisException.con1(String message) : super(message) { 428 AnalysisException.con1(String message) : super(message) {
300 _jtd_constructor_124_impl(message); 429 _jtd_constructor_125_impl(message);
301 } 430 }
302 _jtd_constructor_124_impl(String message) { 431 _jtd_constructor_125_impl(String message) {
303 } 432 }
304 /** 433 /**
305 * Initialize a newly created exception to have the given message and cause. 434 * Initialize a newly created exception to have the given message and cause.
306 * @param message the message associated with the exception 435 * @param message the message associated with the exception
307 * @param cause the underlying exception that caused this exception 436 * @param cause the underlying exception that caused this exception
308 */ 437 */
309 AnalysisException.con2(String message, Exception cause) : super(message, cause ) { 438 AnalysisException.con2(String message, Exception cause) : super(message, cause ) {
310 _jtd_constructor_125_impl(message, cause); 439 _jtd_constructor_126_impl(message, cause);
311 } 440 }
312 _jtd_constructor_125_impl(String message, Exception cause) { 441 _jtd_constructor_126_impl(String message, Exception cause) {
313 } 442 }
314 /** 443 /**
315 * Initialize a newly created exception to have the given cause. 444 * Initialize a newly created exception to have the given cause.
316 * @param cause the underlying exception that caused this exception 445 * @param cause the underlying exception that caused this exception
317 */ 446 */
318 AnalysisException.con3(Exception cause) : super.withCause(cause) { 447 AnalysisException.con3(Exception cause) : super.withCause(cause) {
319 _jtd_constructor_126_impl(cause); 448 _jtd_constructor_127_impl(cause);
320 } 449 }
321 _jtd_constructor_126_impl(Exception cause) { 450 _jtd_constructor_127_impl(Exception cause) {
322 } 451 }
323 } 452 }
324 /** 453 /**
325 * Instances of the class {@code ChangeNotice} represent a change to the analysi s results associated 454 * The interface {@code ChangeNotice} defines the behavior of objects that repre sent a change to the
326 * with a given source. 455 * analysis results associated with a given source.
456 * @coverage dart.engine
327 */ 457 */
328 class ChangeNotice { 458 abstract class ChangeNotice {
329 /**
330 * The source for which the result is being reported.
331 */
332 Source _source;
333 /**
334 * The fully resolved AST that changed as a result of the analysis, or {@code null} if the AST was
335 * not changed.
336 */
337 CompilationUnit _compilationUnit;
338 /**
339 * The errors that changed as a result of the analysis, or {@code null} if err ors were not
340 * changed.
341 */
342 List<AnalysisError> _errors;
343 /**
344 * The line information associated with the source, or {@code null} if errors were not changed.
345 */
346 LineInfo _lineInfo;
347 /**
348 * An empty array of change notices.
349 */
350 static List<ChangeNotice> EMPTY_ARRAY = new List<ChangeNotice>(0);
351 /**
352 * Initialize a newly created result representing the fact that the errors ass ociated with a
353 * source have changed.
354 * @param source the source for which the result is being reported
355 * @param errors the errors that changed as a result of the analysis
356 * @param the line information associated with the source
357 */
358 ChangeNotice.con1(Source source2, List<AnalysisError> errors2, LineInfo lineIn fo3) {
359 _jtd_constructor_127_impl(source2, errors2, lineInfo3);
360 }
361 _jtd_constructor_127_impl(Source source2, List<AnalysisError> errors2, LineInf o lineInfo3) {
362 this._source = source2;
363 this._errors = errors2;
364 this._lineInfo = lineInfo3;
365 }
366 /**
367 * Initialize a newly created result representing the fact that the resolution of a source has
368 * changed.
369 * @param source the source for which the result is being reported
370 * @param compilationUnit the fully resolved AST produced as a result of the a nalysis
371 */
372 ChangeNotice.con2(Source source3, CompilationUnit compilationUnit9) {
373 _jtd_constructor_128_impl(source3, compilationUnit9);
374 }
375 _jtd_constructor_128_impl(Source source3, CompilationUnit compilationUnit9) {
376 this._source = source3;
377 this._compilationUnit = compilationUnit9;
378 }
379 /** 459 /**
380 * Return the fully resolved AST that changed as a result of the analysis, or {@code null} if the 460 * Return the fully resolved AST that changed as a result of the analysis, or {@code null} if the
381 * AST was not changed. 461 * AST was not changed.
382 * @return the fully resolved AST that changed as a result of the analysis 462 * @return the fully resolved AST that changed as a result of the analysis
383 */ 463 */
384 CompilationUnit get compilationUnit => _compilationUnit; 464 CompilationUnit get compilationUnit;
385 /** 465 /**
386 * Return the errors that changed as a result of the analysis, or {@code null} if errors were not 466 * Return the errors that changed as a result of the analysis, or {@code null} if errors were not
387 * changed. 467 * changed.
388 * @return the errors that changed as a result of the analysis 468 * @return the errors that changed as a result of the analysis
389 */ 469 */
390 List<AnalysisError> get errors => _errors; 470 List<AnalysisError> get errors;
391 /** 471 /**
392 * Return the line information associated with the source, or {@code null} if errors were not 472 * Return the line information associated with the source, or {@code null} if errors were not
393 * changed. 473 * changed.
394 * @return the line information associated with the source 474 * @return the line information associated with the source
395 */ 475 */
396 LineInfo get lineInfo => _lineInfo; 476 LineInfo get lineInfo;
397 /** 477 /**
398 * Return the source for which the result is being reported. 478 * Return the source for which the result is being reported.
399 * @return the source for which the result is being reported 479 * @return the source for which the result is being reported
400 */ 480 */
401 Source get source => _source; 481 Source get source;
402 } 482 }
403 /** 483 /**
404 * Instances of the class {@code ChangeSet} indicate what sources have been adde d, changed, or 484 * Instances of the class {@code ChangeSet} indicate what sources have been adde d, changed, or
405 * removed. 485 * removed.
406 * @coverage dart.engine 486 * @coverage dart.engine
407 */ 487 */
408 class ChangeSet { 488 class ChangeSet {
409 /** 489 /**
410 * A table mapping the sources that have been added to their contents. 490 * A list containing the sources that have been added.
411 */ 491 */
412 Map<Source, String> _added3 = new Map<Source, String>(); 492 List<Source> _added2 = new List<Source>();
413 /** 493 /**
414 * A table mapping the sources that have been changed to their contents. 494 * A list containing the sources that have been changed.
415 */ 495 */
416 Map<Source, String> _changed3 = new Map<Source, String>(); 496 List<Source> _changed2 = new List<Source>();
417 /** 497 /**
418 * A list containing the sources that have been removed.. 498 * A list containing the sources that have been removed.
419 */ 499 */
420 List<Source> _removed2 = new List<Source>(); 500 List<Source> _removed2 = new List<Source>();
421 /** 501 /**
422 * A list containing the source containers specifying additional sources that have been removed. 502 * A list containing the source containers specifying additional sources that have been removed.
423 */ 503 */
424 List<SourceContainer> _removedContainers = new List<SourceContainer>(); 504 List<SourceContainer> _removedContainers = new List<SourceContainer>();
425 /** 505 /**
426 * Initialize a newly created change set to be empty. 506 * Initialize a newly created change set to be empty.
427 */ 507 */
428 ChangeSet() : super() { 508 ChangeSet() : super() {
429 } 509 }
430 /** 510 /**
431 * Record that the specified source has been added and that it's content is th e default contents 511 * Record that the specified source has been added and that it's content is th e default contents
432 * of the source. 512 * of the source.
433 * @param source the source that was added 513 * @param source the source that was added
434 */ 514 */
435 void added(Source source) { 515 void added(Source source) {
436 added2(source, null); 516 _added2.add(source);
437 }
438 /**
439 * Record that the specified source has been added and that it has the given c ontent. If the
440 * content is non-{@code null}, this has the effect of overriding the default contents of the
441 * source. If the contents are {@code null}, any previous override is removed so that the default
442 * contents will be used.
443 * @param source the source that was added
444 * @param content the content of the new source
445 */
446 void added2(Source source, String content) {
447 if (source != null) {
448 _added3[source] = content;
449 }
450 } 517 }
451 /** 518 /**
452 * Record that the specified source has been changed and that it's content is the default contents 519 * Record that the specified source has been changed and that it's content is the default contents
453 * of the source. 520 * of the source.
454 * @param source the source that was changed 521 * @param source the source that was changed
455 */ 522 */
456 void changed(Source source) { 523 void changed(Source source) {
457 changed2(source, null); 524 _changed2.add(source);
458 } 525 }
459 /** 526 /**
460 * Record that the specified source has been changed and that it now has the g iven content. If the 527 * Return a collection of the sources that have been added.
461 * content is non-{@code null}, this has the effect of overriding the default contents of the 528 * @return a collection of the sources that have been added
462 * source. If the contents are {@code null}, any previous override is removed so that the default
463 * contents will be used.
464 * @param source the source that was changed
465 * @param content the new content of the source
466 */ 529 */
467 void changed2(Source source, String content) { 530 List<Source> get added3 => _added2;
468 if (source != null) {
469 _changed3[source] = content;
470 }
471 }
472 /** 531 /**
473 * Return a table mapping the sources that have been added to their contents. 532 * Return a collection of sources that have been changed.
474 * @return a table mapping the sources that have been added to their contents 533 * @return a collection of sources that have been changed
475 */ 534 */
476 Map<Source, String> get addedWithContent => _added3; 535 List<Source> get changed3 => _changed2;
477 /**
478 * Return a table mapping the sources that have been changed to their contents .
479 * @return a table mapping the sources that have been changed to their content s
480 */
481 Map<Source, String> get changedWithContent => _changed3;
482 /** 536 /**
483 * Return a list containing the sources that were removed. 537 * Return a list containing the sources that were removed.
484 * @return a list containing the sources that were removed 538 * @return a list containing the sources that were removed
485 */ 539 */
486 List<Source> get removed => _removed2; 540 List<Source> get removed => _removed2;
487 /** 541 /**
488 * Return a list containing the source containers that were removed. 542 * Return a list containing the source containers that were removed.
489 * @return a list containing the source containers that were removed 543 * @return a list containing the source containers that were removed
490 */ 544 */
491 List<SourceContainer> get removedContainers => _removedContainers; 545 List<SourceContainer> get removedContainers => _removedContainers;
492 /** 546 /**
493 * Return {@code true} if this change set does not contain any changes. 547 * Return {@code true} if this change set does not contain any changes.
494 * @return {@code true} if this change set does not contain any changes 548 * @return {@code true} if this change set does not contain any changes
495 */ 549 */
496 bool isEmpty() => _added3.isEmpty && _changed3.isEmpty && _removed2.isEmpty && _removedContainers.isEmpty; 550 bool isEmpty() => _added2.isEmpty && _changed2.isEmpty && _removed2.isEmpty && _removedContainers.isEmpty;
497 /** 551 /**
498 * Record that the specified source has been removed. 552 * Record that the specified source has been removed.
499 * @param source the source that was removed 553 * @param source the source that was removed
500 */ 554 */
501 void removed3(Source source) { 555 void removed3(Source source) {
502 if (source != null) { 556 if (source != null) {
503 _removed2.add(source); 557 _removed2.add(source);
504 } 558 }
505 } 559 }
506 /** 560 /**
(...skipping 10 matching lines...) Expand all
517 * Instances of the class {@code AnalysisContextImpl} implement an {@link Analys isContext analysis 571 * Instances of the class {@code AnalysisContextImpl} implement an {@link Analys isContext analysis
518 * context}. 572 * context}.
519 * @coverage dart.engine 573 * @coverage dart.engine
520 */ 574 */
521 class AnalysisContextImpl implements AnalysisContext { 575 class AnalysisContextImpl implements AnalysisContext {
522 /** 576 /**
523 * The source factory used to create the sources that can be analyzed in this context. 577 * The source factory used to create the sources that can be analyzed in this context.
524 */ 578 */
525 SourceFactory _sourceFactory; 579 SourceFactory _sourceFactory;
526 /** 580 /**
527 * A table mapping sources known to the context to the information known about the source. 581 * A table mapping the sources known to the context to the information known a bout the source.
528 */ 582 */
529 Map<Source, SourceInfo> _sourceMap = new Map<Source, SourceInfo>(); 583 Map<Source, SourceInfo> _sourceMap = new Map<Source, SourceInfo>();
530 /** 584 /**
531 * A cache mapping sources to the compilation units that were produced for the contents of the 585 * A table mapping sources to the change notices that are waiting to be return ed related to that
532 * source. 586 * source.
533 */ 587 */
534 Map<Source, CompilationUnit> _parseCache = new Map<Source, CompilationUnit>(); 588 Map<Source, ChangeNoticeImpl> _pendingNotices = new Map<Source, ChangeNoticeIm pl>();
535 /**
536 * A cache mapping sources to the html parse results that were produced for th e contents of the
537 * source.
538 */
539 Map<Source, HtmlParseResult> _htmlParseCache = new Map<Source, HtmlParseResult >();
540 /**
541 * A cache mapping sources (of the defining compilation units of libraries) to the library
542 * elements for those libraries.
543 */
544 Map<Source, LibraryElement> _libraryElementCache = new Map<Source, LibraryElem ent>();
545 /**
546 * A cache mapping sources (of the defining compilation units of libraries) to the public
547 * namespace for that library.
548 */
549 Map<Source, Namespace> _publicNamespaceCache = new Map<Source, Namespace>();
550 /** 589 /**
551 * The object used to synchronize access to all of the caches. 590 * The object used to synchronize access to all of the caches.
552 */ 591 */
553 Object _cacheLock = new Object(); 592 Object _cacheLock = new Object();
554 /** 593 /**
594 * The name of the 'src' attribute in a HTML tag.
595 */
596 static String _ATTRIBUTE_SRC = "src";
597 /**
598 * The name of the 'script' tag in an HTML file.
599 */
600 static String _TAG_SCRIPT = "script";
601 /**
555 * Initialize a newly created analysis context. 602 * Initialize a newly created analysis context.
556 */ 603 */
557 AnalysisContextImpl() : super() { 604 AnalysisContextImpl() : super() {
558 } 605 }
559 void applyChanges(ChangeSet changeSet) { 606 void applyChanges(ChangeSet changeSet) {
560 if (changeSet.isEmpty()) { 607 if (changeSet.isEmpty()) {
561 return; 608 return;
562 } 609 }
563 { 610 {
564 List<Source> addedSources = new List<Source>();
565 for (MapEntry<Source, String> entry in getMapEntrySet(changeSet.addedWithC ontent)) {
566 Source source = entry.getKey();
567 _sourceFactory.setContents(source, entry.getValue());
568 addedSources.add(source);
569 }
570 List<Source> changedSources = new List<Source>();
571 for (MapEntry<Source, String> entry in getMapEntrySet(changeSet.changedWit hContent)) {
572 Source source = entry.getKey();
573 _sourceFactory.setContents(source, entry.getValue());
574 changedSources.add(source);
575 }
576 List<Source> removedSources = new List<Source>.from(changeSet.removed); 611 List<Source> removedSources = new List<Source>.from(changeSet.removed);
577 for (SourceContainer container in changeSet.removedContainers) { 612 for (SourceContainer container in changeSet.removedContainers) {
578 addSourcesInContainer(removedSources, container); 613 addSourcesInContainer(removedSources, container);
579 } 614 }
580 for (Source source in addedSources) { 615 for (Source source in changeSet.added3) {
581 sourceAvailable(source); 616 sourceAvailable(source);
582 } 617 }
583 for (Source source in changedSources) { 618 for (Source source in changeSet.changed3) {
584 sourceChanged(source); 619 sourceChanged(source);
585 } 620 }
586 for (Source source in removedSources) { 621 for (Source source in removedSources) {
587 sourceRemoved(source); 622 sourceRemoved(source);
588 } 623 }
589 } 624 }
590 } 625 }
626 List<AnalysisError> computeErrors(Source source) {
627 {
628 CompilationUnitInfo info = getCompilationUnitInfo(source);
629 if (info == null) {
630 return AnalysisError.NO_ERRORS;
631 }
632 if (info.hasInvalidParseErrors()) {
633 parseCompilationUnit(source);
634 }
635 if (info.hasInvalidResolutionErrors()) {
636 }
637 return info.allErrors;
638 }
639 }
640 HtmlElement computeHtmlElement(Source source) {
641 if (!AnalysisEngine.isHtmlFileName(source.shortName)) {
642 return null;
643 }
644 {
645 HtmlUnitInfo htmlUnitInfo = getHtmlUnitInfo(source);
646 if (htmlUnitInfo == null) {
647 return null;
648 }
649 HtmlElement element24 = htmlUnitInfo.element;
650 if (element24 == null) {
651 HtmlUnit unit = htmlUnitInfo.resolvedUnit;
652 if (unit == null) {
653 unit = htmlUnitInfo.parsedUnit;
654 if (unit == null) {
655 unit = parseHtmlUnit(source);
656 }
657 }
658 HtmlUnitBuilder builder = new HtmlUnitBuilder(this);
659 element24 = builder.buildHtmlElement2(source, unit);
660 htmlUnitInfo.resolvedUnit = unit;
661 htmlUnitInfo.element = element24;
662 }
663 return element24;
664 }
665 }
666 SourceKind computeKindOf(Source source) {
667 {
668 SourceInfo sourceInfo = getSourceInfo(source);
669 if (sourceInfo == null) {
670 return SourceKind.UNKNOWN;
671 } else if (sourceInfo is DartInfo) {
672 sourceInfo = internalComputeKindOf(source, sourceInfo);
673 }
674 return sourceInfo.kind;
675 }
676 }
677 LibraryElement computeLibraryElement(Source source) {
678 if (!AnalysisEngine.isDartFileName(source.shortName)) {
679 return null;
680 }
681 {
682 LibraryInfo libraryInfo = getLibraryInfo(source);
683 if (libraryInfo == null) {
684 return null;
685 }
686 LibraryElement element25 = libraryInfo.element;
687 if (element25 == null) {
688 if (computeKindOf(source) != SourceKind.LIBRARY) {
689 return null;
690 }
691 LibraryResolver resolver = new LibraryResolver.con1(this);
692 try {
693 element25 = resolver.resolveLibrary(source, true);
694 if (element25 != null) {
695 libraryInfo.element = element25;
696 }
697 } on AnalysisException catch (exception) {
698 AnalysisEngine.instance.logger.logError2("Could not resolve the librar y ${source.fullName}", exception);
699 }
700 }
701 return element25;
702 }
703 }
704 LineInfo computeLineInfo(Source source) {
705 {
706 SourceInfo sourceInfo = getSourceInfo(source);
707 if (sourceInfo == null) {
708 return null;
709 }
710 LineInfo lineInfo4 = sourceInfo.lineInfo;
711 if (lineInfo4 == null) {
712 if (sourceInfo is DartInfo) {
713 sourceInfo = internalComputeKindOf(source, sourceInfo);
714 }
715 if (sourceInfo is HtmlUnitInfo) {
716 parseHtmlUnit(source);
717 lineInfo4 = sourceInfo.lineInfo;
718 } else if (sourceInfo is CompilationUnitInfo) {
719 parseCompilationUnit(source);
720 lineInfo4 = sourceInfo.lineInfo;
721 }
722 }
723 return lineInfo4;
724 }
725 }
591 AnalysisContext extractContext(SourceContainer container) { 726 AnalysisContext extractContext(SourceContainer container) {
592 AnalysisContextImpl newContext = AnalysisEngine.instance.createAnalysisConte xt() as AnalysisContextImpl; 727 AnalysisContextImpl newContext = AnalysisEngine.instance.createAnalysisConte xt() as AnalysisContextImpl;
593 List<Source> sourcesToRemove = new List<Source>(); 728 List<Source> sourcesToRemove = new List<Source>();
594 { 729 {
595 for (MapEntry<Source, SourceInfo> entry in getMapEntrySet(_sourceMap)) { 730 for (MapEntry<Source, SourceInfo> entry in getMapEntrySet(_sourceMap)) {
596 Source source = entry.getKey(); 731 Source source = entry.getKey();
597 if (container.contains(source)) { 732 if (container.contains(source)) {
598 sourcesToRemove.add(source); 733 sourcesToRemove.add(source);
599 newContext._sourceMap[source] = new SourceInfo.con2(entry.getValue()); 734 newContext._sourceMap[source] = entry.getValue().copy();
600 } 735 }
601 } 736 }
602 } 737 }
603 return newContext; 738 return newContext;
604 } 739 }
605 Element getElement(ElementLocation location) { 740 Element getElement(ElementLocation location) {
606 throw new UnsupportedOperationException(); 741 List<String> components2 = ((location as ElementLocationImpl)).components;
742 ElementImpl element;
743 {
744 Source librarySource = _sourceFactory.fromEncoding(components2[0]);
745 try {
746 element = computeLibraryElement(librarySource) as ElementImpl;
747 } on AnalysisException catch (exception) {
748 return null;
749 }
750 }
751 for (int i = 1; i < components2.length; i++) {
752 if (element == null) {
753 return null;
754 }
755 element = element.getChild(components2[i]);
756 }
757 return element;
607 } 758 }
608 List<AnalysisError> getErrors(Source source) { 759 List<AnalysisError> getErrors(Source source) {
609 throw new UnsupportedOperationException(); 760 {
761 SourceInfo info = getSourceInfo(source);
762 if (info is CompilationUnitInfo) {
763 return ((info as CompilationUnitInfo)).allErrors;
764 }
765 return AnalysisError.NO_ERRORS;
766 }
610 } 767 }
611 HtmlElement getHtmlElement(Source source) { 768 HtmlElement getHtmlElement(Source source) {
612 if (!AnalysisEngine.isHtmlFileName(source.shortName)) { 769 {
770 SourceInfo info = getSourceInfo(source);
771 if (info is HtmlUnitInfo) {
772 return ((info as HtmlUnitInfo)).element;
773 }
613 return null; 774 return null;
614 } 775 }
615 throw new UnsupportedOperationException(); 776 }
777 List<Source> getHtmlFilesReferencing(Source source) {
778 {
779 SourceInfo info = getSourceInfo(source);
780 if (info is LibraryInfo) {
781 return ((info as LibraryInfo)).htmlSources;
782 } else if (info is CompilationUnitInfo) {
783 List<Source> sources = new List<Source>();
784 for (Source librarySource in ((info as CompilationUnitInfo)).librarySour ces) {
785 LibraryInfo libraryInfo = getLibraryInfo(librarySource);
786 for (Source htmlSource in libraryInfo.htmlSources) {
787 sources.add(htmlSource);
788 }
789 }
790 if (!sources.isEmpty) {
791 return new List.from(sources);
792 }
793 }
794 return Source.EMPTY_ARRAY;
795 }
616 } 796 }
617 List<Source> get htmlSources => getSources(SourceKind.HTML); 797 List<Source> get htmlSources => getSources(SourceKind.HTML);
618 SourceKind getKnownKindOf(Source source) { 798 SourceKind getKindOf(Source source) {
619 String name = source.shortName; 799 {
620 if (AnalysisEngine.isHtmlFileName(name)) { 800 SourceInfo sourceInfo = getSourceInfo(source);
621 return SourceKind.HTML; 801 if (sourceInfo == null) {
802 return SourceKind.UNKNOWN;
803 }
804 return sourceInfo.kind;
622 } 805 }
623 if (!AnalysisEngine.isDartFileName(name)) { 806 }
624 return SourceKind.UNKNOWN; 807 List<Source> get launchableClientLibrarySources {
625 } 808 List<Source> sources = new List<Source>();
626 { 809 {
627 if (_libraryElementCache.containsKey(source)) { 810 for (MapEntry<Source, SourceInfo> entry in getMapEntrySet(_sourceMap)) {
628 return SourceKind.LIBRARY; 811 Source source = entry.getKey();
629 } 812 SourceInfo info = entry.getValue();
630 CompilationUnit unit = _parseCache[source]; 813 if (identical(info.kind, SourceKind.LIBRARY) && !source.isInSystemLibrar y()) {
631 if (unit != null && hasPartOfDirective(unit)) { 814 sources.add(source);
632 return SourceKind.PART; 815 }
633 } 816 }
634 } 817 }
635 return null; 818 return new List.from(sources);
636 } 819 }
637 List<Source> get launchableClientLibrarySources => librarySources; 820 List<Source> get launchableServerLibrarySources {
638 List<Source> get launchableServerLibrarySources => librarySources; 821 List<Source> sources = new List<Source>();
822 {
823 for (MapEntry<Source, SourceInfo> entry in getMapEntrySet(_sourceMap)) {
824 Source source = entry.getKey();
825 SourceInfo info = entry.getValue();
826 if (identical(info.kind, SourceKind.LIBRARY) && !source.isInSystemLibrar y()) {
827 sources.add(source);
828 }
829 }
830 }
831 return new List.from(sources);
832 }
639 List<Source> getLibrariesContaining(Source source) { 833 List<Source> getLibrariesContaining(Source source) {
640 { 834 {
641 SourceInfo info = _sourceMap[source]; 835 SourceInfo info = getSourceInfo(source);
642 if (info == null) { 836 if (info is CompilationUnitInfo) {
643 return Source.EMPTY_ARRAY; 837 return ((info as CompilationUnitInfo)).librarySources;
644 } 838 }
645 return info.librarySources; 839 return Source.EMPTY_ARRAY;
646 } 840 }
647 } 841 }
648 LibraryElement getLibraryElement(Source source) { 842 LibraryElement getLibraryElement(Source source) {
649 if (!AnalysisEngine.isDartFileName(source.shortName)) { 843 {
844 SourceInfo info = getSourceInfo(source);
845 if (info is LibraryInfo) {
846 return ((info as LibraryInfo)).element;
847 }
650 return null; 848 return null;
651 } 849 }
850 }
851 List<Source> get librarySources => getSources(SourceKind.LIBRARY);
852 LineInfo getLineInfo(Source source) {
652 { 853 {
653 LibraryElement element = _libraryElementCache[source]; 854 SourceInfo info = getSourceInfo(source);
654 if (element == null) { 855 if (info != null) {
655 if (getOrComputeKindOf(source) != SourceKind.LIBRARY) { 856 return info.lineInfo;
656 return null;
657 }
658 LibraryResolver resolver = new LibraryResolver.con1(this);
659 try {
660 element = resolver.resolveLibrary(source, true);
661 if (element != null) {
662 _libraryElementCache[source] = element;
663 }
664 } on AnalysisException catch (exception) {
665 AnalysisEngine.instance.logger.logError2("Could not resolve the librar y ${source.fullName}", exception);
666 }
667 } 857 }
668 return element; 858 return null;
669 } 859 }
670 } 860 }
671 /** 861 /**
672 * Return the element model corresponding to the library defined by the given source, or{@code null} if the element model does not yet exist.
673 * @param source the source defining the library whose element model is to be returned
674 * @return the element model corresponding to the library defined by the given source
675 */
676 LibraryElement getLibraryElementOrNull(Source source) {
677 {
678 return _libraryElementCache[source];
679 }
680 }
681 List<Source> get librarySources => getSources(SourceKind.LIBRARY);
682 SourceKind getOrComputeKindOf(Source source) {
683 SourceKind kind = getKnownKindOf(source);
684 if (kind != null) {
685 return kind;
686 }
687 return computeKindOf(source);
688 }
689 /**
690 * Return a namespace containing mappings for all of the public names defined by the given 862 * Return a namespace containing mappings for all of the public names defined by the given
691 * library. 863 * library.
692 * @param library the library whose public namespace is to be returned 864 * @param library the library whose public namespace is to be returned
693 * @return the public namespace of the given library 865 * @return the public namespace of the given library
694 */ 866 */
695 Namespace getPublicNamespace(LibraryElement library) { 867 Namespace getPublicNamespace(LibraryElement library) {
696 Source source10 = library.definingCompilationUnit.source; 868 Source source8 = library.definingCompilationUnit.source;
697 { 869 {
698 Namespace namespace = _publicNamespaceCache[source10]; 870 LibraryInfo libraryInfo = getLibraryInfo(source8);
871 if (libraryInfo == null) {
872 return null;
873 }
874 Namespace namespace = libraryInfo.publicNamespace;
699 if (namespace == null) { 875 if (namespace == null) {
700 NamespaceBuilder builder = new NamespaceBuilder(); 876 NamespaceBuilder builder = new NamespaceBuilder();
701 namespace = builder.createPublicNamespace(library); 877 namespace = builder.createPublicNamespace(library);
702 _publicNamespaceCache[source10] = namespace; 878 libraryInfo.publicNamespace = namespace;
703 } 879 }
704 return namespace; 880 return namespace;
705 } 881 }
706 } 882 }
707 /** 883 /**
708 * Return a namespace containing mappings for all of the public names defined by the library 884 * Return a namespace containing mappings for all of the public names defined by the library
709 * defined by the given source. 885 * defined by the given source.
710 * @param source the source defining the library whose public namespace is to be returned 886 * @param source the source defining the library whose public namespace is to be returned
711 * @return the public namespace corresponding to the library defined by the gi ven source 887 * @return the public namespace corresponding to the library defined by the gi ven source
888 * @throws AnalysisException if the public namespace could not be computed
712 */ 889 */
713 Namespace getPublicNamespace2(Source source) { 890 Namespace getPublicNamespace2(Source source) {
714 { 891 {
715 Namespace namespace = _publicNamespaceCache[source]; 892 LibraryInfo libraryInfo = getLibraryInfo(source);
893 if (libraryInfo == null) {
894 return null;
895 }
896 Namespace namespace = libraryInfo.publicNamespace;
716 if (namespace == null) { 897 if (namespace == null) {
717 LibraryElement library = getLibraryElement(source); 898 LibraryElement library = computeLibraryElement(source);
718 if (library == null) { 899 if (library == null) {
719 return null; 900 return null;
720 } 901 }
721 NamespaceBuilder builder = new NamespaceBuilder(); 902 NamespaceBuilder builder = new NamespaceBuilder();
722 namespace = builder.createPublicNamespace(library); 903 namespace = builder.createPublicNamespace(library);
723 _publicNamespaceCache[source] = namespace; 904 libraryInfo.publicNamespace = namespace;
724 } 905 }
725 return namespace; 906 return namespace;
726 } 907 }
727 } 908 }
728 SourceFactory get sourceFactory => _sourceFactory; 909 SourceFactory get sourceFactory => _sourceFactory;
910 bool isClientLibrary(Source librarySource) {
911 SourceInfo sourceInfo = getSourceInfo(librarySource);
912 if (sourceInfo is LibraryInfo) {
913 LibraryInfo libraryInfo = sourceInfo as LibraryInfo;
914 if (libraryInfo.hasInvalidLaunchable() || libraryInfo.hasInvalidClientServ er()) {
915 return false;
916 }
917 return libraryInfo.isLaunchable() && libraryInfo.isClient();
918 }
919 return false;
920 }
921 bool isServerLibrary(Source librarySource) {
922 SourceInfo sourceInfo = getSourceInfo(librarySource);
923 if (sourceInfo is LibraryInfo) {
924 LibraryInfo libraryInfo = sourceInfo as LibraryInfo;
925 if (libraryInfo.hasInvalidLaunchable() || libraryInfo.hasInvalidClientServ er()) {
926 return false;
927 }
928 return libraryInfo.isLaunchable() && libraryInfo.isServer();
929 }
930 return false;
931 }
729 void mergeContext(AnalysisContext context) { 932 void mergeContext(AnalysisContext context) {
730 { 933 {
731 for (MapEntry<Source, SourceInfo> entry in getMapEntrySet(((context as Ana lysisContextImpl))._sourceMap)) { 934 for (MapEntry<Source, SourceInfo> entry in getMapEntrySet(((context as Ana lysisContextImpl))._sourceMap)) {
732 Source newSource = entry.getKey(); 935 Source newSource = entry.getKey();
733 SourceInfo existingInfo = _sourceMap[newSource]; 936 SourceInfo existingInfo = getSourceInfo(newSource);
734 if (existingInfo == null) { 937 if (existingInfo == null) {
735 _sourceMap[newSource] = new SourceInfo.con2(entry.getValue()); 938 _sourceMap[newSource] = entry.getValue().copy();
736 } else { 939 } else {
737 } 940 }
738 } 941 }
739 } 942 }
740 } 943 }
741 CompilationUnit parse(Source source) { 944 CompilationUnit parseCompilationUnit(Source source) {
742 { 945 {
743 CompilationUnit unit = _parseCache[source]; 946 CompilationUnitInfo compilationUnitInfo = getCompilationUnitInfo(source);
947 if (compilationUnitInfo == null) {
948 return null;
949 }
950 CompilationUnit unit = compilationUnitInfo.resolvedCompilationUnit;
744 if (unit == null) { 951 if (unit == null) {
745 RecordingErrorListener errorListener = new RecordingErrorListener(); 952 unit = compilationUnitInfo.parsedCompilationUnit;
746 AnalysisContextImpl_ScanResult scanResult = internalScan(source, errorLi stener); 953 if (unit == null) {
747 Parser parser = new Parser(source, errorListener); 954 RecordingErrorListener errorListener = new RecordingErrorListener();
748 unit = parser.parseCompilationUnit(scanResult._token); 955 AnalysisContextImpl_ScanResult scanResult = internalScan(source, error Listener);
749 unit.parsingErrors = errorListener.getErrors2(source); 956 Parser parser = new Parser(source, errorListener);
750 unit.lineInfo = new LineInfo(scanResult._lineStarts); 957 unit = parser.parseCompilationUnit(scanResult._token);
751 _parseCache[source] = unit; 958 LineInfo lineInfo = new LineInfo(scanResult._lineStarts);
959 List<AnalysisError> errors = errorListener.getErrors2(source);
960 unit.parsingErrors = errors;
961 unit.lineInfo = lineInfo;
962 compilationUnitInfo.lineInfo = lineInfo;
963 compilationUnitInfo.parsedCompilationUnit = unit;
964 compilationUnitInfo.parseErrors = errors;
965 }
752 } 966 }
753 return unit; 967 return unit;
754 } 968 }
755 } 969 }
756 CompilationUnit parse3(Source source, AnalysisErrorListener errorListener) { 970 HtmlUnit parseHtmlUnit(Source source) {
757 { 971 {
758 CompilationUnit unit = _parseCache[source]; 972 HtmlUnitInfo htmlUnitInfo = getHtmlUnitInfo(source);
973 if (htmlUnitInfo == null) {
974 return null;
975 }
976 HtmlUnit unit = htmlUnitInfo.resolvedUnit;
759 if (unit == null) { 977 if (unit == null) {
760 AnalysisContextImpl_ScanResult scanResult = internalScan(source, errorLi stener); 978 unit = htmlUnitInfo.parsedUnit;
761 Parser parser = new Parser(source, errorListener); 979 if (unit == null) {
762 unit = parser.parseCompilationUnit(scanResult._token); 980 HtmlParseResult result = new HtmlParser(source).parse(scanHtml(source) );
763 unit.lineInfo = new LineInfo(scanResult._lineStarts); 981 unit = result.htmlUnit;
764 _parseCache[source] = unit; 982 htmlUnitInfo.lineInfo = new LineInfo(result.lineStarts);
983 htmlUnitInfo.parsedUnit = unit;
984 for (SourceInfo sourceInfo in _sourceMap.values) {
985 if (sourceInfo is LibraryInfo) {
986 ((sourceInfo as LibraryInfo)).removeHtmlSource(source);
987 }
988 }
989 for (Source librarySource in getLibrarySources2(source, unit)) {
990 LibraryInfo libraryInfo = getLibraryInfo(librarySource);
991 if (libraryInfo != null) {
992 libraryInfo.addHtmlSource(source);
993 }
994 }
995 }
765 } 996 }
766 return unit; 997 return unit;
767 } 998 }
768 } 999 }
769 HtmlParseResult parseHtml(Source source) { 1000 List<ChangeNotice> performAnalysisTask() {
770 { 1001 {
771 HtmlParseResult result = _htmlParseCache[source]; 1002 if (!performSingleAnalysisTask() && _pendingNotices.isEmpty) {
772 if (result == null) { 1003 return null;
773 result = new HtmlParser(source).parse(scanHtml(source));
774 _htmlParseCache[source] = result;
775 } 1004 }
776 return result; 1005 if (_pendingNotices.isEmpty) {
1006 return ChangeNoticeImpl.EMPTY_ARRAY;
1007 }
1008 List<ChangeNotice> notices = new List.from(_pendingNotices.values);
1009 _pendingNotices.clear();
1010 return notices;
777 } 1011 }
778 } 1012 }
779 List<ChangeNotice> performAnalysisTask() => ChangeNotice.EMPTY_ARRAY;
780 /** 1013 /**
781 * Given a table mapping the source for the libraries represented by the corre sponding elements to 1014 * Given a table mapping the source for the libraries represented by the corre sponding elements to
782 * the elements representing the libraries, record those mappings. 1015 * the elements representing the libraries, record those mappings.
783 * @param elementMap a table mapping the source for the libraries represented by the elements to 1016 * @param elementMap a table mapping the source for the libraries represented by the elements to
784 * the elements representing the libraries 1017 * the elements representing the libraries
785 */ 1018 */
786 void recordLibraryElements(Map<Source, LibraryElement> elementMap) { 1019 void recordLibraryElements(Map<Source, LibraryElement> elementMap) {
1020 Source htmlSource = _sourceFactory.forUri("dart:html");
787 { 1021 {
788 javaMapPutAll(_libraryElementCache, elementMap); 1022 for (MapEntry<Source, LibraryElement> entry in getMapEntrySet(elementMap)) {
1023 LibraryElement library = entry.getValue();
1024 LibraryInfo libraryInfo = getLibraryInfo(entry.getKey());
1025 if (libraryInfo != null) {
1026 libraryInfo.element = library;
1027 libraryInfo.launchable = library.entryPoint != null;
1028 libraryInfo.client = isClient(library, htmlSource, new Set<LibraryElem ent>());
1029 }
1030 Source librarySource = library.source;
1031 if (librarySource != null) {
1032 for (SourceInfo info in _sourceMap.values) {
1033 if (info is CompilationUnitInfo) {
1034 ((info as CompilationUnitInfo)).removeLibrarySource(librarySource) ;
1035 }
1036 }
1037 if (libraryInfo != null) {
1038 libraryInfo.addLibrarySource(librarySource);
1039 }
1040 for (CompilationUnitElement part in library.parts) {
1041 Source partSource = part.source;
1042 CompilationUnitInfo partInfo = partSource == null ? null : getCompil ationUnitInfo(partSource);
1043 if (partInfo != null) {
1044 partInfo.addLibrarySource(librarySource);
1045 }
1046 }
1047 }
1048 }
789 } 1049 }
790 } 1050 }
791 CompilationUnit resolve(Source source, LibraryElement library) => parse(source ); 1051 /**
1052 * Give the resolution errors and line info associated with the given source, add the information
1053 * to the cache.
1054 * @param source the source with which the information is associated
1055 * @param errors the resolution errors associated with the source
1056 * @param lineInfo the line information associated with the source
1057 */
1058 void recordResolutionErrors(Source source, List<AnalysisError> errors, LineInf o lineInfo5) {
1059 {
1060 CompilationUnitInfo compilationUnitInfo = getCompilationUnitInfo(source);
1061 if (compilationUnitInfo != null) {
1062 compilationUnitInfo.lineInfo = lineInfo5;
1063 compilationUnitInfo.resolutionErrors = errors;
1064 }
1065 getNotice(source).setErrors(compilationUnitInfo.allErrors, lineInfo5);
1066 }
1067 }
1068 /**
1069 * Give the resolved compilation unit associated with the given source, add th e unit to the cache.
1070 * @param source the source with which the unit is associated
1071 * @param unit the compilation unit associated with the source
1072 */
1073 void recordResolvedCompilationUnit(Source source, CompilationUnit unit) {
1074 {
1075 CompilationUnitInfo compilationUnitInfo = getCompilationUnitInfo(source);
1076 if (compilationUnitInfo != null) {
1077 compilationUnitInfo.resolvedCompilationUnit = unit;
1078 getNotice(source).compilationUnit = unit;
1079 }
1080 }
1081 }
1082 CompilationUnit resolveCompilationUnit(Source source15, LibraryElement library ) {
1083 if (library == null) {
1084 return null;
1085 }
1086 return resolveCompilationUnit2(source15, library.source);
1087 }
1088 CompilationUnit resolveCompilationUnit2(Source unitSource, Source librarySourc e) {
1089 {
1090 CompilationUnitInfo compilationUnitInfo = getCompilationUnitInfo(unitSourc e);
1091 if (compilationUnitInfo == null) {
1092 return null;
1093 }
1094 CompilationUnit unit = compilationUnitInfo.resolvedCompilationUnit;
1095 if (unit == null) {
1096 computeLibraryElement(librarySource);
1097 unit = compilationUnitInfo.resolvedCompilationUnit;
1098 }
1099 return unit;
1100 }
1101 }
1102 HtmlUnit resolveHtmlUnit(Source unitSource) {
1103 {
1104 HtmlUnitInfo htmlUnitInfo = getHtmlUnitInfo(unitSource);
1105 if (htmlUnitInfo == null) {
1106 return null;
1107 }
1108 HtmlUnit unit = htmlUnitInfo.resolvedUnit;
1109 if (unit == null) {
1110 computeHtmlElement(unitSource);
1111 unit = htmlUnitInfo.resolvedUnit;
1112 }
1113 return unit;
1114 }
1115 }
1116 void setContents(Source source, String contents) {
1117 {
1118 _sourceFactory.setContents(source, contents);
1119 sourceChanged(source);
1120 }
1121 }
792 void set sourceFactory(SourceFactory factory) { 1122 void set sourceFactory(SourceFactory factory) {
793 if (identical(_sourceFactory, factory)) { 1123 if (identical(_sourceFactory, factory)) {
794 return; 1124 return;
795 } else if (factory.context != null) { 1125 } else if (factory.context != null) {
796 throw new IllegalStateException("Source factories cannot be shared between contexts"); 1126 throw new IllegalStateException("Source factories cannot be shared between contexts");
797 } else if (_sourceFactory != null) {
798 _sourceFactory.context = null;
799 } 1127 }
800 factory.context = this; 1128 {
801 _sourceFactory = factory; 1129 if (_sourceFactory != null) {
1130 _sourceFactory.context = null;
1131 }
1132 factory.context = this;
1133 _sourceFactory = factory;
1134 for (SourceInfo sourceInfo in _sourceMap.values) {
1135 if (sourceInfo is HtmlUnitInfo) {
1136 ((sourceInfo as HtmlUnitInfo)).invalidateResolvedUnit();
1137 } else if (sourceInfo is CompilationUnitInfo) {
1138 CompilationUnitInfo compilationUnitInfo = sourceInfo as CompilationUni tInfo;
1139 compilationUnitInfo.invalidateResolvedUnit();
1140 compilationUnitInfo.invalidateResolutionErrors();
1141 if (sourceInfo is LibraryInfo) {
1142 LibraryInfo libraryInfo = sourceInfo as LibraryInfo;
1143 libraryInfo.invalidateElement();
1144 libraryInfo.invalidatePublicNamespace();
1145 libraryInfo.invalidateLaunchable();
1146 libraryInfo.invalidateClientServer();
1147 }
1148 }
1149 }
1150 }
802 } 1151 }
803 Iterable<Source> sourcesToResolve(List<Source> changedSources) { 1152 Iterable<Source> sourcesToResolve(List<Source> changedSources) {
804 List<Source> librarySources = new List<Source>(); 1153 List<Source> librarySources = new List<Source>();
805 for (Source source in changedSources) { 1154 for (Source source in changedSources) {
806 if (identical(getOrComputeKindOf(source), SourceKind.LIBRARY)) { 1155 if (identical(computeKindOf(source), SourceKind.LIBRARY)) {
807 librarySources.add(source); 1156 librarySources.add(source);
808 } 1157 }
809 } 1158 }
810 return librarySources; 1159 return librarySources;
811 } 1160 }
812 /** 1161 /**
813 * Add all of the sources contained in the given source container to the given list of sources. 1162 * Add all of the sources contained in the given source container to the given list of sources.
814 * <p> 1163 * <p>
815 * Note: This method must only be invoked while we are synchronized on {@link #cacheLock}. 1164 * Note: This method must only be invoked while we are synchronized on {@link #cacheLock}.
816 * @param sources the list to which sources are to be added 1165 * @param sources the list to which sources are to be added
817 * @param container the source container containing the sources to be added to the list 1166 * @param container the source container containing the sources to be added to the list
818 */ 1167 */
819 void addSourcesInContainer(List<Source> sources, SourceContainer container) { 1168 void addSourcesInContainer(List<Source> sources, SourceContainer container) {
820 for (Source source in _sourceMap.keys.toSet()) { 1169 for (Source source in _sourceMap.keys.toSet()) {
821 if (container.contains(source)) { 1170 if (container.contains(source)) {
822 sources.add(source); 1171 sources.add(source);
823 } 1172 }
824 } 1173 }
825 } 1174 }
826 SourceKind computeKindOf(Source source) { 1175 /**
827 try { 1176 * Create a source information object suitable for the given source. Return th e source information
828 if (hasPartOfDirective(parse(source))) { 1177 * object that was created, or {@code null} if the source should not be tracke d by this context.
829 return SourceKind.PART; 1178 * @param source the source for which an information object is being created
1179 * @return the source information object that was created
1180 */
1181 SourceInfo createSourceInfo(Source source) {
1182 String name = source.shortName;
1183 if (AnalysisEngine.isHtmlFileName(name)) {
1184 HtmlUnitInfo info = new HtmlUnitInfo();
1185 _sourceMap[source] = info;
1186 return info;
1187 } else if (AnalysisEngine.isDartFileName(name)) {
1188 DartInfo info = DartInfo.instance;
1189 _sourceMap[source] = info;
1190 return info;
1191 }
1192 return null;
1193 }
1194 /**
1195 * Return the compilation unit information associated with the given source, o r {@code null} if
1196 * the source is not known to this context. This method should be used to acce ss the compilation
1197 * unit information rather than accessing the compilation unit map directly be cause sources in the
1198 * SDK are implicitly part of every analysis context and are therefore only ad ded to the map when
1199 * first accessed.
1200 * <p>
1201 * <b>Note:</b> This method must only be invoked while we are synchronized on {@link #cacheLock}.
1202 * @param source the source for which information is being sought
1203 * @return the compilation unit information associated with the given source
1204 */
1205 CompilationUnitInfo getCompilationUnitInfo(Source source) {
1206 SourceInfo sourceInfo = getSourceInfo(source);
1207 if (sourceInfo == null) {
1208 sourceInfo = new CompilationUnitInfo();
1209 _sourceMap[source] = sourceInfo;
1210 return sourceInfo as CompilationUnitInfo;
1211 } else if (sourceInfo is CompilationUnitInfo) {
1212 return sourceInfo as CompilationUnitInfo;
1213 } else if (sourceInfo is DartInfo) {
1214 sourceInfo = internalComputeKindOf(source, sourceInfo);
1215 if (sourceInfo is CompilationUnitInfo) {
1216 return sourceInfo as CompilationUnitInfo;
830 } 1217 }
831 } on AnalysisException catch (exception) {
832 return SourceKind.UNKNOWN;
833 } 1218 }
834 return SourceKind.LIBRARY; 1219 return null;
1220 }
1221 /**
1222 * Return the HTML unit information associated with the given source, or {@cod e null} if the
1223 * source is not known to this context. This method should be used to access t he HTML unit
1224 * information rather than accessing the HTML unit map directly because source s in the SDK are
1225 * implicitly part of every analysis context and are therefore only added to t he map when first
1226 * accessed.
1227 * <p>
1228 * <b>Note:</b> This method must only be invoked while we are synchronized on {@link #cacheLock}.
1229 * @param source the source for which information is being sought
1230 * @return the HTML unit information associated with the given source
1231 */
1232 HtmlUnitInfo getHtmlUnitInfo(Source source) {
1233 SourceInfo sourceInfo = getSourceInfo(source);
1234 if (sourceInfo == null) {
1235 sourceInfo = new HtmlUnitInfo();
1236 _sourceMap[source] = sourceInfo;
1237 return sourceInfo as HtmlUnitInfo;
1238 } else if (sourceInfo is HtmlUnitInfo) {
1239 return sourceInfo as HtmlUnitInfo;
1240 }
1241 return null;
1242 }
1243 /**
1244 * Return the library information associated with the given source, or {@code null} if the source
1245 * is not known to this context. This method should be used to access the libr ary information
1246 * rather than accessing the library map directly because sources in the SDK a re implicitly part
1247 * of every analysis context and are therefore only added to the map when firs t accessed.
1248 * <p>
1249 * <b>Note:</b> This method must only be invoked while we are synchronized on {@link #cacheLock}.
1250 * @param source the source for which information is being sought
1251 * @return the library information associated with the given source
1252 */
1253 LibraryInfo getLibraryInfo(Source source) {
1254 SourceInfo sourceInfo = getSourceInfo(source);
1255 if (sourceInfo == null) {
1256 sourceInfo = new LibraryInfo();
1257 _sourceMap[source] = sourceInfo;
1258 return sourceInfo as LibraryInfo;
1259 } else if (sourceInfo is LibraryInfo) {
1260 return sourceInfo as LibraryInfo;
1261 } else if (sourceInfo is DartInfo) {
1262 sourceInfo = internalComputeKindOf(source, sourceInfo);
1263 if (sourceInfo is LibraryInfo) {
1264 return sourceInfo as LibraryInfo;
1265 }
1266 }
1267 return null;
1268 }
1269 /**
1270 * Return the sources of libraries that are referenced in the specified HTML f ile.
1271 * @param htmlSource the source of the HTML file being analyzed
1272 * @param htmlUnit the AST for the HTML file being analyzed
1273 * @return the sources of libraries that are referenced in the HTML file
1274 */
1275 List<Source> getLibrarySources2(Source htmlSource, HtmlUnit htmlUnit) {
1276 List<Source> libraries = new List<Source>();
1277 htmlUnit.accept(new SimpleXmlVisitor_3(htmlSource, libraries));
1278 return libraries;
1279 }
1280 /**
1281 * Return a change notice for the given source, creating one if one does not a lready exist.
1282 * @param source the source for which changes are being reported
1283 * @return a change notice for the given source
1284 */
1285 ChangeNoticeImpl getNotice(Source source) {
1286 ChangeNoticeImpl notice = _pendingNotices[source];
1287 if (notice == null) {
1288 notice = new ChangeNoticeImpl(source);
1289 _pendingNotices[source] = notice;
1290 }
1291 return notice;
1292 }
1293 /**
1294 * Return the source information associated with the given source, or {@code n ull} if the source
1295 * is not known to this context. This method should be used to access the sour ce information
1296 * rather than accessing the source map directly because sources in the SDK ar e implicitly part of
1297 * every analysis context and are therefore only added to the map when first a ccessed.
1298 * <p>
1299 * <b>Note:</b> This method must only be invoked while we are synchronized on {@link #cacheLock}.
1300 * @param source the source for which information is being sought
1301 * @return the source information associated with the given source
1302 */
1303 SourceInfo getSourceInfo(Source source) {
1304 SourceInfo sourceInfo = _sourceMap[source];
1305 if (sourceInfo == null) {
1306 sourceInfo = createSourceInfo(source);
1307 }
1308 return sourceInfo;
835 } 1309 }
836 /** 1310 /**
837 * Return an array containing all of the sources known to this context that ha ve the given kind. 1311 * Return an array containing all of the sources known to this context that ha ve the given kind.
838 * @param kind the kind of sources to be returned 1312 * @param kind the kind of sources to be returned
839 * @return all of the sources known to this context that have the given kind 1313 * @return all of the sources known to this context that have the given kind
840 */ 1314 */
841 List<Source> getSources(SourceKind kind5) { 1315 List<Source> getSources(SourceKind kind3) {
842 List<Source> sources = new List<Source>(); 1316 List<Source> sources = new List<Source>();
843 { 1317 {
844 for (MapEntry<Source, SourceInfo> entry in getMapEntrySet(_sourceMap)) { 1318 for (MapEntry<Source, SourceInfo> entry in getMapEntrySet(_sourceMap)) {
845 if (identical(entry.getValue().kind, kind5)) { 1319 if (identical(entry.getValue().kind, kind3)) {
846 sources.add(entry.getKey()); 1320 sources.add(entry.getKey());
847 } 1321 }
848 } 1322 }
849 } 1323 }
850 return new List.from(sources); 1324 return new List.from(sources);
851 } 1325 }
852 /** 1326 /**
853 * Return {@code true} if the given compilation unit has a part-of directive. 1327 * Return {@code true} if the given compilation unit has a part-of directive.
854 * @param unit the compilation unit being tested 1328 * @param unit the compilation unit being tested
855 * @return {@code true} if the compilation unit has a part-of directive 1329 * @return {@code true} if the compilation unit has a part-of directive
856 */ 1330 */
857 bool hasPartOfDirective(CompilationUnit unit) { 1331 bool hasPartOfDirective(CompilationUnit unit) {
858 for (Directive directive in unit.directives) { 1332 for (Directive directive in unit.directives) {
859 if (directive is PartOfDirective) { 1333 if (directive is PartOfDirective) {
860 return true; 1334 return true;
861 } 1335 }
862 } 1336 }
863 return false; 1337 return false;
864 } 1338 }
1339 SourceInfo internalComputeKindOf(Source source, SourceInfo info) {
1340 try {
1341 RecordingErrorListener errorListener = new RecordingErrorListener();
1342 AnalysisContextImpl_ScanResult scanResult = internalScan(source, errorList ener);
1343 Parser parser = new Parser(source, errorListener);
1344 CompilationUnit unit = parser.parseCompilationUnit(scanResult._token);
1345 LineInfo lineInfo = new LineInfo(scanResult._lineStarts);
1346 List<AnalysisError> errors = errorListener.getErrors2(source);
1347 unit.parsingErrors = errors;
1348 unit.lineInfo = lineInfo;
1349 CompilationUnitInfo sourceInfo;
1350 if (hasPartOfDirective(unit)) {
1351 sourceInfo = new CompilationUnitInfo();
1352 } else {
1353 sourceInfo = new LibraryInfo();
1354 }
1355 sourceInfo.lineInfo = lineInfo;
1356 sourceInfo.parsedCompilationUnit = unit;
1357 sourceInfo.parseErrors = errors;
1358 _sourceMap[source] = sourceInfo;
1359 return sourceInfo;
1360 } on AnalysisException catch (exception) {
1361 return info;
1362 }
1363 }
865 AnalysisContextImpl_ScanResult internalScan(Source source, AnalysisErrorListen er errorListener) { 1364 AnalysisContextImpl_ScanResult internalScan(Source source, AnalysisErrorListen er errorListener) {
866 AnalysisContextImpl_ScanResult result = new AnalysisContextImpl_ScanResult() ; 1365 AnalysisContextImpl_ScanResult result = new AnalysisContextImpl_ScanResult() ;
867 Source_ContentReceiver receiver = new Source_ContentReceiver_3(source, error Listener, result); 1366 Source_ContentReceiver receiver = new Source_ContentReceiver_4(source, error Listener, result);
868 try { 1367 try {
869 source.getContents(receiver); 1368 source.getContents(receiver);
870 } on JavaException catch (exception) { 1369 } catch (exception) {
871 throw new AnalysisException.con3(exception); 1370 throw new AnalysisException.con3(exception);
872 } 1371 }
873 return result; 1372 return result;
874 } 1373 }
1374 /**
1375 * Return {@code true} if this library is, or depends on, dart:html.
1376 * @param library the library being tested
1377 * @param visitedLibraries a collection of the libraries that have been visite d, used to prevent
1378 * infinite recursion
1379 * @return {@code true} if this library is, or depends on, dart:html
1380 */
1381 bool isClient(LibraryElement library, Source htmlSource, Set<LibraryElement> v isitedLibraries) {
1382 if (visitedLibraries.contains(library)) {
1383 return false;
1384 }
1385 if (library.source == htmlSource) {
1386 return true;
1387 }
1388 javaSetAdd(visitedLibraries, library);
1389 for (LibraryElement imported in library.importedLibraries) {
1390 if (isClient(imported, htmlSource, visitedLibraries)) {
1391 return true;
1392 }
1393 }
1394 for (LibraryElement exported in library.exportedLibraries) {
1395 if (isClient(exported, htmlSource, visitedLibraries)) {
1396 return true;
1397 }
1398 }
1399 return false;
1400 }
1401 /**
1402 * Perform a single analysis task.
1403 * <p>
1404 * <b>Note:</b> This method must only be invoked while we are synchronized on {@link #cacheLock}.
1405 * @return {@code true} if work was done, implying that there might be more wo rk to be done
1406 */
1407 bool performSingleAnalysisTask() {
1408 for (MapEntry<Source, SourceInfo> entry in getMapEntrySet(_sourceMap)) {
1409 SourceInfo sourceInfo = entry.getValue();
1410 if (identical(sourceInfo, DartInfo.instance) || sourceInfo.kind == null) {
1411 internalComputeKindOf(entry.getKey(), sourceInfo);
1412 return true;
1413 }
1414 }
1415 for (MapEntry<Source, SourceInfo> entry in getMapEntrySet(_sourceMap)) {
1416 SourceInfo sourceInfo = entry.getValue();
1417 if (sourceInfo is CompilationUnitInfo) {
1418 CompilationUnitInfo unitInfo = sourceInfo as CompilationUnitInfo;
1419 if (unitInfo.hasInvalidParsedUnit()) {
1420 try {
1421 parseCompilationUnit(entry.getKey());
1422 } on AnalysisException catch (exception) {
1423 unitInfo.parsedCompilationUnit = null;
1424 AnalysisEngine.instance.logger.logError2("Could not parse ${entry.ge tKey().fullName}", exception);
1425 }
1426 return true;
1427 }
1428 } else if (sourceInfo is HtmlUnitInfo) {
1429 HtmlUnitInfo unitInfo = sourceInfo as HtmlUnitInfo;
1430 if (unitInfo.hasInvalidParsedUnit()) {
1431 try {
1432 parseHtmlUnit(entry.getKey());
1433 } on AnalysisException catch (exception) {
1434 unitInfo.parsedUnit = null;
1435 AnalysisEngine.instance.logger.logError2("Could not parse ${entry.ge tKey().fullName}", exception);
1436 }
1437 return true;
1438 }
1439 }
1440 }
1441 for (MapEntry<Source, SourceInfo> entry in getMapEntrySet(_sourceMap)) {
1442 SourceInfo sourceInfo = entry.getValue();
1443 if (sourceInfo is LibraryInfo) {
1444 LibraryInfo libraryInfo = sourceInfo as LibraryInfo;
1445 if (libraryInfo.hasInvalidElement()) {
1446 try {
1447 computeLibraryElement(entry.getKey());
1448 } on AnalysisException catch (exception) {
1449 libraryInfo.element = null;
1450 AnalysisEngine.instance.logger.logError2("Could not compute the libr ary element for ${entry.getKey().fullName}", exception);
1451 }
1452 return true;
1453 }
1454 }
1455 }
1456 return false;
1457 }
875 HtmlScanResult scanHtml(Source source) { 1458 HtmlScanResult scanHtml(Source source) {
876 HtmlScanner scanner = new HtmlScanner(source); 1459 HtmlScanner scanner = new HtmlScanner(source);
877 try { 1460 try {
878 source.getContents(scanner); 1461 source.getContents(scanner);
879 } on JavaException catch (exception) { 1462 } catch (exception) {
880 throw new AnalysisException.con3(exception); 1463 throw new AnalysisException.con3(exception);
881 } 1464 }
882 return scanner.result; 1465 return scanner.result;
883 } 1466 }
884 /** 1467 /**
885 * Note: This method must only be invoked while we are synchronized on {@link #cacheLock}. 1468 * <b>Note:</b> This method must only be invoked while we are synchronized on {@link #cacheLock}.
886 * @param source the source that has been added 1469 * @param source the source that has been added
887 */ 1470 */
888 void sourceAvailable(Source source) { 1471 void sourceAvailable(Source source) {
889 SourceInfo existingInfo = _sourceMap[source]; 1472 SourceInfo existingInfo = _sourceMap[source];
890 if (existingInfo == null) { 1473 if (existingInfo == null) {
891 SourceKind kind = computeKindOf(source); 1474 createSourceInfo(source);
892 _sourceMap[source] = new SourceInfo.con1(source, kind);
893 } 1475 }
894 } 1476 }
895 /** 1477 /**
896 * Note: This method must only be invoked while we are synchronized on {@link #cacheLock}. 1478 * <b>Note:</b> This method must only be invoked while we are synchronized on {@link #cacheLock}.
897 * @param source the source that has been changed 1479 * @param source the source that has been changed
898 */ 1480 */
899 void sourceChanged(Source source) { 1481 void sourceChanged(Source source) {
900 SourceInfo info = _sourceMap[source]; 1482 SourceInfo sourceInfo = _sourceMap[source];
901 if (info == null) { 1483 if (sourceInfo is HtmlUnitInfo) {
902 return; 1484 HtmlUnitInfo htmlUnitInfo = sourceInfo as HtmlUnitInfo;
903 } 1485 htmlUnitInfo.invalidateLineInfo();
904 _parseCache.remove(source); 1486 htmlUnitInfo.invalidateParsedUnit();
905 _htmlParseCache.remove(source); 1487 htmlUnitInfo.invalidateResolvedUnit();
906 _libraryElementCache.remove(source); 1488 } else if (sourceInfo is CompilationUnitInfo) {
907 _publicNamespaceCache.remove(source); 1489 CompilationUnitInfo compilationUnitInfo = sourceInfo as CompilationUnitInf o;
908 SourceKind oldKind = info.kind; 1490 for (Source librarySource in compilationUnitInfo.librarySources) {
909 SourceKind newKind = computeKindOf(source); 1491 LibraryInfo libraryInfo = getLibraryInfo(librarySource);
910 if (newKind != oldKind) { 1492 if (libraryInfo != null) {
911 info.kind = newKind; 1493 libraryInfo.invalidateElement();
912 } 1494 libraryInfo.invalidatePublicNamespace();
913 for (Source librarySource in info.librarySources) { 1495 libraryInfo.invalidateLaunchable();
914 _libraryElementCache.remove(librarySource); 1496 libraryInfo.invalidateClientServer();
915 _publicNamespaceCache.remove(librarySource); 1497 }
1498 }
1499 _sourceMap[source] = DartInfo.instance;
916 } 1500 }
917 } 1501 }
918 /** 1502 /**
919 * Note: This method must only be invoked while we are synchronized on {@link #cacheLock}. 1503 * <b>Note:</b> This method must only be invoked while we are synchronized on {@link #cacheLock}.
920 * @param source the source that has been deleted 1504 * @param source the source that has been deleted
921 */ 1505 */
922 void sourceRemoved(Source source) { 1506 void sourceRemoved(Source source) {
923 SourceInfo info = _sourceMap[source]; 1507 CompilationUnitInfo compilationUnitInfo = getCompilationUnitInfo(source);
924 if (info == null) { 1508 if (compilationUnitInfo != null) {
925 return; 1509 for (Source librarySource in compilationUnitInfo.librarySources) {
926 } 1510 LibraryInfo libraryInfo = getLibraryInfo(librarySource);
927 _parseCache.remove(source); 1511 if (libraryInfo != null) {
928 _libraryElementCache.remove(source); 1512 libraryInfo.invalidateElement();
929 _publicNamespaceCache.remove(source); 1513 libraryInfo.invalidatePublicNamespace();
930 for (Source librarySource in info.librarySources) { 1514 libraryInfo.invalidateLaunchable();
931 _libraryElementCache.remove(librarySource); 1515 libraryInfo.invalidateClientServer();
932 _publicNamespaceCache.remove(librarySource); 1516 }
1517 }
933 } 1518 }
934 _sourceMap.remove(source); 1519 _sourceMap.remove(source);
935 } 1520 }
936 } 1521 }
937 /** 1522 /**
938 * Instances of the class {@code ScanResult} represent the results of scanning a source. 1523 * Instances of the class {@code ScanResult} represent the results of scanning a source.
939 */ 1524 */
940 class AnalysisContextImpl_ScanResult { 1525 class AnalysisContextImpl_ScanResult {
941 /** 1526 /**
942 * The first token in the token stream. 1527 * The first token in the token stream.
943 */ 1528 */
944 Token _token; 1529 Token _token;
945 /** 1530 /**
946 * The line start information that was produced. 1531 * The line start information that was produced.
947 */ 1532 */
948 List<int> _lineStarts; 1533 List<int> _lineStarts;
949 /** 1534 /**
950 * Initialize a newly created result object to be empty. 1535 * Initialize a newly created result object to be empty.
951 */ 1536 */
952 AnalysisContextImpl_ScanResult() : super() { 1537 AnalysisContextImpl_ScanResult() : super() {
953 } 1538 }
954 } 1539 }
955 class Source_ContentReceiver_3 implements Source_ContentReceiver { 1540 class SimpleXmlVisitor_3 extends SimpleXmlVisitor<Object> {
1541 Source htmlSource;
1542 List<Source> libraries;
1543 SimpleXmlVisitor_3(this.htmlSource, this.libraries) : super();
1544 Object visitXmlTagNode(XmlTagNode node) {
1545 if (javaStringEqualsIgnoreCase(node.tag.lexeme, AnalysisContextImpl._TAG_SCR IPT)) {
1546 for (XmlAttributeNode attribute in node.attributes) {
1547 if (javaStringEqualsIgnoreCase(attribute.name.lexeme, AnalysisContextImp l._ATTRIBUTE_SRC)) {
1548 Source librarySource = htmlSource.resolve(attribute.value.lexeme);
1549 if (librarySource.exists()) {
1550 libraries.add(librarySource);
1551 }
1552 }
1553 }
1554 }
1555 return null;
1556 }
1557 }
1558 class Source_ContentReceiver_4 implements Source_ContentReceiver {
956 Source source; 1559 Source source;
957 AnalysisErrorListener errorListener; 1560 AnalysisErrorListener errorListener;
958 AnalysisContextImpl_ScanResult result; 1561 AnalysisContextImpl_ScanResult result;
959 Source_ContentReceiver_3(this.source, this.errorListener, this.result); 1562 Source_ContentReceiver_4(this.source, this.errorListener, this.result);
960 accept(CharBuffer contents) { 1563 accept(CharBuffer contents) {
961 CharBufferScanner scanner = new CharBufferScanner(source, contents, errorLis tener); 1564 CharBufferScanner scanner = new CharBufferScanner(source, contents, errorLis tener);
962 result._token = scanner.tokenize(); 1565 result._token = scanner.tokenize();
963 result._lineStarts = scanner.lineStarts; 1566 result._lineStarts = scanner.lineStarts;
964 } 1567 }
965 void accept2(String contents) { 1568 void accept2(String contents) {
966 StringScanner scanner = new StringScanner(source, contents, errorListener); 1569 StringScanner scanner = new StringScanner(source, contents, errorListener);
967 result._token = scanner.tokenize(); 1570 result._token = scanner.tokenize();
968 result._lineStarts = scanner.lineStarts; 1571 result._lineStarts = scanner.lineStarts;
969 } 1572 }
970 } 1573 }
971 /** 1574 /**
972 * Instances of the class {@code RecordingErrorListener} implement an error list ener that will 1575 * The enumeration {@code CacheState} defines the possible states of cached data .
973 * record the errors that are reported to it in a way that is appropriate for ca ching those errors 1576 */
974 * within an analysis context. 1577 class CacheState {
1578 /**
1579 * A state representing the fact that the data was up-to-date but flushed from the cache in order
1580 * to control memory usage.
1581 */
1582 static final CacheState FLUSHED = new CacheState('FLUSHED', 0);
1583 /**
1584 * A state representing the fact that the data was removed from the cache beca use it was invalid
1585 * and needs to be recomputed.
1586 */
1587 static final CacheState INVALID = new CacheState('INVALID', 1);
1588 /**
1589 * A state representing the fact that the data is in the cache and valid.
1590 */
1591 static final CacheState VALID = new CacheState('VALID', 2);
1592 static final List<CacheState> values = [FLUSHED, INVALID, VALID];
1593 final String __name;
1594 final int __ordinal;
1595 int get ordinal => __ordinal;
1596 CacheState(this.__name, this.__ordinal) {
1597 }
1598 String toString() => __name;
1599 }
1600 /**
1601 * Instances of the class {@code ChangeNoticeImpl} represent a change to the ana lysis results
1602 * associated with a given source.
975 * @coverage dart.engine 1603 * @coverage dart.engine
976 */ 1604 */
977 class RecordingErrorListener implements AnalysisErrorListener { 1605 class ChangeNoticeImpl implements ChangeNotice {
978 /** 1606 /**
979 * A HashMap of lists containing the errors that were collected, keyed by each {@link Source}. 1607 * The source for which the result is being reported.
980 */ 1608 */
981 Map<Source, List<AnalysisError>> _errors = new Map<Source, List<AnalysisError> >(); 1609 Source _source;
982 /** 1610 /**
983 * Answer the errors collected by the listener. 1611 * The fully resolved AST that changed as a result of the analysis, or {@code null} if the AST was
984 * @return an array of errors (not {@code null}, contains no {@code null}s) 1612 * not changed.
985 */ 1613 */
986 List<AnalysisError> get errors { 1614 CompilationUnit _compilationUnit;
987 Set<MapEntry<Source, List<AnalysisError>>> entrySet2 = getMapEntrySet(_error s); 1615 /**
988 if (entrySet2.length == 0) { 1616 * The errors that changed as a result of the analysis, or {@code null} if err ors were not
989 return AnalysisError.NO_ERRORS; 1617 * changed.
990 } 1618 */
991 List<AnalysisError> resultList = new List<AnalysisError>(); 1619 List<AnalysisError> _errors;
992 for (MapEntry<Source, List<AnalysisError>> entry in entrySet2) { 1620 /**
993 resultList.addAll(entry.getValue()); 1621 * The line information associated with the source, or {@code null} if errors were not changed.
994 } 1622 */
995 return new List.from(resultList); 1623 LineInfo _lineInfo;
1624 /**
1625 * An empty array of change notices.
1626 */
1627 static List<ChangeNoticeImpl> EMPTY_ARRAY = new List<ChangeNoticeImpl>(0);
1628 /**
1629 * Initialize a newly created notice associated with the given source.
1630 * @param source the source for which the change is being reported
1631 */
1632 ChangeNoticeImpl(Source source) {
1633 this._source = source;
996 } 1634 }
997 /** 1635 /**
998 * Answer the errors collected by the listener for some passed {@link Source}. 1636 * Return the fully resolved AST that changed as a result of the analysis, or {@code null} if the
999 * @param source some {@link Source} for which the caller wants the set of {@l ink AnalysisError}s 1637 * AST was not changed.
1000 * collected by this listener 1638 * @return the fully resolved AST that changed as a result of the analysis
1001 * @return the errors collected by the listener for the passed {@link Source}
1002 */ 1639 */
1003 List<AnalysisError> getErrors2(Source source) { 1640 CompilationUnit get compilationUnit => _compilationUnit;
1004 List<AnalysisError> errorsForSource = _errors[source]; 1641 /**
1005 if (errorsForSource == null) { 1642 * Return the errors that changed as a result of the analysis, or {@code null} if errors were not
1006 return AnalysisError.NO_ERRORS; 1643 * changed.
1007 } else { 1644 * @return the errors that changed as a result of the analysis
1008 return new List.from(errorsForSource); 1645 */
1009 } 1646 List<AnalysisError> get errors => _errors;
1647 /**
1648 * Return the line information associated with the source, or {@code null} if errors were not
1649 * changed.
1650 * @return the line information associated with the source
1651 */
1652 LineInfo get lineInfo => _lineInfo;
1653 /**
1654 * Return the source for which the result is being reported.
1655 * @return the source for which the result is being reported
1656 */
1657 Source get source => _source;
1658 /**
1659 * Set the fully resolved AST that changed as a result of the analysis to the given AST.
1660 * @param compilationUnit the fully resolved AST that changed as a result of t he analysis
1661 */
1662 void set compilationUnit(CompilationUnit compilationUnit9) {
1663 this._compilationUnit = compilationUnit9;
1010 } 1664 }
1011 void onError(AnalysisError event) { 1665 /**
1012 Source source11 = event.source; 1666 * Set the errors that changed as a result of the analysis to the given errors and set the line
1013 List<AnalysisError> errorsForSource = _errors[source11]; 1667 * information to the given line information.
1014 if (_errors[source11] == null) { 1668 * @param errors the errors that changed as a result of the analysis
1015 errorsForSource = new List<AnalysisError>(); 1669 * @param lineInfo the line information associated with the source
1016 _errors[source11] = errorsForSource; 1670 */
1017 } 1671 void setErrors(List<AnalysisError> errors2, LineInfo lineInfo3) {
1018 errorsForSource.add(event); 1672 this._errors = errors2;
1673 this._lineInfo = lineInfo3;
1019 } 1674 }
1020 } 1675 }
1021 /** 1676 /**
1022 * Instances of the class {@code SourceInfo} maintain the information known by a n analysis context 1677 * Instances of the class {@code CompilationUnitInfo} maintain the information c ached by an analysis
1023 * about an individual source. 1678 * context about an individual compilation unit.
1024 * @coverage dart.engine 1679 * @coverage dart.engine
1025 */ 1680 */
1026 class SourceInfo { 1681 class CompilationUnitInfo extends SourceInfo {
1027 /** 1682 /**
1028 * The kind of the source. 1683 * The state of the cached parsed compilation unit.
1029 */ 1684 */
1030 SourceKind _kind; 1685 CacheState _parsedUnitState = CacheState.INVALID;
1031 /** 1686 /**
1032 * 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. 1687 * The parsed compilation unit, or {@code null} if the parsed compilation unit is not currently
1688 * cached.
1689 */
1690 CompilationUnit _parsedUnit;
1691 /**
1692 * The state of the cached resolved compilation unit.
1693 */
1694 CacheState _resolvedUnitState = CacheState.INVALID;
1695 /**
1696 * The resolved compilation unit, or {@code null} if the resolved compilation unit is not
1697 * currently cached.
1698 */
1699 CompilationUnit _resolvedUnit;
1700 /**
1701 * The state of the cached parse errors.
1702 */
1703 CacheState _parseErrorsState = CacheState.INVALID;
1704 /**
1705 * The errors produced while scanning and parsing the compilation unit, or {@c ode null} if the
1706 * errors are not currently cached.
1707 */
1708 List<AnalysisError> _parseErrors;
1709 /**
1710 * The state of the cached resolution errors.
1711 */
1712 CacheState _resolutionErrorsState = CacheState.INVALID;
1713 /**
1714 * The errors produced while resolving the compilation unit, or {@code null} i f the errors are not
1715 * currently cached.
1716 */
1717 List<AnalysisError> _resolutionErrors;
1718 /**
1719 * The sources for the defining compilation units of the libraries containing the source, or{@code null} if the libraries containing the source are not yet kn own.
1033 */ 1720 */
1034 List<Source> _librarySources = null; 1721 List<Source> _librarySources = null;
1035 SourceInfo.con1(Source source, SourceKind kind3) {
1036 _jtd_constructor_163_impl(source, kind3);
1037 }
1038 _jtd_constructor_163_impl(Source source, SourceKind kind3) {
1039 this._kind = kind3;
1040 }
1041 /** 1722 /**
1042 * Initialize a newly created information holder to hold the same information as the given holder. 1723 * Initialize a newly created information holder to be empty.
1043 * @param info the information holder used to initialize this holder
1044 */ 1724 */
1045 SourceInfo.con2(SourceInfo info) { 1725 CompilationUnitInfo() : super() {
1046 _jtd_constructor_164_impl(info);
1047 }
1048 _jtd_constructor_164_impl(SourceInfo info) {
1049 _kind = info._kind;
1050 _librarySources = new List<Source>.from(info._librarySources);
1051 } 1726 }
1052 /** 1727 /**
1053 * Add the given source to the list of sources for the defining compilation un its for the 1728 * Add the given source to the list of sources for the defining compilation un its for the
1054 * libraries containing this source. 1729 * libraries containing this source.
1055 * @param source the source to be added to the list 1730 * @param source the source to be added to the list
1056 */ 1731 */
1057 void addLibrarySource(Source source) { 1732 void addLibrarySource(Source source) {
1058 if (_librarySources == null) { 1733 if (_librarySources == null) {
1059 _librarySources = new List<Source>(); 1734 _librarySources = new List<Source>();
1060 } 1735 }
1061 _librarySources.add(source); 1736 _librarySources.add(source);
1062 } 1737 }
1063 /** 1738 /**
1064 * Return the kind of the source. 1739 * Remove the parsed compilation unit from the cache.
1065 * @return the kind of the source
1066 */ 1740 */
1067 SourceKind get kind => _kind; 1741 void clearParsedUnit() {
1742 _parsedUnit = null;
1743 }
1744 /**
1745 * Remove the parse errors from the cache.
1746 */
1747 void clearParseErrors() {
1748 _parseErrors = null;
1749 }
1750 /**
1751 * Remove the resolution errors from the cache.
1752 */
1753 void clearResolutionErrors() {
1754 _resolutionErrors = null;
1755 }
1756 /**
1757 * Remove the resolved compilation unit from the cache.
1758 */
1759 void clearResolvedUnit() {
1760 _resolvedUnit = null;
1761 }
1762 CompilationUnitInfo copy() {
1763 CompilationUnitInfo copy = new CompilationUnitInfo();
1764 copy.copyFrom(this);
1765 return copy;
1766 }
1767 /**
1768 * Return all of the errors associated with the compilation unit.
1769 * @return all of the errors associated with the compilation unit
1770 */
1771 List<AnalysisError> get allErrors {
1772 if (_parseErrors == null) {
1773 if (_resolutionErrors == null) {
1774 return null;
1775 }
1776 return _resolutionErrors;
1777 } else if (_resolutionErrors == null) {
1778 return _parseErrors;
1779 }
1780 int parseCount = _parseErrors.length;
1781 int resolutionCount = _resolutionErrors.length;
1782 List<AnalysisError> errors = new List<AnalysisError>(parseCount + resolution Count);
1783 JavaSystem.arraycopy(_parseErrors, 0, errors, 0, parseCount);
1784 JavaSystem.arraycopy(_resolutionErrors, 0, errors, parseCount, resolutionCou nt);
1785 return errors;
1786 }
1787 SourceKind get kind => SourceKind.PART;
1068 /** 1788 /**
1069 * Return the sources for the defining compilation units for the libraries con taining this source. 1789 * Return the sources for the defining compilation units for the libraries con taining this source.
1070 * @return the sources for the defining compilation units for the libraries co ntaining this source 1790 * @return the sources for the defining compilation units for the libraries co ntaining this source
1071 */ 1791 */
1072 List<Source> get librarySources { 1792 List<Source> get librarySources {
1073 if (_librarySources == null) { 1793 if (_librarySources == null) {
1074 return Source.EMPTY_ARRAY; 1794 return Source.EMPTY_ARRAY;
1075 } 1795 }
1076 return new List.from(_librarySources); 1796 return new List.from(_librarySources);
1077 } 1797 }
1078 /** 1798 /**
1799 * Return the parsed compilation unit, or {@code null} if the parsed compilati on unit is not
1800 * currently cached.
1801 * @return the parsed compilation unit
1802 */
1803 CompilationUnit get parsedCompilationUnit => _parsedUnit;
1804 /**
1805 * Return the errors produced while scanning and parsing the compilation unit, or {@code null} if
1806 * the errors are not currently cached.
1807 * @return the errors produced while scanning and parsing the compilation unit
1808 */
1809 List<AnalysisError> get parseErrors => _parseErrors;
1810 /**
1811 * Return the errors produced while resolving the compilation unit, or {@code null} if the errors
1812 * are not currently cached.
1813 * @return the errors produced while resolving the compilation unit
1814 */
1815 List<AnalysisError> get resolutionErrors => _resolutionErrors;
1816 /**
1817 * Return the resolved compilation unit, or {@code null} if the resolved compi lation unit is not
1818 * currently cached.
1819 * @return the resolved compilation unit
1820 */
1821 CompilationUnit get resolvedCompilationUnit => _resolvedUnit;
1822 /**
1823 * Return {@code true} if the parsed compilation unit needs to be recomputed.
1824 * @return {@code true} if the parsed compilation unit needs to be recomputed
1825 */
1826 bool hasInvalidParsedUnit() => identical(_parsedUnitState, CacheState.INVALID) ;
1827 /**
1828 * Return {@code true} if the parse errors needs to be recomputed.
1829 * @return {@code true} if the parse errors needs to be recomputed
1830 */
1831 bool hasInvalidParseErrors() => identical(_parseErrorsState, CacheState.INVALI D);
1832 /**
1833 * Return {@code true} if the resolution errors needs to be recomputed.
1834 * @return {@code true} if the resolution errors needs to be recomputed
1835 */
1836 bool hasInvalidResolutionErrors() => identical(_resolutionErrorsState, CacheSt ate.INVALID);
1837 /**
1838 * Return {@code true} if the resolved compilation unit needs to be recomputed .
1839 * @return {@code true} if the resolved compilation unit needs to be recompute d
1840 */
1841 bool hasInvalidResolvedUnit() => identical(_resolvedUnitState, CacheState.INVA LID);
1842 /**
1843 * Mark the parsed compilation unit as needing to be recomputed.
1844 */
1845 void invalidateParsedUnit() {
1846 _parsedUnitState = CacheState.INVALID;
1847 _parsedUnit = null;
1848 }
1849 /**
1850 * Mark the parse errors as needing to be recomputed.
1851 */
1852 void invalidateParseErrors() {
1853 _parseErrorsState = CacheState.INVALID;
1854 _parseErrors = null;
1855 }
1856 /**
1857 * Mark the resolution errors as needing to be recomputed.
1858 */
1859 void invalidateResolutionErrors() {
1860 _resolutionErrorsState = CacheState.INVALID;
1861 _resolutionErrors = null;
1862 }
1863 /**
1864 * Mark the resolved compilation unit as needing to be recomputed.
1865 */
1866 void invalidateResolvedUnit() {
1867 _resolvedUnitState = CacheState.INVALID;
1868 _resolvedUnit = null;
1869 }
1870 /**
1079 * Remove the given source from the list of sources for the defining compilati on units for the 1871 * Remove the given source from the list of sources for the defining compilati on units for the
1080 * libraries containing this source. 1872 * libraries containing this source.
1081 * @param source the source to be removed to the list 1873 * @param source the source to be removed to the list
1082 */ 1874 */
1083 void removeLibrarySource(Source source) { 1875 void removeLibrarySource(Source source) {
1084 _librarySources.remove(source); 1876 if (_librarySources != null) {
1085 if (_librarySources.isEmpty) { 1877 _librarySources.remove(source);
1086 _librarySources = null; 1878 if (_librarySources.isEmpty) {
1087 } 1879 _librarySources = null;
1088 } 1880 }
1089 /** 1881 }
1090 * Set the kind of the source to the given kind. 1882 }
1091 * @param kind the kind of the source 1883 /**
1092 */ 1884 * Set the parsed compilation unit to the given compilation unit.
1093 void set kind(SourceKind kind4) { 1885 * <p>
1094 this._kind = kind4; 1886 * <b>Note:</b> Do not use this method to clear or invalidate the parsed compi lation unit. Use
1887 * either {@link #clear} or {@link #invalidate}.
1888 * @param unit the parsed compilation unit
1889 */
1890 void set parsedCompilationUnit(CompilationUnit unit) {
1891 _parsedUnit = unit;
1892 _parsedUnitState = CacheState.VALID;
1893 }
1894 /**
1895 * Set the errors produced while scanning and parsing the compilation unit to the given errors.
1896 * <p>
1897 * <b>Note:</b> Do not use this method to clear or invalidate the parse errors . Use either{@link #clear} or {@link #invalidate}.
1898 * @param errors the errors produced while scanning and parsing the compilatio n unit
1899 */
1900 void set parseErrors(List<AnalysisError> errors) {
1901 _parseErrors = errors;
1902 _parseErrorsState = CacheState.VALID;
1903 }
1904 /**
1905 * Set the errors produced while resolving the compilation unit to the given e rrors.
1906 * <p>
1907 * <b>Note:</b> Do not use this method to clear or invalidate the resolution e rrors. Use either{@link #clear} or {@link #invalidate}.
1908 * @param errors the errors produced while resolving the compilation unit
1909 */
1910 void set resolutionErrors(List<AnalysisError> errors) {
1911 _resolutionErrors = errors;
1912 _resolutionErrorsState = CacheState.VALID;
1913 }
1914 /**
1915 * Set the resolved compilation unit to the given compilation unit.
1916 * <p>
1917 * <b>Note:</b> Do not use this method to clear or invalidate the resolved com pilation unit. Use
1918 * either {@link #clear} or {@link #invalidate}.
1919 * @param unit the resolved compilation unit
1920 */
1921 void set resolvedCompilationUnit(CompilationUnit unit) {
1922 _resolvedUnit = unit;
1923 _resolvedUnitState = CacheState.VALID;
1924 }
1925 void copyFrom(SourceInfo info) {
1926 super.copyFrom(info);
1095 } 1927 }
1096 } 1928 }
1097 /** 1929 /**
1930 * The unique instance of the class {@code DartInfo} acts as a placeholder for D art compilation
1931 * units that have not yet had their kind computed.
1932 * @coverage dart.engine
1933 */
1934 class DartInfo extends SourceInfo {
1935 /**
1936 * The unique instance of this class.
1937 */
1938 static DartInfo _UniqueInstance = new DartInfo();
1939 /**
1940 * Return the unique instance of this class.
1941 * @return the unique instance of this class
1942 */
1943 static DartInfo get instance => _UniqueInstance;
1944 /**
1945 * Prevent the creation of instances of this class.
1946 */
1947 DartInfo() : super() {
1948 }
1949 DartInfo copy() => this;
1950 SourceKind get kind => SourceKind.UNKNOWN;
1951 }
1952 /**
1953 * Instances of the class {@code HtmlUnitInfo} maintain the information cached b y an analysis
1954 * context about an individual HTML file.
1955 * @coverage dart.engine
1956 */
1957 class HtmlUnitInfo extends SourceInfo {
1958 /**
1959 * The state of the cached parsed (but not resolved) HTML unit.
1960 */
1961 CacheState _parsedUnitState = CacheState.INVALID;
1962 /**
1963 * The parsed HTML unit, or {@code null} if the parsed HTML unit is not curren tly cached.
1964 */
1965 HtmlUnit _parsedUnit;
1966 /**
1967 * The state of the cached parsed and resolved HTML unit.
1968 */
1969 CacheState _resolvedUnitState = CacheState.INVALID;
1970 /**
1971 * The resolved HTML unit, or {@code null} if the resolved HTML unit is not cu rrently cached.
1972 */
1973 HtmlUnit _resolvedUnit;
1974 /**
1975 * The state of the cached HTML element.
1976 */
1977 CacheState _elementState = CacheState.INVALID;
1978 /**
1979 * The element representing the HTML file, or {@code null} if the element is n ot currently cached.
1980 */
1981 HtmlElement _element;
1982 /**
1983 * Initialize a newly created information holder to be empty.
1984 */
1985 HtmlUnitInfo() : super() {
1986 }
1987 /**
1988 * Remove the parsed HTML unit from the cache.
1989 */
1990 void clearParsedUnit() {
1991 _parsedUnit = null;
1992 }
1993 /**
1994 * Remove the resolved HTML unit from the cache.
1995 */
1996 void clearResolvedUnit() {
1997 _resolvedUnit = null;
1998 }
1999 HtmlUnitInfo copy() {
2000 HtmlUnitInfo copy = new HtmlUnitInfo();
2001 copy.copyFrom(this);
2002 return copy;
2003 }
2004 /**
2005 * Return the element representing the HTML file, or {@code null} if the eleme nt is not currently
2006 * cached.
2007 * @return the element representing the HTML file
2008 */
2009 HtmlElement get element => _element;
2010 SourceKind get kind => SourceKind.HTML;
2011 /**
2012 * Return the parsed HTML unit, or {@code null} if the parsed HTML unit is not currently cached.
2013 * @return the parsed HTML unit
2014 */
2015 HtmlUnit get parsedUnit => _parsedUnit;
2016 /**
2017 * Return the resolved HTML unit, or {@code null} if the resolved HTML unit is not currently
2018 * cached.
2019 * @return the resolved HTML unit
2020 */
2021 HtmlUnit get resolvedUnit => _resolvedUnit;
2022 /**
2023 * Return {@code true} if the HTML element needs to be recomputed.
2024 * @return {@code true} if the HTML element needs to be recomputed
2025 */
2026 bool hasInvalidElement() => identical(_elementState, CacheState.INVALID);
2027 /**
2028 * Return {@code true} if the parsed HTML unit needs to be recomputed.
2029 * @return {@code true} if the parsed HTML unit needs to be recomputed
2030 */
2031 bool hasInvalidParsedUnit() => identical(_parsedUnitState, CacheState.INVALID) ;
2032 /**
2033 * Return {@code true} if the resolved HTML unit needs to be recomputed.
2034 * @return {@code true} if the resolved HTML unit needs to be recomputed
2035 */
2036 bool hasInvalidResolvedUnit() => identical(_resolvedUnitState, CacheState.INVA LID);
2037 /**
2038 * Mark the HTML element as needing to be recomputed.
2039 */
2040 void invalidateElement() {
2041 _elementState = CacheState.INVALID;
2042 _element = null;
2043 }
2044 /**
2045 * Mark the parsed HTML unit as needing to be recomputed.
2046 */
2047 void invalidateParsedUnit() {
2048 _parsedUnitState = CacheState.INVALID;
2049 _parsedUnit = null;
2050 }
2051 /**
2052 * Mark the resolved HTML unit as needing to be recomputed.
2053 */
2054 void invalidateResolvedUnit() {
2055 _resolvedUnitState = CacheState.INVALID;
2056 _resolvedUnit = null;
2057 }
2058 /**
2059 * Set the element representing the HTML file to the given element.
2060 * <p>
2061 * <b>Note:</b> Do not use this method to clear or invalidate the element. Use either{@link #clearElement()} or {@link #invalidateElement()}.
2062 * @param element the element representing the HTML file
2063 */
2064 void set element(HtmlElement element19) {
2065 this._element = element19;
2066 _elementState = CacheState.VALID;
2067 }
2068 /**
2069 * Set the parsed HTML unit to the given HTML unit.
2070 * <p>
2071 * <b>Note:</b> Do not use this method to clear or invalidate the HTML unit. U se either{@link #clearParsedUnit()} or {@link #invalidateParsedUnit()}.
2072 * @param unit the result of parsing the source as an HTML unit
2073 */
2074 void set parsedUnit(HtmlUnit unit) {
2075 _parsedUnit = unit;
2076 _parsedUnitState = CacheState.VALID;
2077 }
2078 /**
2079 * Set the resolved HTML unit to the given HTML unit.
2080 * <p>
2081 * <b>Note:</b> Do not use this method to clear or invalidate the HTML unit. U se either{@link #clearResolvedUnit()} or {@link #invalidateResolvedUnit()}.
2082 * @param unit the result of resolving the source as an HTML unit
2083 */
2084 void set resolvedUnit(HtmlUnit unit) {
2085 _resolvedUnit = unit;
2086 _resolvedUnitState = CacheState.VALID;
2087 }
2088 void copyFrom(SourceInfo info) {
2089 super.copyFrom(info);
2090 }
2091 }
2092 /**
2093 * Instances of the class {@code LibraryInfo} maintain the information cached by an analysis context
2094 * about an individual library.
2095 * @coverage dart.engine
2096 */
2097 class LibraryInfo extends CompilationUnitInfo {
2098 /**
2099 * Mask indicating that this library is launchable: that the file has a main m ethod.
2100 */
2101 static int _LAUNCHABLE = 1 << 1;
2102 /**
2103 * Mask indicating that the library is client code: that the library depends o n the html library.
2104 * If the library is not "client code", then it is referenced as "server code" .
2105 */
2106 static int _CLIENT_CODE = 1 << 2;
2107 /**
2108 * The state of the cached library element.
2109 */
2110 CacheState _elementState = CacheState.INVALID;
2111 /**
2112 * The element representing the library, or {@code null} if the element is not currently cached.
2113 */
2114 LibraryElement _element;
2115 /**
2116 * The state of the cached public namespace.
2117 */
2118 CacheState _publicNamespaceState = CacheState.INVALID;
2119 /**
2120 * The public namespace of the library, or {@code null} if the namespace is no t currently cached.
2121 */
2122 Namespace _publicNamespace;
2123 /**
2124 * The state of the cached client/ server flag.
2125 */
2126 CacheState _clientServerState = CacheState.INVALID;
2127 /**
2128 * The state of the cached launchable flag.
2129 */
2130 CacheState _launchableState = CacheState.INVALID;
2131 /**
2132 * An integer holding bit masks such as {@link #LAUNCHABLE} and {@link #CLIENT _CODE}.
2133 */
2134 int _bitmask = 0;
2135 /**
2136 * The sources for the HTML files that reference this library (via a script ta g), or {@code null}if there are no HTML files that reference the library or if t he HTML files are not yet known.
2137 */
2138 List<Source> _htmlSources = null;
2139 /**
2140 * Initialize a newly created information holder to be empty.
2141 */
2142 LibraryInfo() : super() {
2143 }
2144 /**
2145 * Add the given source to the list of sources for the HTML files that referen ce this library.
2146 * @param source the source to be added to the list
2147 */
2148 void addHtmlSource(Source source) {
2149 if (_htmlSources == null) {
2150 _htmlSources = new List<Source>();
2151 }
2152 _htmlSources.add(source);
2153 }
2154 /**
2155 * Remove the library element from the cache.
2156 */
2157 void clearElement() {
2158 _element = null;
2159 }
2160 /**
2161 * Remove the public namespace from the cache.
2162 */
2163 void clearPublicNamespace() {
2164 _publicNamespace = null;
2165 }
2166 LibraryInfo copy() {
2167 LibraryInfo copy = new LibraryInfo();
2168 copy.copyFrom(this);
2169 return copy;
2170 }
2171 /**
2172 * Return the element representing the library, or {@code null} if the element is not currently
2173 * cached.
2174 * @return the element representing the library
2175 */
2176 LibraryElement get element => _element;
2177 /**
2178 * Return the sources for the HTML files that reference this library.
2179 * @return the sources for the HTML files that reference this library
2180 */
2181 List<Source> get htmlSources {
2182 if (_htmlSources == null) {
2183 return Source.EMPTY_ARRAY;
2184 }
2185 return new List.from(_htmlSources);
2186 }
2187 SourceKind get kind => SourceKind.LIBRARY;
2188 /**
2189 * Return the public namespace of the library, or {@code null} if the namespac e is not currently
2190 * cached.
2191 * @return the public namespace of the library
2192 */
2193 Namespace get publicNamespace => _publicNamespace;
2194 /**
2195 * Return {@code true} if the client/ server flag needs to be recomputed.
2196 * @return {@code true} if the client/ server flag needs to be recomputed
2197 */
2198 bool hasInvalidClientServer() => identical(_clientServerState, CacheState.INVA LID);
2199 /**
2200 * Return {@code true} if the library element needs to be recomputed.
2201 * @return {@code true} if the library element needs to be recomputed
2202 */
2203 bool hasInvalidElement() => identical(_elementState, CacheState.INVALID);
2204 /**
2205 * Return {@code true} if the launchable flag needs to be recomputed.
2206 * @return {@code true} if the launchable flag needs to be recomputed
2207 */
2208 bool hasInvalidLaunchable() => identical(_launchableState, CacheState.INVALID) ;
2209 /**
2210 * Return {@code true} if the public namespace needs to be recomputed.
2211 * @return {@code true} if the public namespace needs to be recomputed
2212 */
2213 bool hasInvalidPublicNamespace() => identical(_publicNamespaceState, CacheStat e.INVALID);
2214 /**
2215 * Mark the client/ server flag as needing to be recomputed.
2216 */
2217 void invalidateClientServer() {
2218 _clientServerState = CacheState.INVALID;
2219 _bitmask &= ~_CLIENT_CODE;
2220 }
2221 /**
2222 * Mark the library element as needing to be recomputed.
2223 */
2224 void invalidateElement() {
2225 _elementState = CacheState.INVALID;
2226 _element = null;
2227 }
2228 /**
2229 * Mark the launchable flag as needing to be recomputed.
2230 */
2231 void invalidateLaunchable() {
2232 _launchableState = CacheState.INVALID;
2233 _bitmask &= ~_LAUNCHABLE;
2234 }
2235 /**
2236 * Mark the public namespace as needing to be recomputed.
2237 */
2238 void invalidatePublicNamespace() {
2239 _publicNamespaceState = CacheState.INVALID;
2240 _publicNamespace = null;
2241 }
2242 /**
2243 * Return <code>true</code> if this library is client based code: the library depends on the html
2244 * library.
2245 * @return <code>true</code> if this library is client based code: the library depends on the html
2246 * library
2247 */
2248 bool isClient() => (_bitmask & _CLIENT_CODE) != 0;
2249 /**
2250 * Return <code>true</code> if this library is launchable: the file includes a main method.
2251 * @return <code>true</code> if this library is launchable: the file includes a main method
2252 */
2253 bool isLaunchable() => (_bitmask & _LAUNCHABLE) != 0;
2254 /**
2255 * Return <code>true</code> if this library is server based code: the library does not depends on
2256 * the html library.
2257 * @return <code>true</code> if this library is server based code: the library does not depends on
2258 * the html library
2259 */
2260 bool isServer() => (_bitmask & _CLIENT_CODE) == 0;
2261 /**
2262 * Remove the given source from the list of sources for the HTML files that re ference this
2263 * library.
2264 * @param source the source to be removed to the list
2265 */
2266 void removeHtmlSource(Source source) {
2267 if (_htmlSources != null) {
2268 _htmlSources.remove(source);
2269 if (_htmlSources.isEmpty) {
2270 _htmlSources = null;
2271 }
2272 }
2273 }
2274 /**
2275 * Sets the value of the client/ server flag.
2276 * <p>
2277 * <b>Note:</b> Do not use this method to invalidate the flag, use{@link #inva lidateClientServer()}.
2278 * @param isClient the new value of the client flag
2279 */
2280 void set client(bool isClient) {
2281 if (isClient) {
2282 _bitmask |= _CLIENT_CODE;
2283 } else {
2284 _bitmask &= ~_CLIENT_CODE;
2285 }
2286 _clientServerState = CacheState.VALID;
2287 }
2288 /**
2289 * Set the element representing the library to the given element.
2290 * <p>
2291 * <b>Note:</b> Do not use this method to clear or invalidate the element. Use either{@link #clearElement()} or {@link #invalidateElement()}.
2292 * @param element the element representing the library
2293 */
2294 void set element(LibraryElement element20) {
2295 this._element = element20;
2296 _elementState = CacheState.VALID;
2297 }
2298 /**
2299 * Sets the value of the launchable flag.
2300 * <p>
2301 * <b>Note:</b> Do not use this method to invalidate the flag, use {@link #inv alidateLaunchable()}.
2302 * @param isClient the new value of the client flag
2303 */
2304 void set launchable(bool launchable2) {
2305 if (launchable2) {
2306 _bitmask |= _LAUNCHABLE;
2307 } else {
2308 _bitmask &= ~_LAUNCHABLE;
2309 }
2310 _launchableState = CacheState.VALID;
2311 }
2312 /**
2313 * Set the public namespace of the library to the given namespace.
2314 * <p>
2315 * <b>Note:</b> Do not use this method to clear or invalidate the element. Use either{@link #clearPublicNamespace()} or {@link #invalidatePublicNamespace()}.
2316 * @param namespace the public namespace of the library
2317 */
2318 void set publicNamespace(Namespace namespace) {
2319 _publicNamespace = namespace;
2320 _publicNamespaceState = CacheState.VALID;
2321 }
2322 void copyFrom(SourceInfo info) {
2323 super.copyFrom(info);
2324 }
2325 }
2326 /**
2327 * Instances of the class {@code RecordingErrorListener} implement an error list ener that will
2328 * record the errors that are reported to it in a way that is appropriate for ca ching those errors
2329 * within an analysis context.
2330 * @coverage dart.engine
2331 */
2332 class RecordingErrorListener implements AnalysisErrorListener {
2333 /**
2334 * A HashMap of lists containing the errors that were collected, keyed by each {@link Source}.
2335 */
2336 Map<Source, List<AnalysisError>> _errors = new Map<Source, List<AnalysisError> >();
2337 /**
2338 * Answer the errors collected by the listener.
2339 * @return an array of errors (not {@code null}, contains no {@code null}s)
2340 */
2341 List<AnalysisError> get errors {
2342 Set<MapEntry<Source, List<AnalysisError>>> entrySet2 = getMapEntrySet(_error s);
2343 if (entrySet2.length == 0) {
2344 return AnalysisError.NO_ERRORS;
2345 }
2346 List<AnalysisError> resultList = new List<AnalysisError>();
2347 for (MapEntry<Source, List<AnalysisError>> entry in entrySet2) {
2348 resultList.addAll(entry.getValue());
2349 }
2350 return new List.from(resultList);
2351 }
2352 /**
2353 * Answer the errors collected by the listener for some passed {@link Source}.
2354 * @param source some {@link Source} for which the caller wants the set of {@l ink AnalysisError}s
2355 * collected by this listener
2356 * @return the errors collected by the listener for the passed {@link Source}
2357 */
2358 List<AnalysisError> getErrors2(Source source) {
2359 List<AnalysisError> errorsForSource = _errors[source];
2360 if (errorsForSource == null) {
2361 return AnalysisError.NO_ERRORS;
2362 } else {
2363 return new List.from(errorsForSource);
2364 }
2365 }
2366 void onError(AnalysisError event) {
2367 Source source9 = event.source;
2368 List<AnalysisError> errorsForSource = _errors[source9];
2369 if (_errors[source9] == null) {
2370 errorsForSource = new List<AnalysisError>();
2371 _errors[source9] = errorsForSource;
2372 }
2373 errorsForSource.add(event);
2374 }
2375 }
2376 /**
2377 * Instances of the class {@code SourceInfo} maintain the information cached by an analysis context
2378 * about an individual source.
2379 * @coverage dart.engine
2380 */
2381 abstract class SourceInfo {
2382 /**
2383 * The state of the cached line information.
2384 */
2385 CacheState _lineInfoState = CacheState.INVALID;
2386 /**
2387 * The line information computed for the source, or {@code null} if the line i nformation is not
2388 * currently cached.
2389 */
2390 LineInfo _lineInfo;
2391 /**
2392 * Initialize a newly created information holder to be empty.
2393 */
2394 SourceInfo() : super() {
2395 }
2396 /**
2397 * Remove the line information from the cache.
2398 */
2399 void clearLineInfo() {
2400 _lineInfo = null;
2401 }
2402 /**
2403 * Return a copy of this information holder.
2404 * @return a copy of this information holder
2405 */
2406 SourceInfo copy();
2407 /**
2408 * Return the kind of the source, or {@code null} if the kind is not currently cached.
2409 * @return the kind of the source
2410 */
2411 SourceKind get kind;
2412 /**
2413 * Return the line information computed for the source, or {@code null} if the line information is
2414 * not currently cached.
2415 * @return the line information computed for the source
2416 */
2417 LineInfo get lineInfo => _lineInfo;
2418 /**
2419 * Return {@code true} if the line information needs to be recomputed.
2420 * @return {@code true} if the line information needs to be recomputed
2421 */
2422 bool hasInvalidLineInfo() => identical(_lineInfoState, CacheState.INVALID);
2423 /**
2424 * Mark the line information as needing to be recomputed.
2425 */
2426 void invalidateLineInfo() {
2427 _lineInfoState = CacheState.INVALID;
2428 _lineInfo = null;
2429 }
2430 /**
2431 * Set the line information for the source to the given line information.
2432 * <p>
2433 * <b>Note:</b> Do not use this method to clear or invalidate the element. Use either{@link #clearLineInfo()} or {@link #invalidateLineInfo()}.
2434 * @param info the line information for the source
2435 */
2436 void set lineInfo(LineInfo info) {
2437 _lineInfo = info;
2438 _lineInfoState = CacheState.VALID;
2439 }
2440 /**
2441 * Copy the information from the given information holder.
2442 * @param info the information holder from which information will be copied
2443 */
2444 void copyFrom(SourceInfo info) {
2445 _lineInfoState = info._lineInfoState;
2446 _lineInfo = info._lineInfo;
2447 }
2448 }
2449 /**
1098 * The interface {@code Logger} defines the behavior of objects that can be used to receive 2450 * The interface {@code Logger} defines the behavior of objects that can be used to receive
1099 * information about errors within the analysis engine. Implementations usually write this 2451 * information about errors within the analysis engine. Implementations usually write this
1100 * information to a file, but can also record the information for later use (suc h as during testing) 2452 * information to a file, but can also record the information for later use (suc h as during testing)
1101 * or even ignore the information. 2453 * or even ignore the information.
1102 * @coverage dart.engine.utilities 2454 * @coverage dart.engine.utilities
1103 */ 2455 */
1104 abstract class Logger { 2456 abstract class Logger {
1105 static Logger NULL = new Logger_NullLogger(); 2457 static Logger NULL = new Logger_NullLogger();
1106 /** 2458 /**
1107 * Log the given message as an error. 2459 * Log the given message as an error.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1140 } 2492 }
1141 void logError2(String message, Exception exception) { 2493 void logError2(String message, Exception exception) {
1142 } 2494 }
1143 void logError3(Exception exception) { 2495 void logError3(Exception exception) {
1144 } 2496 }
1145 void logInformation(String message) { 2497 void logInformation(String message) {
1146 } 2498 }
1147 void logInformation2(String message, Exception exception) { 2499 void logInformation2(String message, Exception exception) {
1148 } 2500 }
1149 } 2501 }
OLDNEW
« no previous file with comments | « pkg/analyzer_experimental/lib/src/generated/element.dart ('k') | pkg/analyzer_experimental/lib/src/generated/error.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698