| OLD | NEW |
| 1 // This code was auto-generated, is not intended to be edited, and is subject to | 1 // This code was auto-generated, is not intended to be edited, and is subject to |
| 2 // significant change. Please see the README file for more information. | 2 // significant change. Please see the README file for more information. |
| 3 library engine; | 3 library engine; |
| 4 import 'java_core.dart'; | 4 import 'java_core.dart'; |
| 5 import 'java_engine.dart'; | 5 import 'java_engine.dart'; |
| 6 import 'utilities_collection.dart'; | 6 import 'utilities_collection.dart'; |
| 7 import 'utilities_general.dart'; | 7 import 'utilities_general.dart'; |
| 8 import 'instrumentation.dart'; | 8 import 'instrumentation.dart'; |
| 9 import 'error.dart'; | 9 import 'error.dart'; |
| 10 import 'source.dart'; | 10 import 'source.dart'; |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 * Create a new context in which analysis can be performed. Any sources in the
specified container | 262 * Create a new context in which analysis can be performed. Any sources in the
specified container |
| 263 * will be removed from this context and added to the newly created context. | 263 * will be removed from this context and added to the newly created context. |
| 264 * | 264 * |
| 265 * @param container the container containing sources that should be removed fr
om this context and | 265 * @param container the container containing sources that should be removed fr
om this context and |
| 266 * added to the returned context | 266 * added to the returned context |
| 267 * @return the analysis context that was created | 267 * @return the analysis context that was created |
| 268 */ | 268 */ |
| 269 AnalysisContext extractContext(SourceContainer container); | 269 AnalysisContext extractContext(SourceContainer container); |
| 270 | 270 |
| 271 /** | 271 /** |
| 272 * Return the set of analysis options controlling the behavior of this context
. | 272 * Return the set of analysis options controlling the behavior of this context
. Changes to the |
| 273 * return options will not affect this context. The options can only be set by
invoking the method |
| 274 * [setAnalysisOptions]. |
| 273 * | 275 * |
| 274 * @return the set of analysis options controlling the behavior of this contex
t | 276 * @return the set of analysis options controlling the behavior of this contex
t |
| 275 */ | 277 */ |
| 276 AnalysisOptions get analysisOptions; | 278 AnalysisOptions get analysisOptions; |
| 277 | 279 |
| 278 /** | 280 /** |
| 279 * Return the element referenced by the given location, or `null` if the eleme
nt is not | 281 * Return the element referenced by the given location, or `null` if the eleme
nt is not |
| 280 * immediately available or if there is no element with the given location. Th
e latter condition | 282 * immediately available or if there is no element with the given location. Th
e latter condition |
| 281 * can occur, for example, if the location describes an element from a differe
nt context or if the | 283 * can occur, for example, if the location describes an element from a differe
nt context or if the |
| 282 * element has been removed from this context as a result of some change since
it was originally | 284 * element has been removed from this context as a result of some change since
it was originally |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 * not known. The line information is used to map offsets from the beginning o
f the source to line | 409 * not known. The line information is used to map offsets from the beginning o
f the source to line |
| 408 * and column pairs. | 410 * and column pairs. |
| 409 * | 411 * |
| 410 * @param source the source whose line information is to be returned | 412 * @param source the source whose line information is to be returned |
| 411 * @return the line information for the given source | 413 * @return the line information for the given source |
| 412 * @see #computeLineInfo(Source) | 414 * @see #computeLineInfo(Source) |
| 413 */ | 415 */ |
| 414 LineInfo getLineInfo(Source source); | 416 LineInfo getLineInfo(Source source); |
| 415 | 417 |
| 416 /** | 418 /** |
| 419 * Return an array containing all of the sources known to this context and the
ir resolution state |
| 420 * is not valid or flush. So, these sources are not safe to update during refa
ctoring, because we |
| 421 * may be don't know all the references in them. |
| 422 * |
| 423 * @return the sources known to this context and are not safe for refactoring |
| 424 */ |
| 425 List<Source> get refactoringUnsafeSources; |
| 426 |
| 427 /** |
| 417 * Return a fully resolved AST for a single compilation unit within the given
library, or | 428 * Return a fully resolved AST for a single compilation unit within the given
library, or |
| 418 * `null` if the resolved AST is not already computed. | 429 * `null` if the resolved AST is not already computed. |
| 419 * | 430 * |
| 420 * @param unitSource the source of the compilation unit | 431 * @param unitSource the source of the compilation unit |
| 421 * @param library the library containing the compilation unit | 432 * @param library the library containing the compilation unit |
| 422 * @return a fully resolved AST for the compilation unit | 433 * @return a fully resolved AST for the compilation unit |
| 423 * @see #resolveCompilationUnit(Source, LibraryElement) | 434 * @see #resolveCompilationUnit(Source, LibraryElement) |
| 424 */ | 435 */ |
| 425 CompilationUnit getResolvedCompilationUnit(Source unitSource, LibraryElement l
ibrary); | 436 CompilationUnit getResolvedCompilationUnit(Source unitSource, LibraryElement l
ibrary); |
| 426 | 437 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 * resolved. | 507 * resolved. |
| 497 * | 508 * |
| 498 * @param source the HTML source to be parsed | 509 * @param source the HTML source to be parsed |
| 499 * @return the parse result (not `null`) | 510 * @return the parse result (not `null`) |
| 500 * @throws AnalysisException if the analysis could not be performed | 511 * @throws AnalysisException if the analysis could not be performed |
| 501 */ | 512 */ |
| 502 HtmlUnit parseHtmlUnit(Source source); | 513 HtmlUnit parseHtmlUnit(Source source); |
| 503 | 514 |
| 504 /** | 515 /** |
| 505 * Perform the next unit of work required to keep the analysis results up-to-d
ate and return | 516 * Perform the next unit of work required to keep the analysis results up-to-d
ate and return |
| 506 * information about the consequent changes to the analysis results. If there
were no results the | 517 * information about the consequent changes to the analysis results. This meth
od can be long |
| 507 * returned array will be empty. If there are no more units of work required,
then this method | 518 * running. |
| 508 * returns `null`. This method can be long running. | |
| 509 * | 519 * |
| 510 * @return an array containing notices of changes to the analysis results | 520 * @return the results of performing the analysis |
| 511 */ | 521 */ |
| 512 List<ChangeNotice> performAnalysisTask(); | 522 AnalysisResult performAnalysisTask(); |
| 513 | 523 |
| 514 /** | 524 /** |
| 515 * Parse and resolve a single source within the given context to produce a ful
ly resolved AST. | 525 * Parse and resolve a single source within the given context to produce a ful
ly resolved AST. |
| 516 * | 526 * |
| 517 * @param unitSource the source to be parsed and resolved | 527 * @param unitSource the source to be parsed and resolved |
| 518 * @param library the library containing the source to be resolved | 528 * @param library the library containing the source to be resolved |
| 519 * @return the result of resolving the AST structure representing the content
of the source in the | 529 * @return the result of resolving the AST structure representing the content
of the source in the |
| 520 * context of the given library | 530 * context of the given library |
| 521 * @throws AnalysisException if the analysis could not be performed | 531 * @throws AnalysisException if the analysis could not be performed |
| 522 * @see #getResolvedCompilationUnit(Source, LibraryElement) | 532 * @see #getResolvedCompilationUnit(Source, LibraryElement) |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 * | 573 * |
| 564 * Changes made to the list after this method returns will <b>not</b> be refle
cted in the priority | 574 * Changes made to the list after this method returns will <b>not</b> be refle
cted in the priority |
| 565 * order. | 575 * order. |
| 566 * | 576 * |
| 567 * @param sources the sources to be given priority over other sources | 577 * @param sources the sources to be given priority over other sources |
| 568 */ | 578 */ |
| 569 void set analysisPriorityOrder(List<Source> sources); | 579 void set analysisPriorityOrder(List<Source> sources); |
| 570 | 580 |
| 571 /** | 581 /** |
| 572 * Set the contents of the given source to the given contents and mark the sou
rce as having | 582 * Set the contents of the given source to the given contents and mark the sou
rce as having |
| 583 * changed. The additional offset and length information is used by the contex
t to determine what |
| 584 * reanalysis is necessary. |
| 585 * |
| 586 * @param source the source whose contents are being overridden |
| 587 * @param contents the text to replace the range in the current contents |
| 588 * @param offset the offset into the current contents |
| 589 * @param oldLength the number of characters in the original contents that wer
e replaced |
| 590 * @param newLength the number of characters in the replacement text |
| 591 */ |
| 592 void setChangedContents(Source source, String contents, int offset, int oldLen
gth, int newLength); |
| 593 |
| 594 /** |
| 595 * Set the contents of the given source to the given contents and mark the sou
rce as having |
| 573 * changed. This has the effect of overriding the default contents of the sour
ce. If the contents | 596 * changed. This has the effect of overriding the default contents of the sour
ce. If the contents |
| 574 * are `null` the override is removed so that the default contents will be ret
urned. | 597 * are `null` the override is removed so that the default contents will be ret
urned. |
| 575 * | 598 * |
| 576 * @param source the source whose contents are being overridden | 599 * @param source the source whose contents are being overridden |
| 577 * @param contents the new contents of the source | 600 * @param contents the new contents of the source |
| 578 */ | 601 */ |
| 579 void setContents(Source source, String contents); | 602 void setContents(Source source, String contents); |
| 580 | 603 |
| 581 /** | 604 /** |
| 582 * Set the source factory used to create the sources that can be analyzed in t
his context to the | 605 * Set the source factory used to create the sources that can be analyzed in t
his context to the |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 653 */ | 676 */ |
| 654 AnalysisException.con3(Exception cause) : super.withCause(cause); | 677 AnalysisException.con3(Exception cause) : super.withCause(cause); |
| 655 } | 678 } |
| 656 /** | 679 /** |
| 657 * The interface `AnalysisOptions` defines the behavior of objects that provide
access to a | 680 * The interface `AnalysisOptions` defines the behavior of objects that provide
access to a |
| 658 * set of analysis options used to control the behavior of an analysis context. | 681 * set of analysis options used to control the behavior of an analysis context. |
| 659 */ | 682 */ |
| 660 abstract class AnalysisOptions { | 683 abstract class AnalysisOptions { |
| 661 | 684 |
| 662 /** | 685 /** |
| 686 * Return the maximum number of sources for which AST structures should be kep
t in the cache. |
| 687 * |
| 688 * @return the maximum number of sources for which AST structures should be ke
pt in the cache |
| 689 */ |
| 690 int get cacheSize; |
| 691 |
| 692 /** |
| 663 * Return `true` if analysis is to generate dart2js related hint results. | 693 * Return `true` if analysis is to generate dart2js related hint results. |
| 664 * | 694 * |
| 665 * @return `true` if analysis is to generate dart2js related hint results | 695 * @return `true` if analysis is to generate dart2js related hint results |
| 666 */ | 696 */ |
| 667 bool get dart2jsHint; | 697 bool get dart2jsHint; |
| 668 | 698 |
| 669 /** | 699 /** |
| 670 * Return `true` if analysis is to generate hint results (e.g. type inference
based | 700 * Return `true` if analysis is to generate hint results (e.g. type inference
based |
| 671 * information and pub best practices). | 701 * information and pub best practices). |
| 672 * | 702 * |
| 673 * @return `true` if analysis is to generate hint results | 703 * @return `true` if analysis is to generate hint results |
| 674 */ | 704 */ |
| 675 bool get hint; | 705 bool get hint; |
| 676 | 706 |
| 677 /** | 707 /** |
| 678 * Return `true` if analysis is to use strict mode. In strict mode, error repo
rting is based | 708 * Return `true` if analysis is to use strict mode. In strict mode, error repo
rting is based |
| 679 * exclusively on the static type information. | 709 * exclusively on the static type information. |
| 680 * | 710 * |
| 681 * @return `true` if analysis is to use strict mode | 711 * @return `true` if analysis is to use strict mode |
| 682 */ | 712 */ |
| 683 bool get strictMode; | 713 bool get strictMode; |
| 684 } | 714 } |
| 685 /** | 715 /** |
| 716 * Instances of the class `AnalysisResult` |
| 717 */ |
| 718 class AnalysisResult { |
| 719 |
| 720 /** |
| 721 * The change notices associated with this result, or `null` if there were no
changes and |
| 722 * there is no more work to be done. |
| 723 */ |
| 724 List<ChangeNotice> changeNotices; |
| 725 |
| 726 /** |
| 727 * The number of milliseconds required to determine which task was to be perfo
rmed. |
| 728 */ |
| 729 int getTime = 0; |
| 730 |
| 731 /** |
| 732 * The name of the class of the task that was performed. |
| 733 */ |
| 734 String taskClassName; |
| 735 |
| 736 /** |
| 737 * The number of milliseconds required to perform the task. |
| 738 */ |
| 739 int performTime = 0; |
| 740 |
| 741 /** |
| 742 * Initialize a newly created analysis result to have the given values. |
| 743 * |
| 744 * @param notices the change notices associated with this result |
| 745 * @param getTime the number of milliseconds required to determine which task
was to be performed |
| 746 * @param taskClassName the name of the class of the task that was performed |
| 747 * @param performTime the number of milliseconds required to perform the task |
| 748 */ |
| 749 AnalysisResult(List<ChangeNotice> notices, int getTime, String taskClassName,
int performTime) { |
| 750 this.changeNotices = notices; |
| 751 this.getTime = getTime; |
| 752 this.taskClassName = taskClassName; |
| 753 this.performTime = performTime; |
| 754 } |
| 755 } |
| 756 /** |
| 686 * The interface `ChangeNotice` defines the behavior of objects that represent a
change to the | 757 * The interface `ChangeNotice` defines the behavior of objects that represent a
change to the |
| 687 * analysis results associated with a given source. | 758 * analysis results associated with a given source. |
| 688 * | 759 * |
| 689 * @coverage dart.engine | 760 * @coverage dart.engine |
| 690 */ | 761 */ |
| 691 abstract class ChangeNotice implements AnalysisErrorInfo { | 762 abstract class ChangeNotice implements AnalysisErrorInfo { |
| 692 | 763 |
| 693 /** | 764 /** |
| 694 * Return the fully resolved AST that changed as a result of the analysis, or
`null` if the | 765 * Return the fully resolved AST that changed as a result of the analysis, or
`null` if the |
| 695 * AST was not changed. | 766 * AST was not changed. |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 841 * A table mapping the sources known to the context to the information known a
bout the source. | 912 * A table mapping the sources known to the context to the information known a
bout the source. |
| 842 */ | 913 */ |
| 843 Map<Source, SourceEntry> _sourceMap = new Map<Source, SourceEntry>(); | 914 Map<Source, SourceEntry> _sourceMap = new Map<Source, SourceEntry>(); |
| 844 | 915 |
| 845 /** | 916 /** |
| 846 * The maximum number of sources for which AST structures should be kept in th
e cache. | 917 * The maximum number of sources for which AST structures should be kept in th
e cache. |
| 847 */ | 918 */ |
| 848 int _maxCacheSize = 0; | 919 int _maxCacheSize = 0; |
| 849 | 920 |
| 850 /** | 921 /** |
| 922 * The policy used to determine which pieces of data to remove from the cache. |
| 923 */ |
| 924 CacheRetentionPolicy _retentionPolicy; |
| 925 |
| 926 /** |
| 851 * A list containing the most recently accessed sources with the most recently
used at the end of | 927 * A list containing the most recently accessed sources with the most recently
used at the end of |
| 852 * the list. When more sources are added than the maximum allowed then the lea
st recently used | 928 * the list. When more sources are added than the maximum allowed then the lea
st recently used |
| 853 * source will be removed and will have it's cached AST structure flushed. | 929 * source will be removed and will have it's cached AST structure flushed. |
| 854 */ | 930 */ |
| 855 List<Source> _recentlyUsed; | 931 List<Source> _recentlyUsed; |
| 856 | 932 |
| 857 /** | 933 /** |
| 858 * An array containing sources for which data should not be flushed. | |
| 859 */ | |
| 860 List<Source> _priorityOrder = Source.EMPTY_ARRAY; | |
| 861 | |
| 862 /** | |
| 863 * The number of times that the flushing of information from the cache has bee
n disabled without | |
| 864 * being re-enabled. | |
| 865 */ | |
| 866 int _cacheRemovalCount = 0; | |
| 867 | |
| 868 /** | |
| 869 * Initialize a newly created cache to maintain at most the given number of AS
T structures in the | 934 * Initialize a newly created cache to maintain at most the given number of AS
T structures in the |
| 870 * cache. | 935 * cache. |
| 871 * | 936 * |
| 872 * @param maxCacheSize the maximum number of sources for which AST structures
should be kept in | 937 * @param maxCacheSize the maximum number of sources for which AST structures
should be kept in |
| 873 * the cache | 938 * the cache |
| 939 * @param retentionPolicy the policy used to determine which pieces of data to
remove from the |
| 940 * cache |
| 874 */ | 941 */ |
| 875 AnalysisCache(int maxCacheSize) { | 942 AnalysisCache(int maxCacheSize, CacheRetentionPolicy retentionPolicy) { |
| 876 this._maxCacheSize = maxCacheSize; | 943 this._maxCacheSize = maxCacheSize; |
| 944 this._retentionPolicy = retentionPolicy; |
| 877 _recentlyUsed = new List<Source>(); | 945 _recentlyUsed = new List<Source>(); |
| 878 } | 946 } |
| 879 | 947 |
| 880 /** | 948 /** |
| 881 * Record that the given source was just accessed. | 949 * Record that the given source was just accessed. |
| 882 * | 950 * |
| 883 * @param source the source that was accessed | 951 * @param source the source that was accessed |
| 884 */ | 952 */ |
| 885 void accessed(Source source) { | 953 void accessed(Source source) { |
| 886 if (_recentlyUsed.remove(source)) { | 954 if (_recentlyUsed.remove(source)) { |
| 887 _recentlyUsed.add(source); | 955 _recentlyUsed.add(source); |
| 888 return; | 956 return; |
| 889 } | 957 } |
| 890 if (_cacheRemovalCount == 0 && _recentlyUsed.length >= _maxCacheSize) { | 958 while (_recentlyUsed.length >= _maxCacheSize) { |
| 891 flushAstFromCache(); | 959 if (!flushAstFromCache()) { |
| 960 break; |
| 961 } |
| 892 } | 962 } |
| 893 _recentlyUsed.add(source); | 963 _recentlyUsed.add(source); |
| 894 } | 964 } |
| 895 | 965 |
| 896 /** | 966 /** |
| 897 * Disable flushing information from the cache until [enableCacheRemoval] has
been | |
| 898 * called. | |
| 899 */ | |
| 900 void disableCacheRemoval() { | |
| 901 _cacheRemovalCount++; | |
| 902 } | |
| 903 | |
| 904 /** | |
| 905 * Re-enable flushing information from the cache. | |
| 906 */ | |
| 907 void enableCacheRemoval() { | |
| 908 if (_cacheRemovalCount > 0) { | |
| 909 _cacheRemovalCount--; | |
| 910 } | |
| 911 if (_cacheRemovalCount == 0) { | |
| 912 while (_recentlyUsed.length > _maxCacheSize) { | |
| 913 flushAstFromCache(); | |
| 914 } | |
| 915 } | |
| 916 } | |
| 917 | |
| 918 /** | |
| 919 * Return a collection containing all of the map entries mapping sources to ca
che entries. Clients | 967 * Return a collection containing all of the map entries mapping sources to ca
che entries. Clients |
| 920 * should not modify the returned collection. | 968 * should not modify the returned collection. |
| 921 * | 969 * |
| 922 * @return a collection containing all of the map entries mapping sources to c
ache entries | 970 * @return a collection containing all of the map entries mapping sources to c
ache entries |
| 923 */ | 971 */ |
| 924 Iterable<MapEntry<Source, SourceEntry>> entrySet() => getMapEntrySet(_sourceMa
p); | 972 Iterable<MapEntry<Source, SourceEntry>> entrySet() => getMapEntrySet(_sourceMa
p); |
| 925 | 973 |
| 926 /** | 974 /** |
| 927 * Return the entry associated with the given source. | 975 * Return the entry associated with the given source. |
| 928 * | 976 * |
| 929 * @param source the source whose entry is to be returned | 977 * @param source the source whose entry is to be returned |
| 930 * @return the entry associated with the given source | 978 * @return the entry associated with the given source |
| 931 */ | 979 */ |
| 932 SourceEntry get(Source source) => _sourceMap[source]; | 980 SourceEntry get(Source source) => _sourceMap[source]; |
| 933 | 981 |
| 934 /** | 982 /** |
| 935 * Return an array containing sources for which data should not be flushed. | |
| 936 * | |
| 937 * @return an array containing sources for which data should not be flushed | |
| 938 */ | |
| 939 List<Source> get priorityOrder => _priorityOrder; | |
| 940 | |
| 941 /** | |
| 942 * Associate the given entry with the given source. | 983 * Associate the given entry with the given source. |
| 943 * | 984 * |
| 944 * @param source the source with which the entry is to be associated | 985 * @param source the source with which the entry is to be associated |
| 945 * @param entry the entry to be associated with the source | 986 * @param entry the entry to be associated with the source |
| 946 */ | 987 */ |
| 947 void put(Source source, SourceEntry entry) { | 988 void put(Source source, SourceEntry entry) { |
| 948 _sourceMap[source] = entry; | 989 _sourceMap[source] = entry; |
| 949 } | 990 } |
| 950 | 991 |
| 951 /** | 992 /** |
| 952 * Remove all information related to the given source from this cache. | 993 * Remove all information related to the given source from this cache. |
| 953 * | 994 * |
| 954 * @param source the source to be removed | 995 * @param source the source to be removed |
| 955 */ | 996 */ |
| 956 void remove(Source source) { | 997 void remove(Source source) { |
| 957 _sourceMap.remove(source); | 998 _sourceMap.remove(source); |
| 958 } | 999 } |
| 959 | 1000 |
| 960 /** | 1001 /** |
| 961 * Set the sources for which data should not be flushed to the given array. | 1002 * Set the maximum size of the cache to the given size. |
| 962 * | 1003 * |
| 963 * @param sources the sources for which data should not be flushed | 1004 * @param size the maximum number of sources for which AST structures should b
e kept in the cache |
| 964 */ | 1005 */ |
| 965 void set priorityOrder(List<Source> sources) { | 1006 void set maxCacheSize(int size) { |
| 966 _priorityOrder = sources; | 1007 _maxCacheSize = size; |
| 1008 while (_recentlyUsed.length > _maxCacheSize) { |
| 1009 if (!flushAstFromCache()) { |
| 1010 break; |
| 1011 } |
| 1012 } |
| 967 } | 1013 } |
| 968 | 1014 |
| 969 /** | 1015 /** |
| 970 * Flush one AST structure from the cache. | 1016 * Return the number of sources that are mapped to cache entries. |
| 1017 * |
| 1018 * @return the number of sources that are mapped to cache entries |
| 971 */ | 1019 */ |
| 972 void flushAstFromCache() { | 1020 int size() => _sourceMap.length; |
| 1021 |
| 1022 /** |
| 1023 * Attempt to flush one AST structure from the cache. |
| 1024 * |
| 1025 * @return `true` if a structure was flushed |
| 1026 */ |
| 1027 bool flushAstFromCache() { |
| 973 Source removedSource = removeAstToFlush(); | 1028 Source removedSource = removeAstToFlush(); |
| 1029 if (removedSource == null) { |
| 1030 return false; |
| 1031 } |
| 974 SourceEntry sourceEntry = _sourceMap[removedSource]; | 1032 SourceEntry sourceEntry = _sourceMap[removedSource]; |
| 975 if (sourceEntry is HtmlEntry) { | 1033 if (sourceEntry is HtmlEntry) { |
| 976 HtmlEntryImpl htmlCopy = ((sourceEntry as HtmlEntry)).writableCopy; | 1034 HtmlEntryImpl htmlCopy = ((sourceEntry as HtmlEntry)).writableCopy; |
| 977 htmlCopy.setState(HtmlEntry.PARSED_UNIT, CacheState.FLUSHED); | 1035 htmlCopy.setState(HtmlEntry.PARSED_UNIT, CacheState.FLUSHED); |
| 978 _sourceMap[removedSource] = htmlCopy; | 1036 _sourceMap[removedSource] = htmlCopy; |
| 979 } else if (sourceEntry is DartEntry) { | 1037 } else if (sourceEntry is DartEntry) { |
| 980 DartEntryImpl dartCopy = ((sourceEntry as DartEntry)).writableCopy; | 1038 DartEntryImpl dartCopy = ((sourceEntry as DartEntry)).writableCopy; |
| 981 dartCopy.flushAstStructures(); | 1039 dartCopy.flushAstStructures(); |
| 982 _sourceMap[removedSource] = dartCopy; | 1040 _sourceMap[removedSource] = dartCopy; |
| 983 } | 1041 } |
| 1042 return true; |
| 984 } | 1043 } |
| 985 | 1044 |
| 986 /** | 1045 /** |
| 987 * Return `true` if the given source is in the array of priority sources. | |
| 988 * | |
| 989 * @return `true` if the given source is in the array of priority sources | |
| 990 */ | |
| 991 bool isPrioritySource(Source source) { | |
| 992 for (Source prioritySource in _priorityOrder) { | |
| 993 if (source == prioritySource) { | |
| 994 return true; | |
| 995 } | |
| 996 } | |
| 997 return false; | |
| 998 } | |
| 999 | |
| 1000 /** | |
| 1001 * Remove and return one source from the list of recently used sources whose A
ST structure can be | 1046 * Remove and return one source from the list of recently used sources whose A
ST structure can be |
| 1002 * flushed from the cache. The source that will be returned will be the source
that has been | 1047 * flushed from the cache. The source that will be returned will be the source
that has been |
| 1003 * unreferenced for the longest period of time but that is not a priority for
analysis. | 1048 * unreferenced for the longest period of time but that is not a priority for
analysis. |
| 1004 * | 1049 * |
| 1005 * @return the source that was removed | 1050 * @return the source that was removed |
| 1006 */ | 1051 */ |
| 1007 Source removeAstToFlush() { | 1052 Source removeAstToFlush() { |
| 1053 int sourceToRemove = -1; |
| 1008 for (int i = 0; i < _recentlyUsed.length; i++) { | 1054 for (int i = 0; i < _recentlyUsed.length; i++) { |
| 1009 Source source = _recentlyUsed[i]; | 1055 Source source = _recentlyUsed[i]; |
| 1010 if (!isPrioritySource(source)) { | 1056 RetentionPriority priority = _retentionPolicy.getAstPriority(source, _sour
ceMap[source]); |
| 1057 if (identical(priority, RetentionPriority.LOW)) { |
| 1011 return _recentlyUsed.removeAt(i); | 1058 return _recentlyUsed.removeAt(i); |
| 1059 } else if (identical(priority, RetentionPriority.MEDIUM) && sourceToRemove
< 0) { |
| 1060 sourceToRemove = i; |
| 1012 } | 1061 } |
| 1013 } | 1062 } |
| 1014 AnalysisEngine.instance.logger.logError2("Internal error: The number of prio
rity sources (${_priorityOrder.length}) is greater than the maximum cache size (
${_maxCacheSize})", new JavaException()); | 1063 if (sourceToRemove < 0) { |
| 1015 return _recentlyUsed.removeAt(0); | 1064 AnalysisEngine.instance.logger.logError2("Internal error: Could not flush
data from the cache", new JavaException()); |
| 1065 return null; |
| 1066 } |
| 1067 return _recentlyUsed.removeAt(sourceToRemove); |
| 1016 } | 1068 } |
| 1017 } | 1069 } |
| 1018 /** | 1070 /** |
| 1071 * Instances of the class `CacheRetentionPolicy` define the behavior of objects
that determine |
| 1072 * how important it is for data to be retained in the analysis cache. |
| 1073 */ |
| 1074 abstract class CacheRetentionPolicy { |
| 1075 |
| 1076 /** |
| 1077 * Return the priority of retaining the AST structure for the given source. |
| 1078 * |
| 1079 * @param source the source whose AST structure is being considered for remova
l |
| 1080 * @param sourceEntry the entry representing the source |
| 1081 * @return the priority of retaining the AST structure for the given source |
| 1082 */ |
| 1083 RetentionPriority getAstPriority(Source source, SourceEntry sourceEntry); |
| 1084 } |
| 1085 /** |
| 1019 * The enumeration `CacheState` defines the possible states of cached data. | 1086 * The enumeration `CacheState` defines the possible states of cached data. |
| 1020 */ | 1087 */ |
| 1021 class CacheState extends Enum<CacheState> { | 1088 class CacheState extends Enum<CacheState> { |
| 1022 | 1089 |
| 1023 /** | 1090 /** |
| 1024 * The data is not in the cache and the last time an attempt was made to compu
te the data an | 1091 * The data is not in the cache and the last time an attempt was made to compu
te the data an |
| 1025 * exception occurred, making it pointless to attempt. | 1092 * exception occurred, making it pointless to attempt. |
| 1026 * | 1093 * |
| 1027 * Valid Transitions: | 1094 * Valid Transitions: |
| 1028 * | 1095 * |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1201 * Return the value of the data represented by the given descriptor in the con
text of the given | 1268 * Return the value of the data represented by the given descriptor in the con
text of the given |
| 1202 * library, or `null` if the data represented by the descriptor is not in the
cache. | 1269 * library, or `null` if the data represented by the descriptor is not in the
cache. |
| 1203 * | 1270 * |
| 1204 * @param descriptor the descriptor representing which data is to be returned | 1271 * @param descriptor the descriptor representing which data is to be returned |
| 1205 * @param librarySource the source of the defining compilation unit of the lib
rary that is the | 1272 * @param librarySource the source of the defining compilation unit of the lib
rary that is the |
| 1206 * context for the data | 1273 * context for the data |
| 1207 * @return the value of the data represented by the given descriptor and libra
ry | 1274 * @return the value of the data represented by the given descriptor and libra
ry |
| 1208 */ | 1275 */ |
| 1209 Object getValue2(DataDescriptor descriptor, Source librarySource); | 1276 Object getValue2(DataDescriptor descriptor, Source librarySource); |
| 1210 DartEntryImpl get writableCopy; | 1277 DartEntryImpl get writableCopy; |
| 1278 |
| 1279 /** |
| 1280 * Return `true` if the data represented by the given descriptor is marked as
being invalid. |
| 1281 * If the descriptor represents library-specific data then this method will re
turn `true` if |
| 1282 * the data associated with any library it marked as invalid. |
| 1283 * |
| 1284 * @param descriptor the descriptor representing which data is being tested |
| 1285 * @return `true` if the data is marked as being invalid |
| 1286 */ |
| 1287 bool hasInvalidData(DataDescriptor descriptor); |
| 1288 |
| 1289 /** |
| 1290 * Return `true` if this data is safe to use in refactoring. |
| 1291 */ |
| 1292 bool get isRefactoringSafe; |
| 1211 } | 1293 } |
| 1212 /** | 1294 /** |
| 1213 * Instances of the class `DartEntryImpl` implement a [DartEntry]. | 1295 * Instances of the class `DartEntryImpl` implement a [DartEntry]. |
| 1214 * | 1296 * |
| 1215 * @coverage dart.engine | 1297 * @coverage dart.engine |
| 1216 */ | 1298 */ |
| 1217 class DartEntryImpl extends SourceEntryImpl implements DartEntry { | 1299 class DartEntryImpl extends SourceEntryImpl implements DartEntry { |
| 1218 | 1300 |
| 1219 /** | 1301 /** |
| 1220 * The state of the cached source kind. | 1302 * The state of the cached source kind. |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1523 return null; | 1605 return null; |
| 1524 } else { | 1606 } else { |
| 1525 throw new IllegalArgumentException("Invalid descriptor: ${descriptor}"); | 1607 throw new IllegalArgumentException("Invalid descriptor: ${descriptor}"); |
| 1526 } | 1608 } |
| 1527 } | 1609 } |
| 1528 DartEntryImpl get writableCopy { | 1610 DartEntryImpl get writableCopy { |
| 1529 DartEntryImpl copy = new DartEntryImpl(); | 1611 DartEntryImpl copy = new DartEntryImpl(); |
| 1530 copy.copyFrom(this); | 1612 copy.copyFrom(this); |
| 1531 return copy; | 1613 return copy; |
| 1532 } | 1614 } |
| 1615 bool hasInvalidData(DataDescriptor descriptor) { |
| 1616 if (identical(descriptor, DartEntry.ELEMENT)) { |
| 1617 return identical(_elementState, CacheState.INVALID); |
| 1618 } else if (identical(descriptor, DartEntry.EXPORTED_LIBRARIES)) { |
| 1619 return identical(_exportedLibrariesState, CacheState.INVALID); |
| 1620 } else if (identical(descriptor, DartEntry.IMPORTED_LIBRARIES)) { |
| 1621 return identical(_importedLibrariesState, CacheState.INVALID); |
| 1622 } else if (identical(descriptor, DartEntry.INCLUDED_PARTS)) { |
| 1623 return identical(_includedPartsState, CacheState.INVALID); |
| 1624 } else if (identical(descriptor, DartEntry.IS_CLIENT)) { |
| 1625 return identical(_clientServerState, CacheState.INVALID); |
| 1626 } else if (identical(descriptor, DartEntry.IS_LAUNCHABLE)) { |
| 1627 return identical(_launchableState, CacheState.INVALID); |
| 1628 } else if (identical(descriptor, DartEntry.PARSE_ERRORS)) { |
| 1629 return identical(_parseErrorsState, CacheState.INVALID); |
| 1630 } else if (identical(descriptor, DartEntry.PARSED_UNIT)) { |
| 1631 return identical(_parsedUnitState, CacheState.INVALID); |
| 1632 } else if (identical(descriptor, DartEntry.PUBLIC_NAMESPACE)) { |
| 1633 return identical(_publicNamespaceState, CacheState.INVALID); |
| 1634 } else if (identical(descriptor, DartEntry.SOURCE_KIND)) { |
| 1635 return identical(_sourceKindState, CacheState.INVALID); |
| 1636 } else if (identical(descriptor, DartEntry.RESOLUTION_ERRORS) || identical(d
escriptor, DartEntry.RESOLVED_UNIT) || identical(descriptor, DartEntry.VERIFICAT
ION_ERRORS) || identical(descriptor, DartEntry.HINTS)) { |
| 1637 DartEntryImpl_ResolutionState state = _resolutionState; |
| 1638 while (state != null) { |
| 1639 if (identical(descriptor, DartEntry.RESOLUTION_ERRORS)) { |
| 1640 return identical(state._resolutionErrorsState, CacheState.INVALID); |
| 1641 } else if (identical(descriptor, DartEntry.RESOLVED_UNIT)) { |
| 1642 return identical(state._resolvedUnitState, CacheState.INVALID); |
| 1643 } else if (identical(descriptor, DartEntry.VERIFICATION_ERRORS)) { |
| 1644 return identical(state._verificationErrorsState, CacheState.INVALID); |
| 1645 } else if (identical(descriptor, DartEntry.HINTS)) { |
| 1646 return identical(state._hintsState, CacheState.INVALID); |
| 1647 } |
| 1648 } |
| 1649 return false; |
| 1650 } else { |
| 1651 return identical(super.getState(descriptor), CacheState.INVALID); |
| 1652 } |
| 1653 } |
| 1533 | 1654 |
| 1534 /** | 1655 /** |
| 1535 * Invalidate all of the information associated with the compilation unit. | 1656 * Invalidate all of the information associated with the compilation unit. |
| 1536 */ | 1657 */ |
| 1537 void invalidateAllInformation() { | 1658 void invalidateAllInformation() { |
| 1538 setState(SourceEntry.LINE_INFO, CacheState.INVALID); | 1659 setState(SourceEntry.LINE_INFO, CacheState.INVALID); |
| 1539 _sourceKind = SourceKind.UNKNOWN; | 1660 _sourceKind = SourceKind.UNKNOWN; |
| 1540 _sourceKindState = CacheState.INVALID; | 1661 _sourceKindState = CacheState.INVALID; |
| 1541 _parseErrors = AnalysisError.NO_ERRORS; | 1662 _parseErrors = AnalysisError.NO_ERRORS; |
| 1542 _parseErrorsState = CacheState.INVALID; | 1663 _parseErrorsState = CacheState.INVALID; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1558 _exportedLibrariesState = CacheState.INVALID; | 1679 _exportedLibrariesState = CacheState.INVALID; |
| 1559 _importedLibraries = Source.EMPTY_ARRAY; | 1680 _importedLibraries = Source.EMPTY_ARRAY; |
| 1560 _importedLibrariesState = CacheState.INVALID; | 1681 _importedLibrariesState = CacheState.INVALID; |
| 1561 _bitmask = 0; | 1682 _bitmask = 0; |
| 1562 _clientServerState = CacheState.INVALID; | 1683 _clientServerState = CacheState.INVALID; |
| 1563 _launchableState = CacheState.INVALID; | 1684 _launchableState = CacheState.INVALID; |
| 1564 _publicNamespace = null; | 1685 _publicNamespace = null; |
| 1565 _publicNamespaceState = CacheState.INVALID; | 1686 _publicNamespaceState = CacheState.INVALID; |
| 1566 _resolutionState.invalidateAllResolutionInformation(); | 1687 _resolutionState.invalidateAllResolutionInformation(); |
| 1567 } | 1688 } |
| 1689 bool get isRefactoringSafe { |
| 1690 DartEntryImpl_ResolutionState state = _resolutionState; |
| 1691 while (state != null) { |
| 1692 CacheState resolvedState = state._resolvedUnitState; |
| 1693 if (resolvedState != CacheState.VALID && resolvedState != CacheState.FLUSH
ED) { |
| 1694 return false; |
| 1695 } |
| 1696 state = state._nextState; |
| 1697 } |
| 1698 return true; |
| 1699 } |
| 1568 | 1700 |
| 1569 /** | 1701 /** |
| 1570 * Record that an error occurred while attempting to scan or parse the entry r
epresented by this | 1702 * Record that an error occurred while attempting to scan or parse the entry r
epresented by this |
| 1571 * entry. This will set the state of all information, including any resolution
-based information, | 1703 * entry. This will set the state of all information, including any resolution
-based information, |
| 1572 * as being in error. | 1704 * as being in error. |
| 1573 */ | 1705 */ |
| 1574 void recordParseError() { | 1706 void recordParseError() { |
| 1575 setState(SourceEntry.LINE_INFO, CacheState.ERROR); | 1707 setState(SourceEntry.LINE_INFO, CacheState.ERROR); |
| 1576 _sourceKind = SourceKind.UNKNOWN; | 1708 _sourceKind = SourceKind.UNKNOWN; |
| 1577 _sourceKindState = CacheState.ERROR; | 1709 _sourceKindState = CacheState.ERROR; |
| (...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2070 _hintsState = CacheState.INVALID; | 2202 _hintsState = CacheState.INVALID; |
| 2071 _hints = AnalysisError.NO_ERRORS; | 2203 _hints = AnalysisError.NO_ERRORS; |
| 2072 } | 2204 } |
| 2073 | 2205 |
| 2074 /** | 2206 /** |
| 2075 * Record that an error occurred while attempting to scan or parse the entry r
epresented by this | 2207 * Record that an error occurred while attempting to scan or parse the entry r
epresented by this |
| 2076 * entry. This will set the state of all resolution-based information as being
in error, but | 2208 * entry. This will set the state of all resolution-based information as being
in error, but |
| 2077 * will not change the state of any parse results. | 2209 * will not change the state of any parse results. |
| 2078 */ | 2210 */ |
| 2079 void recordResolutionError() { | 2211 void recordResolutionError() { |
| 2080 _nextState = null; | |
| 2081 _librarySource = null; | |
| 2082 _resolvedUnitState = CacheState.ERROR; | 2212 _resolvedUnitState = CacheState.ERROR; |
| 2083 _resolvedUnit = null; | 2213 _resolvedUnit = null; |
| 2084 _resolutionErrorsState = CacheState.ERROR; | 2214 _resolutionErrorsState = CacheState.ERROR; |
| 2085 _resolutionErrors = AnalysisError.NO_ERRORS; | 2215 _resolutionErrors = AnalysisError.NO_ERRORS; |
| 2086 _verificationErrorsState = CacheState.ERROR; | 2216 _verificationErrorsState = CacheState.ERROR; |
| 2087 _verificationErrors = AnalysisError.NO_ERRORS; | 2217 _verificationErrors = AnalysisError.NO_ERRORS; |
| 2088 _hintsState = CacheState.ERROR; | 2218 _hintsState = CacheState.ERROR; |
| 2089 _hints = AnalysisError.NO_ERRORS; | 2219 _hints = AnalysisError.NO_ERRORS; |
| 2220 if (_nextState != null) { |
| 2221 _nextState.recordResolutionError(); |
| 2222 } |
| 2090 } | 2223 } |
| 2091 | 2224 |
| 2092 /** | 2225 /** |
| 2093 * Record that an in-process parse has stopped without recording results becau
se the results | 2226 * Record that an in-process parse has stopped without recording results becau
se the results |
| 2094 * were invalidated before they could be recorded. | 2227 * were invalidated before they could be recorded. |
| 2095 */ | 2228 */ |
| 2096 void recordResolutionNotInProcess() { | 2229 void recordResolutionNotInProcess() { |
| 2097 if (identical(_resolvedUnitState, CacheState.IN_PROCESS)) { | 2230 if (identical(_resolvedUnitState, CacheState.IN_PROCESS)) { |
| 2098 _resolvedUnitState = CacheState.INVALID; | 2231 _resolvedUnitState = CacheState.INVALID; |
| 2099 } | 2232 } |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2395 builder.append(_parsedUnitState); | 2528 builder.append(_parsedUnitState); |
| 2396 builder.append("; resolutionErrors = "); | 2529 builder.append("; resolutionErrors = "); |
| 2397 builder.append(_resolutionErrorsState); | 2530 builder.append(_resolutionErrorsState); |
| 2398 builder.append("; referencedLibraries = "); | 2531 builder.append("; referencedLibraries = "); |
| 2399 builder.append(_referencedLibrariesState); | 2532 builder.append(_referencedLibrariesState); |
| 2400 builder.append("; element = "); | 2533 builder.append("; element = "); |
| 2401 builder.append(_elementState); | 2534 builder.append(_elementState); |
| 2402 } | 2535 } |
| 2403 } | 2536 } |
| 2404 /** | 2537 /** |
| 2538 * The enumerated type `RetentionPriority` represents the priority of data in th
e cache in |
| 2539 * terms of the desirability of retaining some specified data about a specified
source. |
| 2540 */ |
| 2541 class RetentionPriority extends Enum<RetentionPriority> { |
| 2542 |
| 2543 /** |
| 2544 * A priority indicating that a given piece of data can be removed from the ca
che without |
| 2545 * reservation. |
| 2546 */ |
| 2547 static final RetentionPriority LOW = new RetentionPriority('LOW', 0); |
| 2548 |
| 2549 /** |
| 2550 * A priority indicating that a given piece of data should not be removed from
the cache unless |
| 2551 * there are no sources for which the corresponding data has a lower priority.
Currently used for |
| 2552 * data that is needed in order to finish some outstanding analysis task. |
| 2553 */ |
| 2554 static final RetentionPriority MEDIUM = new RetentionPriority('MEDIUM', 1); |
| 2555 |
| 2556 /** |
| 2557 * A priority indicating that a given piece of data should not be removed from
the cache. |
| 2558 * Currently used for data related to a priority source. |
| 2559 */ |
| 2560 static final RetentionPriority HIGH = new RetentionPriority('HIGH', 2); |
| 2561 static final List<RetentionPriority> values = [LOW, MEDIUM, HIGH]; |
| 2562 RetentionPriority(String name, int ordinal) : super(name, ordinal); |
| 2563 } |
| 2564 /** |
| 2405 * The interface `SourceEntry` defines the behavior of objects that maintain the
information | 2565 * The interface `SourceEntry` defines the behavior of objects that maintain the
information |
| 2406 * cached by an analysis context about an individual source, no matter what kind
of source it is. | 2566 * cached by an analysis context about an individual source, no matter what kind
of source it is. |
| 2407 * | 2567 * |
| 2408 * Source entries should be treated as if they were immutable unless a writable
copy of the entry | 2568 * Source entries should be treated as if they were immutable unless a writable
copy of the entry |
| 2409 * has been obtained and has not yet been made visible to other threads. | 2569 * has been obtained and has not yet been made visible to other threads. |
| 2410 * | 2570 * |
| 2411 * @coverage dart.engine | 2571 * @coverage dart.engine |
| 2412 */ | 2572 */ |
| 2413 abstract class SourceEntry { | 2573 abstract class SourceEntry { |
| 2414 | 2574 |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2685 } | 2845 } |
| 2686 } | 2846 } |
| 2687 /** | 2847 /** |
| 2688 * Instances of the class `AnalysisContextImpl` implement an [AnalysisContext]. | 2848 * Instances of the class `AnalysisContextImpl` implement an [AnalysisContext]. |
| 2689 * | 2849 * |
| 2690 * @coverage dart.engine | 2850 * @coverage dart.engine |
| 2691 */ | 2851 */ |
| 2692 class AnalysisContextImpl implements InternalAnalysisContext { | 2852 class AnalysisContextImpl implements InternalAnalysisContext { |
| 2693 | 2853 |
| 2694 /** | 2854 /** |
| 2855 * The difference between the maximum cache size and the maximum priority orde
r size. The priority |
| 2856 * list must be capped so that it is less than the cache size. Failure to do s
o can result in an |
| 2857 * infinite loop in performAnalysisTask() because re-caching one AST structure
can cause another |
| 2858 * priority source's AST structure to be flushed. |
| 2859 */ |
| 2860 static int _PRIORITY_ORDER_SIZE_DELTA = 4; |
| 2861 |
| 2862 /** |
| 2695 * The set of analysis options controlling the behavior of this context. | 2863 * The set of analysis options controlling the behavior of this context. |
| 2696 */ | 2864 */ |
| 2697 AnalysisOptions _options = new AnalysisOptionsImpl(); | 2865 AnalysisOptionsImpl _options = new AnalysisOptionsImpl(); |
| 2698 | 2866 |
| 2699 /** | 2867 /** |
| 2700 * The source factory used to create the sources that can be analyzed in this
context. | 2868 * The source factory used to create the sources that can be analyzed in this
context. |
| 2701 */ | 2869 */ |
| 2702 SourceFactory _sourceFactory; | 2870 SourceFactory _sourceFactory; |
| 2703 | 2871 |
| 2704 /** | 2872 /** |
| 2705 * A table mapping the sources known to the context to the information known a
bout the source. | 2873 * A table mapping the sources known to the context to the information known a
bout the source. |
| 2706 */ | 2874 */ |
| 2707 AnalysisCache _cache = new AnalysisCache(_MAX_CACHE_SIZE); | 2875 AnalysisCache _cache; |
| 2876 |
| 2877 /** |
| 2878 * An array containing sources for which data should not be flushed. |
| 2879 */ |
| 2880 List<Source> _priorityOrder = Source.EMPTY_ARRAY; |
| 2708 | 2881 |
| 2709 /** | 2882 /** |
| 2710 * A table mapping sources to the change notices that are waiting to be return
ed related to that | 2883 * A table mapping sources to the change notices that are waiting to be return
ed related to that |
| 2711 * source. | 2884 * source. |
| 2712 */ | 2885 */ |
| 2713 Map<Source, ChangeNoticeImpl> _pendingNotices = new Map<Source, ChangeNoticeIm
pl>(); | 2886 Map<Source, ChangeNoticeImpl> _pendingNotices = new Map<Source, ChangeNoticeIm
pl>(); |
| 2714 | 2887 |
| 2715 /** | 2888 /** |
| 2716 * The object used to synchronize access to all of the caches. The rules relat
ed to the use of | 2889 * The object used to synchronize access to all of the caches. The rules relat
ed to the use of |
| 2717 * this lock object are | 2890 * this lock object are |
| 2718 * | 2891 * |
| 2719 * * no analysis work is done while holding the lock, and | 2892 * * no analysis work is done while holding the lock, and |
| 2720 * * no analysis results can be recorded unless we have obtained the lock and
validated that the | 2893 * * no analysis results can be recorded unless we have obtained the lock and
validated that the |
| 2721 * results are for the same version (modification time) of the source as our c
urrent cache | 2894 * results are for the same version (modification time) of the source as our c
urrent cache |
| 2722 * content. | 2895 * content. |
| 2723 * | 2896 * |
| 2724 */ | 2897 */ |
| 2725 Object _cacheLock = new Object(); | 2898 Object _cacheLock = new Object(); |
| 2726 | 2899 |
| 2727 /** | 2900 /** |
| 2728 * The object used to record the results of performing an analysis task. | 2901 * The object used to record the results of performing an analysis task. |
| 2729 */ | 2902 */ |
| 2730 AnalysisContextImpl_AnalysisTaskResultRecorder _resultRecorder; | 2903 AnalysisContextImpl_AnalysisTaskResultRecorder _resultRecorder; |
| 2731 | 2904 |
| 2732 /** | 2905 /** |
| 2733 * The maximum number of sources for which data should be kept in the cache. | |
| 2734 */ | |
| 2735 static int _MAX_CACHE_SIZE = 64; | |
| 2736 | |
| 2737 /** | |
| 2738 * The maximum number of sources that can be on the priority list. This <b>mus
t</b> be less than | |
| 2739 * the [MAX_CACHE_SIZE] in order to prevent an infinite loop in performAnalysi
sTask(). | |
| 2740 * | |
| 2741 * @see #setAnalysisPriorityOrder(List) | |
| 2742 */ | |
| 2743 static int _MAX_PRIORITY_LIST_SIZE = _MAX_CACHE_SIZE - 4; | |
| 2744 | |
| 2745 /** | |
| 2746 * Initialize a newly created analysis context. | 2906 * Initialize a newly created analysis context. |
| 2747 */ | 2907 */ |
| 2748 AnalysisContextImpl() : super() { | 2908 AnalysisContextImpl() : super() { |
| 2749 _resultRecorder = new AnalysisContextImpl_AnalysisTaskResultRecorder(this); | 2909 _resultRecorder = new AnalysisContextImpl_AnalysisTaskResultRecorder(this); |
| 2910 _cache = new AnalysisCache(AnalysisOptionsImpl.DEFAULT_CACHE_SIZE, new Analy
sisContextImpl_ContextRetentionPolicy(this)); |
| 2750 } | 2911 } |
| 2751 void addSourceInfo(Source source, SourceEntry info) { | 2912 void addSourceInfo(Source source, SourceEntry info) { |
| 2752 _cache.put(source, info); | 2913 _cache.put(source, info); |
| 2753 } | 2914 } |
| 2754 void applyChanges(ChangeSet changeSet) { | 2915 void applyChanges(ChangeSet changeSet) { |
| 2755 if (changeSet.isEmpty) { | 2916 if (changeSet.isEmpty) { |
| 2756 return; | 2917 return; |
| 2757 } | 2918 } |
| 2758 { | 2919 { |
| 2759 List<Source> removedSources = new List<Source>.from(changeSet.removed3); | 2920 List<Source> removedSources = new List<Source>.from(changeSet.removed3); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2879 return null; | 3040 return null; |
| 2880 } | 3041 } |
| 2881 ResolvableCompilationUnit computeResolvableCompilationUnit(Source source) { | 3042 ResolvableCompilationUnit computeResolvableCompilationUnit(Source source) { |
| 2882 while (true) { | 3043 while (true) { |
| 2883 { | 3044 { |
| 2884 DartEntry dartEntry = getReadableDartEntry(source); | 3045 DartEntry dartEntry = getReadableDartEntry(source); |
| 2885 if (dartEntry == null) { | 3046 if (dartEntry == null) { |
| 2886 throw new AnalysisException.con1("computeResolvableCompilationUnit for
non-Dart: ${source.fullName}"); | 3047 throw new AnalysisException.con1("computeResolvableCompilationUnit for
non-Dart: ${source.fullName}"); |
| 2887 } | 3048 } |
| 2888 if (identical(dartEntry.getState(DartEntry.PARSED_UNIT), CacheState.ERRO
R)) { | 3049 if (identical(dartEntry.getState(DartEntry.PARSED_UNIT), CacheState.ERRO
R)) { |
| 2889 throw new AnalysisException.con1("Internal error: computeResolvableCom
pilationUnit could not parse ${source.fullName}"); | 3050 AnalysisException cause = dartEntry.exception; |
| 3051 if (cause == null) { |
| 3052 throw new AnalysisException.con1("Internal error: computeResolvableC
ompilationUnit could not parse ${source.fullName}"); |
| 3053 } else { |
| 3054 throw new AnalysisException.con2("Internal error: computeResolvableC
ompilationUnit could not parse ${source.fullName}", cause); |
| 3055 } |
| 2890 } | 3056 } |
| 2891 DartEntryImpl dartCopy = dartEntry.writableCopy; | 3057 DartEntryImpl dartCopy = dartEntry.writableCopy; |
| 2892 CompilationUnit unit = dartCopy.resolvableCompilationUnit; | 3058 CompilationUnit unit = dartCopy.resolvableCompilationUnit; |
| 2893 if (unit != null) { | 3059 if (unit != null) { |
| 2894 _cache.put(source, dartCopy); | 3060 _cache.put(source, dartCopy); |
| 2895 return new ResolvableCompilationUnit(dartCopy.modificationTime, unit); | 3061 return new ResolvableCompilationUnit(dartCopy.modificationTime, unit); |
| 2896 } | 3062 } |
| 2897 } | 3063 } |
| 2898 cacheDartParseData(source, getReadableDartEntry(source), DartEntry.PARSED_
UNIT); | 3064 cacheDartParseData(source, getReadableDartEntry(source), DartEntry.PARSED_
UNIT); |
| 2899 } | 3065 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 2917 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) { | 3083 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) { |
| 2918 Source source = entry.getKey(); | 3084 Source source = entry.getKey(); |
| 2919 if (container.contains(source)) { | 3085 if (container.contains(source)) { |
| 2920 sourcesToRemove.add(source); | 3086 sourcesToRemove.add(source); |
| 2921 newContext.addSourceInfo(source, entry.getValue().writableCopy); | 3087 newContext.addSourceInfo(source, entry.getValue().writableCopy); |
| 2922 } | 3088 } |
| 2923 } | 3089 } |
| 2924 } | 3090 } |
| 2925 return newContext; | 3091 return newContext; |
| 2926 } | 3092 } |
| 2927 AnalysisOptions get analysisOptions => _options; | 3093 AnalysisOptions get analysisOptions => new AnalysisOptionsImpl.con1(_options); |
| 2928 Element getElement(ElementLocation location) { | 3094 Element getElement(ElementLocation location) { |
| 2929 try { | 3095 try { |
| 2930 List<String> components = ((location as ElementLocationImpl)).components; | 3096 List<String> components = ((location as ElementLocationImpl)).components; |
| 2931 Source librarySource = computeSourceFromEncoding(components[0]); | 3097 Source librarySource = computeSourceFromEncoding(components[0]); |
| 2932 ElementImpl element = computeLibraryElement(librarySource) as ElementImpl; | 3098 ElementImpl element = computeLibraryElement(librarySource) as ElementImpl; |
| 2933 for (int i = 1; i < components.length; i++) { | 3099 for (int i = 1; i < components.length; i++) { |
| 2934 if (element == null) { | 3100 if (element == null) { |
| 2935 return null; | 3101 return null; |
| 2936 } | 3102 } |
| 2937 element = element.getChild(components[i]); | 3103 element = element.getChild(components[i]); |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3126 } | 3292 } |
| 3127 if (identical(dartEntry.getValue(DartEntry.ELEMENT), library)) { | 3293 if (identical(dartEntry.getValue(DartEntry.ELEMENT), library)) { |
| 3128 DartEntryImpl dartCopy = getReadableDartEntry(source).writableCopy; | 3294 DartEntryImpl dartCopy = getReadableDartEntry(source).writableCopy; |
| 3129 dartCopy.setValue(DartEntry.PUBLIC_NAMESPACE, namespace); | 3295 dartCopy.setValue(DartEntry.PUBLIC_NAMESPACE, namespace); |
| 3130 _cache.put(source, dartCopy); | 3296 _cache.put(source, dartCopy); |
| 3131 } | 3297 } |
| 3132 } | 3298 } |
| 3133 } | 3299 } |
| 3134 return namespace; | 3300 return namespace; |
| 3135 } | 3301 } |
| 3302 List<Source> get refactoringUnsafeSources { |
| 3303 List<Source> sources = new List<Source>(); |
| 3304 { |
| 3305 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) { |
| 3306 SourceEntry sourceEntry = entry.getValue(); |
| 3307 if (sourceEntry is DartEntry) { |
| 3308 if (!((sourceEntry as DartEntry)).isRefactoringSafe) { |
| 3309 sources.add(entry.getKey()); |
| 3310 } |
| 3311 } |
| 3312 } |
| 3313 } |
| 3314 return new List.from(sources); |
| 3315 } |
| 3136 CompilationUnit getResolvedCompilationUnit(Source unitSource, LibraryElement l
ibrary) { | 3316 CompilationUnit getResolvedCompilationUnit(Source unitSource, LibraryElement l
ibrary) { |
| 3137 if (library == null) { | 3317 if (library == null) { |
| 3138 return null; | 3318 return null; |
| 3139 } | 3319 } |
| 3140 return getResolvedCompilationUnit2(unitSource, library.source); | 3320 return getResolvedCompilationUnit2(unitSource, library.source); |
| 3141 } | 3321 } |
| 3142 CompilationUnit getResolvedCompilationUnit2(Source unitSource, Source libraryS
ource) { | 3322 CompilationUnit getResolvedCompilationUnit2(Source unitSource, Source libraryS
ource) { |
| 3143 SourceEntry sourceEntry = getReadableSourceEntry(unitSource); | 3323 SourceEntry sourceEntry = getReadableSourceEntry(unitSource); |
| 3144 if (sourceEntry is DartEntry) { | 3324 if (sourceEntry is DartEntry) { |
| 3145 return ((sourceEntry as DartEntry)).getValue2(DartEntry.RESOLVED_UNIT, lib
rarySource); | 3325 return ((sourceEntry as DartEntry)).getValue2(DartEntry.RESOLVED_UNIT, lib
rarySource); |
| 3146 } | 3326 } |
| 3147 return null; | 3327 return null; |
| 3148 } | 3328 } |
| 3149 SourceFactory get sourceFactory => _sourceFactory; | 3329 SourceFactory get sourceFactory => _sourceFactory; |
| 3150 | 3330 |
| 3151 /** | 3331 /** |
| 3152 * Return a list of the sources that would be processed by [performAnalysisTas
k]. This | 3332 * Return a list of the sources that would be processed by [performAnalysisTas
k]. This |
| 3153 * method duplicates, and must therefore be kept in sync with, [getNextTaskAna
lysisTask]. | 3333 * method duplicates, and must therefore be kept in sync with, [getNextTaskAna
lysisTask]. |
| 3154 * This method is intended to be used for testing purposes only. | 3334 * This method is intended to be used for testing purposes only. |
| 3155 * | 3335 * |
| 3156 * @return a list of the sources that would be processed by [performAnalysisTa
sk] | 3336 * @return a list of the sources that would be processed by [performAnalysisTa
sk] |
| 3157 */ | 3337 */ |
| 3158 List<Source> get sourcesNeedingProcessing { | 3338 List<Source> get sourcesNeedingProcessing { |
| 3159 Set<Source> sources = new Set<Source>(); | 3339 Set<Source> sources = new Set<Source>(); |
| 3160 { | 3340 { |
| 3161 bool hintsEnabled = analysisOptions.hint; | 3341 bool hintsEnabled = analysisOptions.hint; |
| 3162 for (Source source in _cache.priorityOrder) { | 3342 for (Source source in _priorityOrder) { |
| 3163 getSourcesNeedingProcessing2(source, _cache.get(source), true, hintsEnab
led, sources); | 3343 getSourcesNeedingProcessing2(source, _cache.get(source), true, hintsEnab
led, sources); |
| 3164 } | 3344 } |
| 3165 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) { | 3345 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) { |
| 3166 getSourcesNeedingProcessing2(entry.getKey(), entry.getValue(), false, hi
ntsEnabled, sources); | 3346 getSourcesNeedingProcessing2(entry.getKey(), entry.getValue(), false, hi
ntsEnabled, sources); |
| 3167 } | 3347 } |
| 3168 } | 3348 } |
| 3169 return new List<Source>.from(sources); | 3349 return new List<Source>.from(sources); |
| 3170 } | 3350 } |
| 3171 AnalysisContentStatistics get statistics { | 3351 AnalysisContentStatistics get statistics { |
| 3172 AnalysisContentStatisticsImpl statistics = new AnalysisContentStatisticsImpl
(); | 3352 AnalysisContentStatisticsImpl statistics = new AnalysisContentStatisticsImpl
(); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3239 SourceEntry existingEntry = getReadableSourceEntry(newSource); | 3419 SourceEntry existingEntry = getReadableSourceEntry(newSource); |
| 3240 if (existingEntry == null) { | 3420 if (existingEntry == null) { |
| 3241 _cache.put(newSource, entry.getValue().writableCopy); | 3421 _cache.put(newSource, entry.getValue().writableCopy); |
| 3242 } else { | 3422 } else { |
| 3243 } | 3423 } |
| 3244 } | 3424 } |
| 3245 } | 3425 } |
| 3246 } | 3426 } |
| 3247 CompilationUnit parseCompilationUnit(Source source) => getDartParseData2(sourc
e, DartEntry.PARSED_UNIT, null); | 3427 CompilationUnit parseCompilationUnit(Source source) => getDartParseData2(sourc
e, DartEntry.PARSED_UNIT, null); |
| 3248 HtmlUnit parseHtmlUnit(Source source) => getHtmlParseData(source, HtmlEntry.PA
RSED_UNIT, null); | 3428 HtmlUnit parseHtmlUnit(Source source) => getHtmlParseData(source, HtmlEntry.PA
RSED_UNIT, null); |
| 3249 List<ChangeNotice> performAnalysisTask() { | 3429 AnalysisResult performAnalysisTask() { |
| 3430 int getStart = JavaSystem.currentTimeMillis(); |
| 3250 AnalysisTask task = nextTaskAnalysisTask; | 3431 AnalysisTask task = nextTaskAnalysisTask; |
| 3432 int getEnd = JavaSystem.currentTimeMillis(); |
| 3251 if (task == null) { | 3433 if (task == null) { |
| 3252 return getChangeNotices(true); | 3434 return new AnalysisResult(getChangeNotices(true), getEnd - getStart, null,
-1); |
| 3253 } | 3435 } |
| 3436 int performStart = JavaSystem.currentTimeMillis(); |
| 3254 try { | 3437 try { |
| 3255 task.perform(_resultRecorder); | 3438 task.perform(_resultRecorder); |
| 3256 } on AnalysisException catch (exception) { | 3439 } on AnalysisException catch (exception) { |
| 3257 if (exception.cause is! JavaIOException) { | 3440 if (exception.cause is! JavaIOException) { |
| 3258 AnalysisEngine.instance.logger.logError2("Internal error while performin
g the task: ${task}", exception); | 3441 AnalysisEngine.instance.logger.logError2("Internal error while performin
g the task: ${task}", exception); |
| 3259 } | 3442 } |
| 3260 } | 3443 } |
| 3261 return getChangeNotices(false); | 3444 int performEnd = JavaSystem.currentTimeMillis(); |
| 3445 return new AnalysisResult(getChangeNotices(false), getEnd - getStart, task.r
untimeType.toString(), performEnd - performStart); |
| 3262 } | 3446 } |
| 3263 void recordLibraryElements(Map<Source, LibraryElement> elementMap) { | 3447 void recordLibraryElements(Map<Source, LibraryElement> elementMap) { |
| 3264 { | 3448 { |
| 3265 Source htmlSource = _sourceFactory.forUri(DartSdk.DART_HTML); | 3449 Source htmlSource = _sourceFactory.forUri(DartSdk.DART_HTML); |
| 3266 for (MapEntry<Source, LibraryElement> entry in getMapEntrySet(elementMap))
{ | 3450 for (MapEntry<Source, LibraryElement> entry in getMapEntrySet(elementMap))
{ |
| 3267 Source librarySource = entry.getKey(); | 3451 Source librarySource = entry.getKey(); |
| 3268 LibraryElement library = entry.getValue(); | 3452 LibraryElement library = entry.getValue(); |
| 3269 DartEntry dartEntry = getReadableDartEntry(librarySource); | 3453 DartEntry dartEntry = getReadableDartEntry(librarySource); |
| 3270 if (dartEntry != null) { | 3454 if (dartEntry != null) { |
| 3271 DartEntryImpl dartCopy = dartEntry.writableCopy; | 3455 DartEntryImpl dartCopy = dartEntry.writableCopy; |
| 3272 recordElementData(dartCopy, library, htmlSource); | 3456 recordElementData(dartCopy, library, htmlSource); |
| 3273 _cache.put(librarySource, dartCopy); | 3457 _cache.put(librarySource, dartCopy); |
| 3274 } | 3458 } |
| 3275 } | 3459 } |
| 3276 } | 3460 } |
| 3277 } | 3461 } |
| 3278 CompilationUnit resolveCompilationUnit(Source unitSource, LibraryElement libra
ry) { | 3462 CompilationUnit resolveCompilationUnit(Source unitSource, LibraryElement libra
ry) { |
| 3279 if (library == null) { | 3463 if (library == null) { |
| 3280 return null; | 3464 return null; |
| 3281 } | 3465 } |
| 3282 return resolveCompilationUnit2(unitSource, library.source); | 3466 return resolveCompilationUnit2(unitSource, library.source); |
| 3283 } | 3467 } |
| 3284 CompilationUnit resolveCompilationUnit2(Source unitSource, Source librarySourc
e) => getDartResolutionData2(unitSource, librarySource, DartEntry.RESOLVED_UNIT,
null); | 3468 CompilationUnit resolveCompilationUnit2(Source unitSource, Source librarySourc
e) => getDartResolutionData2(unitSource, librarySource, DartEntry.RESOLVED_UNIT,
null); |
| 3285 HtmlUnit resolveHtmlUnit(Source htmlSource) => parseHtmlUnit(htmlSource); | 3469 HtmlUnit resolveHtmlUnit(Source htmlSource) => parseHtmlUnit(htmlSource); |
| 3286 void set analysisOptions(AnalysisOptions options) { | 3470 void set analysisOptions(AnalysisOptions options) { |
| 3287 { | 3471 { |
| 3288 this._options = options; | 3472 bool needsRecompute = this._options.dart2jsHint != options.dart2jsHint ||
(this._options.hint && !options.hint); |
| 3289 invalidateAllResolutionInformation(); | 3473 int cacheSize = options.cacheSize; |
| 3474 if (this._options.cacheSize != cacheSize) { |
| 3475 this._options.cacheSize = cacheSize; |
| 3476 _cache.maxCacheSize = cacheSize; |
| 3477 int maxPriorityOrderSize = cacheSize - _PRIORITY_ORDER_SIZE_DELTA; |
| 3478 if (_priorityOrder.length > maxPriorityOrderSize) { |
| 3479 List<Source> newPriorityOrder = new List<Source>(maxPriorityOrderSize)
; |
| 3480 JavaSystem.arraycopy(_priorityOrder, 0, newPriorityOrder, 0, maxPriori
tyOrderSize); |
| 3481 _priorityOrder = newPriorityOrder; |
| 3482 } |
| 3483 } |
| 3484 this._options.dart2jsHint = options.dart2jsHint; |
| 3485 this._options.hint = options.hint; |
| 3486 this._options.strictMode = options.strictMode; |
| 3487 if (needsRecompute) { |
| 3488 invalidateAllResolutionInformation(); |
| 3489 } |
| 3290 } | 3490 } |
| 3291 } | 3491 } |
| 3292 void set analysisPriorityOrder(List<Source> sources) { | 3492 void set analysisPriorityOrder(List<Source> sources) { |
| 3293 { | 3493 { |
| 3294 if (sources == null || sources.isEmpty) { | 3494 if (sources == null || sources.isEmpty) { |
| 3295 _cache.priorityOrder = Source.EMPTY_ARRAY; | 3495 _priorityOrder = Source.EMPTY_ARRAY; |
| 3296 } else { | 3496 } else { |
| 3297 while (sources.remove(null)) { | 3497 while (sources.remove(null)) { |
| 3298 } | 3498 } |
| 3299 if (sources.isEmpty) { | 3499 if (sources.isEmpty) { |
| 3300 _cache.priorityOrder = Source.EMPTY_ARRAY; | 3500 _priorityOrder = Source.EMPTY_ARRAY; |
| 3301 } | 3501 } |
| 3302 int count = Math.min(sources.length, _MAX_PRIORITY_LIST_SIZE); | 3502 int count = Math.min(sources.length, _options.cacheSize - _PRIORITY_ORDE
R_SIZE_DELTA); |
| 3303 List<Source> priorityOrder = new List<Source>(count); | 3503 _priorityOrder = new List<Source>(count); |
| 3304 for (int i = 0; i < count; i++) { | 3504 for (int i = 0; i < count; i++) { |
| 3305 priorityOrder[i] = sources[i]; | 3505 _priorityOrder[i] = sources[i]; |
| 3306 } | 3506 } |
| 3307 _cache.priorityOrder = priorityOrder; | |
| 3308 } | 3507 } |
| 3309 } | 3508 } |
| 3310 } | 3509 } |
| 3510 void setChangedContents(Source source, String contents, int offset, int oldLen
gth, int newLength) { |
| 3511 { |
| 3512 if (_sourceFactory.setContents(source, contents)) { |
| 3513 sourceChanged(source); |
| 3514 } |
| 3515 } |
| 3516 } |
| 3311 void setContents(Source source, String contents) { | 3517 void setContents(Source source, String contents) { |
| 3312 { | 3518 { |
| 3313 if (_sourceFactory.setContents(source, contents)) { | 3519 if (_sourceFactory.setContents(source, contents)) { |
| 3314 sourceChanged(source); | 3520 sourceChanged(source); |
| 3315 } | 3521 } |
| 3316 } | 3522 } |
| 3317 } | 3523 } |
| 3318 void set sourceFactory(SourceFactory factory) { | 3524 void set sourceFactory(SourceFactory factory) { |
| 3319 { | 3525 { |
| 3320 if (identical(_sourceFactory, factory)) { | 3526 if (identical(_sourceFactory, factory)) { |
| (...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3786 | 3992 |
| 3787 /** | 3993 /** |
| 3788 * Look through the cache for a task that needs to be performed. Return the ta
sk that was found, | 3994 * Look through the cache for a task that needs to be performed. Return the ta
sk that was found, |
| 3789 * or `null` if there is no more work to be done. | 3995 * or `null` if there is no more work to be done. |
| 3790 * | 3996 * |
| 3791 * @return the next task that needs to be performed | 3997 * @return the next task that needs to be performed |
| 3792 */ | 3998 */ |
| 3793 AnalysisTask get nextTaskAnalysisTask { | 3999 AnalysisTask get nextTaskAnalysisTask { |
| 3794 { | 4000 { |
| 3795 bool hintsEnabled = analysisOptions.hint; | 4001 bool hintsEnabled = analysisOptions.hint; |
| 3796 for (Source source in _cache.priorityOrder) { | 4002 for (Source source in _priorityOrder) { |
| 3797 AnalysisTask task = getNextTaskAnalysisTask2(source, _cache.get(source),
true, hintsEnabled); | 4003 AnalysisTask task = getNextTaskAnalysisTask2(source, _cache.get(source),
true, hintsEnabled); |
| 3798 if (task != null) { | 4004 if (task != null) { |
| 3799 return task; | 4005 return task; |
| 3800 } | 4006 } |
| 3801 } | 4007 } |
| 3802 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) { | 4008 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) { |
| 3803 AnalysisTask task = getNextTaskAnalysisTask2(entry.getKey(), entry.getVa
lue(), false, hintsEnabled); | 4009 AnalysisTask task = getNextTaskAnalysisTask2(entry.getKey(), entry.getVa
lue(), false, hintsEnabled); |
| 3804 if (task != null) { | 4010 if (task != null) { |
| 3805 return task; | 4011 return task; |
| 3806 } | 4012 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 3825 AnalysisTask getNextTaskAnalysisTask2(Source source, SourceEntry sourceEntry,
bool isPriority, bool hintsEnabled) { | 4031 AnalysisTask getNextTaskAnalysisTask2(Source source, SourceEntry sourceEntry,
bool isPriority, bool hintsEnabled) { |
| 3826 if (sourceEntry is DartEntry) { | 4032 if (sourceEntry is DartEntry) { |
| 3827 DartEntry dartEntry = sourceEntry as DartEntry; | 4033 DartEntry dartEntry = sourceEntry as DartEntry; |
| 3828 CacheState parseErrorsState = dartEntry.getState(DartEntry.PARSE_ERRORS); | 4034 CacheState parseErrorsState = dartEntry.getState(DartEntry.PARSE_ERRORS); |
| 3829 if (identical(parseErrorsState, CacheState.INVALID) || (isPriority && iden
tical(parseErrorsState, CacheState.FLUSHED))) { | 4035 if (identical(parseErrorsState, CacheState.INVALID) || (isPriority && iden
tical(parseErrorsState, CacheState.FLUSHED))) { |
| 3830 DartEntryImpl dartCopy = dartEntry.writableCopy; | 4036 DartEntryImpl dartCopy = dartEntry.writableCopy; |
| 3831 dartCopy.setState(DartEntry.PARSE_ERRORS, CacheState.IN_PROCESS); | 4037 dartCopy.setState(DartEntry.PARSE_ERRORS, CacheState.IN_PROCESS); |
| 3832 _cache.put(source, dartCopy); | 4038 _cache.put(source, dartCopy); |
| 3833 return new ParseDartTask(this, source); | 4039 return new ParseDartTask(this, source); |
| 3834 } | 4040 } |
| 3835 if (isPriority) { | 4041 if (isPriority && parseErrorsState != CacheState.ERROR) { |
| 3836 CompilationUnit parseUnit = dartEntry.anyParsedCompilationUnit; | 4042 CompilationUnit parseUnit = dartEntry.anyParsedCompilationUnit; |
| 3837 if (parseUnit == null) { | 4043 if (parseUnit == null) { |
| 3838 DartEntryImpl dartCopy = dartEntry.writableCopy; | 4044 DartEntryImpl dartCopy = dartEntry.writableCopy; |
| 3839 dartCopy.setState(DartEntry.PARSED_UNIT, CacheState.IN_PROCESS); | 4045 dartCopy.setState(DartEntry.PARSED_UNIT, CacheState.IN_PROCESS); |
| 3840 _cache.put(source, dartCopy); | 4046 _cache.put(source, dartCopy); |
| 3841 return new ParseDartTask(this, source); | 4047 return new ParseDartTask(this, source); |
| 3842 } | 4048 } |
| 3843 } | 4049 } |
| 3844 for (Source librarySource in getLibrariesContaining(source)) { | 4050 for (Source librarySource in getLibrariesContaining(source)) { |
| 3845 SourceEntry libraryEntry = _cache.get(librarySource); | 4051 SourceEntry libraryEntry = _cache.get(librarySource); |
| 3846 if (libraryEntry is DartEntry) { | 4052 if (libraryEntry is DartEntry) { |
| 3847 CacheState elementState = libraryEntry.getState(DartEntry.ELEMENT); | 4053 CacheState elementState = libraryEntry.getState(DartEntry.ELEMENT); |
| 3848 if (identical(elementState, CacheState.INVALID) || (isPriority && iden
tical(elementState, CacheState.FLUSHED))) { | 4054 if (identical(elementState, CacheState.INVALID) || (isPriority && iden
tical(elementState, CacheState.FLUSHED))) { |
| 3849 DartEntryImpl libraryCopy = ((libraryEntry as DartEntry)).writableCo
py; | 4055 DartEntryImpl libraryCopy = ((libraryEntry as DartEntry)).writableCo
py; |
| 3850 libraryCopy.setState(DartEntry.ELEMENT, CacheState.IN_PROCESS); | 4056 libraryCopy.setState(DartEntry.ELEMENT, CacheState.IN_PROCESS); |
| 3851 _cache.put(librarySource, libraryCopy); | 4057 _cache.put(librarySource, libraryCopy); |
| 3852 return new ResolveDartLibraryTask(this, source, librarySource); | 4058 return new ResolveDartLibraryTask(this, source, librarySource); |
| 3853 } | 4059 } |
| 3854 CacheState resolvedUnitState = dartEntry.getState2(DartEntry.RESOLVED_
UNIT, librarySource); | 4060 CacheState resolvedUnitState = dartEntry.getState2(DartEntry.RESOLVED_
UNIT, librarySource); |
| 3855 if (identical(resolvedUnitState, CacheState.INVALID) || (isPriority &&
identical(resolvedUnitState, CacheState.FLUSHED))) { | 4061 if (identical(resolvedUnitState, CacheState.INVALID) || (isPriority &&
identical(resolvedUnitState, CacheState.FLUSHED))) { |
| 3856 LibraryElement libraryElement = libraryEntry.getValue(DartEntry.ELEM
ENT); | 4062 DartEntryImpl dartCopy = dartEntry.writableCopy; |
| 3857 if (libraryElement != null) { | 4063 dartCopy.setState2(DartEntry.RESOLVED_UNIT, librarySource, CacheStat
e.IN_PROCESS); |
| 3858 DartEntryImpl dartCopy = dartEntry.writableCopy; | 4064 _cache.put(source, dartCopy); |
| 3859 dartCopy.setState2(DartEntry.RESOLVED_UNIT, librarySource, CacheSt
ate.IN_PROCESS); | 4065 return new ResolveDartLibraryTask(this, source, librarySource); |
| 3860 _cache.put(source, dartCopy); | |
| 3861 return new ResolveDartUnitTask(this, source, libraryElement); | |
| 3862 } | |
| 3863 } | 4066 } |
| 3864 CacheState verificationErrorsState = dartEntry.getState2(DartEntry.VER
IFICATION_ERRORS, librarySource); | 4067 CacheState verificationErrorsState = dartEntry.getState2(DartEntry.VER
IFICATION_ERRORS, librarySource); |
| 3865 if (identical(verificationErrorsState, CacheState.INVALID) || (isPrior
ity && identical(verificationErrorsState, CacheState.FLUSHED))) { | 4068 if (identical(verificationErrorsState, CacheState.INVALID) || (isPrior
ity && identical(verificationErrorsState, CacheState.FLUSHED))) { |
| 3866 LibraryElement libraryElement = libraryEntry.getValue(DartEntry.ELEM
ENT); | 4069 LibraryElement libraryElement = libraryEntry.getValue(DartEntry.ELEM
ENT); |
| 3867 if (libraryElement != null) { | 4070 if (libraryElement != null) { |
| 3868 DartEntryImpl dartCopy = dartEntry.writableCopy; | 4071 DartEntryImpl dartCopy = dartEntry.writableCopy; |
| 3869 dartCopy.setState2(DartEntry.VERIFICATION_ERRORS, librarySource, C
acheState.IN_PROCESS); | 4072 dartCopy.setState2(DartEntry.VERIFICATION_ERRORS, librarySource, C
acheState.IN_PROCESS); |
| 3870 _cache.put(source, dartCopy); | 4073 _cache.put(source, dartCopy); |
| 3871 return new GenerateDartErrorsTask(this, source, libraryElement); | 4074 return new GenerateDartErrorsTask(this, source, libraryElement); |
| 3872 } | 4075 } |
| (...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4495 } | 4698 } |
| 4496 { | 4699 { |
| 4497 if (allModificationTimesMatch(resolvedLibraries)) { | 4700 if (allModificationTimesMatch(resolvedLibraries)) { |
| 4498 Source htmlSource = sourceFactory.forUri(DartSdk.DART_HTML); | 4701 Source htmlSource = sourceFactory.forUri(DartSdk.DART_HTML); |
| 4499 RecordingErrorListener errorListener = resolver.errorListener; | 4702 RecordingErrorListener errorListener = resolver.errorListener; |
| 4500 for (Library library in resolvedLibraries) { | 4703 for (Library library in resolvedLibraries) { |
| 4501 Source librarySource = library.librarySource; | 4704 Source librarySource = library.librarySource; |
| 4502 for (Source source in library.compilationUnitSources) { | 4705 for (Source source in library.compilationUnitSources) { |
| 4503 CompilationUnit unit = library.getAST(source); | 4706 CompilationUnit unit = library.getAST(source); |
| 4504 List<AnalysisError> errors = errorListener.getErrors2(source); | 4707 List<AnalysisError> errors = errorListener.getErrors2(source); |
| 4505 unit.resolutionErrors = errors; | 4708 LineInfo lineInfo = getLineInfo(source); |
| 4506 LineInfo lineInfo = unit.lineInfo; | |
| 4507 DartEntry dartEntry = _cache.get(source) as DartEntry; | 4709 DartEntry dartEntry = _cache.get(source) as DartEntry; |
| 4508 int sourceTime = source.modificationStamp; | 4710 int sourceTime = source.modificationStamp; |
| 4509 if (dartEntry.modificationTime != sourceTime) { | 4711 if (dartEntry.modificationTime != sourceTime) { |
| 4510 sourceChanged(source); | 4712 sourceChanged(source); |
| 4511 dartEntry = getReadableDartEntry(source); | 4713 dartEntry = getReadableDartEntry(source); |
| 4512 if (dartEntry == null) { | 4714 if (dartEntry == null) { |
| 4513 throw new AnalysisException.con1("A Dart file became a non-Dar
t file: ${source.fullName}"); | 4715 throw new AnalysisException.con1("A Dart file became a non-Dar
t file: ${source.fullName}"); |
| 4514 } | 4716 } |
| 4515 } | 4717 } |
| 4516 DartEntryImpl dartCopy = dartEntry.writableCopy; | 4718 DartEntryImpl dartCopy = dartEntry.writableCopy; |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4773 final AnalysisContextImpl AnalysisContextImpl_this; | 4975 final AnalysisContextImpl AnalysisContextImpl_this; |
| 4774 AnalysisContextImpl_AnalysisTaskResultRecorder(this.AnalysisContextImpl_this); | 4976 AnalysisContextImpl_AnalysisTaskResultRecorder(this.AnalysisContextImpl_this); |
| 4775 SourceEntry visitGenerateDartErrorsTask(GenerateDartErrorsTask task) => Analys
isContextImpl_this.recordGenerateDartErrorsTask(task); | 4977 SourceEntry visitGenerateDartErrorsTask(GenerateDartErrorsTask task) => Analys
isContextImpl_this.recordGenerateDartErrorsTask(task); |
| 4776 SourceEntry visitGenerateDartHintsTask(GenerateDartHintsTask task) => Analysis
ContextImpl_this.recordGenerateDartHintsTask(task); | 4978 SourceEntry visitGenerateDartHintsTask(GenerateDartHintsTask task) => Analysis
ContextImpl_this.recordGenerateDartHintsTask(task); |
| 4777 DartEntry visitParseDartTask(ParseDartTask task) => AnalysisContextImpl_this.r
ecordParseDartTaskResults(task); | 4979 DartEntry visitParseDartTask(ParseDartTask task) => AnalysisContextImpl_this.r
ecordParseDartTaskResults(task); |
| 4778 HtmlEntry visitParseHtmlTask(ParseHtmlTask task) => AnalysisContextImpl_this.r
ecordParseHtmlTaskResults(task); | 4980 HtmlEntry visitParseHtmlTask(ParseHtmlTask task) => AnalysisContextImpl_this.r
ecordParseHtmlTaskResults(task); |
| 4779 DartEntry visitResolveDartLibraryTask(ResolveDartLibraryTask task) => Analysis
ContextImpl_this.recordResolveDartLibraryTaskResults(task); | 4981 DartEntry visitResolveDartLibraryTask(ResolveDartLibraryTask task) => Analysis
ContextImpl_this.recordResolveDartLibraryTaskResults(task); |
| 4780 SourceEntry visitResolveDartUnitTask(ResolveDartUnitTask task) => AnalysisCont
extImpl_this.recordResolveDartUnitTaskResults(task); | 4982 SourceEntry visitResolveDartUnitTask(ResolveDartUnitTask task) => AnalysisCont
extImpl_this.recordResolveDartUnitTaskResults(task); |
| 4781 SourceEntry visitResolveHtmlTask(ResolveHtmlTask task) => AnalysisContextImpl_
this.recordResolveHtmlTaskResults(task); | 4983 SourceEntry visitResolveHtmlTask(ResolveHtmlTask task) => AnalysisContextImpl_
this.recordResolveHtmlTaskResults(task); |
| 4782 } | 4984 } |
| 4985 class AnalysisContextImpl_ContextRetentionPolicy implements CacheRetentionPolicy
{ |
| 4986 final AnalysisContextImpl AnalysisContextImpl_this; |
| 4987 AnalysisContextImpl_ContextRetentionPolicy(this.AnalysisContextImpl_this); |
| 4988 RetentionPriority getAstPriority(Source source, SourceEntry sourceEntry) { |
| 4989 for (Source prioritySource in AnalysisContextImpl_this._priorityOrder) { |
| 4990 if (source == prioritySource) { |
| 4991 return RetentionPriority.HIGH; |
| 4992 } |
| 4993 } |
| 4994 if (sourceEntry is DartEntry) { |
| 4995 DartEntry dartEntry = sourceEntry as DartEntry; |
| 4996 if (astIsNeeded(dartEntry)) { |
| 4997 return RetentionPriority.MEDIUM; |
| 4998 } |
| 4999 } |
| 5000 return RetentionPriority.LOW; |
| 5001 } |
| 5002 bool astIsNeeded(DartEntry dartEntry) => dartEntry.hasInvalidData(DartEntry.HI
NTS) || dartEntry.hasInvalidData(DartEntry.VERIFICATION_ERRORS) || dartEntry.has
InvalidData(DartEntry.RESOLUTION_ERRORS); |
| 5003 } |
| 4783 /** | 5004 /** |
| 4784 * Instances of the class `AnalysisErrorInfoImpl` represent the analysis errors
and line info | 5005 * Instances of the class `AnalysisErrorInfoImpl` represent the analysis errors
and line info |
| 4785 * associated with a source. | 5006 * associated with a source. |
| 4786 */ | 5007 */ |
| 4787 class AnalysisErrorInfoImpl implements AnalysisErrorInfo { | 5008 class AnalysisErrorInfoImpl implements AnalysisErrorInfo { |
| 4788 | 5009 |
| 4789 /** | 5010 /** |
| 4790 * The analysis errors associated with a source, or `null` if there are no err
ors. | 5011 * The analysis errors associated with a source, or `null` if there are no err
ors. |
| 4791 */ | 5012 */ |
| 4792 List<AnalysisError> _errors; | 5013 List<AnalysisError> _errors; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 4822 */ | 5043 */ |
| 4823 LineInfo get lineInfo => _lineInfo; | 5044 LineInfo get lineInfo => _lineInfo; |
| 4824 } | 5045 } |
| 4825 /** | 5046 /** |
| 4826 * Instances of the class `AnalysisOptions` represent a set of analysis options
used to | 5047 * Instances of the class `AnalysisOptions` represent a set of analysis options
used to |
| 4827 * control the behavior of an analysis context. | 5048 * control the behavior of an analysis context. |
| 4828 */ | 5049 */ |
| 4829 class AnalysisOptionsImpl implements AnalysisOptions { | 5050 class AnalysisOptionsImpl implements AnalysisOptions { |
| 4830 | 5051 |
| 4831 /** | 5052 /** |
| 4832 * A flag indicating whether analysis is to use strict mode. In strict mode, e
rror reporting is | 5053 * The maximum number of sources for which data should be kept in the cache. |
| 4833 * based exclusively on the static type information. | |
| 4834 */ | 5054 */ |
| 4835 bool _strictMode = true; | 5055 static int DEFAULT_CACHE_SIZE = 64; |
| 5056 |
| 5057 /** |
| 5058 * The maximum number of sources for which AST structures should be kept in th
e cache. |
| 5059 */ |
| 5060 int _cacheSize = DEFAULT_CACHE_SIZE; |
| 5061 |
| 5062 /** |
| 5063 * A flag indicating whether analysis is to generate dart2js related hint resu
lts. |
| 5064 */ |
| 5065 bool _dart2jsHint = true; |
| 4836 | 5066 |
| 4837 /** | 5067 /** |
| 4838 * A flag indicating whether analysis is to generate hint results (e.g. type i
nference based | 5068 * A flag indicating whether analysis is to generate hint results (e.g. type i
nference based |
| 4839 * information and pub best practices). | 5069 * information and pub best practices). |
| 4840 */ | 5070 */ |
| 4841 bool _hint = true; | 5071 bool _hint = true; |
| 4842 | 5072 |
| 4843 /** | 5073 /** |
| 4844 * A flag indicating whether analysis is to generate dart2js related hint resu
lts. | 5074 * A flag indicating whether analysis is to use strict mode. In strict mode, e
rror reporting is |
| 5075 * based exclusively on the static type information. |
| 4845 */ | 5076 */ |
| 4846 bool _dart2jsHint = true; | 5077 bool _strictMode = true; |
| 5078 |
| 5079 /** |
| 5080 * Initialize a newly created set of analysis options to have their default va
lues. |
| 5081 */ |
| 5082 AnalysisOptionsImpl(); |
| 5083 |
| 5084 /** |
| 5085 * Initialize a newly created set of analysis options to have the same values
as those in the |
| 5086 * given set of analysis options. |
| 5087 * |
| 5088 * @param options the analysis options whose values are being copied |
| 5089 */ |
| 5090 AnalysisOptionsImpl.con1(AnalysisOptions options) { |
| 5091 _cacheSize = options.cacheSize; |
| 5092 _dart2jsHint = options.dart2jsHint; |
| 5093 _hint = options.hint; |
| 5094 _strictMode = options.strictMode; |
| 5095 } |
| 5096 int get cacheSize => _cacheSize; |
| 4847 bool get dart2jsHint => _dart2jsHint; | 5097 bool get dart2jsHint => _dart2jsHint; |
| 4848 bool get hint => _hint; | 5098 bool get hint => _hint; |
| 4849 | 5099 |
| 4850 /** | 5100 /** |
| 4851 * Return `true` if analysis is to use strict mode. In strict mode, error repo
rting is based | 5101 * Return `true` if analysis is to use strict mode. In strict mode, error repo
rting is based |
| 4852 * exclusively on the static type information. | 5102 * exclusively on the static type information. |
| 4853 * | 5103 * |
| 4854 * @return `true` if analysis is to use strict mode | 5104 * @return `true` if analysis is to use strict mode |
| 4855 */ | 5105 */ |
| 4856 bool get strictMode => _strictMode; | 5106 bool get strictMode => _strictMode; |
| 4857 | 5107 |
| 4858 /** | 5108 /** |
| 5109 * Set the maximum number of sources for which AST structures should be kept i
n the cache to the |
| 5110 * given size. |
| 5111 * |
| 5112 * @param cacheSize the maximum number of sources for which AST structures sho
uld be kept in the |
| 5113 * cache |
| 5114 */ |
| 5115 void set cacheSize(int cacheSize) { |
| 5116 this._cacheSize = cacheSize; |
| 5117 } |
| 5118 |
| 5119 /** |
| 4859 * Set whether analysis is to generate dart2js related hint results. | 5120 * Set whether analysis is to generate dart2js related hint results. |
| 4860 * | 5121 * |
| 4861 * @param hint `true` if analysis is to generate dart2js related hint results | 5122 * @param hint `true` if analysis is to generate dart2js related hint results |
| 4862 */ | 5123 */ |
| 4863 void set dart2jsHint(bool dart2jsHints) { | 5124 void set dart2jsHint(bool dart2jsHints) { |
| 4864 this._dart2jsHint = dart2jsHints; | 5125 this._dart2jsHint = dart2jsHints; |
| 4865 } | 5126 } |
| 4866 | 5127 |
| 4867 /** | 5128 /** |
| 4868 * Set whether analysis is to generate hint results (e.g. type inference based
information and pub | 5129 * Set whether analysis is to generate hint results (e.g. type inference based
information and pub |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5200 return super.resolveCompilationUnit2(unitSource, librarySource); | 5461 return super.resolveCompilationUnit2(unitSource, librarySource); |
| 5201 } | 5462 } |
| 5202 } | 5463 } |
| 5203 HtmlUnit resolveHtmlUnit(Source unitSource) { | 5464 HtmlUnit resolveHtmlUnit(Source unitSource) { |
| 5204 if (unitSource.isInSystemLibrary) { | 5465 if (unitSource.isInSystemLibrary) { |
| 5205 return _sdkAnalysisContext.resolveHtmlUnit(unitSource); | 5466 return _sdkAnalysisContext.resolveHtmlUnit(unitSource); |
| 5206 } else { | 5467 } else { |
| 5207 return super.resolveHtmlUnit(unitSource); | 5468 return super.resolveHtmlUnit(unitSource); |
| 5208 } | 5469 } |
| 5209 } | 5470 } |
| 5471 void setChangedContents(Source source, String contents, int offset, int oldLen
gth, int newLength) { |
| 5472 if (source.isInSystemLibrary) { |
| 5473 _sdkAnalysisContext.setChangedContents(source, contents, offset, oldLength
, newLength); |
| 5474 } else { |
| 5475 super.setChangedContents(source, contents, offset, oldLength, newLength); |
| 5476 } |
| 5477 } |
| 5210 void setContents(Source source, String contents) { | 5478 void setContents(Source source, String contents) { |
| 5211 if (source.isInSystemLibrary) { | 5479 if (source.isInSystemLibrary) { |
| 5212 _sdkAnalysisContext.setContents(source, contents); | 5480 _sdkAnalysisContext.setContents(source, contents); |
| 5213 } else { | 5481 } else { |
| 5214 super.setContents(source, contents); | 5482 super.setContents(source, contents); |
| 5215 } | 5483 } |
| 5216 } | 5484 } |
| 5217 void set sourceFactory(SourceFactory factory) { | 5485 void set sourceFactory(SourceFactory factory) { |
| 5218 super.sourceFactory = factory; | 5486 super.sourceFactory = factory; |
| 5219 DartSdk sdk = factory.dartSdk; | 5487 DartSdk sdk = factory.dartSdk; |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5534 InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis-
getLineInfo"); | 5802 InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis-
getLineInfo"); |
| 5535 try { | 5803 try { |
| 5536 instrumentation.metric3("contextId", _contextId); | 5804 instrumentation.metric3("contextId", _contextId); |
| 5537 return basis.getLineInfo(source); | 5805 return basis.getLineInfo(source); |
| 5538 } finally { | 5806 } finally { |
| 5539 instrumentation.log(); | 5807 instrumentation.log(); |
| 5540 } | 5808 } |
| 5541 } | 5809 } |
| 5542 Namespace getPublicNamespace(LibraryElement library) => basis.getPublicNamespa
ce(library); | 5810 Namespace getPublicNamespace(LibraryElement library) => basis.getPublicNamespa
ce(library); |
| 5543 Namespace getPublicNamespace2(Source source) => basis.getPublicNamespace2(sour
ce); | 5811 Namespace getPublicNamespace2(Source source) => basis.getPublicNamespace2(sour
ce); |
| 5812 List<Source> get refactoringUnsafeSources => basis.refactoringUnsafeSources; |
| 5544 CompilationUnit getResolvedCompilationUnit(Source unitSource, LibraryElement l
ibrary) { | 5813 CompilationUnit getResolvedCompilationUnit(Source unitSource, LibraryElement l
ibrary) { |
| 5545 InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis-
getResolvedCompilationUnit"); | 5814 InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis-
getResolvedCompilationUnit"); |
| 5546 try { | 5815 try { |
| 5547 instrumentation.metric3("contextId", _contextId); | 5816 instrumentation.metric3("contextId", _contextId); |
| 5548 return basis.getResolvedCompilationUnit(unitSource, library); | 5817 return basis.getResolvedCompilationUnit(unitSource, library); |
| 5549 } finally { | 5818 } finally { |
| 5550 instrumentation.log(); | 5819 instrumentation.log(); |
| 5551 } | 5820 } |
| 5552 } | 5821 } |
| 5553 CompilationUnit getResolvedCompilationUnit2(Source unitSource, Source libraryS
ource) { | 5822 CompilationUnit getResolvedCompilationUnit2(Source unitSource, Source libraryS
ource) { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5617 try { | 5886 try { |
| 5618 instrumentation.metric3("contextId", _contextId); | 5887 instrumentation.metric3("contextId", _contextId); |
| 5619 return basis.parseHtmlUnit(source); | 5888 return basis.parseHtmlUnit(source); |
| 5620 } on AnalysisException catch (e) { | 5889 } on AnalysisException catch (e) { |
| 5621 recordAnalysisException(instrumentation, e); | 5890 recordAnalysisException(instrumentation, e); |
| 5622 throw e; | 5891 throw e; |
| 5623 } finally { | 5892 } finally { |
| 5624 instrumentation.log(); | 5893 instrumentation.log(); |
| 5625 } | 5894 } |
| 5626 } | 5895 } |
| 5627 List<ChangeNotice> performAnalysisTask() { | 5896 AnalysisResult performAnalysisTask() { |
| 5628 InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis-
performAnalysisTask"); | 5897 InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis-
performAnalysisTask"); |
| 5629 try { | 5898 try { |
| 5630 instrumentation.metric3("contextId", _contextId); | 5899 instrumentation.metric3("contextId", _contextId); |
| 5631 List<ChangeNotice> ret = basis.performAnalysisTask(); | 5900 AnalysisResult result = basis.performAnalysisTask(); |
| 5632 if (ret != null) { | 5901 if (result.changeNotices != null) { |
| 5633 instrumentation.metric2("ChangeNotice-count", ret.length); | 5902 instrumentation.metric2("ChangeNotice-count", result.changeNotices.lengt
h); |
| 5634 } | 5903 } |
| 5635 return ret; | 5904 return result; |
| 5636 } finally { | 5905 } finally { |
| 5637 instrumentation.log2(2); | 5906 instrumentation.log2(2); |
| 5638 } | 5907 } |
| 5639 } | 5908 } |
| 5640 void recordLibraryElements(Map<Source, LibraryElement> elementMap) { | 5909 void recordLibraryElements(Map<Source, LibraryElement> elementMap) { |
| 5641 basis.recordLibraryElements(elementMap); | 5910 basis.recordLibraryElements(elementMap); |
| 5642 } | 5911 } |
| 5643 CompilationUnit resolveCompilationUnit(Source unitSource, LibraryElement libra
ry) { | 5912 CompilationUnit resolveCompilationUnit(Source unitSource, LibraryElement libra
ry) { |
| 5644 InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis-
resolveCompilationUnit"); | 5913 InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis-
resolveCompilationUnit"); |
| 5645 try { | 5914 try { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5687 } | 5956 } |
| 5688 void set analysisPriorityOrder(List<Source> sources) { | 5957 void set analysisPriorityOrder(List<Source> sources) { |
| 5689 InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis-
setAnalysisPriorityOrder"); | 5958 InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis-
setAnalysisPriorityOrder"); |
| 5690 try { | 5959 try { |
| 5691 instrumentation.metric3("contextId", _contextId); | 5960 instrumentation.metric3("contextId", _contextId); |
| 5692 basis.analysisPriorityOrder = sources; | 5961 basis.analysisPriorityOrder = sources; |
| 5693 } finally { | 5962 } finally { |
| 5694 instrumentation.log(); | 5963 instrumentation.log(); |
| 5695 } | 5964 } |
| 5696 } | 5965 } |
| 5966 void setChangedContents(Source source, String contents, int offset, int oldLen
gth, int newLength) { |
| 5967 InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis-
setChangedContents"); |
| 5968 try { |
| 5969 instrumentation.metric3("contextId", _contextId); |
| 5970 basis.setChangedContents(source, contents, offset, oldLength, newLength); |
| 5971 } finally { |
| 5972 instrumentation.log(); |
| 5973 } |
| 5974 } |
| 5697 void setContents(Source source, String contents) { | 5975 void setContents(Source source, String contents) { |
| 5698 InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis-
setContents"); | 5976 InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis-
setContents"); |
| 5699 try { | 5977 try { |
| 5700 instrumentation.metric3("contextId", _contextId); | 5978 instrumentation.metric3("contextId", _contextId); |
| 5701 basis.setContents(source, contents); | 5979 basis.setContents(source, contents); |
| 5702 } finally { | 5980 } finally { |
| 5703 instrumentation.log(); | 5981 instrumentation.log(); |
| 5704 } | 5982 } |
| 5705 } | 5983 } |
| 5706 void set sourceFactory(SourceFactory factory) { | 5984 void set sourceFactory(SourceFactory factory) { |
| (...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6269 * @param source the source for which errors and warnings are to be produced | 6547 * @param source the source for which errors and warnings are to be produced |
| 6270 * @param libraryElement the element model for the library containing the sour
ce | 6548 * @param libraryElement the element model for the library containing the sour
ce |
| 6271 */ | 6549 */ |
| 6272 GenerateDartErrorsTask(InternalAnalysisContext context, Source source, Library
Element libraryElement) : super(context) { | 6550 GenerateDartErrorsTask(InternalAnalysisContext context, Source source, Library
Element libraryElement) : super(context) { |
| 6273 this.source = source; | 6551 this.source = source; |
| 6274 this.libraryElement = libraryElement; | 6552 this.libraryElement = libraryElement; |
| 6275 } | 6553 } |
| 6276 accept(AnalysisTaskVisitor visitor) => visitor.visitGenerateDartErrorsTask(thi
s); | 6554 accept(AnalysisTaskVisitor visitor) => visitor.visitGenerateDartErrorsTask(thi
s); |
| 6277 String get taskDescription => "generate errors and warnings for ${source.fullN
ame}"; | 6555 String get taskDescription => "generate errors and warnings for ${source.fullN
ame}"; |
| 6278 void internalPerform() { | 6556 void internalPerform() { |
| 6557 InternalAnalysisContext context = this.context; |
| 6558 TimestampedData<CompilationUnit> data = context.internalResolveCompilationUn
it(source, libraryElement); |
| 6279 TimeCounter_TimeCounterHandle timeCounter = PerformanceStatistics.errors.sta
rt(); | 6559 TimeCounter_TimeCounterHandle timeCounter = PerformanceStatistics.errors.sta
rt(); |
| 6280 try { | 6560 try { |
| 6281 InternalAnalysisContext context = this.context; | |
| 6282 TimestampedData<CompilationUnit> data = context.internalResolveCompilation
Unit(source, libraryElement); | |
| 6283 modificationTime = data.modificationTime; | 6561 modificationTime = data.modificationTime; |
| 6284 CompilationUnit unit = data.data; | 6562 CompilationUnit unit = data.data; |
| 6285 RecordingErrorListener errorListener = new RecordingErrorListener(); | 6563 RecordingErrorListener errorListener = new RecordingErrorListener(); |
| 6286 ErrorReporter errorReporter = new ErrorReporter(errorListener, source); | 6564 ErrorReporter errorReporter = new ErrorReporter(errorListener, source); |
| 6287 Source coreSource = context.sourceFactory.forUri(DartSdk.DART_CORE); | 6565 Source coreSource = context.sourceFactory.forUri(DartSdk.DART_CORE); |
| 6288 LibraryElement coreLibrary = context.getLibraryElement(coreSource); | 6566 LibraryElement coreLibrary = context.getLibraryElement(coreSource); |
| 6289 TypeProvider typeProvider = new TypeProviderImpl(coreLibrary); | 6567 TypeProvider typeProvider = new TypeProviderImpl(coreLibrary); |
| 6290 ConstantVerifier constantVerifier = new ConstantVerifier(errorReporter, ty
peProvider); | 6568 ConstantVerifier constantVerifier = new ConstantVerifier(errorReporter, ty
peProvider); |
| 6291 unit.accept(constantVerifier); | 6569 unit.accept(constantVerifier); |
| 6292 ErrorVerifier errorVerifier = new ErrorVerifier(errorReporter, libraryElem
ent, typeProvider, new InheritanceManager(libraryElement)); | 6570 ErrorVerifier errorVerifier = new ErrorVerifier(errorReporter, libraryElem
ent, typeProvider, new InheritanceManager(libraryElement)); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6332 } | 6610 } |
| 6333 void internalPerform() { | 6611 void internalPerform() { |
| 6334 RecordingErrorListener errorListener = new RecordingErrorListener(); | 6612 RecordingErrorListener errorListener = new RecordingErrorListener(); |
| 6335 List<CompilationUnitElement> parts = libraryElement.parts; | 6613 List<CompilationUnitElement> parts = libraryElement.parts; |
| 6336 int partCount = parts.length; | 6614 int partCount = parts.length; |
| 6337 List<CompilationUnit> compilationUnits = new List<CompilationUnit>(partCount
+ 1); | 6615 List<CompilationUnit> compilationUnits = new List<CompilationUnit>(partCount
+ 1); |
| 6338 Map<Source, TimestampedData<CompilationUnit>> timestampMap = new Map<Source,
TimestampedData<CompilationUnit>>(); | 6616 Map<Source, TimestampedData<CompilationUnit>> timestampMap = new Map<Source,
TimestampedData<CompilationUnit>>(); |
| 6339 Source unitSource = libraryElement.definingCompilationUnit.source; | 6617 Source unitSource = libraryElement.definingCompilationUnit.source; |
| 6340 TimestampedData<CompilationUnit> resolvedUnit = getCompilationUnit(unitSourc
e); | 6618 TimestampedData<CompilationUnit> resolvedUnit = getCompilationUnit(unitSourc
e); |
| 6341 timestampMap[unitSource] = resolvedUnit; | 6619 timestampMap[unitSource] = resolvedUnit; |
| 6342 compilationUnits[0] = resolvedUnit.data; | 6620 CompilationUnit unit = resolvedUnit.data; |
| 6621 if (unit == null) { |
| 6622 throw new AnalysisException.con1("Internal error: GenerateDartHintsTask fa
iled to access resolved compilation unit for ${unitSource.fullName}"); |
| 6623 } |
| 6624 compilationUnits[0] = unit; |
| 6343 for (int i = 0; i < partCount; i++) { | 6625 for (int i = 0; i < partCount; i++) { |
| 6344 unitSource = parts[i].source; | 6626 unitSource = parts[i].source; |
| 6345 resolvedUnit = getCompilationUnit(unitSource); | 6627 resolvedUnit = getCompilationUnit(unitSource); |
| 6346 timestampMap[unitSource] = resolvedUnit; | 6628 timestampMap[unitSource] = resolvedUnit; |
| 6347 compilationUnits[i + 1] = resolvedUnit.data; | 6629 unit = resolvedUnit.data; |
| 6630 if (unit == null) { |
| 6631 throw new AnalysisException.con1("Internal error: GenerateDartHintsTask
failed to access resolved compilation unit for ${unitSource.fullName}"); |
| 6632 } |
| 6633 compilationUnits[i + 1] = unit; |
| 6348 } | 6634 } |
| 6349 HintGenerator hintGenerator = new HintGenerator(compilationUnits, context, e
rrorListener); | 6635 HintGenerator hintGenerator = new HintGenerator(compilationUnits, context, e
rrorListener); |
| 6350 hintGenerator.generateForLibrary(); | 6636 hintGenerator.generateForLibrary(); |
| 6351 hintMap = new Map<Source, TimestampedData<List<AnalysisError>>>(); | 6637 hintMap = new Map<Source, TimestampedData<List<AnalysisError>>>(); |
| 6352 for (MapEntry<Source, TimestampedData<CompilationUnit>> entry in getMapEntry
Set(timestampMap)) { | 6638 for (MapEntry<Source, TimestampedData<CompilationUnit>> entry in getMapEntry
Set(timestampMap)) { |
| 6353 Source source = entry.getKey(); | 6639 Source source = entry.getKey(); |
| 6354 TimestampedData<CompilationUnit> unitData = entry.getValue(); | 6640 TimestampedData<CompilationUnit> unitData = entry.getValue(); |
| 6355 List<AnalysisError> errors = errorListener.getErrors2(source); | 6641 List<AnalysisError> errors = errorListener.getErrors2(source); |
| 6356 hintMap[source] = new TimestampedData<List<AnalysisError>>(unitData.modifi
cationTime, errors); | 6642 hintMap[source] = new TimestampedData<List<AnalysisError>>(unitData.modifi
cationTime, errors); |
| 6357 unitData.data.hints = errors; | |
| 6358 } | 6643 } |
| 6359 } | 6644 } |
| 6360 | 6645 |
| 6361 /** | 6646 /** |
| 6362 * Return the resolved compilation unit associated with the given source. | 6647 * Return the resolved compilation unit associated with the given source. |
| 6363 * | 6648 * |
| 6364 * @param unitSource the source for the compilation unit whose resolved AST is
to be returned | 6649 * @param unitSource the source for the compilation unit whose resolved AST is
to be returned |
| 6365 * @return the resolved compilation unit associated with the given source | 6650 * @return the resolved compilation unit associated with the given source |
| 6366 * @throws AnalysisException if the resolved compilation unit could not be com
puted | 6651 * @throws AnalysisException if the resolved compilation unit could not be com
puted |
| 6367 */ | 6652 */ |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6513 _hasLibraryDirective2 = true; | 6798 _hasLibraryDirective2 = true; |
| 6514 } else if (directive is PartDirective) { | 6799 } else if (directive is PartDirective) { |
| 6515 Source partSource = resolveSource(source, directive as PartDirective); | 6800 Source partSource = resolveSource(source, directive as PartDirective); |
| 6516 if (partSource != null) { | 6801 if (partSource != null) { |
| 6517 javaSetAdd(_includedSources, partSource); | 6802 javaSetAdd(_includedSources, partSource); |
| 6518 } | 6803 } |
| 6519 } else if (directive is PartOfDirective) { | 6804 } else if (directive is PartOfDirective) { |
| 6520 _hasPartOfDirective2 = true; | 6805 _hasPartOfDirective2 = true; |
| 6521 } | 6806 } |
| 6522 } | 6807 } |
| 6523 compilationUnit.parsingErrors = errors; | |
| 6524 compilationUnit.lineInfo = lineInfo; | |
| 6525 } finally { | 6808 } finally { |
| 6526 timeCounterParse.stop(); | 6809 timeCounterParse.stop(); |
| 6527 } | 6810 } |
| 6528 } | 6811 } |
| 6529 | 6812 |
| 6530 /** | 6813 /** |
| 6531 * Return the result of resolving the URI of the given URI-based directive aga
inst the URI of the | 6814 * Return the result of resolving the URI of the given URI-based directive aga
inst the URI of the |
| 6532 * given library, or `null` if the URI is not valid. | 6815 * given library, or `null` if the URI is not valid. |
| 6533 * | 6816 * |
| 6534 * @param librarySource the source representing the library containing the dir
ective | 6817 * @param librarySource the source representing the library containing the dir
ective |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6833 TimeCounter_TimeCounterHandle counterHandleErrors = PerformanceStatistics.er
rors.start(); | 7116 TimeCounter_TimeCounterHandle counterHandleErrors = PerformanceStatistics.er
rors.start(); |
| 6834 try { | 7117 try { |
| 6835 ErrorReporter errorReporter = new ErrorReporter(errorListener, source); | 7118 ErrorReporter errorReporter = new ErrorReporter(errorListener, source); |
| 6836 ErrorVerifier errorVerifier = new ErrorVerifier(errorReporter, _libraryEle
ment, typeProvider, inheritanceManager); | 7119 ErrorVerifier errorVerifier = new ErrorVerifier(errorReporter, _libraryEle
ment, typeProvider, inheritanceManager); |
| 6837 unit.accept(errorVerifier); | 7120 unit.accept(errorVerifier); |
| 6838 ConstantVerifier constantVerifier = new ConstantVerifier(errorReporter, ty
peProvider); | 7121 ConstantVerifier constantVerifier = new ConstantVerifier(errorReporter, ty
peProvider); |
| 6839 unit.accept(constantVerifier); | 7122 unit.accept(constantVerifier); |
| 6840 } finally { | 7123 } finally { |
| 6841 counterHandleErrors.stop(); | 7124 counterHandleErrors.stop(); |
| 6842 } | 7125 } |
| 6843 unit.resolutionErrors = errorListener.errors; | |
| 6844 resolvedUnit = unit; | 7126 resolvedUnit = unit; |
| 6845 } | 7127 } |
| 6846 | 7128 |
| 6847 /** | 7129 /** |
| 6848 * Search the compilation units that are part of the given library and return
the element | 7130 * Search the compilation units that are part of the given library and return
the element |
| 6849 * representing the compilation unit with the given source. Return `null` if t
here is no | 7131 * representing the compilation unit with the given source. Return `null` if t
here is no |
| 6850 * such compilation unit. | 7132 * such compilation unit. |
| 6851 * | 7133 * |
| 6852 * @param libraryElement the element representing the library being searched t
hrough | 7134 * @param libraryElement the element representing the library being searched t
hrough |
| 6853 * @param unitSource the source for the compilation unit whose element is to b
e returned | 7135 * @param unitSource the source for the compilation unit whose element is to b
e returned |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6976 } | 7258 } |
| 6977 void logError2(String message, Exception exception) { | 7259 void logError2(String message, Exception exception) { |
| 6978 } | 7260 } |
| 6979 void logError3(Exception exception) { | 7261 void logError3(Exception exception) { |
| 6980 } | 7262 } |
| 6981 void logInformation(String message) { | 7263 void logInformation(String message) { |
| 6982 } | 7264 } |
| 6983 void logInformation2(String message, Exception exception) { | 7265 void logInformation2(String message, Exception exception) { |
| 6984 } | 7266 } |
| 6985 } | 7267 } |
| OLD | NEW |