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

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

Issue 14308011: New Analysis Engine snapshot. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 8 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 'dart:collection' show HasNextIterator;
7 import 'dart:uri' show Uri;
6 import 'java_core.dart'; 8 import 'java_core.dart';
7 import 'java_engine.dart'; 9 import 'java_engine.dart';
8 import 'dart:collection' show HasNextIterator; 10 import 'instrumentation.dart';
9 import 'error.dart'; 11 import 'error.dart';
10 import 'source.dart'; 12 import 'source.dart';
11 import 'scanner.dart' show Token, CharBufferScanner, StringScanner; 13 import 'scanner.dart' show Token, CharBufferScanner, StringScanner;
12 import 'ast.dart' show CompilationUnit, Directive, PartOfDirective; 14 import 'ast.dart';
13 import 'parser.dart' show Parser; 15 import 'parser.dart' show Parser;
16 import 'sdk.dart' show DartSdk;
14 import 'element.dart'; 17 import 'element.dart';
15 import 'resolver.dart' show Namespace, NamespaceBuilder, LibraryResolver, HtmlUn itBuilder; 18 import 'resolver.dart';
16 import 'html.dart' show XmlTagNode, XmlAttributeNode, SimpleXmlVisitor, HtmlScan ner, HtmlScanResult, HtmlParser, HtmlParseResult, HtmlUnit; 19 import 'html.dart' show XmlTagNode, XmlAttributeNode, RecursiveXmlVisitor, HtmlS canner, HtmlScanResult, HtmlParser, HtmlParseResult, HtmlUnit;
17 20
18 /** 21 /**
19 * The unique instance of the class {@code AnalysisEngine} serves as the entry p oint for the 22 * The unique instance of the class {@code AnalysisEngine} serves as the entry p oint for the
20 * functionality provided by the analysis engine. 23 * functionality provided by the analysis engine.
21 * @coverage dart.engine 24 * @coverage dart.engine
22 */ 25 */
23 class AnalysisEngine { 26 class AnalysisEngine {
24 /** 27 /**
25 * The suffix used for Dart source files. 28 * The suffix used for Dart source files.
26 */ 29 */
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 Logger _logger = Logger.NULL; 74 Logger _logger = Logger.NULL;
72 /** 75 /**
73 * Prevent the creation of instances of this class. 76 * Prevent the creation of instances of this class.
74 */ 77 */
75 AnalysisEngine() : super() { 78 AnalysisEngine() : super() {
76 } 79 }
77 /** 80 /**
78 * Create a new context in which analysis can be performed. 81 * Create a new context in which analysis can be performed.
79 * @return the analysis context that was created 82 * @return the analysis context that was created
80 */ 83 */
81 AnalysisContext createAnalysisContext() => new AnalysisContextImpl(); 84 AnalysisContext createAnalysisContext() {
85 if (Instrumentation.isNullLogger()) {
86 return new DelegatingAnalysisContextImpl();
87 } else {
88 return new InstrumentedAnalysisContextImpl.con1(new DelegatingAnalysisCont extImpl());
89 }
90 }
82 /** 91 /**
83 * Return the logger that should receive information about errors within the a nalysis engine. 92 * Return the logger that should receive information about errors within the a nalysis engine.
84 * @return the logger that should receive information about errors within the analysis engine 93 * @return the logger that should receive information about errors within the analysis engine
85 */ 94 */
86 Logger get logger => _logger; 95 Logger get logger => _logger;
87 /** 96 /**
88 * Set the logger that should receive information about errors within the anal ysis engine to the 97 * Set the logger that should receive information about errors within the anal ysis engine to the
89 * given logger. 98 * given logger.
90 * @param logger the logger that should receive information about errors withi n the analysis 99 * @param logger the logger that should receive information about errors withi n the analysis
91 * engine 100 * engine
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 * Return the element referenced by the given location, or {@code null} if the element is not 209 * 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 210 * 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 211 * 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 212 * element has been removed from this context as a result of some change since it was originally
204 * obtained. 213 * obtained.
205 * @param location the reference describing the element to be returned 214 * @param location the reference describing the element to be returned
206 * @return the element referenced by the given location 215 * @return the element referenced by the given location
207 */ 216 */
208 Element getElement(ElementLocation location); 217 Element getElement(ElementLocation location);
209 /** 218 /**
210 * Return an array containing all of the errors associated with the given sour ce. The array will 219 * Return an analysis error info containing the array of all of the errors and the line info
211 * be empty if the source is not known to this context or if there are no erro rs in the source. 220 * associated with the given source. The array of errors will be empty if the source is not known
212 * The errors contained in the array can be incomplete. 221 * to this context or if there are no errors in the source. The errors contain ed in the array can
222 * be incomplete.
213 * @param source the source whose errors are to be returned 223 * @param source the source whose errors are to be returned
214 * @return all of the errors associated with the given source 224 * @return all of the errors associated with the given source and the line inf o
215 * @see #computeErrors(Source) 225 * @see #computeErrors(Source)
216 */ 226 */
217 List<AnalysisError> getErrors(Source source); 227 AnalysisErrorInfo getErrors(Source source);
218 /** 228 /**
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 229 * 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. 230 * has not yet been created, or the analysis of the HTML file failed for some reason.
221 * @param source the source defining the HTML file whose element model is to b e returned 231 * @param source the source defining the HTML file whose element model is to b e returned
222 * @return the element model corresponding to the HTML file defined by the giv en source 232 * @return the element model corresponding to the HTML file defined by the giv en source
223 * @see #computeHtmlElement(Source) 233 * @see #computeHtmlElement(Source)
224 */ 234 */
225 HtmlElement getHtmlElement(Source source); 235 HtmlElement getHtmlElement(Source source);
226 /** 236 /**
227 * Return the sources for the HTML files that reference the given compilation unit. If the source 237 * Return the sources for the HTML files that reference the given compilation unit. If the source
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 /** 301 /**
292 * Return the line information for the given source, or {@code null} if the li ne information is 302 * Return the line information for the given source, or {@code null} if the li ne information is
293 * not known. The line information is used to map offsets from the beginning o f the source to line 303 * not known. The line information is used to map offsets from the beginning o f the source to line
294 * and column pairs. 304 * and column pairs.
295 * @param source the source whose line information is to be returned 305 * @param source the source whose line information is to be returned
296 * @return the line information for the given source 306 * @return the line information for the given source
297 * @see #computeLineInfo(Source) 307 * @see #computeLineInfo(Source)
298 */ 308 */
299 LineInfo getLineInfo(Source source); 309 LineInfo getLineInfo(Source source);
300 /** 310 /**
311 * Return a fully resolved AST for a single compilation unit within the given library, or{@code null} if the resolved AST is not already computed.
312 * @param unitSource the source of the compilation unit
313 * @param library the library containing the compilation unit
314 * @return a fully resolved AST for the compilation unit
315 * @see #resolveCompilationUnit(Source,LibraryElement)
316 */
317 CompilationUnit getResolvedCompilationUnit(Source unitSource, LibraryElement l ibrary);
318 /**
319 * Return a fully resolved AST for a single compilation unit within the given library, or{@code null} if the resolved AST is not already computed.
320 * @param unitSource the source of the compilation unit
321 * @param librarySource the source of the defining compilation unit of the lib rary containing the
322 * compilation unit
323 * @return a fully resolved AST for the compilation unit
324 * @see #resolveCompilationUnit(Source,Source)
325 */
326 CompilationUnit getResolvedCompilationUnit2(Source unitSource, Source libraryS ource);
327 /**
301 * Return the source factory used to create the sources that can be analyzed i n this context. 328 * Return the source factory used to create the sources that can be analyzed i n this context.
302 * @return the source factory used to create the sources that can be analyzed in this context 329 * @return the source factory used to create the sources that can be analyzed in this context
303 */ 330 */
304 SourceFactory get sourceFactory; 331 SourceFactory get sourceFactory;
305 /** 332 /**
306 * Return {@code true} if the given source is known to be the defining compila tion unit of a 333 * 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). 334 * library that can be run on a client (references 'dart:html', either directl y or indirectly).
308 * <p> 335 * <p>
309 * <b>Note:</b> In addition to the expected case of returning {@code false} if the source is known 336 * <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 337 * to be a library that cannot be run on a client, this method will also retur n {@code false} if
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 * @return an array containing notices of changes to the analysis results 385 * @return an array containing notices of changes to the analysis results
359 */ 386 */
360 List<ChangeNotice> performAnalysisTask(); 387 List<ChangeNotice> performAnalysisTask();
361 /** 388 /**
362 * Parse and resolve a single source within the given context to produce a ful ly resolved AST. 389 * Parse and resolve a single source within the given context to produce a ful ly resolved AST.
363 * @param unitSource the source to be parsed and resolved 390 * @param unitSource the source to be parsed and resolved
364 * @param library the library containing the source to be resolved 391 * @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 392 * @return the result of resolving the AST structure representing the content of the source in the
366 * context of the given library 393 * context of the given library
367 * @throws AnalysisException if the analysis could not be performed 394 * @throws AnalysisException if the analysis could not be performed
395 * @see #getResolvedCompilationUnit(Source,LibraryElement)
368 */ 396 */
369 CompilationUnit resolveCompilationUnit(Source unitSource, LibraryElement libra ry); 397 CompilationUnit resolveCompilationUnit(Source unitSource, LibraryElement libra ry);
370 /** 398 /**
371 * Parse and resolve a single source within the given context to produce a ful ly resolved AST. 399 * 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 400 * @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 401 * @param librarySource the source of the defining compilation unit of the lib rary containing the
374 * source to be resolved 402 * source to be resolved
375 * @return the result of resolving the AST structure representing the content of the source in the 403 * @return the result of resolving the AST structure representing the content of the source in the
376 * context of the given library 404 * context of the given library
377 * @throws AnalysisException if the analysis could not be performed 405 * @throws AnalysisException if the analysis could not be performed
406 * @see #getResolvedCompilationUnit(Source,Source)
378 */ 407 */
379 CompilationUnit resolveCompilationUnit2(Source unitSource, Source librarySourc e); 408 CompilationUnit resolveCompilationUnit2(Source unitSource, Source librarySourc e);
380 /** 409 /**
381 * Parse and resolve a single source within the given context to produce a ful ly resolved AST. 410 * 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 411 * @param htmlSource the source to be parsed and resolved
383 * @return the result of resolving the AST structure representing the content of the source 412 * @return the result of resolving the AST structure representing the content of the source
384 * @throws AnalysisException if the analysis could not be performed 413 * @throws AnalysisException if the analysis could not be performed
385 */ 414 */
386 HtmlUnit resolveHtmlUnit(Source htmlSource); 415 HtmlUnit resolveHtmlUnit(Source htmlSource);
387 /** 416 /**
(...skipping 13 matching lines...) Expand all
401 */ 430 */
402 void set sourceFactory(SourceFactory factory); 431 void set sourceFactory(SourceFactory factory);
403 /** 432 /**
404 * Given a collection of sources with content that has changed, return an {@li nk Iterable}identifying the sources that need to be resolved. 433 * Given a collection of sources with content that has changed, return an {@li nk Iterable}identifying the sources that need to be resolved.
405 * @param changedSources an array of sources (not {@code null}, contains no {@ code null}s) 434 * @param changedSources an array of sources (not {@code null}, contains no {@ code null}s)
406 * @return An iterable returning the sources to be resolved 435 * @return An iterable returning the sources to be resolved
407 */ 436 */
408 Iterable<Source> sourcesToResolve(List<Source> changedSources); 437 Iterable<Source> sourcesToResolve(List<Source> changedSources);
409 } 438 }
410 /** 439 /**
440 * The interface {@code AnalysisErrorInfo} contains the analysis errors and line information for the
441 * errors.
442 */
443 abstract class AnalysisErrorInfo {
444 /**
445 * Return the errors that as a result of the analysis, or {@code null} if ther e were no errors.
446 * @return the errors as a result of the analysis
447 */
448 List<AnalysisError> get errors;
449 /**
450 * Return the line information associated with the errors, or {@code null} if there were no
451 * errors.
452 * @return the line information associated with the errors
453 */
454 LineInfo get lineInfo;
455 }
456 /**
411 * Instances of the class {@code AnalysisException} represent an exception that occurred during the 457 * Instances of the class {@code AnalysisException} represent an exception that occurred during the
412 * analysis of one or more sources. 458 * analysis of one or more sources.
413 * @coverage dart.engine 459 * @coverage dart.engine
414 */ 460 */
415 class AnalysisException extends JavaException { 461 class AnalysisException extends JavaException {
416 /** 462 /**
417 * Initialize a newly created exception. 463 * Initialize a newly created exception.
418 */ 464 */
419 AnalysisException() : super() { 465 AnalysisException() : super() {
420 _jtd_constructor_124_impl(); 466 _jtd_constructor_125_impl();
421 } 467 }
422 _jtd_constructor_124_impl() { 468 _jtd_constructor_125_impl() {
423 } 469 }
424 /** 470 /**
425 * Initialize a newly created exception to have the given message. 471 * Initialize a newly created exception to have the given message.
426 * @param message the message associated with the exception 472 * @param message the message associated with the exception
427 */ 473 */
428 AnalysisException.con1(String message) : super(message) { 474 AnalysisException.con1(String message) : super(message) {
429 _jtd_constructor_125_impl(message); 475 _jtd_constructor_126_impl(message);
430 } 476 }
431 _jtd_constructor_125_impl(String message) { 477 _jtd_constructor_126_impl(String message) {
432 } 478 }
433 /** 479 /**
434 * Initialize a newly created exception to have the given message and cause. 480 * Initialize a newly created exception to have the given message and cause.
435 * @param message the message associated with the exception 481 * @param message the message associated with the exception
436 * @param cause the underlying exception that caused this exception 482 * @param cause the underlying exception that caused this exception
437 */ 483 */
438 AnalysisException.con2(String message, Exception cause) : super(message, cause ) { 484 AnalysisException.con2(String message, Exception cause) : super(message, cause ) {
439 _jtd_constructor_126_impl(message, cause); 485 _jtd_constructor_127_impl(message, cause);
440 } 486 }
441 _jtd_constructor_126_impl(String message, Exception cause) { 487 _jtd_constructor_127_impl(String message, Exception cause) {
442 } 488 }
443 /** 489 /**
444 * Initialize a newly created exception to have the given cause. 490 * Initialize a newly created exception to have the given cause.
445 * @param cause the underlying exception that caused this exception 491 * @param cause the underlying exception that caused this exception
446 */ 492 */
447 AnalysisException.con3(Exception cause) : super.withCause(cause) { 493 AnalysisException.con3(Exception cause) : super.withCause(cause) {
448 _jtd_constructor_127_impl(cause); 494 _jtd_constructor_128_impl(cause);
449 } 495 }
450 _jtd_constructor_127_impl(Exception cause) { 496 _jtd_constructor_128_impl(Exception cause) {
451 } 497 }
452 } 498 }
453 /** 499 /**
454 * The interface {@code ChangeNotice} defines the behavior of objects that repre sent a change to the 500 * The interface {@code ChangeNotice} defines the behavior of objects that repre sent a change to the
455 * analysis results associated with a given source. 501 * analysis results associated with a given source.
456 * @coverage dart.engine 502 * @coverage dart.engine
457 */ 503 */
458 abstract class ChangeNotice { 504 abstract class ChangeNotice implements AnalysisErrorInfo {
459 /** 505 /**
460 * Return the fully resolved AST that changed as a result of the analysis, or {@code null} if the 506 * Return the fully resolved AST that changed as a result of the analysis, or {@code null} if the
461 * AST was not changed. 507 * AST was not changed.
462 * @return the fully resolved AST that changed as a result of the analysis 508 * @return the fully resolved AST that changed as a result of the analysis
463 */ 509 */
464 CompilationUnit get compilationUnit; 510 CompilationUnit get compilationUnit;
465 /** 511 /**
466 * Return the errors that changed as a result of the analysis, or {@code null} if errors were not
467 * changed.
468 * @return the errors that changed as a result of the analysis
469 */
470 List<AnalysisError> get errors;
471 /**
472 * Return the line information associated with the source, or {@code null} if errors were not
473 * changed.
474 * @return the line information associated with the source
475 */
476 LineInfo get lineInfo;
477 /**
478 * Return the source for which the result is being reported. 512 * Return the source for which the result is being reported.
479 * @return the source for which the result is being reported 513 * @return the source for which the result is being reported
480 */ 514 */
481 Source get source; 515 Source get source;
482 } 516 }
483 /** 517 /**
484 * Instances of the class {@code ChangeSet} indicate what sources have been adde d, changed, or 518 * Instances of the class {@code ChangeSet} indicate what sources have been adde d, changed, or
485 * removed. 519 * removed.
486 * @coverage dart.engine 520 * @coverage dart.engine
487 */ 521 */
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 if (container != null) { 599 if (container != null) {
566 _removedContainers.add(container); 600 _removedContainers.add(container);
567 } 601 }
568 } 602 }
569 } 603 }
570 /** 604 /**
571 * Instances of the class {@code AnalysisContextImpl} implement an {@link Analys isContext analysis 605 * Instances of the class {@code AnalysisContextImpl} implement an {@link Analys isContext analysis
572 * context}. 606 * context}.
573 * @coverage dart.engine 607 * @coverage dart.engine
574 */ 608 */
575 class AnalysisContextImpl implements AnalysisContext { 609 class AnalysisContextImpl implements InternalAnalysisContext {
576 /** 610 /**
577 * The source factory used to create the sources that can be analyzed in this context. 611 * The source factory used to create the sources that can be analyzed in this context.
578 */ 612 */
579 SourceFactory _sourceFactory; 613 SourceFactory _sourceFactory;
580 /** 614 /**
581 * A table mapping the sources known to the context to the information known a bout the source. 615 * A table mapping the sources known to the context to the information known a bout the source.
582 */ 616 */
583 Map<Source, SourceInfo> _sourceMap = new Map<Source, SourceInfo>(); 617 Map<Source, SourceInfo> _sourceMap = new Map<Source, SourceInfo>();
584 /** 618 /**
585 * A table mapping sources to the change notices that are waiting to be return ed related to that 619 * A table mapping sources to the change notices that are waiting to be return ed related to that
586 * source. 620 * source.
587 */ 621 */
588 Map<Source, ChangeNoticeImpl> _pendingNotices = new Map<Source, ChangeNoticeIm pl>(); 622 Map<Source, ChangeNoticeImpl> _pendingNotices = new Map<Source, ChangeNoticeIm pl>();
589 /** 623 /**
624 * A list containing the most recently accessed sources with the most recently used at the end of
625 * the list. When more sources are added than the maximum allowed then the lea st recently used
626 * source will be removed and will have it's cached AST structure flushed.
627 */
628 List<Source> _recentlyUsed = new List<Source>();
629 /**
590 * The object used to synchronize access to all of the caches. 630 * The object used to synchronize access to all of the caches.
591 */ 631 */
592 Object _cacheLock = new Object(); 632 Object _cacheLock = new Object();
593 /** 633 /**
634 * The maximum number of sources for which data should be kept in the cache.
635 */
636 static int _MAX_CACHE_SIZE = 64;
637 /**
594 * The name of the 'src' attribute in a HTML tag. 638 * The name of the 'src' attribute in a HTML tag.
595 */ 639 */
596 static String _ATTRIBUTE_SRC = "src"; 640 static String _ATTRIBUTE_SRC = "src";
597 /** 641 /**
598 * The name of the 'script' tag in an HTML file. 642 * The name of the 'script' tag in an HTML file.
599 */ 643 */
600 static String _TAG_SCRIPT = "script"; 644 static String _TAG_SCRIPT = "script";
601 /** 645 /**
646 * The number of times that the flushing of information from the cache has bee n disabled without
647 * being re-enabled.
648 */
649 int _cacheRemovalCount = 0;
650 /**
602 * Initialize a newly created analysis context. 651 * Initialize a newly created analysis context.
603 */ 652 */
604 AnalysisContextImpl() : super() { 653 AnalysisContextImpl() : super() {
605 } 654 }
655 void addSourceInfo(Source source, SourceInfo info) {
656 _sourceMap[source] = info;
657 }
606 void applyChanges(ChangeSet changeSet) { 658 void applyChanges(ChangeSet changeSet) {
607 if (changeSet.isEmpty()) { 659 if (changeSet.isEmpty()) {
608 return; 660 return;
609 } 661 }
610 { 662 {
611 List<Source> removedSources = new List<Source>.from(changeSet.removed); 663 List<Source> removedSources = new List<Source>.from(changeSet.removed);
612 for (SourceContainer container in changeSet.removedContainers) { 664 for (SourceContainer container in changeSet.removedContainers) {
613 addSourcesInContainer(removedSources, container); 665 addSourcesInContainer(removedSources, container);
614 } 666 }
615 for (Source source in changeSet.added3) { 667 for (Source source in changeSet.added3) {
(...skipping 23 matching lines...) Expand all
639 } 691 }
640 HtmlElement computeHtmlElement(Source source) { 692 HtmlElement computeHtmlElement(Source source) {
641 if (!AnalysisEngine.isHtmlFileName(source.shortName)) { 693 if (!AnalysisEngine.isHtmlFileName(source.shortName)) {
642 return null; 694 return null;
643 } 695 }
644 { 696 {
645 HtmlUnitInfo htmlUnitInfo = getHtmlUnitInfo(source); 697 HtmlUnitInfo htmlUnitInfo = getHtmlUnitInfo(source);
646 if (htmlUnitInfo == null) { 698 if (htmlUnitInfo == null) {
647 return null; 699 return null;
648 } 700 }
649 HtmlElement element24 = htmlUnitInfo.element; 701 HtmlElement element26 = htmlUnitInfo.element;
650 if (element24 == null) { 702 if (element26 == null) {
651 HtmlUnit unit = htmlUnitInfo.resolvedUnit; 703 HtmlUnit unit = htmlUnitInfo.resolvedUnit;
652 if (unit == null) { 704 if (unit == null) {
653 unit = htmlUnitInfo.parsedUnit; 705 unit = htmlUnitInfo.parsedUnit;
654 if (unit == null) { 706 if (unit == null) {
655 unit = parseHtmlUnit(source); 707 unit = parseHtmlUnit(source);
656 } 708 }
657 } 709 }
658 HtmlUnitBuilder builder = new HtmlUnitBuilder(this); 710 HtmlUnitBuilder builder = new HtmlUnitBuilder(this);
659 element24 = builder.buildHtmlElement2(source, unit); 711 element26 = builder.buildHtmlElement2(source, unit);
660 htmlUnitInfo.resolvedUnit = unit; 712 htmlUnitInfo.resolvedUnit = unit;
661 htmlUnitInfo.element = element24; 713 htmlUnitInfo.element = element26;
662 } 714 }
663 return element24; 715 return element26;
664 } 716 }
665 } 717 }
666 SourceKind computeKindOf(Source source) { 718 SourceKind computeKindOf(Source source) {
667 { 719 {
668 SourceInfo sourceInfo = getSourceInfo(source); 720 SourceInfo sourceInfo = getSourceInfo(source);
669 if (sourceInfo == null) { 721 if (sourceInfo == null) {
670 return SourceKind.UNKNOWN; 722 return SourceKind.UNKNOWN;
671 } else if (sourceInfo is DartInfo) { 723 } else if (identical(sourceInfo, DartInfo.pendingInstance)) {
672 sourceInfo = internalComputeKindOf(source, sourceInfo); 724 sourceInfo = internalComputeKindOf(source);
673 } 725 }
674 return sourceInfo.kind; 726 return sourceInfo.kind;
675 } 727 }
676 } 728 }
677 LibraryElement computeLibraryElement(Source source) { 729 LibraryElement computeLibraryElement(Source source) {
678 if (!AnalysisEngine.isDartFileName(source.shortName)) { 730 if (!AnalysisEngine.isDartFileName(source.shortName)) {
679 return null; 731 return null;
680 } 732 }
681 { 733 {
682 LibraryInfo libraryInfo = getLibraryInfo(source); 734 LibraryInfo libraryInfo = getLibraryInfo(source);
683 if (libraryInfo == null) { 735 if (libraryInfo == null) {
684 return null; 736 return null;
685 } 737 }
686 LibraryElement element25 = libraryInfo.element; 738 LibraryElement element27 = libraryInfo.element;
687 if (element25 == null) { 739 if (element27 == null) {
688 if (computeKindOf(source) != SourceKind.LIBRARY) { 740 if (computeKindOf(source) != SourceKind.LIBRARY) {
689 return null; 741 return null;
690 } 742 }
691 LibraryResolver resolver = new LibraryResolver.con1(this); 743 LibraryResolver resolver = new LibraryResolver.con1(this);
692 try { 744 try {
693 element25 = resolver.resolveLibrary(source, true); 745 element27 = resolver.resolveLibrary(source, true);
694 if (element25 != null) { 746 if (element27 != null) {
695 libraryInfo.element = element25; 747 libraryInfo.element = element27;
696 } 748 }
697 } on AnalysisException catch (exception) { 749 } on AnalysisException catch (exception) {
698 AnalysisEngine.instance.logger.logError2("Could not resolve the librar y ${source.fullName}", exception); 750 AnalysisEngine.instance.logger.logError2("Could not resolve the librar y ${source.fullName}", exception);
699 } 751 }
700 } 752 }
701 return element25; 753 return element27;
702 } 754 }
703 } 755 }
704 LineInfo computeLineInfo(Source source) { 756 LineInfo computeLineInfo(Source source) {
705 { 757 {
706 SourceInfo sourceInfo = getSourceInfo(source); 758 SourceInfo sourceInfo = getSourceInfo(source);
707 if (sourceInfo == null) { 759 if (sourceInfo == null) {
708 return null; 760 return null;
709 } 761 }
710 LineInfo lineInfo4 = sourceInfo.lineInfo; 762 LineInfo lineInfo4 = sourceInfo.lineInfo;
711 if (lineInfo4 == null) { 763 if (lineInfo4 == null) {
712 if (sourceInfo is DartInfo) { 764 if (identical(sourceInfo, DartInfo.pendingInstance)) {
713 sourceInfo = internalComputeKindOf(source, sourceInfo); 765 sourceInfo = internalComputeKindOf(source);
714 } 766 }
715 if (sourceInfo is HtmlUnitInfo) { 767 if (sourceInfo is HtmlUnitInfo) {
716 parseHtmlUnit(source); 768 parseHtmlUnit(source);
717 lineInfo4 = sourceInfo.lineInfo; 769 lineInfo4 = sourceInfo.lineInfo;
718 } else if (sourceInfo is CompilationUnitInfo) { 770 } else if (sourceInfo is CompilationUnitInfo) {
719 parseCompilationUnit(source); 771 parseCompilationUnit(source);
720 lineInfo4 = sourceInfo.lineInfo; 772 lineInfo4 = sourceInfo.lineInfo;
721 } 773 }
722 } 774 }
723 return lineInfo4; 775 return lineInfo4;
724 } 776 }
725 } 777 }
726 AnalysisContext extractContext(SourceContainer container) { 778 CompilationUnit computeResolvableCompilationUnit(Source source) {
727 AnalysisContextImpl newContext = AnalysisEngine.instance.createAnalysisConte xt() as AnalysisContextImpl; 779 {
780 CompilationUnitInfo compilationUnitInfo = getCompilationUnitInfo(source);
781 if (compilationUnitInfo == null) {
782 return null;
783 }
784 CompilationUnit unit = compilationUnitInfo.parsedCompilationUnit;
785 if (unit == null) {
786 unit = compilationUnitInfo.resolvedCompilationUnit;
787 }
788 if (unit != null) {
789 return unit.accept(new ASTCloner()) as CompilationUnit;
790 }
791 unit = internalParseCompilationUnit(compilationUnitInfo, source);
792 compilationUnitInfo.clearParsedUnit();
793 return unit;
794 }
795 }
796 AnalysisContext extractContext(SourceContainer container) => extractContextInt o(container, (AnalysisEngine.instance.createAnalysisContext() as AnalysisContext Impl));
797 InternalAnalysisContext extractContextInto(SourceContainer container, Internal AnalysisContext newContext) {
728 List<Source> sourcesToRemove = new List<Source>(); 798 List<Source> sourcesToRemove = new List<Source>();
729 { 799 {
730 for (MapEntry<Source, SourceInfo> entry in getMapEntrySet(_sourceMap)) { 800 for (MapEntry<Source, SourceInfo> entry in getMapEntrySet(_sourceMap)) {
731 Source source = entry.getKey(); 801 Source source = entry.getKey();
732 if (container.contains(source)) { 802 if (container.contains(source)) {
733 sourcesToRemove.add(source); 803 sourcesToRemove.add(source);
734 newContext._sourceMap[source] = entry.getValue().copy(); 804 newContext.addSourceInfo(source, entry.getValue().copy());
735 } 805 }
736 } 806 }
737 } 807 }
738 return newContext; 808 return newContext;
739 } 809 }
740 Element getElement(ElementLocation location) { 810 Element getElement(ElementLocation location) {
741 List<String> components2 = ((location as ElementLocationImpl)).components; 811 List<String> components2 = ((location as ElementLocationImpl)).components;
742 ElementImpl element; 812 ElementImpl element;
743 { 813 {
744 Source librarySource = _sourceFactory.fromEncoding(components2[0]); 814 Source librarySource = _sourceFactory.fromEncoding(components2[0]);
745 try { 815 try {
746 element = computeLibraryElement(librarySource) as ElementImpl; 816 element = computeLibraryElement(librarySource) as ElementImpl;
747 } on AnalysisException catch (exception) { 817 } on AnalysisException catch (exception) {
748 return null; 818 return null;
749 } 819 }
750 } 820 }
751 for (int i = 1; i < components2.length; i++) { 821 for (int i = 1; i < components2.length; i++) {
752 if (element == null) { 822 if (element == null) {
753 return null; 823 return null;
754 } 824 }
755 element = element.getChild(components2[i]); 825 element = element.getChild(components2[i]);
756 } 826 }
757 return element; 827 return element;
758 } 828 }
759 List<AnalysisError> getErrors(Source source) { 829 AnalysisErrorInfo getErrors(Source source) {
760 { 830 {
761 SourceInfo info = getSourceInfo(source); 831 SourceInfo info = getSourceInfo(source);
762 if (info is CompilationUnitInfo) { 832 if (info is CompilationUnitInfo) {
763 return ((info as CompilationUnitInfo)).allErrors; 833 CompilationUnitInfo compilationUnitInfo = info as CompilationUnitInfo;
834 return new AnalysisErrorInfoImpl(compilationUnitInfo.allErrors, compilat ionUnitInfo.lineInfo);
764 } 835 }
765 return AnalysisError.NO_ERRORS; 836 return new AnalysisErrorInfoImpl(AnalysisError.NO_ERRORS, info.lineInfo);
766 } 837 }
767 } 838 }
768 HtmlElement getHtmlElement(Source source) { 839 HtmlElement getHtmlElement(Source source) {
769 { 840 {
770 SourceInfo info = getSourceInfo(source); 841 SourceInfo info = getSourceInfo(source);
771 if (info is HtmlUnitInfo) { 842 if (info is HtmlUnitInfo) {
772 return ((info as HtmlUnitInfo)).element; 843 return ((info as HtmlUnitInfo)).element;
773 } 844 }
774 return null; 845 return null;
775 } 846 }
776 } 847 }
777 List<Source> getHtmlFilesReferencing(Source source) { 848 List<Source> getHtmlFilesReferencing(Source source) {
778 { 849 {
779 SourceInfo info = getSourceInfo(source); 850 List<Source> htmlSources = new List<Source>();
780 if (info is LibraryInfo) { 851 while (true) {
781 return ((info as LibraryInfo)).htmlSources; 852 if (getKindOf(source) == SourceKind.LIBRARY) {
782 } else if (info is CompilationUnitInfo) { 853 } else if (getKindOf(source) == SourceKind.PART) {
783 List<Source> sources = new List<Source>(); 854 List<Source> librarySources = getLibrariesContaining(source);
784 for (Source librarySource in ((info as CompilationUnitInfo)).librarySour ces) { 855 for (MapEntry<Source, SourceInfo> entry in getMapEntrySet(_sourceMap)) {
785 LibraryInfo libraryInfo = getLibraryInfo(librarySource); 856 if (identical(entry.getValue().kind, SourceKind.HTML)) {
786 for (Source htmlSource in libraryInfo.htmlSources) { 857 if (containsAny(((entry.getValue() as HtmlUnitInfo)).librarySource s, librarySources)) {
787 sources.add(htmlSource); 858 htmlSources.add(entry.getKey());
859 }
860 }
788 } 861 }
789 } 862 }
790 if (!sources.isEmpty) { 863 break;
791 return new List.from(sources);
792 }
793 } 864 }
794 return Source.EMPTY_ARRAY; 865 if (htmlSources.isEmpty) {
866 return Source.EMPTY_ARRAY;
867 }
868 return new List.from(htmlSources);
795 } 869 }
796 } 870 }
797 List<Source> get htmlSources => getSources(SourceKind.HTML); 871 List<Source> get htmlSources => getSources(SourceKind.HTML);
798 SourceKind getKindOf(Source source) { 872 SourceKind getKindOf(Source source) {
799 { 873 {
800 SourceInfo sourceInfo = getSourceInfo(source); 874 SourceInfo sourceInfo = getSourceInfo(source);
801 if (sourceInfo == null) { 875 if (sourceInfo == null) {
802 return SourceKind.UNKNOWN; 876 return SourceKind.UNKNOWN;
803 } 877 }
804 return sourceInfo.kind; 878 return sourceInfo.kind;
(...skipping 20 matching lines...) Expand all
825 SourceInfo info = entry.getValue(); 899 SourceInfo info = entry.getValue();
826 if (identical(info.kind, SourceKind.LIBRARY) && !source.isInSystemLibrar y()) { 900 if (identical(info.kind, SourceKind.LIBRARY) && !source.isInSystemLibrar y()) {
827 sources.add(source); 901 sources.add(source);
828 } 902 }
829 } 903 }
830 } 904 }
831 return new List.from(sources); 905 return new List.from(sources);
832 } 906 }
833 List<Source> getLibrariesContaining(Source source) { 907 List<Source> getLibrariesContaining(Source source) {
834 { 908 {
835 SourceInfo info = getSourceInfo(source); 909 List<Source> librarySources = new List<Source>();
836 if (info is CompilationUnitInfo) { 910 for (MapEntry<Source, SourceInfo> entry in getMapEntrySet(_sourceMap)) {
837 return ((info as CompilationUnitInfo)).librarySources; 911 if (identical(entry.getValue().kind, SourceKind.LIBRARY)) {
912 if (contains(((entry.getValue() as LibraryInfo)).unitSources, source)) {
913 librarySources.add(entry.getKey());
914 }
915 }
838 } 916 }
839 return Source.EMPTY_ARRAY; 917 if (librarySources.isEmpty) {
918 return Source.EMPTY_ARRAY;
919 }
920 return new List.from(librarySources);
840 } 921 }
841 } 922 }
842 LibraryElement getLibraryElement(Source source) { 923 LibraryElement getLibraryElement(Source source) {
843 { 924 {
844 SourceInfo info = getSourceInfo(source); 925 SourceInfo info = getSourceInfo(source);
845 if (info is LibraryInfo) { 926 if (info is LibraryInfo) {
846 return ((info as LibraryInfo)).element; 927 return ((info as LibraryInfo)).element;
847 } 928 }
848 return null; 929 return null;
849 } 930 }
850 } 931 }
851 List<Source> get librarySources => getSources(SourceKind.LIBRARY); 932 List<Source> get librarySources => getSources(SourceKind.LIBRARY);
852 LineInfo getLineInfo(Source source) { 933 LineInfo getLineInfo(Source source) {
853 { 934 {
854 SourceInfo info = getSourceInfo(source); 935 SourceInfo info = getSourceInfo(source);
855 if (info != null) { 936 if (info != null) {
856 return info.lineInfo; 937 return info.lineInfo;
857 } 938 }
858 return null; 939 return null;
859 } 940 }
860 } 941 }
861 /**
862 * Return a namespace containing mappings for all of the public names defined by the given
863 * library.
864 * @param library the library whose public namespace is to be returned
865 * @return the public namespace of the given library
866 */
867 Namespace getPublicNamespace(LibraryElement library) { 942 Namespace getPublicNamespace(LibraryElement library) {
868 Source source8 = library.definingCompilationUnit.source; 943 Source source11 = library.definingCompilationUnit.source;
869 { 944 {
870 LibraryInfo libraryInfo = getLibraryInfo(source8); 945 LibraryInfo libraryInfo = getLibraryInfo(source11);
871 if (libraryInfo == null) { 946 if (libraryInfo == null) {
872 return null; 947 return null;
873 } 948 }
874 Namespace namespace = libraryInfo.publicNamespace; 949 Namespace namespace = libraryInfo.publicNamespace;
875 if (namespace == null) { 950 if (namespace == null) {
876 NamespaceBuilder builder = new NamespaceBuilder(); 951 NamespaceBuilder builder = new NamespaceBuilder();
877 namespace = builder.createPublicNamespace(library); 952 namespace = builder.createPublicNamespace(library);
878 libraryInfo.publicNamespace = namespace; 953 libraryInfo.publicNamespace = namespace;
879 } 954 }
880 return namespace; 955 return namespace;
881 } 956 }
882 } 957 }
883 /**
884 * Return a namespace containing mappings for all of the public names defined by the library
885 * defined by the given source.
886 * @param source the source defining the library whose public namespace is to be returned
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
889 */
890 Namespace getPublicNamespace2(Source source) { 958 Namespace getPublicNamespace2(Source source) {
891 { 959 {
892 LibraryInfo libraryInfo = getLibraryInfo(source); 960 LibraryInfo libraryInfo = getLibraryInfo(source);
893 if (libraryInfo == null) { 961 if (libraryInfo == null) {
894 return null; 962 return null;
895 } 963 }
896 Namespace namespace = libraryInfo.publicNamespace; 964 Namespace namespace = libraryInfo.publicNamespace;
897 if (namespace == null) { 965 if (namespace == null) {
898 LibraryElement library = computeLibraryElement(source); 966 LibraryElement library = computeLibraryElement(source);
899 if (library == null) { 967 if (library == null) {
900 return null; 968 return null;
901 } 969 }
902 NamespaceBuilder builder = new NamespaceBuilder(); 970 NamespaceBuilder builder = new NamespaceBuilder();
903 namespace = builder.createPublicNamespace(library); 971 namespace = builder.createPublicNamespace(library);
904 libraryInfo.publicNamespace = namespace; 972 libraryInfo.publicNamespace = namespace;
905 } 973 }
906 return namespace; 974 return namespace;
907 } 975 }
908 } 976 }
977 CompilationUnit getResolvedCompilationUnit(Source unitSource, LibraryElement l ibrary) {
978 if (library == null) {
979 return null;
980 }
981 return getResolvedCompilationUnit2(unitSource, library.source);
982 }
983 CompilationUnit getResolvedCompilationUnit2(Source unitSource, Source libraryS ource) {
984 {
985 accessed(unitSource);
986 CompilationUnitInfo compilationUnitInfo = getCompilationUnitInfo(unitSourc e);
987 if (compilationUnitInfo == null) {
988 return null;
989 }
990 return compilationUnitInfo.resolvedCompilationUnit;
991 }
992 }
909 SourceFactory get sourceFactory => _sourceFactory; 993 SourceFactory get sourceFactory => _sourceFactory;
910 bool isClientLibrary(Source librarySource) { 994 bool isClientLibrary(Source librarySource) {
911 SourceInfo sourceInfo = getSourceInfo(librarySource); 995 SourceInfo sourceInfo = getSourceInfo(librarySource);
912 if (sourceInfo is LibraryInfo) { 996 if (sourceInfo is LibraryInfo) {
913 LibraryInfo libraryInfo = sourceInfo as LibraryInfo; 997 LibraryInfo libraryInfo = sourceInfo as LibraryInfo;
914 if (libraryInfo.hasInvalidLaunchable() || libraryInfo.hasInvalidClientServ er()) { 998 if (libraryInfo.hasInvalidLaunchable() || libraryInfo.hasInvalidClientServ er()) {
915 return false; 999 return false;
916 } 1000 }
917 return libraryInfo.isLaunchable() && libraryInfo.isClient(); 1001 return libraryInfo.isLaunchable() && libraryInfo.isClient();
918 } 1002 }
(...skipping 17 matching lines...) Expand all
936 SourceInfo existingInfo = getSourceInfo(newSource); 1020 SourceInfo existingInfo = getSourceInfo(newSource);
937 if (existingInfo == null) { 1021 if (existingInfo == null) {
938 _sourceMap[newSource] = entry.getValue().copy(); 1022 _sourceMap[newSource] = entry.getValue().copy();
939 } else { 1023 } else {
940 } 1024 }
941 } 1025 }
942 } 1026 }
943 } 1027 }
944 CompilationUnit parseCompilationUnit(Source source) { 1028 CompilationUnit parseCompilationUnit(Source source) {
945 { 1029 {
1030 accessed(source);
946 CompilationUnitInfo compilationUnitInfo = getCompilationUnitInfo(source); 1031 CompilationUnitInfo compilationUnitInfo = getCompilationUnitInfo(source);
947 if (compilationUnitInfo == null) { 1032 if (compilationUnitInfo == null) {
948 return null; 1033 return null;
949 } 1034 }
950 CompilationUnit unit = compilationUnitInfo.resolvedCompilationUnit; 1035 CompilationUnit unit = compilationUnitInfo.resolvedCompilationUnit;
951 if (unit == null) { 1036 if (unit == null) {
952 unit = compilationUnitInfo.parsedCompilationUnit; 1037 unit = compilationUnitInfo.parsedCompilationUnit;
953 if (unit == null) { 1038 if (unit == null) {
954 RecordingErrorListener errorListener = new RecordingErrorListener(); 1039 unit = internalParseCompilationUnit(compilationUnitInfo, source);
955 AnalysisContextImpl_ScanResult scanResult = internalScan(source, error Listener);
956 Parser parser = new Parser(source, errorListener);
957 unit = parser.parseCompilationUnit(scanResult._token);
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 } 1040 }
966 } 1041 }
967 return unit; 1042 return unit;
968 } 1043 }
969 } 1044 }
970 HtmlUnit parseHtmlUnit(Source source) { 1045 HtmlUnit parseHtmlUnit(Source source) {
971 { 1046 {
1047 accessed(source);
972 HtmlUnitInfo htmlUnitInfo = getHtmlUnitInfo(source); 1048 HtmlUnitInfo htmlUnitInfo = getHtmlUnitInfo(source);
973 if (htmlUnitInfo == null) { 1049 if (htmlUnitInfo == null) {
974 return null; 1050 return null;
975 } 1051 }
976 HtmlUnit unit = htmlUnitInfo.resolvedUnit; 1052 HtmlUnit unit = htmlUnitInfo.resolvedUnit;
977 if (unit == null) { 1053 if (unit == null) {
978 unit = htmlUnitInfo.parsedUnit; 1054 unit = htmlUnitInfo.parsedUnit;
979 if (unit == null) { 1055 if (unit == null) {
980 HtmlParseResult result = new HtmlParser(source).parse(scanHtml(source) ); 1056 HtmlParseResult result = new HtmlParser(source).parse(scanHtml(source) );
981 unit = result.htmlUnit; 1057 unit = result.htmlUnit;
982 htmlUnitInfo.lineInfo = new LineInfo(result.lineStarts); 1058 htmlUnitInfo.lineInfo = new LineInfo(result.lineStarts);
983 htmlUnitInfo.parsedUnit = unit; 1059 htmlUnitInfo.parsedUnit = unit;
984 for (SourceInfo sourceInfo in _sourceMap.values) { 1060 htmlUnitInfo.librarySources = getLibrarySources2(source, unit);
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 } 1061 }
996 } 1062 }
997 return unit; 1063 return unit;
998 } 1064 }
999 } 1065 }
1000 List<ChangeNotice> performAnalysisTask() { 1066 List<ChangeNotice> performAnalysisTask() {
1001 { 1067 {
1002 if (!performSingleAnalysisTask() && _pendingNotices.isEmpty) { 1068 if (!performSingleAnalysisTask() && _pendingNotices.isEmpty) {
1003 return null; 1069 return null;
1004 } 1070 }
1005 if (_pendingNotices.isEmpty) { 1071 if (_pendingNotices.isEmpty) {
1006 return ChangeNoticeImpl.EMPTY_ARRAY; 1072 return ChangeNoticeImpl.EMPTY_ARRAY;
1007 } 1073 }
1008 List<ChangeNotice> notices = new List.from(_pendingNotices.values); 1074 List<ChangeNotice> notices = new List.from(_pendingNotices.values);
1009 _pendingNotices.clear(); 1075 _pendingNotices.clear();
1010 return notices; 1076 return notices;
1011 } 1077 }
1012 } 1078 }
1013 /**
1014 * Given a table mapping the source for the libraries represented by the corre sponding elements to
1015 * the elements representing the libraries, record those mappings.
1016 * @param elementMap a table mapping the source for the libraries represented by the elements to
1017 * the elements representing the libraries
1018 */
1019 void recordLibraryElements(Map<Source, LibraryElement> elementMap) { 1079 void recordLibraryElements(Map<Source, LibraryElement> elementMap) {
1020 Source htmlSource = _sourceFactory.forUri("dart:html"); 1080 Source htmlSource = _sourceFactory.forUri("dart:html");
1021 { 1081 {
1022 for (MapEntry<Source, LibraryElement> entry in getMapEntrySet(elementMap)) { 1082 for (MapEntry<Source, LibraryElement> entry in getMapEntrySet(elementMap)) {
1083 Source librarySource = entry.getKey();
1023 LibraryElement library = entry.getValue(); 1084 LibraryElement library = entry.getValue();
1024 LibraryInfo libraryInfo = getLibraryInfo(entry.getKey()); 1085 LibraryInfo libraryInfo = getLibraryInfo(librarySource);
1025 if (libraryInfo != null) { 1086 if (libraryInfo != null) {
1026 libraryInfo.element = library; 1087 libraryInfo.element = library;
1027 libraryInfo.launchable = library.entryPoint != null; 1088 libraryInfo.launchable = library.entryPoint != null;
1028 libraryInfo.client = isClient(library, htmlSource, new Set<LibraryElem ent>()); 1089 libraryInfo.client = isClient(library, htmlSource, new Set<LibraryElem ent>());
1029 } 1090 List<Source> unitSources = new List<Source>();
1030 Source librarySource = library.source; 1091 unitSources.add(librarySource);
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) { 1092 for (CompilationUnitElement part in library.parts) {
1041 Source partSource = part.source; 1093 Source partSource = part.source;
1042 CompilationUnitInfo partInfo = partSource == null ? null : getCompil ationUnitInfo(partSource); 1094 unitSources.add(partSource);
1043 if (partInfo != null) {
1044 partInfo.addLibrarySource(librarySource);
1045 }
1046 } 1095 }
1096 libraryInfo.unitSources = new List.from(unitSources);
1047 } 1097 }
1048 } 1098 }
1049 } 1099 }
1050 } 1100 }
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) { 1101 void recordResolutionErrors(Source source, List<AnalysisError> errors, LineInf o lineInfo5) {
1059 { 1102 {
1060 CompilationUnitInfo compilationUnitInfo = getCompilationUnitInfo(source); 1103 CompilationUnitInfo compilationUnitInfo = getCompilationUnitInfo(source);
1061 if (compilationUnitInfo != null) { 1104 if (compilationUnitInfo != null) {
1062 compilationUnitInfo.lineInfo = lineInfo5; 1105 compilationUnitInfo.lineInfo = lineInfo5;
1063 compilationUnitInfo.resolutionErrors = errors; 1106 compilationUnitInfo.resolutionErrors = errors;
1064 } 1107 }
1065 getNotice(source).setErrors(compilationUnitInfo.allErrors, lineInfo5); 1108 getNotice(source).setErrors(compilationUnitInfo.allErrors, lineInfo5);
1066 } 1109 }
1067 } 1110 }
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) { 1111 void recordResolvedCompilationUnit(Source source, CompilationUnit unit) {
1074 { 1112 {
1075 CompilationUnitInfo compilationUnitInfo = getCompilationUnitInfo(source); 1113 CompilationUnitInfo compilationUnitInfo = getCompilationUnitInfo(source);
1076 if (compilationUnitInfo != null) { 1114 if (compilationUnitInfo != null) {
1077 compilationUnitInfo.resolvedCompilationUnit = unit; 1115 compilationUnitInfo.resolvedCompilationUnit = unit;
1116 compilationUnitInfo.clearParsedUnit();
1078 getNotice(source).compilationUnit = unit; 1117 getNotice(source).compilationUnit = unit;
1079 } 1118 }
1080 } 1119 }
1081 } 1120 }
1082 CompilationUnit resolveCompilationUnit(Source source15, LibraryElement library ) { 1121 CompilationUnit resolveCompilationUnit(Source source20, LibraryElement library ) {
1083 if (library == null) { 1122 if (library == null) {
1084 return null; 1123 return null;
1085 } 1124 }
1086 return resolveCompilationUnit2(source15, library.source); 1125 return resolveCompilationUnit2(source20, library.source);
1087 } 1126 }
1088 CompilationUnit resolveCompilationUnit2(Source unitSource, Source librarySourc e) { 1127 CompilationUnit resolveCompilationUnit2(Source unitSource, Source librarySourc e) {
1089 { 1128 {
1129 accessed(unitSource);
1090 CompilationUnitInfo compilationUnitInfo = getCompilationUnitInfo(unitSourc e); 1130 CompilationUnitInfo compilationUnitInfo = getCompilationUnitInfo(unitSourc e);
1091 if (compilationUnitInfo == null) { 1131 if (compilationUnitInfo == null) {
1092 return null; 1132 return null;
1093 } 1133 }
1094 CompilationUnit unit = compilationUnitInfo.resolvedCompilationUnit; 1134 CompilationUnit unit = compilationUnitInfo.resolvedCompilationUnit;
1095 if (unit == null) { 1135 if (unit == null) {
1096 computeLibraryElement(librarySource); 1136 disableCacheRemoval();
1097 unit = compilationUnitInfo.resolvedCompilationUnit; 1137 try {
1138 LibraryElement libraryElement = computeLibraryElement(librarySource);
1139 unit = compilationUnitInfo.resolvedCompilationUnit;
1140 if (unit == null && libraryElement != null) {
1141 Source coreLibrarySource = libraryElement.context.sourceFactory.forU ri(DartSdk.DART_CORE);
1142 LibraryElement coreElement = computeLibraryElement(coreLibrarySource );
1143 TypeProvider typeProvider = new TypeProviderImpl(coreElement);
1144 CompilationUnit unitAST = computeResolvableCompilationUnit(unitSourc e);
1145 new DeclarationResolver().resolve(unitAST, find(libraryElement, unit Source));
1146 RecordingErrorListener errorListener = new RecordingErrorListener();
1147 TypeResolverVisitor typeResolverVisitor = new TypeResolverVisitor.co n2(libraryElement, unitSource, typeProvider, errorListener);
1148 unitAST.accept(typeResolverVisitor);
1149 ResolverVisitor resolverVisitor = new ResolverVisitor.con2(libraryEl ement, unitSource, typeProvider, errorListener);
1150 unitAST.accept(resolverVisitor);
1151 ErrorReporter errorReporter = new ErrorReporter(errorListener, unitS ource);
1152 ErrorVerifier errorVerifier = new ErrorVerifier(errorReporter, libra ryElement, typeProvider);
1153 unitAST.accept(errorVerifier);
1154 ConstantVerifier constantVerifier = new ConstantVerifier(errorReport er);
1155 unitAST.accept(constantVerifier);
1156 unitAST.resolutionErrors = errorListener.errors;
1157 compilationUnitInfo.resolvedCompilationUnit = unitAST;
1158 unit = unitAST;
1159 }
1160 } finally {
1161 enableCacheRemoval();
1162 }
1098 } 1163 }
1099 return unit; 1164 return unit;
1100 } 1165 }
1101 } 1166 }
1102 HtmlUnit resolveHtmlUnit(Source unitSource) { 1167 HtmlUnit resolveHtmlUnit(Source unitSource) {
1103 { 1168 {
1169 accessed(unitSource);
1104 HtmlUnitInfo htmlUnitInfo = getHtmlUnitInfo(unitSource); 1170 HtmlUnitInfo htmlUnitInfo = getHtmlUnitInfo(unitSource);
1105 if (htmlUnitInfo == null) { 1171 if (htmlUnitInfo == null) {
1106 return null; 1172 return null;
1107 } 1173 }
1108 HtmlUnit unit = htmlUnitInfo.resolvedUnit; 1174 HtmlUnit unit = htmlUnitInfo.resolvedUnit;
1109 if (unit == null) { 1175 if (unit == null) {
1110 computeHtmlElement(unitSource); 1176 disableCacheRemoval();
1111 unit = htmlUnitInfo.resolvedUnit; 1177 try {
1178 computeHtmlElement(unitSource);
1179 unit = htmlUnitInfo.resolvedUnit;
1180 if (unit == null) {
1181 unit = parseHtmlUnit(unitSource);
1182 }
1183 } finally {
1184 enableCacheRemoval();
1185 }
1112 } 1186 }
1113 return unit; 1187 return unit;
1114 } 1188 }
1115 } 1189 }
1116 void setContents(Source source, String contents) { 1190 void setContents(Source source, String contents) {
1117 { 1191 {
1118 _sourceFactory.setContents(source, contents); 1192 _sourceFactory.setContents(source, contents);
1119 sourceChanged(source); 1193 sourceChanged(source);
1120 } 1194 }
1121 } 1195 }
(...skipping 30 matching lines...) Expand all
1152 Iterable<Source> sourcesToResolve(List<Source> changedSources) { 1226 Iterable<Source> sourcesToResolve(List<Source> changedSources) {
1153 List<Source> librarySources = new List<Source>(); 1227 List<Source> librarySources = new List<Source>();
1154 for (Source source in changedSources) { 1228 for (Source source in changedSources) {
1155 if (identical(computeKindOf(source), SourceKind.LIBRARY)) { 1229 if (identical(computeKindOf(source), SourceKind.LIBRARY)) {
1156 librarySources.add(source); 1230 librarySources.add(source);
1157 } 1231 }
1158 } 1232 }
1159 return librarySources; 1233 return librarySources;
1160 } 1234 }
1161 /** 1235 /**
1236 * Record that the given source was just accessed for some unspecified purpose .
1237 * <p>
1238 * Note: This method must only be invoked while we are synchronized on {@link #cacheLock}.
1239 * @param source the source that was accessed
1240 */
1241 void accessed(Source source) {
1242 if (_recentlyUsed.contains(source)) {
1243 _recentlyUsed.remove(source);
1244 _recentlyUsed.add(source);
1245 return;
1246 }
1247 if (_cacheRemovalCount == 0 && _recentlyUsed.length >= _MAX_CACHE_SIZE) {
1248 Source removedSource = _recentlyUsed.removeAt(0);
1249 SourceInfo sourceInfo = _sourceMap[removedSource];
1250 if (sourceInfo is HtmlUnitInfo) {
1251 ((sourceInfo as HtmlUnitInfo)).clearParsedUnit();
1252 ((sourceInfo as HtmlUnitInfo)).clearResolvedUnit();
1253 } else if (sourceInfo is CompilationUnitInfo) {
1254 ((sourceInfo as CompilationUnitInfo)).clearParsedUnit();
1255 ((sourceInfo as CompilationUnitInfo)).clearResolvedUnit();
1256 }
1257 }
1258 _recentlyUsed.add(source);
1259 }
1260 /**
1162 * Add all of the sources contained in the given source container to the given list of sources. 1261 * Add all of the sources contained in the given source container to the given list of sources.
1163 * <p> 1262 * <p>
1164 * Note: This method must only be invoked while we are synchronized on {@link #cacheLock}. 1263 * Note: This method must only be invoked while we are synchronized on {@link #cacheLock}.
1165 * @param sources the list to which sources are to be added 1264 * @param sources the list to which sources are to be added
1166 * @param container the source container containing the sources to be added to the list 1265 * @param container the source container containing the sources to be added to the list
1167 */ 1266 */
1168 void addSourcesInContainer(List<Source> sources, SourceContainer container) { 1267 void addSourcesInContainer(List<Source> sources, SourceContainer container) {
1169 for (Source source in _sourceMap.keys.toSet()) { 1268 for (Source source in _sourceMap.keys.toSet()) {
1170 if (container.contains(source)) { 1269 if (container.contains(source)) {
1171 sources.add(source); 1270 sources.add(source);
1172 } 1271 }
1173 } 1272 }
1174 } 1273 }
1175 /** 1274 /**
1275 * Return {@code true} if the given array of sources contains the given source .
1276 * @param sources the sources being searched
1277 * @param targetSource the source being searched for
1278 * @return {@code true} if the given source is in the array
1279 */
1280 bool contains(List<Source> sources, Source targetSource) {
1281 for (Source source in sources) {
1282 if (source == targetSource) {
1283 return true;
1284 }
1285 }
1286 return false;
1287 }
1288 /**
1289 * Return {@code true} if the given array of sources contains any of the given target sources.
1290 * @param sources the sources being searched
1291 * @param targetSources the sources being searched for
1292 * @return {@code true} if any of the given target sources are in the array
1293 */
1294 bool containsAny(List<Source> sources, List<Source> targetSources) {
1295 for (Source targetSource in targetSources) {
1296 if (contains(sources, targetSource)) {
1297 return true;
1298 }
1299 }
1300 return false;
1301 }
1302 /**
1176 * Create a source information object suitable for the given source. Return th e source information 1303 * Create a source information object suitable for the given source. Return th e source information
1177 * object that was created, or {@code null} if the source should not be tracke d by this context. 1304 * object that was created, or {@code null} if the source should not be tracke d by this context.
1178 * @param source the source for which an information object is being created 1305 * @param source the source for which an information object is being created
1179 * @return the source information object that was created 1306 * @return the source information object that was created
1180 */ 1307 */
1181 SourceInfo createSourceInfo(Source source) { 1308 SourceInfo createSourceInfo(Source source) {
1182 String name = source.shortName; 1309 String name = source.shortName;
1183 if (AnalysisEngine.isHtmlFileName(name)) { 1310 if (AnalysisEngine.isHtmlFileName(name)) {
1184 HtmlUnitInfo info = new HtmlUnitInfo(); 1311 HtmlUnitInfo info = new HtmlUnitInfo();
1185 _sourceMap[source] = info; 1312 _sourceMap[source] = info;
1186 return info; 1313 return info;
1187 } else if (AnalysisEngine.isDartFileName(name)) { 1314 } else if (AnalysisEngine.isDartFileName(name)) {
1188 DartInfo info = DartInfo.instance; 1315 DartInfo info = DartInfo.pendingInstance;
1189 _sourceMap[source] = info; 1316 _sourceMap[source] = info;
1190 return info; 1317 return info;
1191 } 1318 }
1192 return null; 1319 return null;
1193 } 1320 }
1194 /** 1321 /**
1322 * Disable flushing information from the cache until {@link #enableCacheRemova l()} has been
1323 * called.
1324 */
1325 void disableCacheRemoval() {
1326 _cacheRemovalCount++;
1327 }
1328 /**
1329 * Re-enable flushing information from the cache.
1330 */
1331 void enableCacheRemoval() {
1332 if (_cacheRemovalCount > 0) {
1333 _cacheRemovalCount--;
1334 }
1335 if (_cacheRemovalCount == 0) {
1336 while (_recentlyUsed.length >= _MAX_CACHE_SIZE) {
1337 Source removedSource = _recentlyUsed.removeAt(0);
1338 SourceInfo sourceInfo = _sourceMap[removedSource];
1339 if (sourceInfo is HtmlUnitInfo) {
1340 ((sourceInfo as HtmlUnitInfo)).clearParsedUnit();
1341 ((sourceInfo as HtmlUnitInfo)).clearResolvedUnit();
1342 } else if (sourceInfo is CompilationUnitInfo) {
1343 ((sourceInfo as CompilationUnitInfo)).clearParsedUnit();
1344 ((sourceInfo as CompilationUnitInfo)).clearResolvedUnit();
1345 }
1346 }
1347 }
1348 }
1349 /**
1350 * Search the compilation units that are part of the given library and return the element
1351 * representing the compilation unit with the given source. Return {@code null } if there is no
1352 * such compilation unit.
1353 * @param libraryElement the element representing the library being searched t hrough
1354 * @param unitSource the source for the compilation unit whose element is to b e returned
1355 * @return the element representing the compilation unit
1356 */
1357 CompilationUnitElement find(LibraryElement libraryElement, Source unitSource) {
1358 CompilationUnitElement element = libraryElement.definingCompilationUnit;
1359 if (element.source == unitSource) {
1360 return element;
1361 }
1362 for (CompilationUnitElement partElement in libraryElement.parts) {
1363 if (partElement.source == unitSource) {
1364 return partElement;
1365 }
1366 }
1367 return null;
1368 }
1369 /**
1195 * Return the compilation unit information associated with the given source, o r {@code null} if 1370 * 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 1371 * 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 1372 * 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 1373 * SDK are implicitly part of every analysis context and are therefore only ad ded to the map when
1199 * first accessed. 1374 * first accessed.
1200 * <p> 1375 * <p>
1201 * <b>Note:</b> This method must only be invoked while we are synchronized on {@link #cacheLock}. 1376 * <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 1377 * @param source the source for which information is being sought
1203 * @return the compilation unit information associated with the given source 1378 * @return the compilation unit information associated with the given source
1204 */ 1379 */
1205 CompilationUnitInfo getCompilationUnitInfo(Source source) { 1380 CompilationUnitInfo getCompilationUnitInfo(Source source) {
1206 SourceInfo sourceInfo = getSourceInfo(source); 1381 SourceInfo sourceInfo = getSourceInfo(source);
1207 if (sourceInfo == null) { 1382 if (sourceInfo == null) {
1208 sourceInfo = new CompilationUnitInfo(); 1383 sourceInfo = new CompilationUnitInfo();
1209 _sourceMap[source] = sourceInfo; 1384 _sourceMap[source] = sourceInfo;
1210 return sourceInfo as CompilationUnitInfo; 1385 return sourceInfo as CompilationUnitInfo;
1211 } else if (sourceInfo is CompilationUnitInfo) { 1386 } else if (sourceInfo is CompilationUnitInfo) {
1212 return sourceInfo as CompilationUnitInfo; 1387 return sourceInfo as CompilationUnitInfo;
1213 } else if (sourceInfo is DartInfo) { 1388 } else if (identical(sourceInfo, DartInfo.pendingInstance)) {
1214 sourceInfo = internalComputeKindOf(source, sourceInfo); 1389 sourceInfo = internalComputeKindOf(source);
1215 if (sourceInfo is CompilationUnitInfo) { 1390 if (sourceInfo is CompilationUnitInfo) {
1216 return sourceInfo as CompilationUnitInfo; 1391 return sourceInfo as CompilationUnitInfo;
1217 } 1392 }
1218 } 1393 }
1219 return null; 1394 return null;
1220 } 1395 }
1221 /** 1396 /**
1222 * Return the HTML unit information associated with the given source, or {@cod e null} if the 1397 * 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 1398 * 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 1399 * information rather than accessing the HTML unit map directly because source s in the SDK are
(...skipping 26 matching lines...) Expand all
1251 * @return the library information associated with the given source 1426 * @return the library information associated with the given source
1252 */ 1427 */
1253 LibraryInfo getLibraryInfo(Source source) { 1428 LibraryInfo getLibraryInfo(Source source) {
1254 SourceInfo sourceInfo = getSourceInfo(source); 1429 SourceInfo sourceInfo = getSourceInfo(source);
1255 if (sourceInfo == null) { 1430 if (sourceInfo == null) {
1256 sourceInfo = new LibraryInfo(); 1431 sourceInfo = new LibraryInfo();
1257 _sourceMap[source] = sourceInfo; 1432 _sourceMap[source] = sourceInfo;
1258 return sourceInfo as LibraryInfo; 1433 return sourceInfo as LibraryInfo;
1259 } else if (sourceInfo is LibraryInfo) { 1434 } else if (sourceInfo is LibraryInfo) {
1260 return sourceInfo as LibraryInfo; 1435 return sourceInfo as LibraryInfo;
1261 } else if (sourceInfo is DartInfo) { 1436 } else if (identical(sourceInfo, DartInfo.pendingInstance)) {
1262 sourceInfo = internalComputeKindOf(source, sourceInfo); 1437 sourceInfo = internalComputeKindOf(source);
1263 if (sourceInfo is LibraryInfo) { 1438 if (sourceInfo is LibraryInfo) {
1264 return sourceInfo as LibraryInfo; 1439 return sourceInfo as LibraryInfo;
1265 } 1440 }
1266 } 1441 }
1267 return null; 1442 return null;
1268 } 1443 }
1269 /** 1444 /**
1270 * Return the sources of libraries that are referenced in the specified HTML f ile. 1445 * 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 1446 * @param htmlSource the source of the HTML file being analyzed
1272 * @param htmlUnit the AST for the HTML file being analyzed 1447 * @param htmlUnit the AST for the HTML file being analyzed
1273 * @return the sources of libraries that are referenced in the HTML file 1448 * @return the sources of libraries that are referenced in the HTML file
1274 */ 1449 */
1275 List<Source> getLibrarySources2(Source htmlSource, HtmlUnit htmlUnit) { 1450 List<Source> getLibrarySources2(Source htmlSource, HtmlUnit htmlUnit) {
1276 List<Source> libraries = new List<Source>(); 1451 List<Source> libraries = new List<Source>();
1277 htmlUnit.accept(new SimpleXmlVisitor_3(htmlSource, libraries)); 1452 htmlUnit.accept(new RecursiveXmlVisitor_6(this, htmlSource, libraries));
1278 return libraries; 1453 if (libraries.isEmpty) {
1454 return Source.EMPTY_ARRAY;
1455 }
1456 return new List.from(libraries);
1279 } 1457 }
1280 /** 1458 /**
1281 * Return a change notice for the given source, creating one if one does not a lready exist. 1459 * 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 1460 * @param source the source for which changes are being reported
1283 * @return a change notice for the given source 1461 * @return a change notice for the given source
1284 */ 1462 */
1285 ChangeNoticeImpl getNotice(Source source) { 1463 ChangeNoticeImpl getNotice(Source source) {
1286 ChangeNoticeImpl notice = _pendingNotices[source]; 1464 ChangeNoticeImpl notice = _pendingNotices[source];
1287 if (notice == null) { 1465 if (notice == null) {
1288 notice = new ChangeNoticeImpl(source); 1466 notice = new ChangeNoticeImpl(source);
(...skipping 28 matching lines...) Expand all
1317 { 1495 {
1318 for (MapEntry<Source, SourceInfo> entry in getMapEntrySet(_sourceMap)) { 1496 for (MapEntry<Source, SourceInfo> entry in getMapEntrySet(_sourceMap)) {
1319 if (identical(entry.getValue().kind, kind3)) { 1497 if (identical(entry.getValue().kind, kind3)) {
1320 sources.add(entry.getKey()); 1498 sources.add(entry.getKey());
1321 } 1499 }
1322 } 1500 }
1323 } 1501 }
1324 return new List.from(sources); 1502 return new List.from(sources);
1325 } 1503 }
1326 /** 1504 /**
1327 * Return {@code true} if the given compilation unit has a part-of directive. 1505 * Return {@code true} if the given compilation unit has a part-of directive b ut no library
1506 * directive.
1328 * @param unit the compilation unit being tested 1507 * @param unit the compilation unit being tested
1329 * @return {@code true} if the compilation unit has a part-of directive 1508 * @return {@code true} if the compilation unit has a part-of directive
1330 */ 1509 */
1331 bool hasPartOfDirective(CompilationUnit unit) { 1510 bool hasPartOfDirective(CompilationUnit unit) {
1511 bool hasPartOf = false;
1332 for (Directive directive in unit.directives) { 1512 for (Directive directive in unit.directives) {
1333 if (directive is PartOfDirective) { 1513 if (directive is PartOfDirective) {
1334 return true; 1514 hasPartOf = true;
1515 } else if (directive is LibraryDirective) {
1516 return false;
1335 } 1517 }
1336 } 1518 }
1337 return false; 1519 return hasPartOf;
1338 } 1520 }
1339 SourceInfo internalComputeKindOf(Source source, SourceInfo info) { 1521 /**
1522 * Compute the kind of the given source. This method should only be invoked wh en the kind is not
1523 * already known. In such a case the source is currently being represented by a {@link DartInfo}.
1524 * After this method has run the source will be represented by a new informati on object that is
1525 * appropriate to the computed kind of the source.
1526 * @param source the source for which a kind is to be computed
1527 * @return the new source info that was created to represent the source
1528 */
1529 SourceInfo internalComputeKindOf(Source source) {
1340 try { 1530 try {
1531 accessed(source);
1341 RecordingErrorListener errorListener = new RecordingErrorListener(); 1532 RecordingErrorListener errorListener = new RecordingErrorListener();
1342 AnalysisContextImpl_ScanResult scanResult = internalScan(source, errorList ener); 1533 AnalysisContextImpl_ScanResult scanResult = internalScan(source, errorList ener);
1343 Parser parser = new Parser(source, errorListener); 1534 Parser parser = new Parser(source, errorListener);
1344 CompilationUnit unit = parser.parseCompilationUnit(scanResult._token); 1535 CompilationUnit unit = parser.parseCompilationUnit(scanResult._token);
1345 LineInfo lineInfo = new LineInfo(scanResult._lineStarts); 1536 LineInfo lineInfo = new LineInfo(scanResult._lineStarts);
1346 List<AnalysisError> errors = errorListener.getErrors2(source); 1537 List<AnalysisError> errors = errorListener.getErrors2(source);
1347 unit.parsingErrors = errors; 1538 unit.parsingErrors = errors;
1348 unit.lineInfo = lineInfo; 1539 unit.lineInfo = lineInfo;
1349 CompilationUnitInfo sourceInfo; 1540 CompilationUnitInfo sourceInfo;
1350 if (hasPartOfDirective(unit)) { 1541 if (hasPartOfDirective(unit)) {
1351 sourceInfo = new CompilationUnitInfo(); 1542 sourceInfo = new CompilationUnitInfo();
1352 } else { 1543 } else {
1353 sourceInfo = new LibraryInfo(); 1544 sourceInfo = new LibraryInfo();
1354 } 1545 }
1355 sourceInfo.lineInfo = lineInfo; 1546 sourceInfo.lineInfo = lineInfo;
1356 sourceInfo.parsedCompilationUnit = unit; 1547 sourceInfo.parsedCompilationUnit = unit;
1357 sourceInfo.parseErrors = errors; 1548 sourceInfo.parseErrors = errors;
1358 _sourceMap[source] = sourceInfo; 1549 _sourceMap[source] = sourceInfo;
1359 return sourceInfo; 1550 return sourceInfo;
1360 } on AnalysisException catch (exception) { 1551 } on AnalysisException catch (exception) {
1361 return info; 1552 DartInfo sourceInfo = DartInfo.errorInstance;
1553 _sourceMap[source] = sourceInfo;
1554 return sourceInfo;
1362 } 1555 }
1363 } 1556 }
1557 CompilationUnit internalParseCompilationUnit(CompilationUnitInfo compilationUn itInfo, Source source) {
1558 accessed(source);
1559 RecordingErrorListener errorListener = new RecordingErrorListener();
1560 AnalysisContextImpl_ScanResult scanResult = internalScan(source, errorListen er);
1561 Parser parser = new Parser(source, errorListener);
1562 CompilationUnit unit = parser.parseCompilationUnit(scanResult._token);
1563 LineInfo lineInfo = new LineInfo(scanResult._lineStarts);
1564 List<AnalysisError> errors = errorListener.getErrors2(source);
1565 unit.parsingErrors = errors;
1566 unit.lineInfo = lineInfo;
1567 compilationUnitInfo.lineInfo = lineInfo;
1568 compilationUnitInfo.parsedCompilationUnit = unit;
1569 compilationUnitInfo.parseErrors = errors;
1570 return unit;
1571 }
1364 AnalysisContextImpl_ScanResult internalScan(Source source, AnalysisErrorListen er errorListener) { 1572 AnalysisContextImpl_ScanResult internalScan(Source source, AnalysisErrorListen er errorListener) {
1365 AnalysisContextImpl_ScanResult result = new AnalysisContextImpl_ScanResult() ; 1573 AnalysisContextImpl_ScanResult result = new AnalysisContextImpl_ScanResult() ;
1366 Source_ContentReceiver receiver = new Source_ContentReceiver_4(source, error Listener, result); 1574 Source_ContentReceiver receiver = new Source_ContentReceiver_7(source, error Listener, result);
1367 try { 1575 try {
1368 source.getContents(receiver); 1576 source.getContents(receiver);
1369 } catch (exception) { 1577 } catch (exception) {
1370 throw new AnalysisException.con3(exception); 1578 throw new AnalysisException.con3(exception);
1371 } 1579 }
1372 return result; 1580 return result;
1373 } 1581 }
1374 /** 1582 /**
1583 * In response to a change to at least one of the compilation units in the giv en library,
1584 * invalidate any results that are dependent on the result of resolving that l ibrary.
1585 * @param librarySource the source of the library being invalidated
1586 * @param libraryInfo the information for the library being invalidated
1587 */
1588 void invalidateLibraryResolution(Source librarySource, LibraryInfo libraryInfo ) {
1589 if (libraryInfo != null) {
1590 libraryInfo.invalidateElement();
1591 libraryInfo.invalidateLaunchable();
1592 libraryInfo.invalidatePublicNamespace();
1593 libraryInfo.invalidateResolutionErrors();
1594 libraryInfo.invalidateResolvedUnit();
1595 for (Source unitSource in libraryInfo.unitSources) {
1596 CompilationUnitInfo partInfo = getCompilationUnitInfo(unitSource);
1597 partInfo.invalidateResolutionErrors();
1598 partInfo.invalidateResolvedUnit();
1599 }
1600 libraryInfo.invalidateUnitSources();
1601 }
1602 }
1603 /**
1375 * Return {@code true} if this library is, or depends on, dart:html. 1604 * Return {@code true} if this library is, or depends on, dart:html.
1376 * @param library the library being tested 1605 * @param library the library being tested
1377 * @param visitedLibraries a collection of the libraries that have been visite d, used to prevent 1606 * @param visitedLibraries a collection of the libraries that have been visite d, used to prevent
1378 * infinite recursion 1607 * infinite recursion
1379 * @return {@code true} if this library is, or depends on, dart:html 1608 * @return {@code true} if this library is, or depends on, dart:html
1380 */ 1609 */
1381 bool isClient(LibraryElement library, Source htmlSource, Set<LibraryElement> v isitedLibraries) { 1610 bool isClient(LibraryElement library, Source htmlSource, Set<LibraryElement> v isitedLibraries) {
1382 if (visitedLibraries.contains(library)) { 1611 if (visitedLibraries.contains(library)) {
1383 return false; 1612 return false;
1384 } 1613 }
(...skipping 15 matching lines...) Expand all
1400 } 1629 }
1401 /** 1630 /**
1402 * Perform a single analysis task. 1631 * Perform a single analysis task.
1403 * <p> 1632 * <p>
1404 * <b>Note:</b> This method must only be invoked while we are synchronized on {@link #cacheLock}. 1633 * <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 1634 * @return {@code true} if work was done, implying that there might be more wo rk to be done
1406 */ 1635 */
1407 bool performSingleAnalysisTask() { 1636 bool performSingleAnalysisTask() {
1408 for (MapEntry<Source, SourceInfo> entry in getMapEntrySet(_sourceMap)) { 1637 for (MapEntry<Source, SourceInfo> entry in getMapEntrySet(_sourceMap)) {
1409 SourceInfo sourceInfo = entry.getValue(); 1638 SourceInfo sourceInfo = entry.getValue();
1410 if (identical(sourceInfo, DartInfo.instance) || sourceInfo.kind == null) { 1639 if (identical(sourceInfo, DartInfo.pendingInstance)) {
1411 internalComputeKindOf(entry.getKey(), sourceInfo); 1640 internalComputeKindOf(entry.getKey());
1412 return true; 1641 return true;
1413 } 1642 }
1414 } 1643 }
1415 for (MapEntry<Source, SourceInfo> entry in getMapEntrySet(_sourceMap)) { 1644 for (MapEntry<Source, SourceInfo> entry in getMapEntrySet(_sourceMap)) {
1416 SourceInfo sourceInfo = entry.getValue(); 1645 SourceInfo sourceInfo = entry.getValue();
1417 if (sourceInfo is CompilationUnitInfo) { 1646 if (sourceInfo is CompilationUnitInfo) {
1418 CompilationUnitInfo unitInfo = sourceInfo as CompilationUnitInfo; 1647 CompilationUnitInfo unitInfo = sourceInfo as CompilationUnitInfo;
1419 if (unitInfo.hasInvalidParsedUnit()) { 1648 if (unitInfo.hasInvalidParsedUnit()) {
1420 try { 1649 try {
1421 parseCompilationUnit(entry.getKey()); 1650 parseCompilationUnit(entry.getKey());
(...skipping 18 matching lines...) Expand all
1440 } 1669 }
1441 for (MapEntry<Source, SourceInfo> entry in getMapEntrySet(_sourceMap)) { 1670 for (MapEntry<Source, SourceInfo> entry in getMapEntrySet(_sourceMap)) {
1442 SourceInfo sourceInfo = entry.getValue(); 1671 SourceInfo sourceInfo = entry.getValue();
1443 if (sourceInfo is LibraryInfo) { 1672 if (sourceInfo is LibraryInfo) {
1444 LibraryInfo libraryInfo = sourceInfo as LibraryInfo; 1673 LibraryInfo libraryInfo = sourceInfo as LibraryInfo;
1445 if (libraryInfo.hasInvalidElement()) { 1674 if (libraryInfo.hasInvalidElement()) {
1446 try { 1675 try {
1447 computeLibraryElement(entry.getKey()); 1676 computeLibraryElement(entry.getKey());
1448 } on AnalysisException catch (exception) { 1677 } on AnalysisException catch (exception) {
1449 libraryInfo.element = null; 1678 libraryInfo.element = null;
1450 AnalysisEngine.instance.logger.logError2("Could not compute the libr ary element for ${entry.getKey().fullName}", exception); 1679 AnalysisEngine.instance.logger.logError2("Could not resolve ${entry. getKey().fullName}", exception);
1451 } 1680 }
1452 return true; 1681 return true;
1453 } 1682 }
1683 } else if (sourceInfo is HtmlUnitInfo) {
1684 HtmlUnitInfo unitInfo = sourceInfo as HtmlUnitInfo;
1685 if (unitInfo.hasInvalidResolvedUnit()) {
1686 try {
1687 resolveHtmlUnit(entry.getKey());
1688 } on AnalysisException catch (exception) {
1689 unitInfo.resolvedUnit = null;
1690 AnalysisEngine.instance.logger.logError2("Could not resolve ${entry. getKey().fullName}", exception);
1691 }
1692 return true;
1693 }
1454 } 1694 }
1455 } 1695 }
1456 return false; 1696 return false;
1457 } 1697 }
1458 HtmlScanResult scanHtml(Source source) { 1698 HtmlScanResult scanHtml(Source source) {
1459 HtmlScanner scanner = new HtmlScanner(source); 1699 HtmlScanner scanner = new HtmlScanner(source);
1460 try { 1700 try {
1461 source.getContents(scanner); 1701 source.getContents(scanner);
1462 } catch (exception) { 1702 } catch (exception) {
1463 throw new AnalysisException.con3(exception); 1703 throw new AnalysisException.con3(exception);
(...skipping 11 matching lines...) Expand all
1475 } 1715 }
1476 } 1716 }
1477 /** 1717 /**
1478 * <b>Note:</b> This method must only be invoked while we are synchronized on {@link #cacheLock}. 1718 * <b>Note:</b> This method must only be invoked while we are synchronized on {@link #cacheLock}.
1479 * @param source the source that has been changed 1719 * @param source the source that has been changed
1480 */ 1720 */
1481 void sourceChanged(Source source) { 1721 void sourceChanged(Source source) {
1482 SourceInfo sourceInfo = _sourceMap[source]; 1722 SourceInfo sourceInfo = _sourceMap[source];
1483 if (sourceInfo is HtmlUnitInfo) { 1723 if (sourceInfo is HtmlUnitInfo) {
1484 HtmlUnitInfo htmlUnitInfo = sourceInfo as HtmlUnitInfo; 1724 HtmlUnitInfo htmlUnitInfo = sourceInfo as HtmlUnitInfo;
1725 htmlUnitInfo.invalidateElement();
1485 htmlUnitInfo.invalidateLineInfo(); 1726 htmlUnitInfo.invalidateLineInfo();
1486 htmlUnitInfo.invalidateParsedUnit(); 1727 htmlUnitInfo.invalidateParsedUnit();
1487 htmlUnitInfo.invalidateResolvedUnit(); 1728 htmlUnitInfo.invalidateResolvedUnit();
1729 } else if (sourceInfo is LibraryInfo) {
1730 LibraryInfo libraryInfo = sourceInfo as LibraryInfo;
1731 invalidateLibraryResolution(source, libraryInfo);
1732 _sourceMap[source] = DartInfo.pendingInstance;
1488 } else if (sourceInfo is CompilationUnitInfo) { 1733 } else if (sourceInfo is CompilationUnitInfo) {
1489 CompilationUnitInfo compilationUnitInfo = sourceInfo as CompilationUnitInf o; 1734 for (Source librarySource in getLibrariesContaining(source)) {
1490 for (Source librarySource in compilationUnitInfo.librarySources) {
1491 LibraryInfo libraryInfo = getLibraryInfo(librarySource); 1735 LibraryInfo libraryInfo = getLibraryInfo(librarySource);
1492 if (libraryInfo != null) { 1736 invalidateLibraryResolution(librarySource, libraryInfo);
1493 libraryInfo.invalidateElement();
1494 libraryInfo.invalidatePublicNamespace();
1495 libraryInfo.invalidateLaunchable();
1496 libraryInfo.invalidateClientServer();
1497 }
1498 } 1737 }
1499 _sourceMap[source] = DartInfo.instance; 1738 _sourceMap[source] = DartInfo.pendingInstance;
1500 } 1739 }
1501 } 1740 }
1502 /** 1741 /**
1503 * <b>Note:</b> This method must only be invoked while we are synchronized on {@link #cacheLock}. 1742 * <b>Note:</b> This method must only be invoked while we are synchronized on {@link #cacheLock}.
1504 * @param source the source that has been deleted 1743 * @param source the source that has been deleted
1505 */ 1744 */
1506 void sourceRemoved(Source source) { 1745 void sourceRemoved(Source source) {
1507 CompilationUnitInfo compilationUnitInfo = getCompilationUnitInfo(source); 1746 CompilationUnitInfo compilationUnitInfo = getCompilationUnitInfo(source);
1508 if (compilationUnitInfo != null) { 1747 if (compilationUnitInfo != null) {
1509 for (Source librarySource in compilationUnitInfo.librarySources) { 1748 for (Source librarySource in getLibrariesContaining(source)) {
1510 LibraryInfo libraryInfo = getLibraryInfo(librarySource); 1749 LibraryInfo libraryInfo = getLibraryInfo(librarySource);
1511 if (libraryInfo != null) { 1750 invalidateLibraryResolution(librarySource, libraryInfo);
1512 libraryInfo.invalidateElement();
1513 libraryInfo.invalidatePublicNamespace();
1514 libraryInfo.invalidateLaunchable();
1515 libraryInfo.invalidateClientServer();
1516 }
1517 } 1751 }
1518 } 1752 }
1519 _sourceMap.remove(source); 1753 _sourceMap.remove(source);
1520 } 1754 }
1521 } 1755 }
1522 /** 1756 /**
1523 * Instances of the class {@code ScanResult} represent the results of scanning a source. 1757 * Instances of the class {@code ScanResult} represent the results of scanning a source.
1524 */ 1758 */
1525 class AnalysisContextImpl_ScanResult { 1759 class AnalysisContextImpl_ScanResult {
1526 /** 1760 /**
1761 * The time at which the contents of the source were last set.
1762 */
1763 int _modificationTime = 0;
1764 /**
1527 * The first token in the token stream. 1765 * The first token in the token stream.
1528 */ 1766 */
1529 Token _token; 1767 Token _token;
1530 /** 1768 /**
1531 * The line start information that was produced. 1769 * The line start information that was produced.
1532 */ 1770 */
1533 List<int> _lineStarts; 1771 List<int> _lineStarts;
1534 /** 1772 /**
1535 * Initialize a newly created result object to be empty. 1773 * Initialize a newly created result object to be empty.
1536 */ 1774 */
1537 AnalysisContextImpl_ScanResult() : super() { 1775 AnalysisContextImpl_ScanResult() : super() {
1538 } 1776 }
1539 } 1777 }
1540 class SimpleXmlVisitor_3 extends SimpleXmlVisitor<Object> { 1778 class RecursiveXmlVisitor_6 extends RecursiveXmlVisitor<Object> {
1779 final AnalysisContextImpl AnalysisContextImpl_this;
1541 Source htmlSource; 1780 Source htmlSource;
1542 List<Source> libraries; 1781 List<Source> libraries;
1543 SimpleXmlVisitor_3(this.htmlSource, this.libraries) : super(); 1782 RecursiveXmlVisitor_6(this.AnalysisContextImpl_this, this.htmlSource, this.lib raries) : super();
1544 Object visitXmlTagNode(XmlTagNode node) { 1783 Object visitXmlTagNode(XmlTagNode node) {
1545 if (javaStringEqualsIgnoreCase(node.tag.lexeme, AnalysisContextImpl._TAG_SCR IPT)) { 1784 if (javaStringEqualsIgnoreCase(node.tag.lexeme, AnalysisContextImpl._TAG_SCR IPT)) {
1546 for (XmlAttributeNode attribute in node.attributes) { 1785 for (XmlAttributeNode attribute in node.attributes) {
1547 if (javaStringEqualsIgnoreCase(attribute.name.lexeme, AnalysisContextImp l._ATTRIBUTE_SRC)) { 1786 if (javaStringEqualsIgnoreCase(attribute.name.lexeme, AnalysisContextImp l._ATTRIBUTE_SRC)) {
1548 Source librarySource = htmlSource.resolve(attribute.value.lexeme); 1787 try {
1549 if (librarySource.exists()) { 1788 Uri uri = new Uri.fromComponents(path: attribute.text);
1550 libraries.add(librarySource); 1789 String fileName = uri.path;
1790 if (AnalysisEngine.isDartFileName(fileName)) {
1791 Source librarySource = AnalysisContextImpl_this._sourceFactory.res olveUri(htmlSource, fileName);
1792 if (librarySource.exists()) {
1793 libraries.add(librarySource);
1794 }
1795 }
1796 } catch (exception) {
1797 AnalysisEngine.instance.logger.logError2("Invalid URL ('${attribute. text}') in script tag in '${htmlSource.fullName}'", exception);
1551 } 1798 }
1552 } 1799 }
1553 } 1800 }
1554 } 1801 }
1555 return null; 1802 return super.visitXmlTagNode(node);
1556 } 1803 }
1557 } 1804 }
1558 class Source_ContentReceiver_4 implements Source_ContentReceiver { 1805 class Source_ContentReceiver_7 implements Source_ContentReceiver {
1559 Source source; 1806 Source source;
1560 AnalysisErrorListener errorListener; 1807 AnalysisErrorListener errorListener;
1561 AnalysisContextImpl_ScanResult result; 1808 AnalysisContextImpl_ScanResult result;
1562 Source_ContentReceiver_4(this.source, this.errorListener, this.result); 1809 Source_ContentReceiver_7(this.source, this.errorListener, this.result);
1563 accept(CharBuffer contents) { 1810 void accept(CharBuffer contents, int modificationTime4) {
1564 CharBufferScanner scanner = new CharBufferScanner(source, contents, errorLis tener); 1811 CharBufferScanner scanner = new CharBufferScanner(source, contents, errorLis tener);
1812 result._modificationTime = modificationTime4;
1565 result._token = scanner.tokenize(); 1813 result._token = scanner.tokenize();
1566 result._lineStarts = scanner.lineStarts; 1814 result._lineStarts = scanner.lineStarts;
1567 } 1815 }
1568 void accept2(String contents) { 1816 void accept2(String contents, int modificationTime5) {
1569 StringScanner scanner = new StringScanner(source, contents, errorListener); 1817 StringScanner scanner = new StringScanner(source, contents, errorListener);
1818 result._modificationTime = modificationTime5;
1570 result._token = scanner.tokenize(); 1819 result._token = scanner.tokenize();
1571 result._lineStarts = scanner.lineStarts; 1820 result._lineStarts = scanner.lineStarts;
1572 } 1821 }
1573 } 1822 }
1574 /** 1823 /**
1824 * Instances of the class {@code AnalysisErrorInfoImpl} represent the analysis e rrors and line info
1825 * associated with a source.
1826 */
1827 class AnalysisErrorInfoImpl implements AnalysisErrorInfo {
1828 /**
1829 * The analysis errors associated with a source, or {@code null} if there are no errors.
1830 */
1831 List<AnalysisError> _errors;
1832 /**
1833 * The line information associated with the errors, or {@code null} if there a re no errors.
1834 */
1835 LineInfo _lineInfo;
1836 /**
1837 * Initialize an newly created error info with the errors and line information
1838 * @param errors the errors as a result of analysis
1839 * @param lineinfo the line info for the errors
1840 */
1841 AnalysisErrorInfoImpl(List<AnalysisError> errors, LineInfo lineInfo) {
1842 this._errors = errors;
1843 this._lineInfo = lineInfo;
1844 }
1845 /**
1846 * Return the errors of analysis, or {@code null} if there were no errors.
1847 * @return the errors as a result of the analysis
1848 */
1849 List<AnalysisError> get errors => _errors;
1850 /**
1851 * Return the line information associated with the errors, or {@code null} if there were no
1852 * errors.
1853 * @return the line information associated with the errors
1854 */
1855 LineInfo get lineInfo => _lineInfo;
1856 }
1857 /**
1575 * The enumeration {@code CacheState} defines the possible states of cached data . 1858 * The enumeration {@code CacheState} defines the possible states of cached data .
1576 */ 1859 */
1577 class CacheState { 1860 class CacheState implements Comparable<CacheState> {
1578 /** 1861 /**
1579 * A state representing the fact that the data was up-to-date but flushed from the cache in order 1862 * A state representing the fact that the data was up-to-date but flushed from the cache in order
1580 * to control memory usage. 1863 * to control memory usage.
1581 */ 1864 */
1582 static final CacheState FLUSHED = new CacheState('FLUSHED', 0); 1865 static final CacheState FLUSHED = new CacheState('FLUSHED', 0);
1583 /** 1866 /**
1584 * A state representing the fact that the data was removed from the cache beca use it was invalid 1867 * A state representing the fact that the data was removed from the cache beca use it was invalid
1585 * and needs to be recomputed. 1868 * and needs to be recomputed.
1586 */ 1869 */
1587 static final CacheState INVALID = new CacheState('INVALID', 1); 1870 static final CacheState INVALID = new CacheState('INVALID', 1);
1588 /** 1871 /**
1589 * A state representing the fact that the data is in the cache and valid. 1872 * A state representing the fact that the data is in the cache and valid.
1590 */ 1873 */
1591 static final CacheState VALID = new CacheState('VALID', 2); 1874 static final CacheState VALID = new CacheState('VALID', 2);
1592 static final List<CacheState> values = [FLUSHED, INVALID, VALID]; 1875 static final List<CacheState> values = [FLUSHED, INVALID, VALID];
1593 final String __name; 1876 final String __name;
1594 final int __ordinal; 1877 final int __ordinal;
1595 int get ordinal => __ordinal; 1878 int get ordinal => __ordinal;
1596 CacheState(this.__name, this.__ordinal) { 1879 CacheState(this.__name, this.__ordinal) {
1597 } 1880 }
1881 int compareTo(CacheState other) => __ordinal - other.__ordinal;
1598 String toString() => __name; 1882 String toString() => __name;
1599 } 1883 }
1600 /** 1884 /**
1601 * Instances of the class {@code ChangeNoticeImpl} represent a change to the ana lysis results 1885 * Instances of the class {@code ChangeNoticeImpl} represent a change to the ana lysis results
1602 * associated with a given source. 1886 * associated with a given source.
1603 * @coverage dart.engine 1887 * @coverage dart.engine
1604 */ 1888 */
1605 class ChangeNoticeImpl implements ChangeNotice { 1889 class ChangeNoticeImpl implements ChangeNotice {
1606 /** 1890 /**
1607 * The source for which the result is being reported. 1891 * The source for which the result is being reported.
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
1709 /** 1993 /**
1710 * The state of the cached resolution errors. 1994 * The state of the cached resolution errors.
1711 */ 1995 */
1712 CacheState _resolutionErrorsState = CacheState.INVALID; 1996 CacheState _resolutionErrorsState = CacheState.INVALID;
1713 /** 1997 /**
1714 * The errors produced while resolving the compilation unit, or {@code null} i f the errors are not 1998 * The errors produced while resolving the compilation unit, or {@code null} i f the errors are not
1715 * currently cached. 1999 * currently cached.
1716 */ 2000 */
1717 List<AnalysisError> _resolutionErrors; 2001 List<AnalysisError> _resolutionErrors;
1718 /** 2002 /**
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.
1720 */
1721 List<Source> _librarySources = null;
1722 /**
1723 * Initialize a newly created information holder to be empty. 2003 * Initialize a newly created information holder to be empty.
1724 */ 2004 */
1725 CompilationUnitInfo() : super() { 2005 CompilationUnitInfo() : super() {
1726 } 2006 }
1727 /** 2007 /**
1728 * Add the given source to the list of sources for the defining compilation un its for the
1729 * libraries containing this source.
1730 * @param source the source to be added to the list
1731 */
1732 void addLibrarySource(Source source) {
1733 if (_librarySources == null) {
1734 _librarySources = new List<Source>();
1735 }
1736 _librarySources.add(source);
1737 }
1738 /**
1739 * Remove the parsed compilation unit from the cache. 2008 * Remove the parsed compilation unit from the cache.
1740 */ 2009 */
1741 void clearParsedUnit() { 2010 void clearParsedUnit() {
1742 _parsedUnit = null; 2011 _parsedUnit = null;
2012 _parsedUnitState = CacheState.FLUSHED;
1743 } 2013 }
1744 /** 2014 /**
1745 * Remove the parse errors from the cache. 2015 * Remove the parse errors from the cache.
1746 */ 2016 */
1747 void clearParseErrors() { 2017 void clearParseErrors() {
1748 _parseErrors = null; 2018 _parseErrors = null;
2019 _parseErrorsState = CacheState.FLUSHED;
1749 } 2020 }
1750 /** 2021 /**
1751 * Remove the resolution errors from the cache. 2022 * Remove the resolution errors from the cache.
1752 */ 2023 */
1753 void clearResolutionErrors() { 2024 void clearResolutionErrors() {
1754 _resolutionErrors = null; 2025 _resolutionErrors = null;
2026 _resolutionErrorsState = CacheState.FLUSHED;
1755 } 2027 }
1756 /** 2028 /**
1757 * Remove the resolved compilation unit from the cache. 2029 * Remove the resolved compilation unit from the cache.
1758 */ 2030 */
1759 void clearResolvedUnit() { 2031 void clearResolvedUnit() {
1760 _resolvedUnit = null; 2032 _resolvedUnit = null;
2033 _resolvedUnitState = CacheState.FLUSHED;
1761 } 2034 }
1762 CompilationUnitInfo copy() { 2035 CompilationUnitInfo copy() {
1763 CompilationUnitInfo copy = new CompilationUnitInfo(); 2036 CompilationUnitInfo copy = new CompilationUnitInfo();
1764 copy.copyFrom(this); 2037 copy.copyFrom(this);
1765 return copy; 2038 return copy;
1766 } 2039 }
1767 /** 2040 /**
1768 * Return all of the errors associated with the compilation unit. 2041 * Return all of the errors associated with the compilation unit.
1769 * @return all of the errors associated with the compilation unit 2042 * @return all of the errors associated with the compilation unit
1770 */ 2043 */
1771 List<AnalysisError> get allErrors { 2044 List<AnalysisError> get allErrors {
1772 if (_parseErrors == null) { 2045 if (_parseErrors == null) {
1773 if (_resolutionErrors == null) { 2046 if (_resolutionErrors == null) {
1774 return null; 2047 return null;
1775 } 2048 }
1776 return _resolutionErrors; 2049 return _resolutionErrors;
1777 } else if (_resolutionErrors == null) { 2050 } else if (_resolutionErrors == null) {
1778 return _parseErrors; 2051 return _parseErrors;
1779 } 2052 }
1780 int parseCount = _parseErrors.length; 2053 int parseCount = _parseErrors.length;
1781 int resolutionCount = _resolutionErrors.length; 2054 int resolutionCount = _resolutionErrors.length;
1782 List<AnalysisError> errors = new List<AnalysisError>(parseCount + resolution Count); 2055 List<AnalysisError> errors = new List<AnalysisError>(parseCount + resolution Count);
1783 JavaSystem.arraycopy(_parseErrors, 0, errors, 0, parseCount); 2056 JavaSystem.arraycopy(_parseErrors, 0, errors, 0, parseCount);
1784 JavaSystem.arraycopy(_resolutionErrors, 0, errors, parseCount, resolutionCou nt); 2057 JavaSystem.arraycopy(_resolutionErrors, 0, errors, parseCount, resolutionCou nt);
1785 return errors; 2058 return errors;
1786 } 2059 }
1787 SourceKind get kind => SourceKind.PART; 2060 SourceKind get kind => SourceKind.PART;
1788 /** 2061 /**
1789 * Return the sources for the defining compilation units for the libraries con taining this source.
1790 * @return the sources for the defining compilation units for the libraries co ntaining this source
1791 */
1792 List<Source> get librarySources {
1793 if (_librarySources == null) {
1794 return Source.EMPTY_ARRAY;
1795 }
1796 return new List.from(_librarySources);
1797 }
1798 /**
1799 * Return the parsed compilation unit, or {@code null} if the parsed compilati on unit is not 2062 * Return the parsed compilation unit, or {@code null} if the parsed compilati on unit is not
1800 * currently cached. 2063 * currently cached.
1801 * @return the parsed compilation unit 2064 * @return the parsed compilation unit
1802 */ 2065 */
1803 CompilationUnit get parsedCompilationUnit => _parsedUnit; 2066 CompilationUnit get parsedCompilationUnit => _parsedUnit;
1804 /** 2067 /**
1805 * Return the errors produced while scanning and parsing the compilation unit, or {@code null} if 2068 * Return the errors produced while scanning and parsing the compilation unit, or {@code null} if
1806 * the errors are not currently cached. 2069 * the errors are not currently cached.
1807 * @return the errors produced while scanning and parsing the compilation unit 2070 * @return the errors produced while scanning and parsing the compilation unit
1808 */ 2071 */
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1861 _resolutionErrors = null; 2124 _resolutionErrors = null;
1862 } 2125 }
1863 /** 2126 /**
1864 * Mark the resolved compilation unit as needing to be recomputed. 2127 * Mark the resolved compilation unit as needing to be recomputed.
1865 */ 2128 */
1866 void invalidateResolvedUnit() { 2129 void invalidateResolvedUnit() {
1867 _resolvedUnitState = CacheState.INVALID; 2130 _resolvedUnitState = CacheState.INVALID;
1868 _resolvedUnit = null; 2131 _resolvedUnit = null;
1869 } 2132 }
1870 /** 2133 /**
1871 * Remove the given source from the list of sources for the defining compilati on units for the
1872 * libraries containing this source.
1873 * @param source the source to be removed to the list
1874 */
1875 void removeLibrarySource(Source source) {
1876 if (_librarySources != null) {
1877 _librarySources.remove(source);
1878 if (_librarySources.isEmpty) {
1879 _librarySources = null;
1880 }
1881 }
1882 }
1883 /**
1884 * Set the parsed compilation unit to the given compilation unit. 2134 * Set the parsed compilation unit to the given compilation unit.
1885 * <p> 2135 * <p>
1886 * <b>Note:</b> Do not use this method to clear or invalidate the parsed compi lation unit. Use 2136 * <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}. 2137 * either {@link #clear} or {@link #invalidate}.
1888 * @param unit the parsed compilation unit 2138 * @param unit the parsed compilation unit
1889 */ 2139 */
1890 void set parsedCompilationUnit(CompilationUnit unit) { 2140 void set parsedCompilationUnit(CompilationUnit unit) {
1891 _parsedUnit = unit; 2141 _parsedUnit = unit;
1892 _parsedUnitState = CacheState.VALID; 2142 _parsedUnitState = CacheState.VALID;
1893 } 2143 }
(...skipping 26 matching lines...) Expand all
1920 */ 2170 */
1921 void set resolvedCompilationUnit(CompilationUnit unit) { 2171 void set resolvedCompilationUnit(CompilationUnit unit) {
1922 _resolvedUnit = unit; 2172 _resolvedUnit = unit;
1923 _resolvedUnitState = CacheState.VALID; 2173 _resolvedUnitState = CacheState.VALID;
1924 } 2174 }
1925 void copyFrom(SourceInfo info) { 2175 void copyFrom(SourceInfo info) {
1926 super.copyFrom(info); 2176 super.copyFrom(info);
1927 } 2177 }
1928 } 2178 }
1929 /** 2179 /**
1930 * The unique instance of the class {@code DartInfo} acts as a placeholder for D art compilation 2180 * Instances of the class {@code DartInfo} acts as a placeholder for Dart compil ation units that
1931 * units that have not yet had their kind computed. 2181 * have not yet had their kind computed.
1932 * @coverage dart.engine 2182 * @coverage dart.engine
1933 */ 2183 */
1934 class DartInfo extends SourceInfo { 2184 class DartInfo extends SourceInfo {
1935 /** 2185 /**
1936 * The unique instance of this class. 2186 * The instance of this class used to represent a compilation unit for which a n attempt was made
2187 * to compute the kind but the kind could not be computed.
1937 */ 2188 */
1938 static DartInfo _UniqueInstance = new DartInfo(); 2189 static DartInfo _ErrorInstance = new DartInfo();
1939 /** 2190 /**
1940 * Return the unique instance of this class. 2191 * The instance of this class used to represent a compilation unit for which n o attempt has been
1941 * @return the unique instance of this class 2192 * made to compute the kind.
1942 */ 2193 */
1943 static DartInfo get instance => _UniqueInstance; 2194 static DartInfo _PendingInstance = new DartInfo();
2195 /**
2196 * Return an instance of this class representing a compilation unit for which an attempt was made
2197 * to compute the kind but the kind could not be computed.
2198 * @return an instance of this class used to indicate that the computation of the kind resulted in
2199 * an error and there is no point trying again
2200 */
2201 static DartInfo get errorInstance => _ErrorInstance;
2202 /**
2203 * Return an instance of this class representing a compilation unit for which no attempt has been
2204 * made to compute the kind.
2205 * @return an instance of this class used to indicate that the computation of the kind is pending
2206 */
2207 static DartInfo get pendingInstance => _PendingInstance;
1944 /** 2208 /**
1945 * Prevent the creation of instances of this class. 2209 * Prevent the creation of instances of this class.
1946 */ 2210 */
1947 DartInfo() : super() { 2211 DartInfo() : super() {
1948 } 2212 }
1949 DartInfo copy() => this; 2213 DartInfo copy() => this;
1950 SourceKind get kind => SourceKind.UNKNOWN; 2214 SourceKind get kind => SourceKind.UNKNOWN;
1951 } 2215 }
1952 /** 2216 /**
2217 * Instances of the class {@code DelegatingAnalysisContextImpl} extend {@link An alysisContextImplanalysis context} to delegate sources to the appropriate analys is context. For instance, if the
2218 * source is in a system library then the analysis context from the {@link DartS dk} is used.
2219 * @coverage dart.engine
2220 */
2221 class DelegatingAnalysisContextImpl extends AnalysisContextImpl {
2222 /**
2223 * This references the {@link InternalAnalysisContext} held onto by the {@link DartSdk} which is
2224 * used (instead of this {@link AnalysisContext}) for SDK sources. This field is set when
2225 * #setSourceFactory(SourceFactory) is called, and references the analysis con text in the{@link DartUriResolver} in the {@link SourceFactory}, this analysis c ontext assumes that there
2226 * will be such a resolver.
2227 */
2228 InternalAnalysisContext _sdkAnalysisContext;
2229 /**
2230 * Initialize a newly created delegating analysis context.
2231 */
2232 DelegatingAnalysisContextImpl() : super() {
2233 }
2234 void addSourceInfo(Source source, SourceInfo info) {
2235 if (source.isInSystemLibrary()) {
2236 _sdkAnalysisContext.addSourceInfo(source, info);
2237 } else {
2238 super.addSourceInfo(source, info);
2239 }
2240 }
2241 List<AnalysisError> computeErrors(Source source) {
2242 if (source.isInSystemLibrary()) {
2243 return _sdkAnalysisContext.computeErrors(source);
2244 } else {
2245 return super.computeErrors(source);
2246 }
2247 }
2248 HtmlElement computeHtmlElement(Source source) {
2249 if (source.isInSystemLibrary()) {
2250 return _sdkAnalysisContext.computeHtmlElement(source);
2251 } else {
2252 return super.computeHtmlElement(source);
2253 }
2254 }
2255 SourceKind computeKindOf(Source source) {
2256 if (source.isInSystemLibrary()) {
2257 return _sdkAnalysisContext.computeKindOf(source);
2258 } else {
2259 return super.computeKindOf(source);
2260 }
2261 }
2262 LibraryElement computeLibraryElement(Source source) {
2263 if (source.isInSystemLibrary()) {
2264 return _sdkAnalysisContext.computeLibraryElement(source);
2265 } else {
2266 return super.computeLibraryElement(source);
2267 }
2268 }
2269 LineInfo computeLineInfo(Source source) {
2270 if (source.isInSystemLibrary()) {
2271 return _sdkAnalysisContext.computeLineInfo(source);
2272 } else {
2273 return super.computeLineInfo(source);
2274 }
2275 }
2276 CompilationUnit computeResolvableCompilationUnit(Source source) {
2277 if (source.isInSystemLibrary()) {
2278 return _sdkAnalysisContext.computeResolvableCompilationUnit(source);
2279 } else {
2280 return super.computeResolvableCompilationUnit(source);
2281 }
2282 }
2283 AnalysisErrorInfo getErrors(Source source) {
2284 if (source.isInSystemLibrary()) {
2285 return _sdkAnalysisContext.getErrors(source);
2286 } else {
2287 return super.getErrors(source);
2288 }
2289 }
2290 HtmlElement getHtmlElement(Source source) {
2291 if (source.isInSystemLibrary()) {
2292 return _sdkAnalysisContext.getHtmlElement(source);
2293 } else {
2294 return super.getHtmlElement(source);
2295 }
2296 }
2297 List<Source> getHtmlFilesReferencing(Source source) {
2298 if (source.isInSystemLibrary()) {
2299 return _sdkAnalysisContext.getHtmlFilesReferencing(source);
2300 } else {
2301 return super.getHtmlFilesReferencing(source);
2302 }
2303 }
2304 SourceKind getKindOf(Source source) {
2305 if (source.isInSystemLibrary()) {
2306 return _sdkAnalysisContext.getKindOf(source);
2307 } else {
2308 return super.getKindOf(source);
2309 }
2310 }
2311 List<Source> getLibrariesContaining(Source source) {
2312 if (source.isInSystemLibrary()) {
2313 return _sdkAnalysisContext.getLibrariesContaining(source);
2314 } else {
2315 return super.getLibrariesContaining(source);
2316 }
2317 }
2318 LibraryElement getLibraryElement(Source source) {
2319 if (source.isInSystemLibrary()) {
2320 return _sdkAnalysisContext.getLibraryElement(source);
2321 } else {
2322 return super.getLibraryElement(source);
2323 }
2324 }
2325 List<Source> get librarySources => ArrayUtils.addAll(super.librarySources, _sd kAnalysisContext.librarySources);
2326 LineInfo getLineInfo(Source source) {
2327 if (source.isInSystemLibrary()) {
2328 return _sdkAnalysisContext.getLineInfo(source);
2329 } else {
2330 return super.getLineInfo(source);
2331 }
2332 }
2333 Namespace getPublicNamespace(LibraryElement library) {
2334 Source source12 = library.source;
2335 if (source12.isInSystemLibrary()) {
2336 return _sdkAnalysisContext.getPublicNamespace(library);
2337 } else {
2338 return super.getPublicNamespace(library);
2339 }
2340 }
2341 Namespace getPublicNamespace2(Source source) {
2342 if (source.isInSystemLibrary()) {
2343 return _sdkAnalysisContext.getPublicNamespace2(source);
2344 } else {
2345 return super.getPublicNamespace2(source);
2346 }
2347 }
2348 CompilationUnit getResolvedCompilationUnit(Source unitSource, LibraryElement l ibrary) {
2349 if (unitSource.isInSystemLibrary()) {
2350 return _sdkAnalysisContext.getResolvedCompilationUnit(unitSource, library) ;
2351 } else {
2352 return super.getResolvedCompilationUnit(unitSource, library);
2353 }
2354 }
2355 CompilationUnit getResolvedCompilationUnit2(Source unitSource, Source libraryS ource) {
2356 if (unitSource.isInSystemLibrary()) {
2357 return _sdkAnalysisContext.getResolvedCompilationUnit2(unitSource, library Source);
2358 } else {
2359 return super.getResolvedCompilationUnit2(unitSource, librarySource);
2360 }
2361 }
2362 bool isClientLibrary(Source librarySource) {
2363 if (librarySource.isInSystemLibrary()) {
2364 return _sdkAnalysisContext.isClientLibrary(librarySource);
2365 } else {
2366 return super.isClientLibrary(librarySource);
2367 }
2368 }
2369 bool isServerLibrary(Source librarySource) {
2370 if (librarySource.isInSystemLibrary()) {
2371 return _sdkAnalysisContext.isServerLibrary(librarySource);
2372 } else {
2373 return super.isServerLibrary(librarySource);
2374 }
2375 }
2376 CompilationUnit parseCompilationUnit(Source source) {
2377 if (source.isInSystemLibrary()) {
2378 return _sdkAnalysisContext.parseCompilationUnit(source);
2379 } else {
2380 return super.parseCompilationUnit(source);
2381 }
2382 }
2383 HtmlUnit parseHtmlUnit(Source source) {
2384 if (source.isInSystemLibrary()) {
2385 return _sdkAnalysisContext.parseHtmlUnit(source);
2386 } else {
2387 return super.parseHtmlUnit(source);
2388 }
2389 }
2390 void recordLibraryElements(Map<Source, LibraryElement> elementMap) {
2391 if (elementMap.isEmpty) {
2392 return;
2393 }
2394 Source source = new JavaIterator(elementMap.keys.toSet()).next();
2395 if (source.isInSystemLibrary()) {
2396 _sdkAnalysisContext.recordLibraryElements(elementMap);
2397 } else {
2398 super.recordLibraryElements(elementMap);
2399 }
2400 }
2401 void recordResolutionErrors(Source source, List<AnalysisError> errors, LineInf o lineInfo) {
2402 if (source.isInSystemLibrary()) {
2403 _sdkAnalysisContext.recordResolutionErrors(source, errors, lineInfo);
2404 } else {
2405 super.recordResolutionErrors(source, errors, lineInfo);
2406 }
2407 }
2408 void recordResolvedCompilationUnit(Source source, CompilationUnit unit) {
2409 if (source.isInSystemLibrary()) {
2410 _sdkAnalysisContext.recordResolvedCompilationUnit(source, unit);
2411 } else {
2412 super.recordResolvedCompilationUnit(source, unit);
2413 }
2414 }
2415 CompilationUnit resolveCompilationUnit(Source source, LibraryElement library) {
2416 if (source.isInSystemLibrary()) {
2417 return _sdkAnalysisContext.resolveCompilationUnit(source, library);
2418 } else {
2419 return super.resolveCompilationUnit(source, library);
2420 }
2421 }
2422 CompilationUnit resolveCompilationUnit2(Source unitSource, Source librarySourc e) {
2423 if (unitSource.isInSystemLibrary()) {
2424 return _sdkAnalysisContext.resolveCompilationUnit2(unitSource, librarySour ce);
2425 } else {
2426 return super.resolveCompilationUnit2(unitSource, librarySource);
2427 }
2428 }
2429 HtmlUnit resolveHtmlUnit(Source unitSource) {
2430 if (unitSource.isInSystemLibrary()) {
2431 return _sdkAnalysisContext.resolveHtmlUnit(unitSource);
2432 } else {
2433 return super.resolveHtmlUnit(unitSource);
2434 }
2435 }
2436 void setContents(Source source, String contents) {
2437 if (source.isInSystemLibrary()) {
2438 _sdkAnalysisContext.setContents(source, contents);
2439 } else {
2440 super.setContents(source, contents);
2441 }
2442 }
2443 void set sourceFactory(SourceFactory factory) {
2444 super.sourceFactory = factory;
2445 DartSdk sdk = factory.dartSdk;
2446 if (sdk != null) {
2447 _sdkAnalysisContext = sdk.context as InternalAnalysisContext;
2448 } else {
2449 throw new IllegalStateException("SourceFactorys provided to DelegatingAnal ysisContextImpls must have a DartSdk associated with the provided SourceFactory. ");
2450 }
2451 }
2452 }
2453 /**
1953 * Instances of the class {@code HtmlUnitInfo} maintain the information cached b y an analysis 2454 * Instances of the class {@code HtmlUnitInfo} maintain the information cached b y an analysis
1954 * context about an individual HTML file. 2455 * context about an individual HTML file.
1955 * @coverage dart.engine 2456 * @coverage dart.engine
1956 */ 2457 */
1957 class HtmlUnitInfo extends SourceInfo { 2458 class HtmlUnitInfo extends SourceInfo {
1958 /** 2459 /**
1959 * The state of the cached parsed (but not resolved) HTML unit. 2460 * The state of the cached parsed (but not resolved) HTML unit.
1960 */ 2461 */
1961 CacheState _parsedUnitState = CacheState.INVALID; 2462 CacheState _parsedUnitState = CacheState.INVALID;
1962 /** 2463 /**
(...skipping 10 matching lines...) Expand all
1973 HtmlUnit _resolvedUnit; 2474 HtmlUnit _resolvedUnit;
1974 /** 2475 /**
1975 * The state of the cached HTML element. 2476 * The state of the cached HTML element.
1976 */ 2477 */
1977 CacheState _elementState = CacheState.INVALID; 2478 CacheState _elementState = CacheState.INVALID;
1978 /** 2479 /**
1979 * The element representing the HTML file, or {@code null} if the element is n ot currently cached. 2480 * The element representing the HTML file, or {@code null} if the element is n ot currently cached.
1980 */ 2481 */
1981 HtmlElement _element; 2482 HtmlElement _element;
1982 /** 2483 /**
2484 * The state of the cached library sources.
2485 */
2486 CacheState _librarySourcesState = CacheState.INVALID;
2487 /**
2488 * The sources of libraries referenced by this HTML file.
2489 */
2490 List<Source> _librarySources = Source.EMPTY_ARRAY;
2491 /**
1983 * Initialize a newly created information holder to be empty. 2492 * Initialize a newly created information holder to be empty.
1984 */ 2493 */
1985 HtmlUnitInfo() : super() { 2494 HtmlUnitInfo() : super() {
1986 } 2495 }
1987 /** 2496 /**
1988 * Remove the parsed HTML unit from the cache. 2497 * Remove the parsed HTML unit from the cache.
1989 */ 2498 */
1990 void clearParsedUnit() { 2499 void clearParsedUnit() {
1991 _parsedUnit = null; 2500 _parsedUnit = null;
2501 _parsedUnitState = CacheState.FLUSHED;
1992 } 2502 }
1993 /** 2503 /**
1994 * Remove the resolved HTML unit from the cache. 2504 * Remove the resolved HTML unit from the cache.
1995 */ 2505 */
1996 void clearResolvedUnit() { 2506 void clearResolvedUnit() {
1997 _resolvedUnit = null; 2507 _resolvedUnit = null;
2508 _resolvedUnitState = CacheState.FLUSHED;
1998 } 2509 }
1999 HtmlUnitInfo copy() { 2510 HtmlUnitInfo copy() {
2000 HtmlUnitInfo copy = new HtmlUnitInfo(); 2511 HtmlUnitInfo copy = new HtmlUnitInfo();
2001 copy.copyFrom(this); 2512 copy.copyFrom(this);
2002 return copy; 2513 return copy;
2003 } 2514 }
2004 /** 2515 /**
2005 * Return the element representing the HTML file, or {@code null} if the eleme nt is not currently 2516 * Return the element representing the HTML file, or {@code null} if the eleme nt is not currently
2006 * cached. 2517 * cached.
2007 * @return the element representing the HTML file 2518 * @return the element representing the HTML file
2008 */ 2519 */
2009 HtmlElement get element => _element; 2520 HtmlElement get element => _element;
2010 SourceKind get kind => SourceKind.HTML; 2521 SourceKind get kind => SourceKind.HTML;
2011 /** 2522 /**
2523 * Return the sources of libraries referenced by this HTML file.
2524 * @return the sources of libraries referenced by this HTML file
2525 */
2526 List<Source> get librarySources => _librarySources;
2527 /**
2012 * Return the parsed HTML unit, or {@code null} if the parsed HTML unit is not currently cached. 2528 * Return the parsed HTML unit, or {@code null} if the parsed HTML unit is not currently cached.
2013 * @return the parsed HTML unit 2529 * @return the parsed HTML unit
2014 */ 2530 */
2015 HtmlUnit get parsedUnit => _parsedUnit; 2531 HtmlUnit get parsedUnit => _parsedUnit;
2016 /** 2532 /**
2017 * Return the resolved HTML unit, or {@code null} if the resolved HTML unit is not currently 2533 * Return the resolved HTML unit, or {@code null} if the resolved HTML unit is not currently
2018 * cached. 2534 * cached.
2019 * @return the resolved HTML unit 2535 * @return the resolved HTML unit
2020 */ 2536 */
2021 HtmlUnit get resolvedUnit => _resolvedUnit; 2537 HtmlUnit get resolvedUnit => _resolvedUnit;
(...skipping 13 matching lines...) Expand all
2035 */ 2551 */
2036 bool hasInvalidResolvedUnit() => identical(_resolvedUnitState, CacheState.INVA LID); 2552 bool hasInvalidResolvedUnit() => identical(_resolvedUnitState, CacheState.INVA LID);
2037 /** 2553 /**
2038 * Mark the HTML element as needing to be recomputed. 2554 * Mark the HTML element as needing to be recomputed.
2039 */ 2555 */
2040 void invalidateElement() { 2556 void invalidateElement() {
2041 _elementState = CacheState.INVALID; 2557 _elementState = CacheState.INVALID;
2042 _element = null; 2558 _element = null;
2043 } 2559 }
2044 /** 2560 /**
2561 * Mark the library sources as needing to be recomputed.
2562 */
2563 void invalidateLibrarySources() {
2564 _librarySourcesState = CacheState.INVALID;
2565 _librarySources = Source.EMPTY_ARRAY;
2566 }
2567 /**
2045 * Mark the parsed HTML unit as needing to be recomputed. 2568 * Mark the parsed HTML unit as needing to be recomputed.
2046 */ 2569 */
2047 void invalidateParsedUnit() { 2570 void invalidateParsedUnit() {
2048 _parsedUnitState = CacheState.INVALID; 2571 _parsedUnitState = CacheState.INVALID;
2049 _parsedUnit = null; 2572 _parsedUnit = null;
2050 } 2573 }
2051 /** 2574 /**
2052 * Mark the resolved HTML unit as needing to be recomputed. 2575 * Mark the resolved HTML unit as needing to be recomputed.
2053 */ 2576 */
2054 void invalidateResolvedUnit() { 2577 void invalidateResolvedUnit() {
2578 invalidateElement();
2055 _resolvedUnitState = CacheState.INVALID; 2579 _resolvedUnitState = CacheState.INVALID;
2056 _resolvedUnit = null; 2580 _resolvedUnit = null;
2057 } 2581 }
2058 /** 2582 /**
2059 * Set the element representing the HTML file to the given element. 2583 * Set the element representing the HTML file to the given element.
2060 * <p> 2584 * <p>
2061 * <b>Note:</b> Do not use this method to clear or invalidate the element. Use either{@link #clearElement()} or {@link #invalidateElement()}. 2585 * <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 2586 * @param element the element representing the HTML file
2063 */ 2587 */
2064 void set element(HtmlElement element19) { 2588 void set element(HtmlElement element19) {
2065 this._element = element19; 2589 this._element = element19;
2066 _elementState = CacheState.VALID; 2590 _elementState = CacheState.VALID;
2067 } 2591 }
2068 /** 2592 /**
2593 * Set the sources of libraries referenced by this HTML file to the given sour ces.
2594 * @param sources the sources of libraries referenced by this HTML file
2595 */
2596 void set librarySources(List<Source> sources) {
2597 _librarySources = sources;
2598 _librarySourcesState = CacheState.VALID;
2599 }
2600 /**
2069 * Set the parsed HTML unit to the given HTML unit. 2601 * Set the parsed HTML unit to the given HTML unit.
2070 * <p> 2602 * <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()}. 2603 * <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 2604 * @param unit the result of parsing the source as an HTML unit
2073 */ 2605 */
2074 void set parsedUnit(HtmlUnit unit) { 2606 void set parsedUnit(HtmlUnit unit) {
2075 _parsedUnit = unit; 2607 _parsedUnit = unit;
2076 _parsedUnitState = CacheState.VALID; 2608 _parsedUnitState = CacheState.VALID;
2077 } 2609 }
2078 /** 2610 /**
2079 * Set the resolved HTML unit to the given HTML unit. 2611 * Set the resolved HTML unit to the given HTML unit.
2080 * <p> 2612 * <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()}. 2613 * <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 2614 * @param unit the result of resolving the source as an HTML unit
2083 */ 2615 */
2084 void set resolvedUnit(HtmlUnit unit) { 2616 void set resolvedUnit(HtmlUnit unit) {
2085 _resolvedUnit = unit; 2617 _resolvedUnit = unit;
2086 _resolvedUnitState = CacheState.VALID; 2618 _resolvedUnitState = CacheState.VALID;
2087 } 2619 }
2088 void copyFrom(SourceInfo info) { 2620 void copyFrom(SourceInfo info) {
2089 super.copyFrom(info); 2621 super.copyFrom(info);
2090 } 2622 }
2091 } 2623 }
2092 /** 2624 /**
2625 * Instances of the class {@code InstrumentedAnalysisContextImpl} implement an{@ link AnalysisContext analysis context} by recording instrumentation data and del egating to
2626 * another analysis context to do the non-instrumentation work.
2627 * @coverage dart.engine
2628 */
2629 class InstrumentedAnalysisContextImpl implements InternalAnalysisContext {
2630 /**
2631 * Record an exception that was thrown during analysis.
2632 * @param instrumentation the instrumentation builder being used to record the exception
2633 * @param exception the exception being reported
2634 */
2635 static void recordAnalysisException(InstrumentationBuilder instrumentation, An alysisException exception) {
2636 instrumentation.record(exception);
2637 }
2638 /**
2639 * The unique identifier used to identify this analysis context in the instrum entation data.
2640 */
2641 String _contextId = UUID.randomUUID().toString();
2642 /**
2643 * The analysis context to which all of the non-instrumentation work is delega ted.
2644 */
2645 InternalAnalysisContext _basis;
2646 /**
2647 * Create a new {@link InstrumentedAnalysisContextImpl} which wraps a new{@lin k AnalysisContextImpl} as the basis context.
2648 */
2649 InstrumentedAnalysisContextImpl() {
2650 _jtd_constructor_175_impl();
2651 }
2652 _jtd_constructor_175_impl() {
2653 _jtd_constructor_176_impl(new AnalysisContextImpl());
2654 }
2655 /**
2656 * Create a new {@link InstrumentedAnalysisContextImpl} with a specified basis context, aka the
2657 * context to wrap and instrument.
2658 * @param context some {@link InstrumentedAnalysisContext} to wrap and instrum ent
2659 */
2660 InstrumentedAnalysisContextImpl.con1(InternalAnalysisContext context) {
2661 _jtd_constructor_176_impl(context);
2662 }
2663 _jtd_constructor_176_impl(InternalAnalysisContext context) {
2664 _basis = context;
2665 }
2666 void addSourceInfo(Source source, SourceInfo info) {
2667 _basis.addSourceInfo(source, info);
2668 }
2669 void applyChanges(ChangeSet changeSet) {
2670 InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis- applyChanges");
2671 try {
2672 instrumentation.metric3("contextId", _contextId);
2673 _basis.applyChanges(changeSet);
2674 } finally {
2675 instrumentation.log();
2676 }
2677 }
2678 List<AnalysisError> computeErrors(Source source) {
2679 InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis- computeErrors");
2680 try {
2681 instrumentation.metric3("contextId", _contextId);
2682 List<AnalysisError> errors = _basis.computeErrors(source);
2683 instrumentation.metric2("Errors-count", errors.length);
2684 return errors;
2685 } finally {
2686 instrumentation.log();
2687 }
2688 }
2689 HtmlElement computeHtmlElement(Source source) {
2690 InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis- computeHtmlElement");
2691 try {
2692 instrumentation.metric3("contextId", _contextId);
2693 return _basis.computeHtmlElement(source);
2694 } on AnalysisException catch (e) {
2695 recordAnalysisException(instrumentation, e);
2696 throw e;
2697 } finally {
2698 instrumentation.log();
2699 }
2700 }
2701 SourceKind computeKindOf(Source source) {
2702 InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis- computeKindOf");
2703 try {
2704 instrumentation.metric3("contextId", _contextId);
2705 return _basis.computeKindOf(source);
2706 } finally {
2707 instrumentation.log();
2708 }
2709 }
2710 LibraryElement computeLibraryElement(Source source) {
2711 InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis- computeLibraryElement");
2712 try {
2713 instrumentation.metric3("contextId", _contextId);
2714 return _basis.computeLibraryElement(source);
2715 } on AnalysisException catch (e) {
2716 recordAnalysisException(instrumentation, e);
2717 throw e;
2718 } finally {
2719 instrumentation.log();
2720 }
2721 }
2722 LineInfo computeLineInfo(Source source) {
2723 InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis- computeLineInfo");
2724 try {
2725 instrumentation.metric3("contextId", _contextId);
2726 return _basis.computeLineInfo(source);
2727 } on AnalysisException catch (e) {
2728 recordAnalysisException(instrumentation, e);
2729 throw e;
2730 } finally {
2731 instrumentation.log();
2732 }
2733 }
2734 CompilationUnit computeResolvableCompilationUnit(Source source) => _basis.comp uteResolvableCompilationUnit(source);
2735 AnalysisContext extractContext(SourceContainer container) {
2736 InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis- extractContext");
2737 try {
2738 instrumentation.metric3("contextId", _contextId);
2739 InstrumentedAnalysisContextImpl newContext = new InstrumentedAnalysisConte xtImpl();
2740 _basis.extractContextInto(container, newContext._basis);
2741 return newContext;
2742 } finally {
2743 instrumentation.log();
2744 }
2745 }
2746 InternalAnalysisContext extractContextInto(SourceContainer container, Internal AnalysisContext newContext) => _basis.extractContextInto(container, newContext);
2747 /**
2748 * @return the underlying {@link AnalysisContext}.
2749 */
2750 AnalysisContext get basis => _basis;
2751 Element getElement(ElementLocation location) {
2752 InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis- getElement");
2753 try {
2754 instrumentation.metric3("contextId", _contextId);
2755 return _basis.getElement(location);
2756 } finally {
2757 instrumentation.log();
2758 }
2759 }
2760 AnalysisErrorInfo getErrors(Source source) {
2761 InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis- getErrors");
2762 try {
2763 instrumentation.metric3("contextId", _contextId);
2764 AnalysisErrorInfo ret = _basis.getErrors(source);
2765 if (ret != null) {
2766 instrumentation.metric2("Errors-count", ret.errors.length);
2767 }
2768 return ret;
2769 } finally {
2770 instrumentation.log();
2771 }
2772 }
2773 HtmlElement getHtmlElement(Source source) {
2774 InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis- getHtmlElement");
2775 try {
2776 instrumentation.metric3("contextId", _contextId);
2777 return _basis.getHtmlElement(source);
2778 } finally {
2779 instrumentation.log();
2780 }
2781 }
2782 List<Source> getHtmlFilesReferencing(Source source) {
2783 InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis- getHtmlFilesReferencing");
2784 try {
2785 instrumentation.metric3("contextId", _contextId);
2786 List<Source> ret = _basis.getHtmlFilesReferencing(source);
2787 if (ret != null) {
2788 instrumentation.metric2("Source-count", ret.length);
2789 }
2790 return ret;
2791 } finally {
2792 instrumentation.log();
2793 }
2794 }
2795 List<Source> get htmlSources {
2796 InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis- getHtmlSources");
2797 try {
2798 instrumentation.metric3("contextId", _contextId);
2799 List<Source> ret = _basis.htmlSources;
2800 if (ret != null) {
2801 instrumentation.metric2("Source-count", ret.length);
2802 }
2803 return ret;
2804 } finally {
2805 instrumentation.log();
2806 }
2807 }
2808 SourceKind getKindOf(Source source) {
2809 InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis- getKindOf");
2810 try {
2811 instrumentation.metric3("contextId", _contextId);
2812 return _basis.getKindOf(source);
2813 } finally {
2814 instrumentation.log();
2815 }
2816 }
2817 List<Source> get launchableClientLibrarySources {
2818 InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis- getLaunchableClientLibrarySources");
2819 try {
2820 instrumentation.metric3("contextId", _contextId);
2821 List<Source> ret = _basis.launchableClientLibrarySources;
2822 if (ret != null) {
2823 instrumentation.metric2("Source-count", ret.length);
2824 }
2825 return ret;
2826 } finally {
2827 instrumentation.log();
2828 }
2829 }
2830 List<Source> get launchableServerLibrarySources {
2831 InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis- getLaunchableServerLibrarySources");
2832 try {
2833 instrumentation.metric3("contextId", _contextId);
2834 List<Source> ret = _basis.launchableServerLibrarySources;
2835 if (ret != null) {
2836 instrumentation.metric2("Source-count", ret.length);
2837 }
2838 return ret;
2839 } finally {
2840 instrumentation.log();
2841 }
2842 }
2843 List<Source> getLibrariesContaining(Source source) {
2844 InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis- getLibrariesContaining");
2845 try {
2846 instrumentation.metric3("contextId", _contextId);
2847 List<Source> ret = _basis.getLibrariesContaining(source);
2848 if (ret != null) {
2849 instrumentation.metric2("Source-count", ret.length);
2850 }
2851 return ret;
2852 } finally {
2853 instrumentation.log();
2854 }
2855 }
2856 LibraryElement getLibraryElement(Source source) {
2857 InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis- getLibraryElement");
2858 try {
2859 instrumentation.metric3("contextId", _contextId);
2860 return _basis.getLibraryElement(source);
2861 } finally {
2862 instrumentation.log();
2863 }
2864 }
2865 List<Source> get librarySources {
2866 InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis- getLibrarySources");
2867 try {
2868 instrumentation.metric3("contextId", _contextId);
2869 List<Source> ret = _basis.librarySources;
2870 if (ret != null) {
2871 instrumentation.metric2("Source-count", ret.length);
2872 }
2873 return ret;
2874 } finally {
2875 instrumentation.log();
2876 }
2877 }
2878 LineInfo getLineInfo(Source source) {
2879 InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis- getLineInfo");
2880 try {
2881 instrumentation.metric3("contextId", _contextId);
2882 return _basis.getLineInfo(source);
2883 } finally {
2884 instrumentation.log();
2885 }
2886 }
2887 Namespace getPublicNamespace(LibraryElement library) => _basis.getPublicNamesp ace(library);
2888 Namespace getPublicNamespace2(Source source) => _basis.getPublicNamespace2(sou rce);
2889 CompilationUnit getResolvedCompilationUnit(Source unitSource, LibraryElement l ibrary) {
2890 InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis- getResolvedCompilationUnit");
2891 try {
2892 instrumentation.metric3("contextId", _contextId);
2893 return _basis.getResolvedCompilationUnit(unitSource, library);
2894 } finally {
2895 instrumentation.log();
2896 }
2897 }
2898 CompilationUnit getResolvedCompilationUnit2(Source unitSource, Source libraryS ource) {
2899 InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis- getResolvedCompilationUnit");
2900 try {
2901 instrumentation.metric3("contextId", _contextId);
2902 return _basis.getResolvedCompilationUnit2(unitSource, librarySource);
2903 } finally {
2904 instrumentation.log();
2905 }
2906 }
2907 SourceFactory get sourceFactory {
2908 InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis- getSourceFactory");
2909 try {
2910 instrumentation.metric3("contextId", _contextId);
2911 return _basis.sourceFactory;
2912 } finally {
2913 instrumentation.log();
2914 }
2915 }
2916 bool isClientLibrary(Source librarySource) {
2917 InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis- isClientLibrary");
2918 try {
2919 instrumentation.metric3("contextId", _contextId);
2920 return _basis.isClientLibrary(librarySource);
2921 } finally {
2922 instrumentation.log();
2923 }
2924 }
2925 bool isServerLibrary(Source librarySource) {
2926 InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis- isServerLibrary");
2927 try {
2928 instrumentation.metric3("contextId", _contextId);
2929 return _basis.isServerLibrary(librarySource);
2930 } finally {
2931 instrumentation.log();
2932 }
2933 }
2934 void mergeContext(AnalysisContext context) {
2935 InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis- mergeContext");
2936 try {
2937 instrumentation.metric3("contextId", _contextId);
2938 if (context is InstrumentedAnalysisContextImpl) {
2939 context = ((context as InstrumentedAnalysisContextImpl))._basis;
2940 }
2941 _basis.mergeContext(context);
2942 } finally {
2943 instrumentation.log();
2944 }
2945 }
2946 CompilationUnit parseCompilationUnit(Source source) {
2947 InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis- parseCompilationUnit");
2948 try {
2949 instrumentation.metric3("contextId", _contextId);
2950 return _basis.parseCompilationUnit(source);
2951 } on AnalysisException catch (e) {
2952 recordAnalysisException(instrumentation, e);
2953 throw e;
2954 } finally {
2955 instrumentation.log();
2956 }
2957 }
2958 HtmlUnit parseHtmlUnit(Source source) {
2959 InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis- parseHtmlUnit");
2960 try {
2961 instrumentation.metric3("contextId", _contextId);
2962 return _basis.parseHtmlUnit(source);
2963 } on AnalysisException catch (e) {
2964 recordAnalysisException(instrumentation, e);
2965 throw e;
2966 } finally {
2967 instrumentation.log();
2968 }
2969 }
2970 List<ChangeNotice> performAnalysisTask() {
2971 InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis- performAnalysisTask");
2972 try {
2973 instrumentation.metric3("contextId", _contextId);
2974 List<ChangeNotice> ret = _basis.performAnalysisTask();
2975 if (ret != null) {
2976 instrumentation.metric2("ChangeNotice-count", ret.length);
2977 }
2978 return ret;
2979 } finally {
2980 instrumentation.log();
2981 }
2982 }
2983 void recordLibraryElements(Map<Source, LibraryElement> elementMap) {
2984 _basis.recordLibraryElements(elementMap);
2985 }
2986 void recordResolutionErrors(Source source, List<AnalysisError> errors, LineInf o lineInfo) {
2987 _basis.recordResolutionErrors(source, errors, lineInfo);
2988 }
2989 void recordResolvedCompilationUnit(Source source, CompilationUnit unit) {
2990 _basis.recordResolvedCompilationUnit(source, unit);
2991 }
2992 CompilationUnit resolveCompilationUnit(Source unitSource, LibraryElement libra ry) {
2993 InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis- resolveCompilationUnit");
2994 try {
2995 instrumentation.metric3("contextId", _contextId);
2996 return _basis.resolveCompilationUnit(unitSource, library);
2997 } on AnalysisException catch (e) {
2998 recordAnalysisException(instrumentation, e);
2999 throw e;
3000 } finally {
3001 instrumentation.log();
3002 }
3003 }
3004 CompilationUnit resolveCompilationUnit2(Source unitSource, Source librarySourc e) {
3005 InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis- resolveCompilationUnit");
3006 try {
3007 instrumentation.metric3("contextId", _contextId);
3008 return _basis.resolveCompilationUnit2(unitSource, librarySource);
3009 } on AnalysisException catch (e) {
3010 recordAnalysisException(instrumentation, e);
3011 throw e;
3012 } finally {
3013 instrumentation.log();
3014 }
3015 }
3016 HtmlUnit resolveHtmlUnit(Source htmlSource) {
3017 InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis- resolveHtmlUnit");
3018 try {
3019 instrumentation.metric3("contextId", _contextId);
3020 return _basis.resolveHtmlUnit(htmlSource);
3021 } on AnalysisException catch (e) {
3022 recordAnalysisException(instrumentation, e);
3023 throw e;
3024 } finally {
3025 instrumentation.log();
3026 }
3027 }
3028 void setContents(Source source, String contents) {
3029 InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis- setContents");
3030 try {
3031 instrumentation.metric3("contextId", _contextId);
3032 _basis.setContents(source, contents);
3033 } finally {
3034 instrumentation.log();
3035 }
3036 }
3037 void set sourceFactory(SourceFactory factory) {
3038 InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis- setSourceFactory");
3039 try {
3040 instrumentation.metric3("contextId", _contextId);
3041 _basis.sourceFactory = factory;
3042 } finally {
3043 instrumentation.log();
3044 }
3045 }
3046 Iterable<Source> sourcesToResolve(List<Source> changedSources) {
3047 InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis- sourcesToResolve");
3048 try {
3049 instrumentation.metric3("contextId", _contextId);
3050 return _basis.sourcesToResolve(changedSources);
3051 } finally {
3052 instrumentation.log();
3053 }
3054 }
3055 }
3056 /**
3057 * The interface {@code InternalAnalysisContext} defines additional behavior for an analysis context
3058 * that is required by internal users of the context.
3059 */
3060 abstract class InternalAnalysisContext implements AnalysisContext {
3061 /**
3062 * Add the given source with the given information to this context.
3063 * @param source the source to be added
3064 * @param info the information about the source
3065 */
3066 void addSourceInfo(Source source, SourceInfo info);
3067 /**
3068 * Return an AST structure corresponding to the given source, but ensure that the structure has
3069 * not already been resolved and will not be resolved by any other threads or in any other
3070 * library.
3071 * @param source the compilation unit for which an AST structure should be ret urned
3072 * @return the AST structure representing the content of the source
3073 * @throws AnalysisException if the analysis could not be performed
3074 */
3075 CompilationUnit computeResolvableCompilationUnit(Source source);
3076 /**
3077 * Initialize the specified context by removing the specified sources from the receiver and adding
3078 * them to the specified context.
3079 * @param container the container containing sources that should be removed fr om this context and
3080 * added to the returned context
3081 * @param newContext the context to be initialized
3082 * @return the analysis context that was initialized
3083 */
3084 InternalAnalysisContext extractContextInto(SourceContainer container, Internal AnalysisContext newContext);
3085 /**
3086 * Return a namespace containing mappings for all of the public names defined by the given
3087 * library.
3088 * @param library the library whose public namespace is to be returned
3089 * @return the public namespace of the given library
3090 */
3091 Namespace getPublicNamespace(LibraryElement library);
3092 /**
3093 * Return a namespace containing mappings for all of the public names defined by the library
3094 * defined by the given source.
3095 * @param source the source defining the library whose public namespace is to be returned
3096 * @return the public namespace corresponding to the library defined by the gi ven source
3097 * @throws AnalysisException if the public namespace could not be computed
3098 */
3099 Namespace getPublicNamespace2(Source source);
3100 /**
3101 * Given a table mapping the source for the libraries represented by the corre sponding elements to
3102 * the elements representing the libraries, record those mappings.
3103 * @param elementMap a table mapping the source for the libraries represented by the elements to
3104 * the elements representing the libraries
3105 */
3106 void recordLibraryElements(Map<Source, LibraryElement> elementMap);
3107 /**
3108 * Give the resolution errors and line info associated with the given source, add the information
3109 * to the cache.
3110 * @param source the source with which the information is associated
3111 * @param errors the resolution errors associated with the source
3112 * @param lineInfo the line information associated with the source
3113 */
3114 void recordResolutionErrors(Source source, List<AnalysisError> errors, LineInf o lineInfo);
3115 /**
3116 * Give the resolved compilation unit associated with the given source, add th e unit to the cache.
3117 * @param source the source with which the unit is associated
3118 * @param unit the compilation unit associated with the source
3119 */
3120 void recordResolvedCompilationUnit(Source source, CompilationUnit unit);
3121 }
3122 /**
2093 * Instances of the class {@code LibraryInfo} maintain the information cached by an analysis context 3123 * Instances of the class {@code LibraryInfo} maintain the information cached by an analysis context
2094 * about an individual library. 3124 * about an individual library.
2095 * @coverage dart.engine 3125 * @coverage dart.engine
2096 */ 3126 */
2097 class LibraryInfo extends CompilationUnitInfo { 3127 class LibraryInfo extends CompilationUnitInfo {
2098 /** 3128 /**
2099 * Mask indicating that this library is launchable: that the file has a main m ethod. 3129 * Mask indicating that this library is launchable: that the file has a main m ethod.
2100 */ 3130 */
2101 static int _LAUNCHABLE = 1 << 1; 3131 static int _LAUNCHABLE = 1 << 1;
2102 /** 3132 /**
2103 * Mask indicating that the library is client code: that the library depends o n the html library. 3133 * 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" . 3134 * If the library is not "client code", then it is referenced as "server code" .
2105 */ 3135 */
2106 static int _CLIENT_CODE = 1 << 2; 3136 static int _CLIENT_CODE = 1 << 2;
2107 /** 3137 /**
2108 * The state of the cached library element. 3138 * The state of the cached library element.
2109 */ 3139 */
2110 CacheState _elementState = CacheState.INVALID; 3140 CacheState _elementState = CacheState.INVALID;
2111 /** 3141 /**
2112 * The element representing the library, or {@code null} if the element is not currently cached. 3142 * The element representing the library, or {@code null} if the element is not currently cached.
2113 */ 3143 */
2114 LibraryElement _element; 3144 LibraryElement _element;
2115 /** 3145 /**
3146 * The state of the cached unit sources.
3147 */
3148 CacheState _unitSourcesState = CacheState.INVALID;
3149 /**
3150 * The sources of the compilation units that compose the library, including bo th the defining
3151 * compilation unit and any parts.
3152 */
3153 List<Source> _unitSources = Source.EMPTY_ARRAY;
3154 /**
2116 * The state of the cached public namespace. 3155 * The state of the cached public namespace.
2117 */ 3156 */
2118 CacheState _publicNamespaceState = CacheState.INVALID; 3157 CacheState _publicNamespaceState = CacheState.INVALID;
2119 /** 3158 /**
2120 * The public namespace of the library, or {@code null} if the namespace is no t currently cached. 3159 * The public namespace of the library, or {@code null} if the namespace is no t currently cached.
2121 */ 3160 */
2122 Namespace _publicNamespace; 3161 Namespace _publicNamespace;
2123 /** 3162 /**
2124 * The state of the cached client/ server flag. 3163 * The state of the cached client/ server flag.
2125 */ 3164 */
2126 CacheState _clientServerState = CacheState.INVALID; 3165 CacheState _clientServerState = CacheState.INVALID;
2127 /** 3166 /**
2128 * The state of the cached launchable flag. 3167 * The state of the cached launchable flag.
2129 */ 3168 */
2130 CacheState _launchableState = CacheState.INVALID; 3169 CacheState _launchableState = CacheState.INVALID;
2131 /** 3170 /**
2132 * An integer holding bit masks such as {@link #LAUNCHABLE} and {@link #CLIENT _CODE}. 3171 * An integer holding bit masks such as {@link #LAUNCHABLE} and {@link #CLIENT _CODE}.
2133 */ 3172 */
2134 int _bitmask = 0; 3173 int _bitmask = 0;
2135 /** 3174 /**
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. 3175 * Initialize a newly created information holder to be empty.
2141 */ 3176 */
2142 LibraryInfo() : super() { 3177 LibraryInfo() : super() {
2143 } 3178 }
2144 /** 3179 /**
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. 3180 * Remove the library element from the cache.
2156 */ 3181 */
2157 void clearElement() { 3182 void clearElement() {
2158 _element = null; 3183 _element = null;
3184 _elementState = CacheState.FLUSHED;
2159 } 3185 }
2160 /** 3186 /**
2161 * Remove the public namespace from the cache. 3187 * Remove the public namespace from the cache.
2162 */ 3188 */
2163 void clearPublicNamespace() { 3189 void clearPublicNamespace() {
2164 _publicNamespace = null; 3190 _publicNamespace = null;
3191 _publicNamespaceState = CacheState.FLUSHED;
2165 } 3192 }
2166 LibraryInfo copy() { 3193 LibraryInfo copy() {
2167 LibraryInfo copy = new LibraryInfo(); 3194 LibraryInfo copy = new LibraryInfo();
2168 copy.copyFrom(this); 3195 copy.copyFrom(this);
2169 return copy; 3196 return copy;
2170 } 3197 }
2171 /** 3198 /**
2172 * Return the element representing the library, or {@code null} if the element is not currently 3199 * Return the element representing the library, or {@code null} if the element is not currently
2173 * cached. 3200 * cached.
2174 * @return the element representing the library 3201 * @return the element representing the library
2175 */ 3202 */
2176 LibraryElement get element => _element; 3203 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; 3204 SourceKind get kind => SourceKind.LIBRARY;
2188 /** 3205 /**
2189 * Return the public namespace of the library, or {@code null} if the namespac e is not currently 3206 * Return the public namespace of the library, or {@code null} if the namespac e is not currently
2190 * cached. 3207 * cached.
2191 * @return the public namespace of the library 3208 * @return the public namespace of the library
2192 */ 3209 */
2193 Namespace get publicNamespace => _publicNamespace; 3210 Namespace get publicNamespace => _publicNamespace;
2194 /** 3211 /**
3212 * Return the sources of the compilation units that compose the library, inclu ding both the
3213 * defining compilation unit and any parts.
3214 * @return the sources of the compilation units that compose the library
3215 */
3216 List<Source> get unitSources => _unitSources;
3217 /**
2195 * Return {@code true} if the client/ server flag needs to be recomputed. 3218 * 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 3219 * @return {@code true} if the client/ server flag needs to be recomputed
2197 */ 3220 */
2198 bool hasInvalidClientServer() => identical(_clientServerState, CacheState.INVA LID); 3221 bool hasInvalidClientServer() => identical(_clientServerState, CacheState.INVA LID);
2199 /** 3222 /**
2200 * Return {@code true} if the library element needs to be recomputed. 3223 * Return {@code true} if the library element needs to be recomputed.
2201 * @return {@code true} if the library element needs to be recomputed 3224 * @return {@code true} if the library element needs to be recomputed
2202 */ 3225 */
2203 bool hasInvalidElement() => identical(_elementState, CacheState.INVALID); 3226 bool hasInvalidElement() => identical(_elementState, CacheState.INVALID);
2204 /** 3227 /**
(...skipping 28 matching lines...) Expand all
2233 _bitmask &= ~_LAUNCHABLE; 3256 _bitmask &= ~_LAUNCHABLE;
2234 } 3257 }
2235 /** 3258 /**
2236 * Mark the public namespace as needing to be recomputed. 3259 * Mark the public namespace as needing to be recomputed.
2237 */ 3260 */
2238 void invalidatePublicNamespace() { 3261 void invalidatePublicNamespace() {
2239 _publicNamespaceState = CacheState.INVALID; 3262 _publicNamespaceState = CacheState.INVALID;
2240 _publicNamespace = null; 3263 _publicNamespace = null;
2241 } 3264 }
2242 /** 3265 /**
2243 * Return <code>true</code> if this library is client based code: the library depends on the html 3266 * Mark the compilation unit sources as needing to be recomputed.
3267 */
3268 void invalidateUnitSources() {
3269 _unitSourcesState = CacheState.INVALID;
3270 _unitSources = Source.EMPTY_ARRAY;
3271 }
3272 /**
3273 * Return {@code true} if this library is client based code: the library depen ds on the html
2244 * library. 3274 * library.
2245 * @return <code>true</code> if this library is client based code: the library depends on the html 3275 * @return {@code true} if this library is client based code: the library depe nds on the html
2246 * library 3276 * library
2247 */ 3277 */
2248 bool isClient() => (_bitmask & _CLIENT_CODE) != 0; 3278 bool isClient() => (_bitmask & _CLIENT_CODE) != 0;
2249 /** 3279 /**
2250 * Return <code>true</code> if this library is launchable: the file includes a main method. 3280 * Return {@code true} 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 3281 * @return {@code true} if this library is launchable: the file includes a mai n method
2252 */ 3282 */
2253 bool isLaunchable() => (_bitmask & _LAUNCHABLE) != 0; 3283 bool isLaunchable() => (_bitmask & _LAUNCHABLE) != 0;
2254 /** 3284 /**
2255 * Return <code>true</code> if this library is server based code: the library does not depends on 3285 * Return {@code true} if this library is server based code: the library does not depends on the
2256 * the html library. 3286 * html library.
2257 * @return <code>true</code> if this library is server based code: the library does not depends on 3287 * @return {@code true} if this library is server based code: the library does not depends on the
2258 * the html library 3288 * html library
2259 */ 3289 */
2260 bool isServer() => (_bitmask & _CLIENT_CODE) == 0; 3290 bool isServer() => (_bitmask & _CLIENT_CODE) == 0;
2261 /** 3291 /**
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. 3292 * Sets the value of the client/ server flag.
2276 * <p> 3293 * <p>
2277 * <b>Note:</b> Do not use this method to invalidate the flag, use{@link #inva lidateClientServer()}. 3294 * <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 3295 * @param isClient the new value of the client flag
2279 */ 3296 */
2280 void set client(bool isClient) { 3297 void set client(bool isClient) {
2281 if (isClient) { 3298 if (isClient) {
2282 _bitmask |= _CLIENT_CODE; 3299 _bitmask |= _CLIENT_CODE;
2283 } else { 3300 } else {
2284 _bitmask &= ~_CLIENT_CODE; 3301 _bitmask &= ~_CLIENT_CODE;
(...skipping 27 matching lines...) Expand all
2312 /** 3329 /**
2313 * Set the public namespace of the library to the given namespace. 3330 * Set the public namespace of the library to the given namespace.
2314 * <p> 3331 * <p>
2315 * <b>Note:</b> Do not use this method to clear or invalidate the element. Use either{@link #clearPublicNamespace()} or {@link #invalidatePublicNamespace()}. 3332 * <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 3333 * @param namespace the public namespace of the library
2317 */ 3334 */
2318 void set publicNamespace(Namespace namespace) { 3335 void set publicNamespace(Namespace namespace) {
2319 _publicNamespace = namespace; 3336 _publicNamespace = namespace;
2320 _publicNamespaceState = CacheState.VALID; 3337 _publicNamespaceState = CacheState.VALID;
2321 } 3338 }
3339 /**
3340 * Set the sources of the compilation units that compose the library to the gi ven sources.
3341 * @param sources the sources of the compilation units that compose the librar y
3342 */
3343 void set unitSources(List<Source> sources) {
3344 _unitSourcesState = CacheState.VALID;
3345 _unitSources = sources;
3346 }
2322 void copyFrom(SourceInfo info) { 3347 void copyFrom(SourceInfo info) {
2323 super.copyFrom(info); 3348 super.copyFrom(info);
2324 } 3349 }
2325 } 3350 }
2326 /** 3351 /**
2327 * Instances of the class {@code RecordingErrorListener} implement an error list ener that will 3352 * 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 3353 * record the errors that are reported to it in a way that is appropriate for ca ching those errors
2329 * within an analysis context. 3354 * within an analysis context.
2330 * @coverage dart.engine 3355 * @coverage dart.engine
2331 */ 3356 */
(...skipping 25 matching lines...) Expand all
2357 */ 3382 */
2358 List<AnalysisError> getErrors2(Source source) { 3383 List<AnalysisError> getErrors2(Source source) {
2359 List<AnalysisError> errorsForSource = _errors[source]; 3384 List<AnalysisError> errorsForSource = _errors[source];
2360 if (errorsForSource == null) { 3385 if (errorsForSource == null) {
2361 return AnalysisError.NO_ERRORS; 3386 return AnalysisError.NO_ERRORS;
2362 } else { 3387 } else {
2363 return new List.from(errorsForSource); 3388 return new List.from(errorsForSource);
2364 } 3389 }
2365 } 3390 }
2366 void onError(AnalysisError event) { 3391 void onError(AnalysisError event) {
2367 Source source9 = event.source; 3392 Source source13 = event.source;
2368 List<AnalysisError> errorsForSource = _errors[source9]; 3393 List<AnalysisError> errorsForSource = _errors[source13];
2369 if (_errors[source9] == null) { 3394 if (_errors[source13] == null) {
2370 errorsForSource = new List<AnalysisError>(); 3395 errorsForSource = new List<AnalysisError>();
2371 _errors[source9] = errorsForSource; 3396 _errors[source13] = errorsForSource;
2372 } 3397 }
2373 errorsForSource.add(event); 3398 errorsForSource.add(event);
2374 } 3399 }
2375 } 3400 }
2376 /** 3401 /**
3402 * Instances of the class {@code ResolutionEraser} remove any resolution informa tion from an AST
3403 * structure when used to visit that structure.
3404 */
3405 class ResolutionEraser extends GeneralizingASTVisitor<Object> {
3406 Object visitAssignmentExpression(AssignmentExpression node) {
3407 node.element = null;
3408 return super.visitAssignmentExpression(node);
3409 }
3410 Object visitBinaryExpression(BinaryExpression node) {
3411 node.element = null;
3412 return super.visitBinaryExpression(node);
3413 }
3414 Object visitCompilationUnit(CompilationUnit node) {
3415 node.element = null;
3416 return super.visitCompilationUnit(node);
3417 }
3418 Object visitConstructorDeclaration(ConstructorDeclaration node) {
3419 node.element = null;
3420 return super.visitConstructorDeclaration(node);
3421 }
3422 Object visitConstructorName(ConstructorName node) {
3423 node.element = null;
3424 return super.visitConstructorName(node);
3425 }
3426 Object visitDirective(Directive node) {
3427 node.element = null;
3428 return super.visitDirective(node);
3429 }
3430 Object visitExpression(Expression node) {
3431 node.staticType = null;
3432 node.propagatedType = null;
3433 return super.visitExpression(node);
3434 }
3435 Object visitFunctionExpression(FunctionExpression node) {
3436 node.element = null;
3437 return super.visitFunctionExpression(node);
3438 }
3439 Object visitFunctionExpressionInvocation(FunctionExpressionInvocation node) {
3440 node.element = null;
3441 return super.visitFunctionExpressionInvocation(node);
3442 }
3443 Object visitIndexExpression(IndexExpression node) {
3444 node.element = null;
3445 return super.visitIndexExpression(node);
3446 }
3447 Object visitInstanceCreationExpression(InstanceCreationExpression node) {
3448 node.element = null;
3449 return super.visitInstanceCreationExpression(node);
3450 }
3451 Object visitPostfixExpression(PostfixExpression node) {
3452 node.element = null;
3453 return super.visitPostfixExpression(node);
3454 }
3455 Object visitPrefixExpression(PrefixExpression node) {
3456 node.element = null;
3457 return super.visitPrefixExpression(node);
3458 }
3459 Object visitRedirectingConstructorInvocation(RedirectingConstructorInvocation node) {
3460 node.element = null;
3461 return super.visitRedirectingConstructorInvocation(node);
3462 }
3463 Object visitSimpleIdentifier(SimpleIdentifier node) {
3464 node.element = null;
3465 return super.visitSimpleIdentifier(node);
3466 }
3467 Object visitSuperConstructorInvocation(SuperConstructorInvocation node) {
3468 node.element = null;
3469 return super.visitSuperConstructorInvocation(node);
3470 }
3471 }
3472 /**
2377 * Instances of the class {@code SourceInfo} maintain the information cached by an analysis context 3473 * Instances of the class {@code SourceInfo} maintain the information cached by an analysis context
2378 * about an individual source. 3474 * about an individual source.
2379 * @coverage dart.engine 3475 * @coverage dart.engine
2380 */ 3476 */
2381 abstract class SourceInfo { 3477 abstract class SourceInfo {
2382 /** 3478 /**
2383 * The state of the cached line information. 3479 * The state of the cached line information.
2384 */ 3480 */
2385 CacheState _lineInfoState = CacheState.INVALID; 3481 CacheState _lineInfoState = CacheState.INVALID;
2386 /** 3482 /**
2387 * The line information computed for the source, or {@code null} if the line i nformation is not 3483 * The line information computed for the source, or {@code null} if the line i nformation is not
2388 * currently cached. 3484 * currently cached.
2389 */ 3485 */
2390 LineInfo _lineInfo; 3486 LineInfo _lineInfo;
2391 /** 3487 /**
2392 * Initialize a newly created information holder to be empty. 3488 * Initialize a newly created information holder to be empty.
2393 */ 3489 */
2394 SourceInfo() : super() { 3490 SourceInfo() : super() {
2395 } 3491 }
2396 /** 3492 /**
2397 * Remove the line information from the cache. 3493 * Remove the line information from the cache.
2398 */ 3494 */
2399 void clearLineInfo() { 3495 void clearLineInfo() {
2400 _lineInfo = null; 3496 _lineInfo = null;
3497 _lineInfoState = CacheState.FLUSHED;
2401 } 3498 }
2402 /** 3499 /**
2403 * Return a copy of this information holder. 3500 * Return a copy of this information holder.
2404 * @return a copy of this information holder 3501 * @return a copy of this information holder
2405 */ 3502 */
2406 SourceInfo copy(); 3503 SourceInfo copy();
2407 /** 3504 /**
2408 * Return the kind of the source, or {@code null} if the kind is not currently cached. 3505 * Return the kind of the source, or {@code null} if the kind is not currently cached.
2409 * @return the kind of the source 3506 * @return the kind of the source
2410 */ 3507 */
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
2492 } 3589 }
2493 void logError2(String message, Exception exception) { 3590 void logError2(String message, Exception exception) {
2494 } 3591 }
2495 void logError3(Exception exception) { 3592 void logError3(Exception exception) {
2496 } 3593 }
2497 void logInformation(String message) { 3594 void logInformation(String message) {
2498 } 3595 }
2499 void logInformation2(String message, Exception exception) { 3596 void logInformation2(String message, Exception exception) {
2500 } 3597 }
2501 } 3598 }
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