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

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

Issue 185403018: Unroll 'synchronized {}' in java2dart. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Include fix from Java Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 // This code was auto-generated, is not intended to be edited, and is subject to 5 // This code was auto-generated, is not intended to be edited, and is subject to
6 // significant change. Please see the README file for more information. 6 // significant change. Please see the README file for more information.
7 7
8 library engine; 8 library engine;
9 9
10 import 'java_core.dart'; 10 import 'java_core.dart';
(...skipping 3671 matching lines...) Expand 10 before | Expand all | Expand 10 after
3682 void addSourceInfo(Source source, SourceEntry info) { 3682 void addSourceInfo(Source source, SourceEntry info) {
3683 // This implementation assumes that the access to the cache does not need to be synchronized 3683 // This implementation assumes that the access to the cache does not need to be synchronized
3684 // because no other object can have access to this context while this method is being invoked. 3684 // because no other object can have access to this context while this method is being invoked.
3685 _cache.put(source, info); 3685 _cache.put(source, info);
3686 } 3686 }
3687 3687
3688 void applyChanges(ChangeSet changeSet) { 3688 void applyChanges(ChangeSet changeSet) {
3689 if (changeSet.isEmpty) { 3689 if (changeSet.isEmpty) {
3690 return; 3690 return;
3691 } 3691 }
3692 { 3692 _recentTasks.clear();
3693 _recentTasks.clear(); 3693 //
3694 // 3694 // First, compute the list of sources that have been removed.
3695 // First, compute the list of sources that have been removed. 3695 //
3696 // 3696 List<Source> removedSources = new List<Source>.from(changeSet.removed3);
3697 List<Source> removedSources = new List<Source>.from(changeSet.removed3); 3697 for (SourceContainer container in changeSet.removedContainers) {
3698 for (SourceContainer container in changeSet.removedContainers) { 3698 addSourcesInContainer(removedSources, container);
3699 addSourcesInContainer(removedSources, container); 3699 }
3700 //
3701 // Then determine which cached results are no longer valid.
3702 //
3703 bool addedDartSource = false;
3704 for (Source source in changeSet.added3) {
3705 if (sourceAvailable(source)) {
3706 addedDartSource = true;
3700 } 3707 }
3701 // 3708 }
3702 // Then determine which cached results are no longer valid. 3709 for (Source source in changeSet.changed3) {
3703 // 3710 sourceChanged(source);
3704 bool addedDartSource = false; 3711 }
3705 for (Source source in changeSet.added3) { 3712 for (Source source in removedSources) {
3706 if (sourceAvailable(source)) { 3713 sourceRemoved(source);
3707 addedDartSource = true; 3714 }
3708 } 3715 if (addedDartSource) {
3709 } 3716 // TODO(brianwilkerson) This is hugely inefficient, but we need to re-anal yze any libraries
3710 for (Source source in changeSet.changed3) { 3717 // that might have been referencing the not-yet-existing source that was j ust added. Longer
3711 sourceChanged(source); 3718 // term we need to keep track of which libraries are referencing non-exist ing sources and
3712 } 3719 // only re-analyze those libraries.
3713 for (Source source in removedSources) { 3720 logInformation("Added Dart sources, invalidating all resolution informatio n");
3714 sourceRemoved(source); 3721 for (MapEntry<Source, SourceEntry> mapEntry in _cache.entrySet()) {
3715 } 3722 Source source = mapEntry.getKey();
3716 if (addedDartSource) { 3723 SourceEntry sourceEntry = mapEntry.getValue();
3717 // TODO(brianwilkerson) This is hugely inefficient, but we need to re-an alyze any libraries 3724 if (!source.isInSystemLibrary && sourceEntry is DartEntry) {
3718 // that might have been referencing the not-yet-existing source that was just added. Longer 3725 DartEntry dartEntry = sourceEntry;
3719 // term we need to keep track of which libraries are referencing non-exi sting sources and 3726 DartEntryImpl dartCopy = dartEntry.writableCopy;
3720 // only re-analyze those libraries. 3727 removeFromParts(source, dartEntry);
3721 logInformation("Added Dart sources, invalidating all resolution informat ion"); 3728 dartCopy.invalidateAllResolutionInformation();
3722 for (MapEntry<Source, SourceEntry> mapEntry in _cache.entrySet()) { 3729 mapEntry.setValue(dartCopy);
3723 Source source = mapEntry.getKey(); 3730 SourcePriority priority = SourcePriority.UNKNOWN;
3724 SourceEntry sourceEntry = mapEntry.getValue(); 3731 SourceKind kind = dartCopy.kind;
3725 if (!source.isInSystemLibrary && sourceEntry is DartEntry) { 3732 if (identical(kind, SourceKind.LIBRARY)) {
3726 DartEntry dartEntry = sourceEntry; 3733 priority = SourcePriority.LIBRARY;
3727 DartEntryImpl dartCopy = dartEntry.writableCopy; 3734 } else if (identical(kind, SourceKind.PART)) {
3728 removeFromParts(source, dartEntry); 3735 priority = SourcePriority.NORMAL_PART;
3729 dartCopy.invalidateAllResolutionInformation();
3730 mapEntry.setValue(dartCopy);
3731 SourcePriority priority = SourcePriority.UNKNOWN;
3732 SourceKind kind = dartCopy.kind;
3733 if (identical(kind, SourceKind.LIBRARY)) {
3734 priority = SourcePriority.LIBRARY;
3735 } else if (identical(kind, SourceKind.PART)) {
3736 priority = SourcePriority.NORMAL_PART;
3737 }
3738 _workManager.add(source, priority);
3739 } 3736 }
3737 _workManager.add(source, priority);
3740 } 3738 }
3741 } 3739 }
3742 } 3740 }
3743 } 3741 }
3744 3742
3745 String computeDocumentationComment(Element element) { 3743 String computeDocumentationComment(Element element) {
3746 if (element == null) { 3744 if (element == null) {
3747 return null; 3745 return null;
3748 } 3746 }
3749 Source source = element.source; 3747 Source source = element.source;
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
3871 ht.HtmlUnit unit = htmlEntry.getValue(HtmlEntry.RESOLVED_UNIT); 3869 ht.HtmlUnit unit = htmlEntry.getValue(HtmlEntry.RESOLVED_UNIT);
3872 if (unit == null) { 3870 if (unit == null) {
3873 AnalysisException cause = htmlEntry.exception; 3871 AnalysisException cause = htmlEntry.exception;
3874 throw new AnalysisException.con2("Internal error: computeResolvableAngular ComponentHtmlUnit could not resolve ${source.fullName}", cause); 3872 throw new AnalysisException.con2("Internal error: computeResolvableAngular ComponentHtmlUnit could not resolve ${source.fullName}", cause);
3875 } 3873 }
3876 // If the unit is ever modified by resolution then we will need to create a copy of it. 3874 // If the unit is ever modified by resolution then we will need to create a copy of it.
3877 return new ResolvableHtmlUnit(htmlEntry.modificationTime, unit); 3875 return new ResolvableHtmlUnit(htmlEntry.modificationTime, unit);
3878 } 3876 }
3879 3877
3880 ResolvableCompilationUnit computeResolvableCompilationUnit(Source source) { 3878 ResolvableCompilationUnit computeResolvableCompilationUnit(Source source) {
3881 { 3879 DartEntry dartEntry = getReadableDartEntry(source);
3882 DartEntry dartEntry = getReadableDartEntry(source); 3880 if (dartEntry == null) {
3883 if (dartEntry == null) { 3881 throw new AnalysisException.con1("computeResolvableCompilationUnit for non -Dart: ${source.fullName}");
3884 throw new AnalysisException.con1("computeResolvableCompilationUnit for n on-Dart: ${source.fullName}");
3885 }
3886 dartEntry = cacheDartParseData(source, dartEntry, DartEntry.PARSED_UNIT);
3887 DartEntryImpl dartCopy = dartEntry.writableCopy;
3888 CompilationUnit unit = dartCopy.resolvableCompilationUnit;
3889 if (unit == null) {
3890 throw new AnalysisException.con2("Internal error: computeResolvableCompi lationUnit could not parse ${source.fullName}", dartEntry.exception);
3891 }
3892 _cache.put(source, dartCopy);
3893 return new ResolvableCompilationUnit(dartCopy.modificationTime, unit);
3894 } 3882 }
3883 dartEntry = cacheDartParseData(source, dartEntry, DartEntry.PARSED_UNIT);
3884 DartEntryImpl dartCopy = dartEntry.writableCopy;
3885 CompilationUnit unit = dartCopy.resolvableCompilationUnit;
3886 if (unit == null) {
3887 throw new AnalysisException.con2("Internal error: computeResolvableCompila tionUnit could not parse ${source.fullName}", dartEntry.exception);
3888 }
3889 _cache.put(source, dartCopy);
3890 return new ResolvableCompilationUnit(dartCopy.modificationTime, unit);
3895 } 3891 }
3896 3892
3897 ResolvableHtmlUnit computeResolvableHtmlUnit(Source source) { 3893 ResolvableHtmlUnit computeResolvableHtmlUnit(Source source) {
3898 HtmlEntry htmlEntry = getReadableHtmlEntry(source); 3894 HtmlEntry htmlEntry = getReadableHtmlEntry(source);
3899 if (htmlEntry == null) { 3895 if (htmlEntry == null) {
3900 throw new AnalysisException.con1("computeResolvableHtmlUnit invoked for no n-HTML file: ${source.fullName}"); 3896 throw new AnalysisException.con1("computeResolvableHtmlUnit invoked for no n-HTML file: ${source.fullName}");
3901 } 3897 }
3902 htmlEntry = cacheHtmlParseData(source, htmlEntry, HtmlEntry.PARSED_UNIT); 3898 htmlEntry = cacheHtmlParseData(source, htmlEntry, HtmlEntry.PARSED_UNIT);
3903 ht.HtmlUnit unit = htmlEntry.getValue(HtmlEntry.PARSED_UNIT); 3899 ht.HtmlUnit unit = htmlEntry.getValue(HtmlEntry.PARSED_UNIT);
3904 if (unit == null) { 3900 if (unit == null) {
3905 throw new AnalysisException.con1("Internal error: computeResolvableHtmlUni t could not parse ${source.fullName}"); 3901 throw new AnalysisException.con1("Internal error: computeResolvableHtmlUni t could not parse ${source.fullName}");
3906 } 3902 }
3907 // If the unit is ever modified by resolution then we will need to create a copy of it. 3903 // If the unit is ever modified by resolution then we will need to create a copy of it.
3908 return new ResolvableHtmlUnit(htmlEntry.modificationTime, unit); 3904 return new ResolvableHtmlUnit(htmlEntry.modificationTime, unit);
3909 } 3905 }
3910 3906
3911 bool exists(Source source) { 3907 bool exists(Source source) {
3912 if (source == null) { 3908 if (source == null) {
3913 return false; 3909 return false;
3914 } 3910 }
3915 { 3911 if (_contentCache.getContents(source) != null) {
3916 if (_contentCache.getContents(source) != null) { 3912 return true;
3917 return true;
3918 }
3919 } 3913 }
3920 return source.exists(); 3914 return source.exists();
3921 } 3915 }
3922 3916
3923 AnalysisContext extractContext(SourceContainer container) => extractContextInt o(container, AnalysisEngine.instance.createAnalysisContext() as InternalAnalysis Context); 3917 AnalysisContext extractContext(SourceContainer container) => extractContextInt o(container, AnalysisEngine.instance.createAnalysisContext() as InternalAnalysis Context);
3924 3918
3925 InternalAnalysisContext extractContextInto(SourceContainer container, Internal AnalysisContext newContext) { 3919 InternalAnalysisContext extractContextInto(SourceContainer container, Internal AnalysisContext newContext) {
3926 List<Source> sourcesToRemove = new List<Source>(); 3920 List<Source> sourcesToRemove = new List<Source>();
3927 { 3921 // Move sources in the specified directory to the new context
3928 // Move sources in the specified directory to the new context 3922 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) {
3929 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) { 3923 Source source = entry.getKey();
3930 Source source = entry.getKey(); 3924 if (container.contains(source)) {
3931 if (container.contains(source)) { 3925 sourcesToRemove.add(source);
3932 sourcesToRemove.add(source); 3926 newContext.addSourceInfo(source, entry.getValue().writableCopy);
3933 newContext.addSourceInfo(source, entry.getValue().writableCopy);
3934 }
3935 } 3927 }
3936 } 3928 }
3937 return newContext; 3929 return newContext;
3938 } 3930 }
3939 3931
3940 AnalysisOptions get analysisOptions => _options; 3932 AnalysisOptions get analysisOptions => _options;
3941 3933
3942 CompilationUnitElement getCompilationUnitElement(Source unitSource, Source lib rarySource) { 3934 CompilationUnitElement getCompilationUnitElement(Source unitSource, Source lib rarySource) {
3943 LibraryElement libraryElement = getLibraryElement(librarySource); 3935 LibraryElement libraryElement = getLibraryElement(librarySource);
3944 if (libraryElement != null) { 3936 if (libraryElement != null) {
3945 // try defining unit 3937 // try defining unit
3946 CompilationUnitElement definingUnit = libraryElement.definingCompilationUn it; 3938 CompilationUnitElement definingUnit = libraryElement.definingCompilationUn it;
3947 if (definingUnit.source == unitSource) { 3939 if (definingUnit.source == unitSource) {
3948 return definingUnit; 3940 return definingUnit;
3949 } 3941 }
3950 // try parts 3942 // try parts
3951 for (CompilationUnitElement partUnit in libraryElement.parts) { 3943 for (CompilationUnitElement partUnit in libraryElement.parts) {
3952 if (partUnit.source == unitSource) { 3944 if (partUnit.source == unitSource) {
3953 return partUnit; 3945 return partUnit;
3954 } 3946 }
3955 } 3947 }
3956 } 3948 }
3957 return null; 3949 return null;
3958 } 3950 }
3959 3951
3960 TimestampedData<String> getContents(Source source) { 3952 TimestampedData<String> getContents(Source source) {
3961 { 3953 String contents = _contentCache.getContents(source);
3962 String contents = _contentCache.getContents(source); 3954 if (contents != null) {
3963 if (contents != null) { 3955 return new TimestampedData<String>(_contentCache.getModificationStamp(sour ce), contents);
3964 return new TimestampedData<String>(_contentCache.getModificationStamp(so urce), contents);
3965 }
3966 } 3956 }
3967 return source.contents; 3957 return source.contents;
3968 } 3958 }
3969 3959
3970 void getContentsToReceiver(Source source, Source_ContentReceiver receiver) { 3960 void getContentsToReceiver(Source source, Source_ContentReceiver receiver) {
3971 { 3961 String contents = _contentCache.getContents(source);
3972 String contents = _contentCache.getContents(source); 3962 if (contents != null) {
3973 if (contents != null) { 3963 receiver.accept(contents, _contentCache.getModificationStamp(source));
3974 receiver.accept(contents, _contentCache.getModificationStamp(source)); 3964 return;
3975 return;
3976 }
3977 } 3965 }
3978 source.getContentsToReceiver(receiver); 3966 source.getContentsToReceiver(receiver);
3979 } 3967 }
3980 3968
3981 Element getElement(ElementLocation location) { 3969 Element getElement(ElementLocation location) {
3982 // TODO(brianwilkerson) This should not be a "get" method. 3970 // TODO(brianwilkerson) This should not be a "get" method.
3983 try { 3971 try {
3984 List<String> components = (location as ElementLocationImpl).components; 3972 List<String> components = (location as ElementLocationImpl).components;
3985 Source librarySource = computeSourceFromEncoding(components[0]); 3973 Source librarySource = computeSourceFromEncoding(components[0]);
3986 ElementImpl element = computeLibraryElement(librarySource) as ElementImpl; 3974 ElementImpl element = computeLibraryElement(librarySource) as ElementImpl;
(...skipping 27 matching lines...) Expand all
4014 return sourceEntry.getValue(HtmlEntry.ELEMENT); 4002 return sourceEntry.getValue(HtmlEntry.ELEMENT);
4015 } 4003 }
4016 return null; 4004 return null;
4017 } 4005 }
4018 4006
4019 List<Source> getHtmlFilesReferencing(Source source) { 4007 List<Source> getHtmlFilesReferencing(Source source) {
4020 SourceKind sourceKind = getKindOf(source); 4008 SourceKind sourceKind = getKindOf(source);
4021 if (sourceKind == null) { 4009 if (sourceKind == null) {
4022 return Source.EMPTY_ARRAY; 4010 return Source.EMPTY_ARRAY;
4023 } 4011 }
4024 { 4012 List<Source> htmlSources = new List<Source>();
4025 List<Source> htmlSources = new List<Source>(); 4013 while (true) {
4026 while (true) { 4014 if (sourceKind == SourceKind.LIBRARY) {
4027 if (sourceKind == SourceKind.LIBRARY) { 4015 } else if (sourceKind == SourceKind.PART) {
4028 } else if (sourceKind == SourceKind.PART) { 4016 List<Source> librarySources = getLibrariesContaining(source);
4029 List<Source> librarySources = getLibrariesContaining(source); 4017 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) {
4030 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) { 4018 SourceEntry sourceEntry = entry.getValue();
4031 SourceEntry sourceEntry = entry.getValue(); 4019 if (identical(sourceEntry.kind, SourceKind.HTML)) {
4032 if (identical(sourceEntry.kind, SourceKind.HTML)) { 4020 List<Source> referencedLibraries = (sourceEntry as HtmlEntry).getVal ue(HtmlEntry.REFERENCED_LIBRARIES);
4033 List<Source> referencedLibraries = (sourceEntry as HtmlEntry).getV alue(HtmlEntry.REFERENCED_LIBRARIES); 4021 if (containsAny(referencedLibraries, librarySources)) {
4034 if (containsAny(referencedLibraries, librarySources)) { 4022 htmlSources.add(entry.getKey());
4035 htmlSources.add(entry.getKey());
4036 }
4037 } 4023 }
4038 } 4024 }
4039 } 4025 }
4040 break;
4041 } 4026 }
4042 if (htmlSources.isEmpty) { 4027 break;
4043 return Source.EMPTY_ARRAY;
4044 }
4045 return new List.from(htmlSources);
4046 } 4028 }
4029 if (htmlSources.isEmpty) {
4030 return Source.EMPTY_ARRAY;
4031 }
4032 return new List.from(htmlSources);
4047 } 4033 }
4048 4034
4049 List<Source> get htmlSources => getSources(SourceKind.HTML); 4035 List<Source> get htmlSources => getSources(SourceKind.HTML);
4050 4036
4051 SourceKind getKindOf(Source source) { 4037 SourceKind getKindOf(Source source) {
4052 SourceEntry sourceEntry = getReadableSourceEntry(source); 4038 SourceEntry sourceEntry = getReadableSourceEntry(source);
4053 if (sourceEntry == null) { 4039 if (sourceEntry == null) {
4054 return SourceKind.UNKNOWN; 4040 return SourceKind.UNKNOWN;
4055 } 4041 }
4056 return sourceEntry.kind; 4042 return sourceEntry.kind;
4057 } 4043 }
4058 4044
4059 List<Source> get launchableClientLibrarySources { 4045 List<Source> get launchableClientLibrarySources {
4060 // TODO(brianwilkerson) This needs to filter out libraries that do not refer ence dart:html, 4046 // TODO(brianwilkerson) This needs to filter out libraries that do not refer ence dart:html,
4061 // either directly or indirectly. 4047 // either directly or indirectly.
4062 List<Source> sources = new List<Source>(); 4048 List<Source> sources = new List<Source>();
4063 { 4049 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) {
4064 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) { 4050 Source source = entry.getKey();
4065 Source source = entry.getKey(); 4051 SourceEntry sourceEntry = entry.getValue();
4066 SourceEntry sourceEntry = entry.getValue(); 4052 if (identical(sourceEntry.kind, SourceKind.LIBRARY) && !source.isInSystemL ibrary) {
4067 if (identical(sourceEntry.kind, SourceKind.LIBRARY) && !source.isInSyste mLibrary) { 4053 // DartEntry dartEntry = (DartEntry) sourceEntry;
4068 // DartEntry dartEntry = (DartEntry) sourceEntry; 4054 // if (dartEntry.getValue(DartEntry.IS_LAUNCHABLE) && dartEntry .getValue(DartEntry.IS_CLIENT)) {
4069 // if (dartEntry.getValue(DartEntry.IS_LAUNCHABLE) && dartEnt ry.getValue(DartEntry.IS_CLIENT)) { 4055 sources.add(source);
4070 sources.add(source);
4071 }
4072 } 4056 }
4073 } 4057 }
4074 return new List.from(sources); 4058 return new List.from(sources);
4075 } 4059 }
4076 4060
4077 List<Source> get launchableServerLibrarySources { 4061 List<Source> get launchableServerLibrarySources {
4078 // TODO(brianwilkerson) This needs to filter out libraries that reference da rt:html, either 4062 // TODO(brianwilkerson) This needs to filter out libraries that reference da rt:html, either
4079 // directly or indirectly. 4063 // directly or indirectly.
4080 List<Source> sources = new List<Source>(); 4064 List<Source> sources = new List<Source>();
4081 { 4065 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) {
4082 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) { 4066 Source source = entry.getKey();
4083 Source source = entry.getKey(); 4067 SourceEntry sourceEntry = entry.getValue();
4084 SourceEntry sourceEntry = entry.getValue(); 4068 if (identical(sourceEntry.kind, SourceKind.LIBRARY) && !source.isInSystemL ibrary) {
4085 if (identical(sourceEntry.kind, SourceKind.LIBRARY) && !source.isInSyste mLibrary) { 4069 // DartEntry dartEntry = (DartEntry) sourceEntry;
4086 // DartEntry dartEntry = (DartEntry) sourceEntry; 4070 // if (dartEntry.getValue(DartEntry.IS_LAUNCHABLE) && !dartEntr y.getValue(DartEntry.IS_CLIENT)) {
4087 // if (dartEntry.getValue(DartEntry.IS_LAUNCHABLE) && !dartEn try.getValue(DartEntry.IS_CLIENT)) { 4071 sources.add(source);
4088 sources.add(source);
4089 }
4090 } 4072 }
4091 } 4073 }
4092 return new List.from(sources); 4074 return new List.from(sources);
4093 } 4075 }
4094 4076
4095 List<Source> getLibrariesContaining(Source source) { 4077 List<Source> getLibrariesContaining(Source source) {
4096 DartEntry dartEntry = getReadableDartEntry(source); 4078 DartEntry dartEntry = getReadableDartEntry(source);
4097 if (dartEntry == null) { 4079 if (dartEntry == null) {
4098 return Source.EMPTY_ARRAY; 4080 return Source.EMPTY_ARRAY;
4099 } 4081 }
4100 return dartEntry.getValue(DartEntry.CONTAINING_LIBRARIES); 4082 return dartEntry.getValue(DartEntry.CONTAINING_LIBRARIES);
4101 } 4083 }
4102 4084
4103 List<Source> getLibrariesDependingOn(Source librarySource) { 4085 List<Source> getLibrariesDependingOn(Source librarySource) {
4104 { 4086 List<Source> dependentLibraries = new List<Source>();
4105 List<Source> dependentLibraries = new List<Source>(); 4087 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) {
4106 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) { 4088 SourceEntry sourceEntry = entry.getValue();
4107 SourceEntry sourceEntry = entry.getValue(); 4089 if (identical(sourceEntry.kind, SourceKind.LIBRARY)) {
4108 if (identical(sourceEntry.kind, SourceKind.LIBRARY)) { 4090 if (contains((sourceEntry as DartEntry).getValue(DartEntry.EXPORTED_LIBR ARIES), librarySource)) {
4109 if (contains((sourceEntry as DartEntry).getValue(DartEntry.EXPORTED_LI BRARIES), librarySource)) { 4091 dependentLibraries.add(entry.getKey());
4110 dependentLibraries.add(entry.getKey()); 4092 }
4111 } 4093 if (contains((sourceEntry as DartEntry).getValue(DartEntry.IMPORTED_LIBR ARIES), librarySource)) {
4112 if (contains((sourceEntry as DartEntry).getValue(DartEntry.IMPORTED_LI BRARIES), librarySource)) { 4094 dependentLibraries.add(entry.getKey());
4113 dependentLibraries.add(entry.getKey());
4114 }
4115 } 4095 }
4116 } 4096 }
4117 if (dependentLibraries.isEmpty) {
4118 return Source.EMPTY_ARRAY;
4119 }
4120 return new List.from(dependentLibraries);
4121 } 4097 }
4098 if (dependentLibraries.isEmpty) {
4099 return Source.EMPTY_ARRAY;
4100 }
4101 return new List.from(dependentLibraries);
4122 } 4102 }
4123 4103
4124 LibraryElement getLibraryElement(Source source) { 4104 LibraryElement getLibraryElement(Source source) {
4125 SourceEntry sourceEntry = getReadableSourceEntry(source); 4105 SourceEntry sourceEntry = getReadableSourceEntry(source);
4126 if (sourceEntry is DartEntry) { 4106 if (sourceEntry is DartEntry) {
4127 return sourceEntry.getValue(DartEntry.ELEMENT); 4107 return sourceEntry.getValue(DartEntry.ELEMENT);
4128 } 4108 }
4129 return null; 4109 return null;
4130 } 4110 }
4131 4111
4132 List<Source> get librarySources => getSources(SourceKind.LIBRARY); 4112 List<Source> get librarySources => getSources(SourceKind.LIBRARY);
4133 4113
4134 LineInfo getLineInfo(Source source) { 4114 LineInfo getLineInfo(Source source) {
4135 SourceEntry sourceEntry = getReadableSourceEntry(source); 4115 SourceEntry sourceEntry = getReadableSourceEntry(source);
4136 if (sourceEntry != null) { 4116 if (sourceEntry != null) {
4137 return sourceEntry.getValue(SourceEntry.LINE_INFO); 4117 return sourceEntry.getValue(SourceEntry.LINE_INFO);
4138 } 4118 }
4139 return null; 4119 return null;
4140 } 4120 }
4141 4121
4142 int getModificationStamp(Source source) { 4122 int getModificationStamp(Source source) {
4143 { 4123 int stamp = _contentCache.getModificationStamp(source);
4144 int stamp = _contentCache.getModificationStamp(source); 4124 if (stamp != null) {
4145 if (stamp != null) { 4125 return stamp;
4146 return stamp;
4147 }
4148 } 4126 }
4149 return source.modificationStamp; 4127 return source.modificationStamp;
4150 } 4128 }
4151 4129
4152 Namespace getPublicNamespace(LibraryElement library) { 4130 Namespace getPublicNamespace(LibraryElement library) {
4153 // TODO(brianwilkerson) Rename this to not start with 'get'. Note that this is not part of the 4131 // TODO(brianwilkerson) Rename this to not start with 'get'. Note that this is not part of the
4154 // API of the interface. 4132 // API of the interface.
4155 Source source = library.definingCompilationUnit.source; 4133 Source source = library.definingCompilationUnit.source;
4156 DartEntry dartEntry = getReadableDartEntry(source); 4134 DartEntry dartEntry = getReadableDartEntry(source);
4157 if (dartEntry == null) { 4135 if (dartEntry == null) {
4158 return null; 4136 return null;
4159 } 4137 }
4160 Namespace namespace = null; 4138 Namespace namespace = null;
4161 if (identical(dartEntry.getValue(DartEntry.ELEMENT), library)) { 4139 if (identical(dartEntry.getValue(DartEntry.ELEMENT), library)) {
4162 namespace = dartEntry.getValue(DartEntry.PUBLIC_NAMESPACE); 4140 namespace = dartEntry.getValue(DartEntry.PUBLIC_NAMESPACE);
4163 } 4141 }
4164 if (namespace == null) { 4142 if (namespace == null) {
4165 NamespaceBuilder builder = new NamespaceBuilder(); 4143 NamespaceBuilder builder = new NamespaceBuilder();
4166 namespace = builder.createPublicNamespace(library); 4144 namespace = builder.createPublicNamespace(library);
4167 { 4145 dartEntry = getReadableDartEntry(source);
4168 dartEntry = getReadableDartEntry(source); 4146 if (dartEntry == null) {
4169 if (dartEntry == null) { 4147 AnalysisEngine.instance.logger.logError2("Could not compute the public n amespace for ${library.source.fullName}", new AnalysisException.con1("A Dart fil e became a non-Dart file: ${source.fullName}"));
4170 AnalysisEngine.instance.logger.logError2("Could not compute the public namespace for ${library.source.fullName}", new AnalysisException.con1("A Dart f ile became a non-Dart file: ${source.fullName}")); 4148 return null;
4171 return null; 4149 }
4172 } 4150 if (identical(dartEntry.getValue(DartEntry.ELEMENT), library)) {
4173 if (identical(dartEntry.getValue(DartEntry.ELEMENT), library)) { 4151 DartEntryImpl dartCopy = getReadableDartEntry(source).writableCopy;
4174 DartEntryImpl dartCopy = getReadableDartEntry(source).writableCopy; 4152 dartCopy.setValue(DartEntry.PUBLIC_NAMESPACE, namespace);
4175 dartCopy.setValue(DartEntry.PUBLIC_NAMESPACE, namespace); 4153 _cache.put(source, dartCopy);
4176 _cache.put(source, dartCopy);
4177 }
4178 } 4154 }
4179 } 4155 }
4180 return namespace; 4156 return namespace;
4181 } 4157 }
4182 4158
4183 Namespace getPublicNamespace2(Source source) { 4159 Namespace getPublicNamespace2(Source source) {
4184 // TODO(brianwilkerson) Rename this to not start with 'get'. Note that this is not part of the 4160 // TODO(brianwilkerson) Rename this to not start with 'get'. Note that this is not part of the
4185 // API of the interface. 4161 // API of the interface.
4186 DartEntry dartEntry = getReadableDartEntry(source); 4162 DartEntry dartEntry = getReadableDartEntry(source);
4187 if (dartEntry == null) { 4163 if (dartEntry == null) {
4188 return null; 4164 return null;
4189 } 4165 }
4190 Namespace namespace = dartEntry.getValue(DartEntry.PUBLIC_NAMESPACE); 4166 Namespace namespace = dartEntry.getValue(DartEntry.PUBLIC_NAMESPACE);
4191 if (namespace == null) { 4167 if (namespace == null) {
4192 LibraryElement library = computeLibraryElement(source); 4168 LibraryElement library = computeLibraryElement(source);
4193 if (library == null) { 4169 if (library == null) {
4194 return null; 4170 return null;
4195 } 4171 }
4196 NamespaceBuilder builder = new NamespaceBuilder(); 4172 NamespaceBuilder builder = new NamespaceBuilder();
4197 namespace = builder.createPublicNamespace(library); 4173 namespace = builder.createPublicNamespace(library);
4198 { 4174 dartEntry = getReadableDartEntry(source);
4199 dartEntry = getReadableDartEntry(source); 4175 if (dartEntry == null) {
4200 if (dartEntry == null) { 4176 throw new AnalysisException.con1("A Dart file became a non-Dart file: ${ source.fullName}");
4201 throw new AnalysisException.con1("A Dart file became a non-Dart file: ${source.fullName}"); 4177 }
4202 } 4178 if (identical(dartEntry.getValue(DartEntry.ELEMENT), library)) {
4203 if (identical(dartEntry.getValue(DartEntry.ELEMENT), library)) { 4179 DartEntryImpl dartCopy = getReadableDartEntry(source).writableCopy;
4204 DartEntryImpl dartCopy = getReadableDartEntry(source).writableCopy; 4180 dartCopy.setValue(DartEntry.PUBLIC_NAMESPACE, namespace);
4205 dartCopy.setValue(DartEntry.PUBLIC_NAMESPACE, namespace); 4181 _cache.put(source, dartCopy);
4206 _cache.put(source, dartCopy);
4207 }
4208 } 4182 }
4209 } 4183 }
4210 return namespace; 4184 return namespace;
4211 } 4185 }
4212 4186
4213 List<Source> get refactoringUnsafeSources { 4187 List<Source> get refactoringUnsafeSources {
4214 List<Source> sources = new List<Source>(); 4188 List<Source> sources = new List<Source>();
4215 { 4189 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) {
4216 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) { 4190 SourceEntry sourceEntry = entry.getValue();
4217 SourceEntry sourceEntry = entry.getValue(); 4191 if (sourceEntry is DartEntry) {
4218 if (sourceEntry is DartEntry) { 4192 if (!sourceEntry.isRefactoringSafe) {
4219 if (!sourceEntry.isRefactoringSafe) { 4193 sources.add(entry.getKey());
4220 sources.add(entry.getKey());
4221 }
4222 } 4194 }
4223 } 4195 }
4224 } 4196 }
4225 return new List.from(sources); 4197 return new List.from(sources);
4226 } 4198 }
4227 4199
4228 CompilationUnit getResolvedCompilationUnit(Source unitSource, LibraryElement l ibrary) { 4200 CompilationUnit getResolvedCompilationUnit(Source unitSource, LibraryElement l ibrary) {
4229 if (library == null) { 4201 if (library == null) {
4230 return null; 4202 return null;
4231 } 4203 }
(...skipping 21 matching lines...) Expand all
4253 4225
4254 /** 4226 /**
4255 * Return a list of the sources that would be processed by [performAnalysisTas k]. This 4227 * Return a list of the sources that would be processed by [performAnalysisTas k]. This
4256 * method duplicates, and must therefore be kept in sync with, [getNextAnalysi sTask]. 4228 * method duplicates, and must therefore be kept in sync with, [getNextAnalysi sTask].
4257 * This method is intended to be used for testing purposes only. 4229 * This method is intended to be used for testing purposes only.
4258 * 4230 *
4259 * @return a list of the sources that would be processed by [performAnalysisTa sk] 4231 * @return a list of the sources that would be processed by [performAnalysisTa sk]
4260 */ 4232 */
4261 List<Source> get sourcesNeedingProcessing { 4233 List<Source> get sourcesNeedingProcessing {
4262 Set<Source> sources = new Set<Source>(); 4234 Set<Source> sources = new Set<Source>();
4263 { 4235 bool hintsEnabled = _options.hint;
4264 bool hintsEnabled = _options.hint; 4236 //
4265 // 4237 // Look for priority sources that need to be analyzed.
4266 // Look for priority sources that need to be analyzed. 4238 //
4267 // 4239 for (Source source in _priorityOrder) {
4268 for (Source source in _priorityOrder) { 4240 getSourcesNeedingProcessing2(source, _cache.get(source), true, hintsEnable d, sources);
4269 getSourcesNeedingProcessing2(source, _cache.get(source), true, hintsEnab led, sources); 4241 }
4270 } 4242 //
4271 // 4243 // Look for non-priority sources that need to be analyzed.
4272 // Look for non-priority sources that need to be analyzed. 4244 //
4273 // 4245 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) {
4274 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) { 4246 getSourcesNeedingProcessing2(entry.getKey(), entry.getValue(), false, hint sEnabled, sources);
4275 getSourcesNeedingProcessing2(entry.getKey(), entry.getValue(), false, hi ntsEnabled, sources);
4276 }
4277 } 4247 }
4278 return new List<Source>.from(sources); 4248 return new List<Source>.from(sources);
4279 } 4249 }
4280 4250
4281 AnalysisContentStatistics get statistics { 4251 AnalysisContentStatistics get statistics {
4282 AnalysisContentStatisticsImpl statistics = new AnalysisContentStatisticsImpl (); 4252 AnalysisContentStatisticsImpl statistics = new AnalysisContentStatisticsImpl ();
4283 { 4253 for (MapEntry<Source, SourceEntry> mapEntry in _cache.entrySet()) {
4284 for (MapEntry<Source, SourceEntry> mapEntry in _cache.entrySet()) { 4254 statistics.addSource(mapEntry.getKey());
4285 statistics.addSource(mapEntry.getKey()); 4255 SourceEntry entry = mapEntry.getValue();
4286 SourceEntry entry = mapEntry.getValue(); 4256 if (entry is DartEntry) {
4287 if (entry is DartEntry) { 4257 Source source = mapEntry.getKey();
4288 Source source = mapEntry.getKey(); 4258 DartEntry dartEntry = entry;
4289 DartEntry dartEntry = entry; 4259 SourceKind kind = dartEntry.getValue(DartEntry.SOURCE_KIND);
4290 SourceKind kind = dartEntry.getValue(DartEntry.SOURCE_KIND); 4260 // get library independent values
4291 // get library independent values 4261 statistics.putCacheItem2(dartEntry, SourceEntry.LINE_INFO);
4292 statistics.putCacheItem2(dartEntry, SourceEntry.LINE_INFO); 4262 statistics.putCacheItem2(dartEntry, DartEntry.PARSE_ERRORS);
4293 statistics.putCacheItem2(dartEntry, DartEntry.PARSE_ERRORS); 4263 statistics.putCacheItem2(dartEntry, DartEntry.PARSED_UNIT);
4294 statistics.putCacheItem2(dartEntry, DartEntry.PARSED_UNIT); 4264 statistics.putCacheItem2(dartEntry, DartEntry.SOURCE_KIND);
4295 statistics.putCacheItem2(dartEntry, DartEntry.SOURCE_KIND); 4265 if (identical(kind, SourceKind.LIBRARY)) {
4296 if (identical(kind, SourceKind.LIBRARY)) { 4266 statistics.putCacheItem2(dartEntry, DartEntry.ELEMENT);
4297 statistics.putCacheItem2(dartEntry, DartEntry.ELEMENT); 4267 statistics.putCacheItem2(dartEntry, DartEntry.EXPORTED_LIBRARIES);
4298 statistics.putCacheItem2(dartEntry, DartEntry.EXPORTED_LIBRARIES); 4268 statistics.putCacheItem2(dartEntry, DartEntry.IMPORTED_LIBRARIES);
4299 statistics.putCacheItem2(dartEntry, DartEntry.IMPORTED_LIBRARIES); 4269 statistics.putCacheItem2(dartEntry, DartEntry.INCLUDED_PARTS);
4300 statistics.putCacheItem2(dartEntry, DartEntry.INCLUDED_PARTS); 4270 statistics.putCacheItem2(dartEntry, DartEntry.IS_CLIENT);
4301 statistics.putCacheItem2(dartEntry, DartEntry.IS_CLIENT); 4271 statistics.putCacheItem2(dartEntry, DartEntry.IS_LAUNCHABLE);
4302 statistics.putCacheItem2(dartEntry, DartEntry.IS_LAUNCHABLE);
4303 }
4304 // get library-specific values
4305 List<Source> librarySources = getLibrariesContaining(source);
4306 for (Source librarySource in librarySources) {
4307 statistics.putCacheItem(dartEntry, librarySource, DartEntry.HINTS);
4308 statistics.putCacheItem(dartEntry, librarySource, DartEntry.RESOLUTI ON_ERRORS);
4309 statistics.putCacheItem(dartEntry, librarySource, DartEntry.RESOLVED _UNIT);
4310 statistics.putCacheItem(dartEntry, librarySource, DartEntry.VERIFICA TION_ERRORS);
4311 }
4312 } else if (entry is HtmlEntry) {
4313 HtmlEntry htmlEntry = entry;
4314 statistics.putCacheItem2(htmlEntry, SourceEntry.LINE_INFO);
4315 statistics.putCacheItem2(htmlEntry, HtmlEntry.PARSE_ERRORS);
4316 statistics.putCacheItem2(htmlEntry, HtmlEntry.PARSED_UNIT);
4317 statistics.putCacheItem2(htmlEntry, HtmlEntry.RESOLUTION_ERRORS);
4318 statistics.putCacheItem2(htmlEntry, HtmlEntry.RESOLVED_UNIT);
4319 statistics.putCacheItem2(htmlEntry, HtmlEntry.HINTS);
4320 } 4272 }
4273 // get library-specific values
4274 List<Source> librarySources = getLibrariesContaining(source);
4275 for (Source librarySource in librarySources) {
4276 statistics.putCacheItem(dartEntry, librarySource, DartEntry.HINTS);
4277 statistics.putCacheItem(dartEntry, librarySource, DartEntry.RESOLUTION _ERRORS);
4278 statistics.putCacheItem(dartEntry, librarySource, DartEntry.RESOLVED_U NIT);
4279 statistics.putCacheItem(dartEntry, librarySource, DartEntry.VERIFICATI ON_ERRORS);
4280 }
4281 } else if (entry is HtmlEntry) {
4282 HtmlEntry htmlEntry = entry;
4283 statistics.putCacheItem2(htmlEntry, SourceEntry.LINE_INFO);
4284 statistics.putCacheItem2(htmlEntry, HtmlEntry.PARSE_ERRORS);
4285 statistics.putCacheItem2(htmlEntry, HtmlEntry.PARSED_UNIT);
4286 statistics.putCacheItem2(htmlEntry, HtmlEntry.RESOLUTION_ERRORS);
4287 statistics.putCacheItem2(htmlEntry, HtmlEntry.RESOLVED_UNIT);
4321 } 4288 }
4322 } 4289 }
4323 return statistics; 4290 return statistics;
4324 } 4291 }
4325 4292
4326 TypeProvider get typeProvider { 4293 TypeProvider get typeProvider {
4327 Source coreSource = sourceFactory.forUri(DartSdk.DART_CORE); 4294 Source coreSource = sourceFactory.forUri(DartSdk.DART_CORE);
4328 return new TypeProviderImpl(computeLibraryElement(coreSource)); 4295 return new TypeProviderImpl(computeLibraryElement(coreSource));
4329 } 4296 }
4330 4297
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
4378 return false; 4345 return false;
4379 } 4346 }
4380 4347
4381 void mergeContext(AnalysisContext context) { 4348 void mergeContext(AnalysisContext context) {
4382 if (context is InstrumentedAnalysisContextImpl) { 4349 if (context is InstrumentedAnalysisContextImpl) {
4383 context = (context as InstrumentedAnalysisContextImpl).basis; 4350 context = (context as InstrumentedAnalysisContextImpl).basis;
4384 } 4351 }
4385 if (context is! AnalysisContextImpl) { 4352 if (context is! AnalysisContextImpl) {
4386 return; 4353 return;
4387 } 4354 }
4388 { 4355 // TODO(brianwilkerson) This does not lock against the other context's cache Lock.
4389 // TODO(brianwilkerson) This does not lock against the other context's cac heLock. 4356 for (MapEntry<Source, SourceEntry> entry in (context as AnalysisContextImpl) ._cache.entrySet()) {
4390 for (MapEntry<Source, SourceEntry> entry in (context as AnalysisContextImp l)._cache.entrySet()) { 4357 Source newSource = entry.getKey();
4391 Source newSource = entry.getKey(); 4358 SourceEntry existingEntry = getReadableSourceEntry(newSource);
4392 SourceEntry existingEntry = getReadableSourceEntry(newSource); 4359 if (existingEntry == null) {
4393 if (existingEntry == null) { 4360 // TODO(brianwilkerson) Decide whether we really need to copy the info.
4394 // TODO(brianwilkerson) Decide whether we really need to copy the info . 4361 _cache.put(newSource, entry.getValue().writableCopy);
4395 _cache.put(newSource, entry.getValue().writableCopy); 4362 } else {
4396 } else {
4397 }
4398 } 4363 }
4399 } 4364 }
4400 } 4365 }
4401 4366
4402 CompilationUnit parseCompilationUnit(Source source) => getDartParseData2(sourc e, DartEntry.PARSED_UNIT, null); 4367 CompilationUnit parseCompilationUnit(Source source) => getDartParseData2(sourc e, DartEntry.PARSED_UNIT, null);
4403 4368
4404 ht.HtmlUnit parseHtmlUnit(Source source) => getHtmlParseData(source, HtmlEntry .PARSED_UNIT, null); 4369 ht.HtmlUnit parseHtmlUnit(Source source) => getHtmlParseData(source, HtmlEntry .PARSED_UNIT, null);
4405 4370
4406 AnalysisResult performAnalysisTask() { 4371 AnalysisResult performAnalysisTask() {
4407 int getStart = JavaSystem.currentTimeMillis(); 4372 int getStart = JavaSystem.currentTimeMillis();
(...skipping 19 matching lines...) Expand all
4427 } on AnalysisException catch (exception) { 4392 } on AnalysisException catch (exception) {
4428 if (exception.cause is! JavaIOException) { 4393 if (exception.cause is! JavaIOException) {
4429 AnalysisEngine.instance.logger.logError2("Internal error while performin g the task: ${task}", exception); 4394 AnalysisEngine.instance.logger.logError2("Internal error while performin g the task: ${task}", exception);
4430 } 4395 }
4431 } 4396 }
4432 int performEnd = JavaSystem.currentTimeMillis(); 4397 int performEnd = JavaSystem.currentTimeMillis();
4433 return new AnalysisResult(getChangeNotices(false), getEnd - getStart, task.r untimeType.toString(), performEnd - performStart); 4398 return new AnalysisResult(getChangeNotices(false), getEnd - getStart, task.r untimeType.toString(), performEnd - performStart);
4434 } 4399 }
4435 4400
4436 void recordLibraryElements(Map<Source, LibraryElement> elementMap) { 4401 void recordLibraryElements(Map<Source, LibraryElement> elementMap) {
4437 { 4402 Source htmlSource = _sourceFactory.forUri(DartSdk.DART_HTML);
4438 Source htmlSource = _sourceFactory.forUri(DartSdk.DART_HTML); 4403 for (MapEntry<Source, LibraryElement> entry in getMapEntrySet(elementMap)) {
4439 for (MapEntry<Source, LibraryElement> entry in getMapEntrySet(elementMap)) { 4404 Source librarySource = entry.getKey();
4440 Source librarySource = entry.getKey(); 4405 LibraryElement library = entry.getValue();
4441 LibraryElement library = entry.getValue(); 4406 //
4442 // 4407 // Cache the element in the library's info.
4443 // Cache the element in the library's info. 4408 //
4444 // 4409 DartEntry dartEntry = getReadableDartEntry(librarySource);
4445 DartEntry dartEntry = getReadableDartEntry(librarySource); 4410 if (dartEntry != null) {
4446 if (dartEntry != null) { 4411 DartEntryImpl dartCopy = dartEntry.writableCopy;
4447 DartEntryImpl dartCopy = dartEntry.writableCopy; 4412 recordElementData(dartEntry, dartCopy, library, library.source, htmlSour ce);
4448 recordElementData(dartEntry, dartCopy, library, library.source, htmlSo urce); 4413 _cache.put(librarySource, dartCopy);
4449 _cache.put(librarySource, dartCopy);
4450 }
4451 } 4414 }
4452 } 4415 }
4453 } 4416 }
4454 4417
4455 CompilationUnit resolveCompilationUnit(Source unitSource, LibraryElement libra ry) { 4418 CompilationUnit resolveCompilationUnit(Source unitSource, LibraryElement libra ry) {
4456 if (library == null) { 4419 if (library == null) {
4457 return null; 4420 return null;
4458 } 4421 }
4459 return resolveCompilationUnit2(unitSource, library.source); 4422 return resolveCompilationUnit2(unitSource, library.source);
4460 } 4423 }
4461 4424
4462 CompilationUnit resolveCompilationUnit2(Source unitSource, Source librarySourc e) => getDartResolutionData2(unitSource, librarySource, DartEntry.RESOLVED_UNIT, null); 4425 CompilationUnit resolveCompilationUnit2(Source unitSource, Source librarySourc e) => getDartResolutionData2(unitSource, librarySource, DartEntry.RESOLVED_UNIT, null);
4463 4426
4464 ht.HtmlUnit resolveHtmlUnit(Source htmlSource) { 4427 ht.HtmlUnit resolveHtmlUnit(Source htmlSource) {
4465 computeHtmlElement(htmlSource); 4428 computeHtmlElement(htmlSource);
4466 return parseHtmlUnit(htmlSource); 4429 return parseHtmlUnit(htmlSource);
4467 } 4430 }
4468 4431
4469 void set analysisOptions(AnalysisOptions options) { 4432 void set analysisOptions(AnalysisOptions options) {
4470 { 4433 bool needsRecompute = this._options.analyzeFunctionBodies != options.analyze FunctionBodies || this._options.dart2jsHint != options.dart2jsHint || (this._opt ions.hint && !options.hint) || this._options.preserveComments != options.preserv eComments;
4471 bool needsRecompute = this._options.analyzeFunctionBodies != options.analy zeFunctionBodies || this._options.dart2jsHint != options.dart2jsHint || (this._o ptions.hint && !options.hint) || this._options.preserveComments != options.prese rveComments; 4434 int cacheSize = options.cacheSize;
4472 int cacheSize = options.cacheSize; 4435 if (this._options.cacheSize != cacheSize) {
4473 if (this._options.cacheSize != cacheSize) { 4436 this._options.cacheSize = cacheSize;
4474 this._options.cacheSize = cacheSize; 4437 _cache.maxCacheSize = cacheSize;
4475 _cache.maxCacheSize = cacheSize; 4438 //
4476 // 4439 // Cap the size of the priority list to being less than the cache size. Fa ilure to do so can
4477 // Cap the size of the priority list to being less than the cache size. Failure to do so can 4440 // result in an infinite loop in performAnalysisTask() because re-caching one AST structure
4478 // result in an infinite loop in performAnalysisTask() because re-cachin g one AST structure 4441 // can cause another priority source's AST structure to be flushed.
4479 // can cause another priority source's AST structure to be flushed. 4442 //
4480 // 4443 int maxPriorityOrderSize = cacheSize - _PRIORITY_ORDER_SIZE_DELTA;
4481 int maxPriorityOrderSize = cacheSize - _PRIORITY_ORDER_SIZE_DELTA; 4444 if (_priorityOrder.length > maxPriorityOrderSize) {
4482 if (_priorityOrder.length > maxPriorityOrderSize) { 4445 List<Source> newPriorityOrder = new List<Source>(maxPriorityOrderSize);
4483 List<Source> newPriorityOrder = new List<Source>(maxPriorityOrderSize) ; 4446 JavaSystem.arraycopy(_priorityOrder, 0, newPriorityOrder, 0, maxPriority OrderSize);
4484 JavaSystem.arraycopy(_priorityOrder, 0, newPriorityOrder, 0, maxPriori tyOrderSize); 4447 _priorityOrder = newPriorityOrder;
4485 _priorityOrder = newPriorityOrder;
4486 }
4487 } 4448 }
4488 this._options.analyzeFunctionBodies = options.analyzeFunctionBodies; 4449 }
4489 this._options.dart2jsHint = options.dart2jsHint; 4450 this._options.analyzeFunctionBodies = options.analyzeFunctionBodies;
4490 this._options.hint = options.hint; 4451 this._options.dart2jsHint = options.dart2jsHint;
4491 this._options.incremental = options.incremental; 4452 this._options.hint = options.hint;
4492 this._options.preserveComments = options.preserveComments; 4453 this._options.incremental = options.incremental;
4493 if (needsRecompute) { 4454 this._options.preserveComments = options.preserveComments;
4494 invalidateAllResolutionInformation(); 4455 if (needsRecompute) {
4495 } 4456 invalidateAllResolutionInformation();
4496 } 4457 }
4497 } 4458 }
4498 4459
4499 void set analysisPriorityOrder(List<Source> sources) { 4460 void set analysisPriorityOrder(List<Source> sources) {
4500 { 4461 if (sources == null || sources.isEmpty) {
4501 if (sources == null || sources.isEmpty) { 4462 _priorityOrder = Source.EMPTY_ARRAY;
4463 } else {
4464 while (sources.remove(null)) {
4465 }
4466 if (sources.isEmpty) {
4502 _priorityOrder = Source.EMPTY_ARRAY; 4467 _priorityOrder = Source.EMPTY_ARRAY;
4503 } else { 4468 }
4504 while (sources.remove(null)) { 4469 //
4505 } 4470 // Cap the size of the priority list to being less than the cache size. Fa ilure to do so can
4506 if (sources.isEmpty) { 4471 // result in an infinite loop in performAnalysisTask() because re-caching one AST structure
4507 _priorityOrder = Source.EMPTY_ARRAY; 4472 // can cause another priority source's AST structure to be flushed.
4508 } 4473 //
4509 // 4474 int count = Math.min(sources.length, _options.cacheSize - _PRIORITY_ORDER_ SIZE_DELTA);
4510 // Cap the size of the priority list to being less than the cache size. Failure to do so can 4475 _priorityOrder = new List<Source>(count);
4511 // result in an infinite loop in performAnalysisTask() because re-cachin g one AST structure 4476 for (int i = 0; i < count; i++) {
4512 // can cause another priority source's AST structure to be flushed. 4477 _priorityOrder[i] = sources[i];
4513 //
4514 int count = Math.min(sources.length, _options.cacheSize - _PRIORITY_ORDE R_SIZE_DELTA);
4515 _priorityOrder = new List<Source>(count);
4516 for (int i = 0; i < count; i++) {
4517 _priorityOrder[i] = sources[i];
4518 }
4519 } 4478 }
4520 } 4479 }
4521 } 4480 }
4522 4481
4523 void setChangedContents(Source source, String contents, int offset, int oldLen gth, int newLength) { 4482 void setChangedContents(Source source, String contents, int offset, int oldLen gth, int newLength) {
4524 { 4483 _recentTasks.clear();
4525 _recentTasks.clear(); 4484 String originalContents = _contentCache.setContents(source, contents);
4526 String originalContents = _contentCache.setContents(source, contents); 4485 if (contents != null) {
4527 if (contents != null) { 4486 if (contents != originalContents) {
4528 if (contents != originalContents) { 4487 if (_options.incremental) {
4529 if (_options.incremental) { 4488 _incrementalAnalysisCache = IncrementalAnalysisCache.update(_increment alAnalysisCache, source, originalContents, contents, offset, oldLength, newLengt h, getReadableSourceEntry(source));
4530 _incrementalAnalysisCache = IncrementalAnalysisCache.update(_increme ntalAnalysisCache, source, originalContents, contents, offset, oldLength, newLen gth, getReadableSourceEntry(source));
4531 }
4532 sourceChanged(source);
4533 SourceEntry sourceEntry = _cache.get(source);
4534 if (sourceEntry != null) {
4535 SourceEntryImpl sourceCopy = sourceEntry.writableCopy;
4536 sourceCopy.modificationTime = _contentCache.getModificationStamp(sou rce);
4537 sourceCopy.setValue(SourceEntry.CONTENT, contents);
4538 _cache.put(source, sourceCopy);
4539 }
4540 } 4489 }
4541 } else if (originalContents != null) {
4542 _incrementalAnalysisCache = IncrementalAnalysisCache.clear(_incrementalA nalysisCache, source);
4543 sourceChanged(source); 4490 sourceChanged(source);
4491 SourceEntry sourceEntry = _cache.get(source);
4492 if (sourceEntry != null) {
4493 SourceEntryImpl sourceCopy = sourceEntry.writableCopy;
4494 sourceCopy.modificationTime = _contentCache.getModificationStamp(sourc e);
4495 sourceCopy.setValue(SourceEntry.CONTENT, contents);
4496 _cache.put(source, sourceCopy);
4497 }
4544 } 4498 }
4499 } else if (originalContents != null) {
4500 _incrementalAnalysisCache = IncrementalAnalysisCache.clear(_incrementalAna lysisCache, source);
4501 sourceChanged(source);
4545 } 4502 }
4546 } 4503 }
4547 4504
4548 void setContents(Source source, String contents) { 4505 void setContents(Source source, String contents) {
4549 { 4506 _recentTasks.clear();
4550 _recentTasks.clear(); 4507 String originalContents = _contentCache.setContents(source, contents);
4551 String originalContents = _contentCache.setContents(source, contents); 4508 if (contents != null) {
4552 if (contents != null) { 4509 if (contents != originalContents) {
4553 if (contents != originalContents) {
4554 _incrementalAnalysisCache = IncrementalAnalysisCache.clear(_incrementa lAnalysisCache, source);
4555 sourceChanged(source);
4556 SourceEntry sourceEntry = _cache.get(source);
4557 if (sourceEntry != null) {
4558 SourceEntryImpl sourceCopy = sourceEntry.writableCopy;
4559 sourceCopy.modificationTime = _contentCache.getModificationStamp(sou rce);
4560 sourceCopy.setValue(SourceEntry.CONTENT, contents);
4561 _cache.put(source, sourceCopy);
4562 }
4563 }
4564 } else if (originalContents != null) {
4565 _incrementalAnalysisCache = IncrementalAnalysisCache.clear(_incrementalA nalysisCache, source); 4510 _incrementalAnalysisCache = IncrementalAnalysisCache.clear(_incrementalA nalysisCache, source);
4566 sourceChanged(source); 4511 sourceChanged(source);
4512 SourceEntry sourceEntry = _cache.get(source);
4513 if (sourceEntry != null) {
4514 SourceEntryImpl sourceCopy = sourceEntry.writableCopy;
4515 sourceCopy.modificationTime = _contentCache.getModificationStamp(sourc e);
4516 sourceCopy.setValue(SourceEntry.CONTENT, contents);
4517 _cache.put(source, sourceCopy);
4518 }
4567 } 4519 }
4520 } else if (originalContents != null) {
4521 _incrementalAnalysisCache = IncrementalAnalysisCache.clear(_incrementalAna lysisCache, source);
4522 sourceChanged(source);
4568 } 4523 }
4569 } 4524 }
4570 4525
4571 void set sourceFactory(SourceFactory factory) { 4526 void set sourceFactory(SourceFactory factory) {
4572 { 4527 if (identical(_sourceFactory, factory)) {
4573 if (identical(_sourceFactory, factory)) { 4528 return;
4574 return; 4529 } else if (factory.context != null) {
4575 } else if (factory.context != null) { 4530 throw new IllegalStateException("Source factories cannot be shared between contexts");
4576 throw new IllegalStateException("Source factories cannot be shared betwe en contexts");
4577 }
4578 if (_sourceFactory != null) {
4579 _sourceFactory.context = null;
4580 }
4581 factory.context = this;
4582 _sourceFactory = factory;
4583 invalidateAllResolutionInformation();
4584 } 4531 }
4532 if (_sourceFactory != null) {
4533 _sourceFactory.context = null;
4534 }
4535 factory.context = this;
4536 _sourceFactory = factory;
4537 invalidateAllResolutionInformation();
4585 } 4538 }
4586 4539
4587 /** 4540 /**
4588 * Record the results produced by performing a [ResolveDartLibraryTask]. If th e results were 4541 * Record the results produced by performing a [ResolveDartLibraryTask]. If th e results were
4589 * computed from data that is now out-of-date, then the results will not be re corded. 4542 * computed from data that is now out-of-date, then the results will not be re corded.
4590 * 4543 *
4591 * @param task the task that was performed 4544 * @param task the task that was performed
4592 * @return an entry containing the computed results 4545 * @return an entry containing the computed results
4593 * @throws AnalysisException if the results could not be recorded 4546 * @throws AnalysisException if the results could not be recorded
4594 */ 4547 */
(...skipping 19 matching lines...) Expand all
4614 DartEntryImpl dartCopy = unitEntry.writableCopy; 4567 DartEntryImpl dartCopy = unitEntry.writableCopy;
4615 dartCopy.recordResolutionError(); 4568 dartCopy.recordResolutionError();
4616 dartCopy.exception = thrownException; 4569 dartCopy.exception = thrownException;
4617 _cache.put(unitSource, dartCopy); 4570 _cache.put(unitSource, dartCopy);
4618 _cache.remove(unitSource); 4571 _cache.remove(unitSource);
4619 if (thrownException != null) { 4572 if (thrownException != null) {
4620 throw thrownException; 4573 throw thrownException;
4621 } 4574 }
4622 return dartCopy; 4575 return dartCopy;
4623 } 4576 }
4624 { 4577 if (allModificationTimesMatch(resolvedLibraries)) {
4625 if (allModificationTimesMatch(resolvedLibraries)) { 4578 Source htmlSource = sourceFactory.forUri(DartSdk.DART_HTML);
4626 Source htmlSource = sourceFactory.forUri(DartSdk.DART_HTML); 4579 RecordingErrorListener errorListener = resolver.errorListener;
4627 RecordingErrorListener errorListener = resolver.errorListener; 4580 for (Library library in resolvedLibraries) {
4628 for (Library library in resolvedLibraries) { 4581 Source librarySource = library.librarySource;
4629 Source librarySource = library.librarySource; 4582 for (Source source in library.compilationUnitSources) {
4630 for (Source source in library.compilationUnitSources) { 4583 CompilationUnit unit = library.getAST(source);
4631 CompilationUnit unit = library.getAST(source); 4584 List<AnalysisError> errors = errorListener.getErrors2(source);
4632 List<AnalysisError> errors = errorListener.getErrors2(source); 4585 LineInfo lineInfo = getLineInfo(source);
4633 LineInfo lineInfo = getLineInfo(source); 4586 DartEntry dartEntry = _cache.get(source) as DartEntry;
4634 DartEntry dartEntry = _cache.get(source) as DartEntry; 4587 int sourceTime = getModificationStamp(source);
4635 int sourceTime = getModificationStamp(source); 4588 if (dartEntry.modificationTime != sourceTime) {
4636 if (dartEntry.modificationTime != sourceTime) { 4589 // The source has changed without the context being notified. Simu late notification.
4637 // The source has changed without the context being notified. Si mulate notification. 4590 sourceChanged(source);
4638 sourceChanged(source); 4591 dartEntry = getReadableDartEntry(source);
4639 dartEntry = getReadableDartEntry(source); 4592 if (dartEntry == null) {
4640 if (dartEntry == null) { 4593 throw new AnalysisException.con1("A Dart file became a non-Dart file: ${source.fullName}");
4641 throw new AnalysisException.con1("A Dart file became a non-Dar t file: ${source.fullName}");
4642 }
4643 } 4594 }
4595 }
4596 DartEntryImpl dartCopy = dartEntry.writableCopy;
4597 if (thrownException == null) {
4598 dartCopy.setValue(SourceEntry.LINE_INFO, lineInfo);
4599 dartCopy.setState(DartEntry.PARSED_UNIT, CacheState.FLUSHED);
4600 dartCopy.setValue2(DartEntry.RESOLVED_UNIT, librarySource, unit);
4601 dartCopy.setValue2(DartEntry.RESOLUTION_ERRORS, librarySource, err ors);
4602 if (source == librarySource) {
4603 recordElementData(dartEntry, dartCopy, library.libraryElement, l ibrarySource, htmlSource);
4604 }
4605 _cache.storedAst(source);
4606 } else {
4607 dartCopy.recordResolutionError();
4608 _cache.remove(source);
4609 }
4610 dartCopy.exception = thrownException;
4611 _cache.put(source, dartCopy);
4612 if (source != librarySource) {
4613 _workManager.add(source, SourcePriority.PRIORITY_PART);
4614 }
4615 if (source == unitSource) {
4616 unitEntry = dartCopy;
4617 }
4618 ChangeNoticeImpl notice = getNotice(source);
4619 notice.compilationUnit = unit;
4620 notice.setErrors(dartCopy.allErrors, lineInfo);
4621 }
4622 }
4623 } else {
4624 PrintStringWriter writer = new PrintStringWriter();
4625 writer.println("Library resolution results discarded for");
4626 for (Library library in resolvedLibraries) {
4627 for (Source source in library.compilationUnitSources) {
4628 DartEntry dartEntry = getReadableDartEntry(source);
4629 if (dartEntry != null) {
4630 int resultTime = library.getModificationTime(source);
4631 writer.println(" ${debuggingString(source)}; sourceTime = ${getMo dificationStamp(source)}, resultTime = ${resultTime}, cacheTime = ${dartEntry.mo dificationTime}");
4644 DartEntryImpl dartCopy = dartEntry.writableCopy; 4632 DartEntryImpl dartCopy = dartEntry.writableCopy;
4645 if (thrownException == null) { 4633 if (thrownException == null || resultTime >= 0) {
4646 dartCopy.setValue(SourceEntry.LINE_INFO, lineInfo); 4634 //
4647 dartCopy.setState(DartEntry.PARSED_UNIT, CacheState.FLUSHED); 4635 // The analysis was performed on out-of-date sources. Mark the c ache so that the
4648 dartCopy.setValue2(DartEntry.RESOLVED_UNIT, librarySource, unit) ; 4636 // sources will be re-analyzed using the up-to-date sources.
4649 dartCopy.setValue2(DartEntry.RESOLUTION_ERRORS, librarySource, e rrors); 4637 //
4650 if (source == librarySource) { 4638 dartCopy.recordResolutionNotInProcess();
4651 recordElementData(dartEntry, dartCopy, library.libraryElement, librarySource, htmlSource);
4652 }
4653 _cache.storedAst(source);
4654 } else { 4639 } else {
4640 //
4641 // We could not determine whether the sources were up-to-date or out-of-date. Mark
4642 // the cache so that we won't attempt to re-analyze the sources until there's a
4643 // good chance that we'll be able to do so without error.
4644 //
4655 dartCopy.recordResolutionError(); 4645 dartCopy.recordResolutionError();
4656 _cache.remove(source); 4646 _cache.remove(source);
4657 } 4647 }
4658 dartCopy.exception = thrownException; 4648 dartCopy.exception = thrownException;
4659 _cache.put(source, dartCopy); 4649 _cache.put(source, dartCopy);
4660 if (source != librarySource) {
4661 _workManager.add(source, SourcePriority.PRIORITY_PART);
4662 }
4663 if (source == unitSource) { 4650 if (source == unitSource) {
4664 unitEntry = dartCopy; 4651 unitEntry = dartCopy;
4665 } 4652 }
4666 ChangeNoticeImpl notice = getNotice(source); 4653 } else {
4667 notice.compilationUnit = unit; 4654 writer.println(" ${debuggingString(source)}; sourceTime = ${getMo dificationStamp(source)}, no entry");
4668 notice.setErrors(dartCopy.allErrors, lineInfo);
4669 } 4655 }
4670 } 4656 }
4671 } else {
4672 PrintStringWriter writer = new PrintStringWriter();
4673 writer.println("Library resolution results discarded for");
4674 for (Library library in resolvedLibraries) {
4675 for (Source source in library.compilationUnitSources) {
4676 DartEntry dartEntry = getReadableDartEntry(source);
4677 if (dartEntry != null) {
4678 int resultTime = library.getModificationTime(source);
4679 writer.println(" ${debuggingString(source)}; sourceTime = ${get ModificationStamp(source)}, resultTime = ${resultTime}, cacheTime = ${dartEntry. modificationTime}");
4680 DartEntryImpl dartCopy = dartEntry.writableCopy;
4681 if (thrownException == null || resultTime >= 0) {
4682 //
4683 // The analysis was performed on out-of-date sources. Mark the cache so that the
4684 // sources will be re-analyzed using the up-to-date sources.
4685 //
4686 dartCopy.recordResolutionNotInProcess();
4687 } else {
4688 //
4689 // We could not determine whether the sources were up-to-date or out-of-date. Mark
4690 // the cache so that we won't attempt to re-analyze the source s until there's a
4691 // good chance that we'll be able to do so without error.
4692 //
4693 dartCopy.recordResolutionError();
4694 _cache.remove(source);
4695 }
4696 dartCopy.exception = thrownException;
4697 _cache.put(source, dartCopy);
4698 if (source == unitSource) {
4699 unitEntry = dartCopy;
4700 }
4701 } else {
4702 writer.println(" ${debuggingString(source)}; sourceTime = ${get ModificationStamp(source)}, no entry");
4703 }
4704 }
4705 }
4706 logInformation(writer.toString());
4707 } 4657 }
4658 logInformation(writer.toString());
4708 } 4659 }
4709 } 4660 }
4710 if (thrownException != null) { 4661 if (thrownException != null) {
4711 throw thrownException; 4662 throw thrownException;
4712 } 4663 }
4713 if (unitEntry == null) { 4664 if (unitEntry == null) {
4714 unitEntry = getReadableDartEntry(unitSource); 4665 unitEntry = getReadableDartEntry(unitSource);
4715 if (unitEntry == null) { 4666 if (unitEntry == null) {
4716 throw new AnalysisException.con1("A Dart file became a non-Dart file: ${ unitSource.fullName}"); 4667 throw new AnalysisException.con1("A Dart file became a non-Dart file: ${ unitSource.fullName}");
4717 } 4668 }
4718 } 4669 }
4719 return unitEntry; 4670 return unitEntry;
4720 } 4671 }
4721 4672
4722 /** 4673 /**
4723 * Record that we have accessed the AST structure associated with the given so urce. At the moment, 4674 * Record that we have accessed the AST structure associated with the given so urce. At the moment,
4724 * there is no differentiation between the parsed and resolved forms of the AS T. 4675 * there is no differentiation between the parsed and resolved forms of the AS T.
4725 * 4676 *
4726 * @param source the source whose AST structure was accessed 4677 * @param source the source whose AST structure was accessed
4727 */ 4678 */
4728 void accessedAst(Source source) { 4679 void accessedAst(Source source) {
4729 { 4680 _cache.accessedAst(source);
4730 _cache.accessedAst(source);
4731 }
4732 } 4681 }
4733 4682
4734 /** 4683 /**
4735 * Add all of the sources contained in the given source container to the given list of sources. 4684 * Add all of the sources contained in the given source container to the given list of sources.
4736 * 4685 *
4737 * Note: This method must only be invoked while we are synchronized on [cacheL ock]. 4686 * Note: This method must only be invoked while we are synchronized on [cacheL ock].
4738 * 4687 *
4739 * @param sources the list to which sources are to be added 4688 * @param sources the list to which sources are to be added
4740 * @param container the source container containing the sources to be added to the list 4689 * @param container the source container containing the sources to be added to the list
4741 */ 4690 */
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
5037 } 4986 }
5038 return htmlEntry; 4987 return htmlEntry;
5039 } 4988 }
5040 4989
5041 /** 4990 /**
5042 * Given the encoded form of a source, use the source factory to reconstitute the original source. 4991 * Given the encoded form of a source, use the source factory to reconstitute the original source.
5043 * 4992 *
5044 * @param encoding the encoded form of a source 4993 * @param encoding the encoded form of a source
5045 * @return the source represented by the encoding 4994 * @return the source represented by the encoding
5046 */ 4995 */
5047 Source computeSourceFromEncoding(String encoding) { 4996 Source computeSourceFromEncoding(String encoding) => _sourceFactory.fromEncodi ng(encoding);
5048 {
5049 return _sourceFactory.fromEncoding(encoding);
5050 }
5051 }
5052 4997
5053 /** 4998 /**
5054 * Return `true` if the given array of sources contains the given source. 4999 * Return `true` if the given array of sources contains the given source.
5055 * 5000 *
5056 * @param sources the sources being searched 5001 * @param sources the sources being searched
5057 * @param targetSource the source being searched for 5002 * @param targetSource the source being searched for
5058 * @return `true` if the given source is in the array 5003 * @return `true` if the given source is in the array
5059 */ 5004 */
5060 bool contains(List<Source> sources, Source targetSource) { 5005 bool contains(List<Source> sources, Source targetSource) {
5061 for (Source source in sources) { 5006 for (Source source in sources) {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
5115 5060
5116 /** 5061 /**
5117 * Return an array containing all of the change notices that are waiting to be returned. If there 5062 * Return an array containing all of the change notices that are waiting to be returned. If there
5118 * are no notices, then return either `null` or an empty array, depending on t he value of 5063 * are no notices, then return either `null` or an empty array, depending on t he value of
5119 * the argument. 5064 * the argument.
5120 * 5065 *
5121 * @param nullIfEmpty `true` if `null` should be returned when there are no no tices 5066 * @param nullIfEmpty `true` if `null` should be returned when there are no no tices
5122 * @return the change notices that are waiting to be returned 5067 * @return the change notices that are waiting to be returned
5123 */ 5068 */
5124 List<ChangeNotice> getChangeNotices(bool nullIfEmpty) { 5069 List<ChangeNotice> getChangeNotices(bool nullIfEmpty) {
5125 { 5070 if (_pendingNotices.isEmpty) {
5126 if (_pendingNotices.isEmpty) { 5071 if (nullIfEmpty) {
5127 if (nullIfEmpty) { 5072 return null;
5128 return null;
5129 }
5130 return ChangeNoticeImpl.EMPTY_ARRAY;
5131 } 5073 }
5132 List<ChangeNotice> notices = new List.from(_pendingNotices.values); 5074 return ChangeNoticeImpl.EMPTY_ARRAY;
5133 _pendingNotices.clear();
5134 return notices;
5135 } 5075 }
5076 List<ChangeNotice> notices = new List.from(_pendingNotices.values);
5077 _pendingNotices.clear();
5078 return notices;
5136 } 5079 }
5137 5080
5138 /** 5081 /**
5139 * Given a source for a Dart file, return the data represented by the given de scriptor that is 5082 * Given a source for a Dart file, return the data represented by the given de scriptor that is
5140 * associated with that source. This method assumes that the data can be produ ced by resolving the 5083 * associated with that source. This method assumes that the data can be produ ced by resolving the
5141 * directives in the source if they are not already cached. 5084 * directives in the source if they are not already cached.
5142 * 5085 *
5143 * @param source the source representing the Dart file 5086 * @param source the source representing the Dart file
5144 * @param dartEntry the cache entry associated with the Dart file 5087 * @param dartEntry the cache entry associated with the Dart file
5145 * @param descriptor the descriptor representing the data to be returned 5088 * @param descriptor the descriptor representing the data to be returned
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
5420 return htmlEntry.getValue(descriptor); 5363 return htmlEntry.getValue(descriptor);
5421 } 5364 }
5422 5365
5423 /** 5366 /**
5424 * Look through the cache for a task that needs to be performed. Return the ta sk that was found, 5367 * Look through the cache for a task that needs to be performed. Return the ta sk that was found,
5425 * or `null` if there is no more work to be done. 5368 * or `null` if there is no more work to be done.
5426 * 5369 *
5427 * @return the next task that needs to be performed 5370 * @return the next task that needs to be performed
5428 */ 5371 */
5429 AnalysisTask get nextAnalysisTask { 5372 AnalysisTask get nextAnalysisTask {
5430 { 5373 bool hintsEnabled = _options.hint;
5431 bool hintsEnabled = _options.hint; 5374 bool sdkErrorsEnabled = _options.generateSdkErrors;
5432 bool sdkErrorsEnabled = _options.generateSdkErrors; 5375 bool hasBlockedTask = false;
5433 bool hasBlockedTask = false; 5376 //
5434 // 5377 // Look for incremental analysis
5435 // Look for incremental analysis 5378 //
5436 // 5379 if (_incrementalAnalysisCache != null && _incrementalAnalysisCache.hasWork() ) {
5437 if (_incrementalAnalysisCache != null && _incrementalAnalysisCache.hasWork ()) { 5380 AnalysisTask task = new IncrementalAnalysisTask(this, _incrementalAnalysis Cache);
5438 AnalysisTask task = new IncrementalAnalysisTask(this, _incrementalAnalys isCache); 5381 _incrementalAnalysisCache = null;
5439 _incrementalAnalysisCache = null; 5382 return task;
5383 }
5384 //
5385 // Look for a priority source that needs to be analyzed.
5386 //
5387 for (Source source in _priorityOrder) {
5388 AnalysisContextImpl_TaskData taskData = getNextNondependentAnalysisTask(so urce, true, hintsEnabled, sdkErrorsEnabled);
5389 AnalysisTask task = taskData.task;
5390 if (task != null) {
5440 return task; 5391 return task;
5392 } else if (taskData.isBlocked) {
5393 hasBlockedTask = true;
5441 } 5394 }
5442 // 5395 }
5443 // Look for a priority source that needs to be analyzed. 5396 //
5444 // 5397 // Look for a non-priority source that needs to be analyzed.
5445 for (Source source in _priorityOrder) { 5398 //
5446 AnalysisContextImpl_TaskData taskData = getNextNondependentAnalysisTask( source, hintsEnabled, sdkErrorsEnabled); 5399 Source source = _workManager.nextSource;
5447 AnalysisTask task = taskData.task; 5400 while (source != null) {
5448 if (task != null) { 5401 AnalysisContextImpl_TaskData taskData = getNextNondependentAnalysisTask(so urce, false, hintsEnabled, sdkErrorsEnabled);
5449 return task; 5402 AnalysisTask task = taskData.task;
5450 } else if (taskData.isBlocked) { 5403 if (task != null) {
5451 hasBlockedTask = true; 5404 return task;
5452 } 5405 } else if (taskData.isBlocked) {
5406 hasBlockedTask = true;
5407 } else {
5408 _workManager.remove(source);
5453 } 5409 }
5454 // 5410 source = _workManager.nextSource;
5455 // Look for a non-priority source that needs to be analyzed.
5456 //
5457 Source source = _workManager.nextSource;
5458 while (source != null) {
5459 AnalysisContextImpl_TaskData taskData = getNextNondependentAnalysisTask( source, hintsEnabled, sdkErrorsEnabled);
5460 AnalysisTask task = taskData.task;
5461 if (task != null) {
5462 return task;
5463 } else if (taskData.isBlocked) {
5464 hasBlockedTask = true;
5465 } else {
5466 _workManager.remove(source);
5467 }
5468 source = _workManager.nextSource;
5469 }
5470 // //
5471 // // Look for a non-priority source that needs to be analyzed and wa s missed by the loop above.
5472 // //
5473 // for (Map.Entry<Source, SourceEntry> entry : cache.entrySet()) {
5474 // source = entry.getKey();
5475 // TaskData taskData = getNextAnalysisTaskForSource(source, entry.g etValue(), false, hintsEnabled);
5476 // AnalysisTask task = taskData.getTask();
5477 // if (task != null) {
5478 // System.out.println("Failed to analyze " + source.getFullName() );
5479 // return task;
5480 // }
5481 // }
5482 if (hasBlockedTask) {
5483 return WaitForAsyncTask.instance;
5484 }
5485 return null;
5486 } 5411 }
5412 // //
5413 // // Look for a non-priority source that needs to be analyzed and was missed by the loop above.
5414 // //
5415 // for (Map.Entry<Source, SourceEntry> entry : cache.entrySet()) {
5416 // source = entry.getKey();
5417 // TaskData taskData = getNextAnalysisTaskForSource(source, entry.get Value(), false, hintsEnabled);
5418 // AnalysisTask task = taskData.getTask();
5419 // if (task != null) {
5420 // System.out.println("Failed to analyze " + source.getFullName());
5421 // return task;
5422 // }
5423 // }
5424 if (hasBlockedTask) {
5425 return WaitForAsyncTask.instance;
5426 }
5427 return null;
5487 } 5428 }
5488 5429
5489 /** 5430 /**
5490 * Look at the given source to see whether a task needs to be performed relate d to it. Return the 5431 * Look at the given source to see whether a task needs to be performed relate d to it. Return the
5491 * task that should be performed, or `null` if there is no more work to be don e for the 5432 * task that should be performed, or `null` if there is no more work to be don e for the
5492 * source. 5433 * source.
5493 * 5434 *
5494 * <b>Note:</b> This method must only be invoked while we are synchronized on [cacheLock]. 5435 * <b>Note:</b> This method must only be invoked while we are synchronized on [cacheLock].
5495 * 5436 *
5496 * @param source the source to be checked 5437 * @param source the source to be checked
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
5688 HtmlEntryImpl htmlCopy = htmlEntry.writableCopy; 5629 HtmlEntryImpl htmlCopy = htmlEntry.writableCopy;
5689 htmlCopy.setState(HtmlEntry.ANGULAR_ERRORS, CacheState.IN_PROCESS); 5630 htmlCopy.setState(HtmlEntry.ANGULAR_ERRORS, CacheState.IN_PROCESS);
5690 _cache.put(source, htmlCopy); 5631 _cache.put(source, htmlCopy);
5691 return new AnalysisContextImpl_TaskData(new ResolveAngularComponentTem plateTask(this, source, component, application), false, null); 5632 return new AnalysisContextImpl_TaskData(new ResolveAngularComponentTem plateTask(this, source, component, application), false, null);
5692 } 5633 }
5693 } 5634 }
5694 } 5635 }
5695 return new AnalysisContextImpl_TaskData(null, false, null); 5636 return new AnalysisContextImpl_TaskData(null, false, null);
5696 } 5637 }
5697 5638
5698 AnalysisContextImpl_TaskData getNextNondependentAnalysisTask(Source source, bo ol hintsEnabled, bool sdkErrorsEnabled) { 5639 AnalysisContextImpl_TaskData getNextNondependentAnalysisTask(Source source, bo ol isPriority, bool hintsEnabled, bool sdkErrorsEnabled) {
5699 AnalysisContextImpl_TaskData taskData = getNextAnalysisTaskForSource(source, _cache.get(source), true, hintsEnabled, sdkErrorsEnabled); 5640 AnalysisContextImpl_TaskData taskData = getNextAnalysisTaskForSource(source, _cache.get(source), isPriority, hintsEnabled, sdkErrorsEnabled);
5700 if (taskData.task != null || taskData.isBlocked) { 5641 if (taskData.task != null || taskData.isBlocked) {
5701 return taskData; 5642 return taskData;
5702 } 5643 }
5703 while (taskData.dependentSource != null) { 5644 while (taskData.dependentSource != null) {
5704 taskData = getNextAnalysisTaskForSource(source, _cache.get(source), true, hintsEnabled, sdkErrorsEnabled); 5645 taskData = getNextAnalysisTaskForSource(source, _cache.get(source), isPrio rity, hintsEnabled, sdkErrorsEnabled);
5705 if (taskData.task != null || taskData.isBlocked) { 5646 if (taskData.task != null || taskData.isBlocked) {
5706 return taskData; 5647 return taskData;
5707 } 5648 }
5708 } 5649 }
5709 return new AnalysisContextImpl_TaskData(null, false, null); 5650 return new AnalysisContextImpl_TaskData(null, false, null);
5710 } 5651 }
5711 5652
5712 /** 5653 /**
5713 * Return a change notice for the given source, creating one if one does not a lready exist. 5654 * Return a change notice for the given source, creating one if one does not a lready exist.
5714 * 5655 *
(...skipping 10 matching lines...) Expand all
5725 } 5666 }
5726 5667
5727 /** 5668 /**
5728 * Return the cache entry associated with the given source, or `null` if the s ource is not a 5669 * Return the cache entry associated with the given source, or `null` if the s ource is not a
5729 * Dart file. 5670 * Dart file.
5730 * 5671 *
5731 * @param source the source for which a cache entry is being sought 5672 * @param source the source for which a cache entry is being sought
5732 * @return the source cache entry associated with the given source 5673 * @return the source cache entry associated with the given source
5733 */ 5674 */
5734 DartEntry getReadableDartEntry(Source source) { 5675 DartEntry getReadableDartEntry(Source source) {
5735 { 5676 SourceEntry sourceEntry = _cache.get(source);
5736 SourceEntry sourceEntry = _cache.get(source); 5677 if (sourceEntry == null) {
5737 if (sourceEntry == null) { 5678 sourceEntry = createSourceEntry(source);
5738 sourceEntry = createSourceEntry(source);
5739 }
5740 if (sourceEntry is DartEntry) {
5741 return sourceEntry as DartEntry;
5742 }
5743 return null;
5744 } 5679 }
5680 if (sourceEntry is DartEntry) {
5681 return sourceEntry as DartEntry;
5682 }
5683 return null;
5745 } 5684 }
5746 5685
5747 /** 5686 /**
5748 * Return the cache entry associated with the given source, or `null` if the s ource is not 5687 * Return the cache entry associated with the given source, or `null` if the s ource is not
5749 * an HTML file. 5688 * an HTML file.
5750 * 5689 *
5751 * @param source the source for which a cache entry is being sought 5690 * @param source the source for which a cache entry is being sought
5752 * @return the source cache entry associated with the given source 5691 * @return the source cache entry associated with the given source
5753 */ 5692 */
5754 HtmlEntry getReadableHtmlEntry(Source source) { 5693 HtmlEntry getReadableHtmlEntry(Source source) {
5755 { 5694 SourceEntry sourceEntry = _cache.get(source);
5756 SourceEntry sourceEntry = _cache.get(source); 5695 if (sourceEntry == null) {
5757 if (sourceEntry == null) { 5696 sourceEntry = createSourceEntry(source);
5758 sourceEntry = createSourceEntry(source);
5759 }
5760 if (sourceEntry is HtmlEntry) {
5761 return sourceEntry as HtmlEntry;
5762 }
5763 return null;
5764 } 5697 }
5698 if (sourceEntry is HtmlEntry) {
5699 return sourceEntry as HtmlEntry;
5700 }
5701 return null;
5765 } 5702 }
5766 5703
5767 /** 5704 /**
5768 * Return the cache entry associated with the given source, or `null` if there is no entry 5705 * Return the cache entry associated with the given source, or `null` if there is no entry
5769 * associated with the source. 5706 * associated with the source.
5770 * 5707 *
5771 * @param source the source for which a cache entry is being sought 5708 * @param source the source for which a cache entry is being sought
5772 * @return the source cache entry associated with the given source 5709 * @return the source cache entry associated with the given source
5773 */ 5710 */
5774 SourceEntry getReadableSourceEntry(Source source) { 5711 SourceEntry getReadableSourceEntry(Source source) {
5775 { 5712 SourceEntry sourceEntry = _cache.get(source);
5776 SourceEntry sourceEntry = _cache.get(source); 5713 if (sourceEntry == null) {
5777 if (sourceEntry == null) { 5714 sourceEntry = createSourceEntry(source);
5778 sourceEntry = createSourceEntry(source);
5779 }
5780 return sourceEntry;
5781 } 5715 }
5716 return sourceEntry;
5782 } 5717 }
5783 5718
5784 /** 5719 /**
5785 * Return an array containing all of the sources known to this context that ha ve the given kind. 5720 * Return an array containing all of the sources known to this context that ha ve the given kind.
5786 * 5721 *
5787 * @param kind the kind of sources to be returned 5722 * @param kind the kind of sources to be returned
5788 * @return all of the sources known to this context that have the given kind 5723 * @return all of the sources known to this context that have the given kind
5789 */ 5724 */
5790 List<Source> getSources(SourceKind kind) { 5725 List<Source> getSources(SourceKind kind) {
5791 List<Source> sources = new List<Source>(); 5726 List<Source> sources = new List<Source>();
5792 { 5727 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) {
5793 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) { 5728 if (identical(entry.getValue().kind, kind)) {
5794 if (identical(entry.getValue().kind, kind)) { 5729 sources.add(entry.getKey());
5795 sources.add(entry.getKey());
5796 }
5797 } 5730 }
5798 } 5731 }
5799 return new List.from(sources); 5732 return new List.from(sources);
5800 } 5733 }
5801 5734
5802 /** 5735 /**
5803 * Look at the given source to see whether a task needs to be performed relate d to it. If so, add 5736 * Look at the given source to see whether a task needs to be performed relate d to it. If so, add
5804 * the source to the set of sources that need to be processed. This method dup licates, and must 5737 * the source to the set of sources that need to be processed. This method dup licates, and must
5805 * therefore be kept in sync with, 5738 * therefore be kept in sync with,
5806 * [getNextAnalysisTask]. This method is intended to 5739 * [getNextAnalysisTask]. This method is intended to
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
6174 * 6107 *
6175 * @param task the task that was performed 6108 * @param task the task that was performed
6176 * @return an entry containing the computed results 6109 * @return an entry containing the computed results
6177 * @throws AnalysisException if the results could not be recorded 6110 * @throws AnalysisException if the results could not be recorded
6178 */ 6111 */
6179 DartEntry recordGenerateDartErrorsTask(GenerateDartErrorsTask task) { 6112 DartEntry recordGenerateDartErrorsTask(GenerateDartErrorsTask task) {
6180 Source source = task.source; 6113 Source source = task.source;
6181 Source librarySource = task.libraryElement.source; 6114 Source librarySource = task.libraryElement.source;
6182 AnalysisException thrownException = task.exception; 6115 AnalysisException thrownException = task.exception;
6183 DartEntry dartEntry = null; 6116 DartEntry dartEntry = null;
6184 { 6117 SourceEntry sourceEntry = _cache.get(source);
6185 SourceEntry sourceEntry = _cache.get(source); 6118 if (sourceEntry == null) {
6186 if (sourceEntry == null) { 6119 throw new ObsoleteSourceAnalysisException(source);
6187 throw new ObsoleteSourceAnalysisException(source); 6120 } else if (sourceEntry is! DartEntry) {
6188 } else if (sourceEntry is! DartEntry) { 6121 // This shouldn't be possible because we should never have performed the t ask if the source
6189 // This shouldn't be possible because we should never have performed the task if the source 6122 // didn't represent a Dart file, but check to be safe.
6190 // didn't represent a Dart file, but check to be safe. 6123 throw new AnalysisException.con1("Internal error: attempting to verify non -Dart file as a Dart file: ${source.fullName}");
6191 throw new AnalysisException.con1("Internal error: attempting to verify n on-Dart file as a Dart file: ${source.fullName}"); 6124 }
6125 dartEntry = sourceEntry as DartEntry;
6126 int sourceTime = getModificationStamp(source);
6127 int resultTime = task.modificationTime;
6128 if (sourceTime == resultTime) {
6129 if (dartEntry.modificationTime != sourceTime) {
6130 // The source has changed without the context being notified. Simulate n otification.
6131 sourceChanged(source);
6132 dartEntry = getReadableDartEntry(source);
6133 if (dartEntry == null) {
6134 throw new AnalysisException.con1("A Dart file became a non-Dart file: ${source.fullName}");
6135 }
6192 } 6136 }
6193 dartEntry = sourceEntry as DartEntry; 6137 DartEntryImpl dartCopy = dartEntry.writableCopy;
6194 int sourceTime = getModificationStamp(source); 6138 if (thrownException == null) {
6195 int resultTime = task.modificationTime; 6139 dartCopy.setValue2(DartEntry.VERIFICATION_ERRORS, librarySource, task.er rors);
6196 if (sourceTime == resultTime) { 6140 ChangeNoticeImpl notice = getNotice(source);
6197 if (dartEntry.modificationTime != sourceTime) { 6141 notice.setErrors(dartCopy.allErrors, dartCopy.getValue(SourceEntry.LINE_ INFO));
6198 // The source has changed without the context being notified. Simulate notification.
6199 sourceChanged(source);
6200 dartEntry = getReadableDartEntry(source);
6201 if (dartEntry == null) {
6202 throw new AnalysisException.con1("A Dart file became a non-Dart file : ${source.fullName}");
6203 }
6204 }
6205 DartEntryImpl dartCopy = dartEntry.writableCopy;
6206 if (thrownException == null) {
6207 dartCopy.setValue2(DartEntry.VERIFICATION_ERRORS, librarySource, task. errors);
6208 ChangeNoticeImpl notice = getNotice(source);
6209 notice.setErrors(dartCopy.allErrors, dartCopy.getValue(SourceEntry.LIN E_INFO));
6210 } else {
6211 dartCopy.setState2(DartEntry.VERIFICATION_ERRORS, librarySource, Cache State.ERROR);
6212 }
6213 dartCopy.exception = thrownException;
6214 _cache.put(source, dartCopy);
6215 dartEntry = dartCopy;
6216 } else { 6142 } else {
6217 logInformation2("Generated errors discarded for ${debuggingString(source )}; sourceTime = ${sourceTime}, resultTime = ${resultTime}, cacheTime = ${dartEn try.modificationTime}", thrownException); 6143 dartCopy.setState2(DartEntry.VERIFICATION_ERRORS, librarySource, CacheSt ate.ERROR);
6218 DartEntryImpl dartCopy = dartEntry.writableCopy;
6219 if (thrownException == null || resultTime >= 0) {
6220 //
6221 // The analysis was performed on out-of-date sources. Mark the cache s o that the source
6222 // will be re-verified using the up-to-date sources.
6223 //
6224 // dartCopy.setState(DartEntry.VERIFICATION_ERRORS, librarySo urce, CacheState.INVALID);
6225 removeFromParts(source, dartEntry);
6226 dartCopy.invalidateAllInformation();
6227 dartCopy.modificationTime = sourceTime;
6228 _cache.removedAst(source);
6229 _workManager.add(source, SourcePriority.UNKNOWN);
6230 } else {
6231 //
6232 // We could not determine whether the sources were up-to-date or out-o f-date. Mark the
6233 // cache so that we won't attempt to re-verify the source until there' s a good chance
6234 // that we'll be able to do so without error.
6235 //
6236 dartCopy.setState2(DartEntry.VERIFICATION_ERRORS, librarySource, Cache State.ERROR);
6237 }
6238 dartCopy.exception = thrownException;
6239 _cache.put(source, dartCopy);
6240 dartEntry = dartCopy;
6241 } 6144 }
6145 dartCopy.exception = thrownException;
6146 _cache.put(source, dartCopy);
6147 dartEntry = dartCopy;
6148 } else {
6149 logInformation2("Generated errors discarded for ${debuggingString(source)} ; sourceTime = ${sourceTime}, resultTime = ${resultTime}, cacheTime = ${dartEntr y.modificationTime}", thrownException);
6150 DartEntryImpl dartCopy = dartEntry.writableCopy;
6151 if (thrownException == null || resultTime >= 0) {
6152 //
6153 // The analysis was performed on out-of-date sources. Mark the cache so that the source
6154 // will be re-verified using the up-to-date sources.
6155 //
6156 // dartCopy.setState(DartEntry.VERIFICATION_ERRORS, librarySour ce, CacheState.INVALID);
6157 removeFromParts(source, dartEntry);
6158 dartCopy.invalidateAllInformation();
6159 dartCopy.modificationTime = sourceTime;
6160 _cache.removedAst(source);
6161 _workManager.add(source, SourcePriority.UNKNOWN);
6162 } else {
6163 //
6164 // We could not determine whether the sources were up-to-date or out-of- date. Mark the
6165 // cache so that we won't attempt to re-verify the source until there's a good chance
6166 // that we'll be able to do so without error.
6167 //
6168 dartCopy.setState2(DartEntry.VERIFICATION_ERRORS, librarySource, CacheSt ate.ERROR);
6169 }
6170 dartCopy.exception = thrownException;
6171 _cache.put(source, dartCopy);
6172 dartEntry = dartCopy;
6242 } 6173 }
6243 if (thrownException != null) { 6174 if (thrownException != null) {
6244 throw thrownException; 6175 throw thrownException;
6245 } 6176 }
6246 return dartEntry; 6177 return dartEntry;
6247 } 6178 }
6248 6179
6249 /** 6180 /**
6250 * Record the results produced by performing a [GenerateDartHintsTask]. If the results were 6181 * Record the results produced by performing a [GenerateDartHintsTask]. If the results were
6251 * computed from data that is now out-of-date, then the results will not be re corded. 6182 * computed from data that is now out-of-date, then the results will not be re corded.
6252 * 6183 *
6253 * @param task the task that was performed 6184 * @param task the task that was performed
6254 * @return an entry containing the computed results 6185 * @return an entry containing the computed results
6255 * @throws AnalysisException if the results could not be recorded 6186 * @throws AnalysisException if the results could not be recorded
6256 */ 6187 */
6257 DartEntry recordGenerateDartHintsTask(GenerateDartHintsTask task) { 6188 DartEntry recordGenerateDartHintsTask(GenerateDartHintsTask task) {
6258 Source librarySource = task.libraryElement.source; 6189 Source librarySource = task.libraryElement.source;
6259 AnalysisException thrownException = task.exception; 6190 AnalysisException thrownException = task.exception;
6260 DartEntry libraryEntry = null; 6191 DartEntry libraryEntry = null;
6261 Map<Source, TimestampedData<List<AnalysisError>>> hintMap = task.hintMap; 6192 Map<Source, TimestampedData<List<AnalysisError>>> hintMap = task.hintMap;
6262 if (hintMap == null) { 6193 if (hintMap == null) {
6263 { 6194 // We don't have any information about which sources to mark as invalid ot her than the library
6264 // We don't have any information about which sources to mark as invalid other than the library 6195 // source.
6265 // source. 6196 SourceEntry sourceEntry = _cache.get(librarySource);
6266 SourceEntry sourceEntry = _cache.get(librarySource); 6197 if (sourceEntry == null) {
6267 if (sourceEntry == null) { 6198 throw new ObsoleteSourceAnalysisException(librarySource);
6268 throw new ObsoleteSourceAnalysisException(librarySource); 6199 } else if (sourceEntry is! DartEntry) {
6269 } else if (sourceEntry is! DartEntry) { 6200 // This shouldn't be possible because we should never have performed the task if the source
6270 // This shouldn't be possible because we should never have performed t he task if the source 6201 // didn't represent a Dart file, but check to be safe.
6271 // didn't represent a Dart file, but check to be safe. 6202 throw new AnalysisException.con1("Internal error: attempting to generate hints for non-Dart file as a Dart file: ${librarySource.fullName}");
6272 throw new AnalysisException.con1("Internal error: attempting to genera te hints for non-Dart file as a Dart file: ${librarySource.fullName}");
6273 }
6274 if (thrownException == null) {
6275 thrownException = new AnalysisException.con1("GenerateDartHintsTask re turned a null hint map without throwing an exception: ${librarySource.fullName}" );
6276 }
6277 DartEntryImpl dartCopy = (sourceEntry as DartEntry).writableCopy;
6278 dartCopy.setState2(DartEntry.HINTS, librarySource, CacheState.ERROR);
6279 dartCopy.exception = thrownException;
6280 _cache.put(librarySource, dartCopy);
6281 } 6203 }
6204 if (thrownException == null) {
6205 thrownException = new AnalysisException.con1("GenerateDartHintsTask retu rned a null hint map without throwing an exception: ${librarySource.fullName}");
6206 }
6207 DartEntryImpl dartCopy = (sourceEntry as DartEntry).writableCopy;
6208 dartCopy.setState2(DartEntry.HINTS, librarySource, CacheState.ERROR);
6209 dartCopy.exception = thrownException;
6210 _cache.put(librarySource, dartCopy);
6282 throw thrownException; 6211 throw thrownException;
6283 } 6212 }
6284 for (MapEntry<Source, TimestampedData<List<AnalysisError>>> entry in getMapE ntrySet(hintMap)) { 6213 for (MapEntry<Source, TimestampedData<List<AnalysisError>>> entry in getMapE ntrySet(hintMap)) {
6285 Source unitSource = entry.getKey(); 6214 Source unitSource = entry.getKey();
6286 TimestampedData<List<AnalysisError>> results = entry.getValue(); 6215 TimestampedData<List<AnalysisError>> results = entry.getValue();
6287 { 6216 SourceEntry sourceEntry = _cache.get(unitSource);
6288 SourceEntry sourceEntry = _cache.get(unitSource); 6217 if (sourceEntry is! DartEntry) {
6289 if (sourceEntry is! DartEntry) { 6218 // This shouldn't be possible because we should never have performed the task if the source
6290 // This shouldn't be possible because we should never have performed t he task if the source 6219 // didn't represent a Dart file, but check to be safe.
6291 // didn't represent a Dart file, but check to be safe. 6220 throw new AnalysisException.con1("Internal error: attempting to parse no n-Dart file as a Dart file: ${unitSource.fullName}");
6292 throw new AnalysisException.con1("Internal error: attempting to parse non-Dart file as a Dart file: ${unitSource.fullName}"); 6221 }
6222 DartEntry dartEntry = sourceEntry as DartEntry;
6223 if (unitSource == librarySource) {
6224 libraryEntry = dartEntry;
6225 }
6226 int sourceTime = getModificationStamp(unitSource);
6227 int resultTime = results.modificationTime;
6228 if (sourceTime == resultTime) {
6229 if (dartEntry.modificationTime != sourceTime) {
6230 // The source has changed without the context being notified. Simulate notification.
6231 sourceChanged(unitSource);
6232 dartEntry = getReadableDartEntry(unitSource);
6233 if (dartEntry == null) {
6234 throw new AnalysisException.con1("A Dart file became a non-Dart file : ${unitSource.fullName}");
6235 }
6293 } 6236 }
6294 DartEntry dartEntry = sourceEntry as DartEntry; 6237 DartEntryImpl dartCopy = dartEntry.writableCopy;
6295 if (unitSource == librarySource) { 6238 if (thrownException == null) {
6296 libraryEntry = dartEntry; 6239 dartCopy.setValue2(DartEntry.HINTS, librarySource, results.data);
6240 ChangeNoticeImpl notice = getNotice(unitSource);
6241 notice.setErrors(dartCopy.allErrors, dartCopy.getValue(SourceEntry.LIN E_INFO));
6242 } else {
6243 dartCopy.setState2(DartEntry.HINTS, librarySource, CacheState.ERROR);
6297 } 6244 }
6298 int sourceTime = getModificationStamp(unitSource); 6245 dartCopy.exception = thrownException;
6299 int resultTime = results.modificationTime; 6246 _cache.put(unitSource, dartCopy);
6300 if (sourceTime == resultTime) { 6247 dartEntry = dartCopy;
6301 if (dartEntry.modificationTime != sourceTime) { 6248 } else {
6302 // The source has changed without the context being notified. Simula te notification. 6249 logInformation2("Generated hints discarded for ${debuggingString(unitSou rce)}; sourceTime = ${sourceTime}, resultTime = ${resultTime}, cacheTime = ${dar tEntry.modificationTime}", thrownException);
6303 sourceChanged(unitSource); 6250 if (identical(dartEntry.getState2(DartEntry.HINTS, librarySource), Cache State.IN_PROCESS)) {
6304 dartEntry = getReadableDartEntry(unitSource);
6305 if (dartEntry == null) {
6306 throw new AnalysisException.con1("A Dart file became a non-Dart fi le: ${unitSource.fullName}");
6307 }
6308 }
6309 DartEntryImpl dartCopy = dartEntry.writableCopy; 6251 DartEntryImpl dartCopy = dartEntry.writableCopy;
6310 if (thrownException == null) { 6252 if (thrownException == null || resultTime >= 0) {
6311 dartCopy.setValue2(DartEntry.HINTS, librarySource, results.data); 6253 //
6312 ChangeNoticeImpl notice = getNotice(unitSource); 6254 // The analysis was performed on out-of-date sources. Mark the cache so that the sources
6313 notice.setErrors(dartCopy.allErrors, dartCopy.getValue(SourceEntry.L INE_INFO)); 6255 // will be re-analyzed using the up-to-date sources.
6256 //
6257 // dartCopy.setState(DartEntry.HINTS, librarySource, Ca cheState.INVALID);
6258 removeFromParts(unitSource, dartEntry);
6259 dartCopy.invalidateAllInformation();
6260 dartCopy.modificationTime = sourceTime;
6261 _cache.removedAst(unitSource);
6262 _workManager.add(unitSource, SourcePriority.UNKNOWN);
6314 } else { 6263 } else {
6264 //
6265 // We could not determine whether the sources were up-to-date or out -of-date. Mark the
6266 // cache so that we won't attempt to re-analyze the sources until th ere's a good chance
6267 // that we'll be able to do so without error.
6268 //
6315 dartCopy.setState2(DartEntry.HINTS, librarySource, CacheState.ERROR) ; 6269 dartCopy.setState2(DartEntry.HINTS, librarySource, CacheState.ERROR) ;
6316 } 6270 }
6317 dartCopy.exception = thrownException; 6271 dartCopy.exception = thrownException;
6318 _cache.put(unitSource, dartCopy); 6272 _cache.put(unitSource, dartCopy);
6319 dartEntry = dartCopy; 6273 dartEntry = dartCopy;
6320 } else {
6321 logInformation2("Generated hints discarded for ${debuggingString(unitS ource)}; sourceTime = ${sourceTime}, resultTime = ${resultTime}, cacheTime = ${d artEntry.modificationTime}", thrownException);
6322 if (identical(dartEntry.getState2(DartEntry.HINTS, librarySource), Cac heState.IN_PROCESS)) {
6323 DartEntryImpl dartCopy = dartEntry.writableCopy;
6324 if (thrownException == null || resultTime >= 0) {
6325 //
6326 // The analysis was performed on out-of-date sources. Mark the cac he so that the sources
6327 // will be re-analyzed using the up-to-date sources.
6328 //
6329 // dartCopy.setState(DartEntry.HINTS, librarySource, CacheState.INVALID);
6330 removeFromParts(unitSource, dartEntry);
6331 dartCopy.invalidateAllInformation();
6332 dartCopy.modificationTime = sourceTime;
6333 _cache.removedAst(unitSource);
6334 _workManager.add(unitSource, SourcePriority.UNKNOWN);
6335 } else {
6336 //
6337 // We could not determine whether the sources were up-to-date or o ut-of-date. Mark the
6338 // cache so that we won't attempt to re-analyze the sources until there's a good chance
6339 // that we'll be able to do so without error.
6340 //
6341 dartCopy.setState2(DartEntry.HINTS, librarySource, CacheState.ERRO R);
6342 }
6343 dartCopy.exception = thrownException;
6344 _cache.put(unitSource, dartCopy);
6345 dartEntry = dartCopy;
6346 }
6347 } 6274 }
6348 } 6275 }
6349 } 6276 }
6350 if (thrownException != null) { 6277 if (thrownException != null) {
6351 throw thrownException; 6278 throw thrownException;
6352 } 6279 }
6353 return libraryEntry; 6280 return libraryEntry;
6354 } 6281 }
6355 6282
6356 /** 6283 /**
6357 * Record the results produced by performing a [GetContentTask]. 6284 * Record the results produced by performing a [GetContentTask].
6358 * 6285 *
6359 * @param task the task that was performed 6286 * @param task the task that was performed
6360 * @return an entry containing the computed results 6287 * @return an entry containing the computed results
6361 * @throws AnalysisException if the results could not be recorded 6288 * @throws AnalysisException if the results could not be recorded
6362 */ 6289 */
6363 SourceEntry recordGetContentsTask(GetContentTask task) { 6290 SourceEntry recordGetContentsTask(GetContentTask task) {
6364 if (!task.isComplete) { 6291 if (!task.isComplete) {
6365 return null; 6292 return null;
6366 } 6293 }
6367 Source source = task.source; 6294 Source source = task.source;
6368 AnalysisException thrownException = task.exception; 6295 AnalysisException thrownException = task.exception;
6369 SourceEntry sourceEntry = null; 6296 SourceEntry sourceEntry = null;
6370 { 6297 sourceEntry = _cache.get(source);
6371 sourceEntry = _cache.get(source); 6298 if (sourceEntry == null) {
6372 if (sourceEntry == null) { 6299 throw new ObsoleteSourceAnalysisException(source);
6373 throw new ObsoleteSourceAnalysisException(source);
6374 }
6375 SourceEntryImpl sourceCopy = sourceEntry.writableCopy;
6376 if (thrownException == null) {
6377 sourceCopy.modificationTime = task.modificationTime;
6378 sourceCopy.setValue(SourceEntry.CONTENT, task.content);
6379 } else {
6380 sourceCopy.exception = thrownException;
6381 sourceCopy.recordContentError();
6382 _workManager.remove(source);
6383 }
6384 _cache.put(source, sourceCopy);
6385 sourceEntry = sourceCopy;
6386 } 6300 }
6301 SourceEntryImpl sourceCopy = sourceEntry.writableCopy;
6302 if (thrownException == null) {
6303 sourceCopy.modificationTime = task.modificationTime;
6304 sourceCopy.setValue(SourceEntry.CONTENT, task.content);
6305 } else {
6306 sourceCopy.exception = thrownException;
6307 sourceCopy.recordContentError();
6308 _workManager.remove(source);
6309 }
6310 _cache.put(source, sourceCopy);
6311 sourceEntry = sourceCopy;
6387 if (thrownException != null) { 6312 if (thrownException != null) {
6388 throw thrownException; 6313 throw thrownException;
6389 } 6314 }
6390 return sourceEntry; 6315 return sourceEntry;
6391 } 6316 }
6392 6317
6393 /** 6318 /**
6394 * Record the results produced by performing a [IncrementalAnalysisTask]. 6319 * Record the results produced by performing a [IncrementalAnalysisTask].
6395 * 6320 *
6396 * @param task the task that was performed 6321 * @param task the task that was performed
6397 * @return an entry containing the computed results 6322 * @return an entry containing the computed results
6398 * @throws AnalysisException if the results could not be recorded 6323 * @throws AnalysisException if the results could not be recorded
6399 */ 6324 */
6400 DartEntry recordIncrementalAnalysisTaskResults(IncrementalAnalysisTask task) { 6325 DartEntry recordIncrementalAnalysisTaskResults(IncrementalAnalysisTask task) {
6401 { 6326 CompilationUnit unit = task.compilationUnit;
6402 CompilationUnit unit = task.compilationUnit; 6327 if (unit != null) {
6403 if (unit != null) { 6328 ChangeNoticeImpl notice = getNotice(task.source);
6404 ChangeNoticeImpl notice = getNotice(task.source); 6329 notice.compilationUnit = unit;
6405 notice.compilationUnit = unit; 6330 _incrementalAnalysisCache = IncrementalAnalysisCache.cacheResult(task.cach e, unit);
6406 _incrementalAnalysisCache = IncrementalAnalysisCache.cacheResult(task.ca che, unit);
6407 }
6408 } 6331 }
6409 return null; 6332 return null;
6410 } 6333 }
6411 6334
6412 /** 6335 /**
6413 * Record the results produced by performing a [ParseDartTask]. If the results were computed 6336 * Record the results produced by performing a [ParseDartTask]. If the results were computed
6414 * from data that is now out-of-date, then the results will not be recorded. 6337 * from data that is now out-of-date, then the results will not be recorded.
6415 * 6338 *
6416 * @param task the task that was performed 6339 * @param task the task that was performed
6417 * @return an entry containing the computed results 6340 * @return an entry containing the computed results
6418 * @throws AnalysisException if the results could not be recorded 6341 * @throws AnalysisException if the results could not be recorded
6419 */ 6342 */
6420 DartEntry recordParseDartTaskResults(ParseDartTask task) { 6343 DartEntry recordParseDartTaskResults(ParseDartTask task) {
6421 Source source = task.source; 6344 Source source = task.source;
6422 AnalysisException thrownException = task.exception; 6345 AnalysisException thrownException = task.exception;
6423 DartEntry dartEntry = null; 6346 DartEntry dartEntry = null;
6424 { 6347 SourceEntry sourceEntry = _cache.get(source);
6425 SourceEntry sourceEntry = _cache.get(source); 6348 if (sourceEntry == null) {
6426 if (sourceEntry == null) { 6349 throw new ObsoleteSourceAnalysisException(source);
6427 throw new ObsoleteSourceAnalysisException(source); 6350 } else if (sourceEntry is! DartEntry) {
6428 } else if (sourceEntry is! DartEntry) { 6351 // This shouldn't be possible because we should never have performed the t ask if the source
6429 // This shouldn't be possible because we should never have performed the task if the source 6352 // didn't represent a Dart file, but check to be safe.
6430 // didn't represent a Dart file, but check to be safe. 6353 throw new AnalysisException.con1("Internal error: attempting to parse non- Dart file as a Dart file: ${source.fullName}");
6431 throw new AnalysisException.con1("Internal error: attempting to parse no n-Dart file as a Dart file: ${source.fullName}"); 6354 }
6355 dartEntry = sourceEntry as DartEntry;
6356 int sourceTime = getModificationStamp(source);
6357 int resultTime = task.modificationTime;
6358 if (sourceTime == resultTime) {
6359 if (dartEntry.modificationTime != sourceTime) {
6360 // The source has changed without the context being notified. Simulate n otification.
6361 sourceChanged(source);
6362 dartEntry = getReadableDartEntry(source);
6363 if (dartEntry == null) {
6364 throw new AnalysisException.con1("A Dart file became a non-Dart file: ${source.fullName}");
6365 }
6432 } 6366 }
6433 dartEntry = sourceEntry as DartEntry; 6367 DartEntryImpl dartCopy = dartEntry.writableCopy;
6434 int sourceTime = getModificationStamp(source); 6368 if (thrownException == null) {
6435 int resultTime = task.modificationTime; 6369 if (task.hasPartOfDirective() && !task.hasLibraryDirective()) {
6436 if (sourceTime == resultTime) { 6370 dartCopy.setValue(DartEntry.SOURCE_KIND, SourceKind.PART);
6437 if (dartEntry.modificationTime != sourceTime) { 6371 dartCopy.removeContainingLibrary(source);
6438 // The source has changed without the context being notified. Simulate notification. 6372 _workManager.add(source, SourcePriority.NORMAL_PART);
6439 sourceChanged(source); 6373 } else {
6440 dartEntry = getReadableDartEntry(source); 6374 dartCopy.setValue(DartEntry.SOURCE_KIND, SourceKind.LIBRARY);
6441 if (dartEntry == null) { 6375 dartCopy.containingLibrary = source;
6442 throw new AnalysisException.con1("A Dart file became a non-Dart file : ${source.fullName}"); 6376 _workManager.add(source, SourcePriority.LIBRARY);
6443 }
6444 } 6377 }
6445 DartEntryImpl dartCopy = dartEntry.writableCopy; 6378 dartCopy.setValue(DartEntry.PARSED_UNIT, task.compilationUnit);
6446 if (thrownException == null) { 6379 dartCopy.setValue(DartEntry.PARSE_ERRORS, task.errors);
6447 if (task.hasPartOfDirective() && !task.hasLibraryDirective()) { 6380 _cache.storedAst(source);
6448 dartCopy.setValue(DartEntry.SOURCE_KIND, SourceKind.PART); 6381 ChangeNoticeImpl notice = getNotice(source);
6449 dartCopy.removeContainingLibrary(source); 6382 notice.setErrors(dartCopy.allErrors, dartCopy.getValue(SourceEntry.LINE_ INFO));
6450 _workManager.add(source, SourcePriority.NORMAL_PART); 6383 // Verify that the incrementally parsed and resolved unit in the increme ntal cache
6451 } else { 6384 // is structurally equivalent to the fully parsed unit
6452 dartCopy.setValue(DartEntry.SOURCE_KIND, SourceKind.LIBRARY); 6385 _incrementalAnalysisCache = IncrementalAnalysisCache.verifyStructure(_in crementalAnalysisCache, source, task.compilationUnit);
6453 dartCopy.containingLibrary = source;
6454 _workManager.add(source, SourcePriority.LIBRARY);
6455 }
6456 dartCopy.setValue(DartEntry.PARSED_UNIT, task.compilationUnit);
6457 dartCopy.setValue(DartEntry.PARSE_ERRORS, task.errors);
6458 _cache.storedAst(source);
6459 ChangeNoticeImpl notice = getNotice(source);
6460 notice.setErrors(dartCopy.allErrors, dartCopy.getValue(SourceEntry.LIN E_INFO));
6461 // Verify that the incrementally parsed and resolved unit in the incre mental cache
6462 // is structurally equivalent to the fully parsed unit
6463 _incrementalAnalysisCache = IncrementalAnalysisCache.verifyStructure(_ incrementalAnalysisCache, source, task.compilationUnit);
6464 } else {
6465 removeFromParts(source, dartEntry);
6466 dartCopy.recordParseError();
6467 _cache.removedAst(source);
6468 }
6469 dartCopy.exception = thrownException;
6470 _cache.put(source, dartCopy);
6471 dartEntry = dartCopy;
6472 } else { 6386 } else {
6473 logInformation2("Parse results discarded for ${debuggingString(source)}; sourceTime = ${sourceTime}, resultTime = ${resultTime}, cacheTime = ${dartEntry .modificationTime}", thrownException); 6387 removeFromParts(source, dartEntry);
6474 DartEntryImpl dartCopy = dartEntry.writableCopy; 6388 dartCopy.recordParseError();
6475 if (thrownException == null || resultTime >= 0) { 6389 _cache.removedAst(source);
6476 //
6477 // The analysis was performed on out-of-date sources. Mark the cache s o that the sources
6478 // will be re-analyzed using the up-to-date sources.
6479 //
6480 // dartCopy.recordParseNotInProcess();
6481 removeFromParts(source, dartEntry);
6482 dartCopy.invalidateAllInformation();
6483 dartCopy.modificationTime = sourceTime;
6484 _cache.removedAst(source);
6485 _workManager.add(source, SourcePriority.UNKNOWN);
6486 } else {
6487 //
6488 // We could not determine whether the sources were up-to-date or out-o f-date. Mark the
6489 // cache so that we won't attempt to re-analyze the sources until ther e's a good chance
6490 // that we'll be able to do so without error.
6491 //
6492 dartCopy.recordParseError();
6493 }
6494 dartCopy.exception = thrownException;
6495 _cache.put(source, dartCopy);
6496 dartEntry = dartCopy;
6497 } 6390 }
6391 dartCopy.exception = thrownException;
6392 _cache.put(source, dartCopy);
6393 dartEntry = dartCopy;
6394 } else {
6395 logInformation2("Parse results discarded for ${debuggingString(source)}; s ourceTime = ${sourceTime}, resultTime = ${resultTime}, cacheTime = ${dartEntry.m odificationTime}", thrownException);
6396 DartEntryImpl dartCopy = dartEntry.writableCopy;
6397 if (thrownException == null || resultTime >= 0) {
6398 //
6399 // The analysis was performed on out-of-date sources. Mark the cache so that the sources
6400 // will be re-analyzed using the up-to-date sources.
6401 //
6402 // dartCopy.recordParseNotInProcess();
6403 removeFromParts(source, dartEntry);
6404 dartCopy.invalidateAllInformation();
6405 dartCopy.modificationTime = sourceTime;
6406 _cache.removedAst(source);
6407 _workManager.add(source, SourcePriority.UNKNOWN);
6408 } else {
6409 //
6410 // We could not determine whether the sources were up-to-date or out-of- date. Mark the
6411 // cache so that we won't attempt to re-analyze the sources until there' s a good chance
6412 // that we'll be able to do so without error.
6413 //
6414 dartCopy.recordParseError();
6415 }
6416 dartCopy.exception = thrownException;
6417 _cache.put(source, dartCopy);
6418 dartEntry = dartCopy;
6498 } 6419 }
6499 if (thrownException != null) { 6420 if (thrownException != null) {
6500 throw thrownException; 6421 throw thrownException;
6501 } 6422 }
6502 return dartEntry; 6423 return dartEntry;
6503 } 6424 }
6504 6425
6505 /** 6426 /**
6506 * Record the results produced by performing a [ParseHtmlTask]. If the results were computed 6427 * Record the results produced by performing a [ParseHtmlTask]. If the results were computed
6507 * from data that is now out-of-date, then the results will not be recorded. 6428 * from data that is now out-of-date, then the results will not be recorded.
6508 * 6429 *
6509 * @param task the task that was performed 6430 * @param task the task that was performed
6510 * @return an entry containing the computed results 6431 * @return an entry containing the computed results
6511 * @throws AnalysisException if the results could not be recorded 6432 * @throws AnalysisException if the results could not be recorded
6512 */ 6433 */
6513 HtmlEntry recordParseHtmlTaskResults(ParseHtmlTask task) { 6434 HtmlEntry recordParseHtmlTaskResults(ParseHtmlTask task) {
6514 Source source = task.source; 6435 Source source = task.source;
6515 AnalysisException thrownException = task.exception; 6436 AnalysisException thrownException = task.exception;
6516 HtmlEntry htmlEntry = null; 6437 HtmlEntry htmlEntry = null;
6517 { 6438 SourceEntry sourceEntry = _cache.get(source);
6518 SourceEntry sourceEntry = _cache.get(source); 6439 if (sourceEntry == null) {
6519 if (sourceEntry == null) { 6440 throw new ObsoleteSourceAnalysisException(source);
6520 throw new ObsoleteSourceAnalysisException(source); 6441 } else if (sourceEntry is! HtmlEntry) {
6521 } else if (sourceEntry is! HtmlEntry) { 6442 // This shouldn't be possible because we should never have performed the t ask if the source
6522 // This shouldn't be possible because we should never have performed the task if the source 6443 // didn't represent an HTML file, but check to be safe.
6523 // didn't represent an HTML file, but check to be safe. 6444 throw new AnalysisException.con1("Internal error: attempting to parse non- HTML file as a HTML file: ${source.fullName}");
6524 throw new AnalysisException.con1("Internal error: attempting to parse no n-HTML file as a HTML file: ${source.fullName}"); 6445 }
6446 htmlEntry = sourceEntry as HtmlEntry;
6447 int sourceTime = getModificationStamp(source);
6448 int resultTime = task.modificationTime;
6449 if (sourceTime == resultTime) {
6450 if (htmlEntry.modificationTime != sourceTime) {
6451 // The source has changed without the context being notified. Simulate n otification.
6452 sourceChanged(source);
6453 htmlEntry = getReadableHtmlEntry(source);
6454 if (htmlEntry == null) {
6455 throw new AnalysisException.con1("An HTML file became a non-HTML file: ${source.fullName}");
6456 }
6525 } 6457 }
6526 htmlEntry = sourceEntry as HtmlEntry; 6458 HtmlEntryImpl htmlCopy = (sourceEntry as HtmlEntry).writableCopy;
6527 int sourceTime = getModificationStamp(source); 6459 if (thrownException == null) {
6528 int resultTime = task.modificationTime; 6460 LineInfo lineInfo = task.lineInfo;
6529 if (sourceTime == resultTime) { 6461 ht.HtmlUnit unit = task.htmlUnit;
6530 if (htmlEntry.modificationTime != sourceTime) { 6462 htmlCopy.setValue(SourceEntry.LINE_INFO, lineInfo);
6531 // The source has changed without the context being notified. Simulate notification. 6463 htmlCopy.setValue(HtmlEntry.PARSED_UNIT, unit);
6532 sourceChanged(source); 6464 htmlCopy.setValue(HtmlEntry.PARSE_ERRORS, task.errors);
6533 htmlEntry = getReadableHtmlEntry(source); 6465 htmlCopy.setValue(HtmlEntry.REFERENCED_LIBRARIES, task.referencedLibrari es);
6534 if (htmlEntry == null) { 6466 _cache.storedAst(source);
6535 throw new AnalysisException.con1("An HTML file became a non-HTML fil e: ${source.fullName}"); 6467 ChangeNoticeImpl notice = getNotice(source);
6536 } 6468 notice.setErrors(htmlCopy.allErrors, lineInfo);
6537 }
6538 HtmlEntryImpl htmlCopy = (sourceEntry as HtmlEntry).writableCopy;
6539 if (thrownException == null) {
6540 LineInfo lineInfo = task.lineInfo;
6541 ht.HtmlUnit unit = task.htmlUnit;
6542 htmlCopy.setValue(SourceEntry.LINE_INFO, lineInfo);
6543 htmlCopy.setValue(HtmlEntry.PARSED_UNIT, unit);
6544 htmlCopy.setValue(HtmlEntry.PARSE_ERRORS, task.errors);
6545 htmlCopy.setValue(HtmlEntry.REFERENCED_LIBRARIES, task.referencedLibra ries);
6546 _cache.storedAst(source);
6547 ChangeNoticeImpl notice = getNotice(source);
6548 notice.setErrors(htmlCopy.allErrors, lineInfo);
6549 } else {
6550 htmlCopy.recordParseError();
6551 _cache.removedAst(source);
6552 }
6553 htmlCopy.exception = thrownException;
6554 _cache.put(source, htmlCopy);
6555 htmlEntry = htmlCopy;
6556 } else { 6469 } else {
6557 logInformation2("Parse results discarded for ${debuggingString(source)}; sourceTime = ${sourceTime}, resultTime = ${resultTime}, cacheTime = ${htmlEntry .modificationTime}", thrownException); 6470 htmlCopy.recordParseError();
6558 HtmlEntryImpl htmlCopy = (sourceEntry as HtmlEntry).writableCopy; 6471 _cache.removedAst(source);
6559 if (thrownException == null || resultTime >= 0) {
6560 //
6561 // The analysis was performed on out-of-date sources. Mark the cache s o that the sources
6562 // will be re-analyzed using the up-to-date sources.
6563 //
6564 // if (htmlCopy.getState(SourceEntry.LINE_INFO) == CacheState .IN_PROCESS) {
6565 // htmlCopy.setState(SourceEntry.LINE_INFO, CacheState.INVA LID);
6566 // }
6567 // if (htmlCopy.getState(HtmlEntry.PARSED_UNIT) == CacheState .IN_PROCESS) {
6568 // htmlCopy.setState(HtmlEntry.PARSED_UNIT, CacheState.INVA LID);
6569 // }
6570 // if (htmlCopy.getState(HtmlEntry.REFERENCED_LIBRARIES) == C acheState.IN_PROCESS) {
6571 // htmlCopy.setState(HtmlEntry.REFERENCED_LIBRARIES, CacheS tate.INVALID);
6572 // }
6573 htmlCopy.invalidateAllInformation();
6574 htmlCopy.modificationTime = sourceTime;
6575 _cache.removedAst(source);
6576 } else {
6577 //
6578 // We could not determine whether the sources were up-to-date or out-o f-date. Mark the
6579 // cache so that we won't attempt to re-analyze the sources until ther e's a good chance
6580 // that we'll be able to do so without error.
6581 //
6582 htmlCopy.setState(SourceEntry.LINE_INFO, CacheState.ERROR);
6583 htmlCopy.setState(HtmlEntry.PARSED_UNIT, CacheState.ERROR);
6584 htmlCopy.setState(HtmlEntry.RESOLVED_UNIT, CacheState.ERROR);
6585 htmlCopy.setState(HtmlEntry.REFERENCED_LIBRARIES, CacheState.ERROR);
6586 }
6587 htmlCopy.exception = thrownException;
6588 _cache.put(source, htmlCopy);
6589 htmlEntry = htmlCopy;
6590 } 6472 }
6473 htmlCopy.exception = thrownException;
6474 _cache.put(source, htmlCopy);
6475 htmlEntry = htmlCopy;
6476 } else {
6477 logInformation2("Parse results discarded for ${debuggingString(source)}; s ourceTime = ${sourceTime}, resultTime = ${resultTime}, cacheTime = ${htmlEntry.m odificationTime}", thrownException);
6478 HtmlEntryImpl htmlCopy = (sourceEntry as HtmlEntry).writableCopy;
6479 if (thrownException == null || resultTime >= 0) {
6480 //
6481 // The analysis was performed on out-of-date sources. Mark the cache so that the sources
6482 // will be re-analyzed using the up-to-date sources.
6483 //
6484 // if (htmlCopy.getState(SourceEntry.LINE_INFO) == CacheState.I N_PROCESS) {
6485 // htmlCopy.setState(SourceEntry.LINE_INFO, CacheState.INVALI D);
6486 // }
6487 // if (htmlCopy.getState(HtmlEntry.PARSED_UNIT) == CacheState.I N_PROCESS) {
6488 // htmlCopy.setState(HtmlEntry.PARSED_UNIT, CacheState.INVALI D);
6489 // }
6490 // if (htmlCopy.getState(HtmlEntry.REFERENCED_LIBRARIES) == Cac heState.IN_PROCESS) {
6491 // htmlCopy.setState(HtmlEntry.REFERENCED_LIBRARIES, CacheSta te.INVALID);
6492 // }
6493 htmlCopy.invalidateAllInformation();
6494 htmlCopy.modificationTime = sourceTime;
6495 _cache.removedAst(source);
6496 } else {
6497 //
6498 // We could not determine whether the sources were up-to-date or out-of- date. Mark the
6499 // cache so that we won't attempt to re-analyze the sources until there' s a good chance
6500 // that we'll be able to do so without error.
6501 //
6502 htmlCopy.setState(SourceEntry.LINE_INFO, CacheState.ERROR);
6503 htmlCopy.setState(HtmlEntry.PARSED_UNIT, CacheState.ERROR);
6504 htmlCopy.setState(HtmlEntry.RESOLVED_UNIT, CacheState.ERROR);
6505 htmlCopy.setState(HtmlEntry.REFERENCED_LIBRARIES, CacheState.ERROR);
6506 }
6507 htmlCopy.exception = thrownException;
6508 _cache.put(source, htmlCopy);
6509 htmlEntry = htmlCopy;
6591 } 6510 }
6592 if (thrownException != null) { 6511 if (thrownException != null) {
6593 throw thrownException; 6512 throw thrownException;
6594 } 6513 }
6595 return htmlEntry; 6514 return htmlEntry;
6596 } 6515 }
6597 6516
6598 /** 6517 /**
6599 * Record the results produced by performing a [ResolveAngularComponentTemplat eTask]. If the 6518 * Record the results produced by performing a [ResolveAngularComponentTemplat eTask]. If the
6600 * results were computed from data that is now out-of-date, then the results w ill not be recorded. 6519 * results were computed from data that is now out-of-date, then the results w ill not be recorded.
6601 * 6520 *
6602 * @param task the task that was performed 6521 * @param task the task that was performed
6603 * @throws AnalysisException if the results could not be recorded 6522 * @throws AnalysisException if the results could not be recorded
6604 */ 6523 */
6605 HtmlEntry recordResolveAngularComponentTemplateTaskResults(ResolveAngularCompo nentTemplateTask task) { 6524 HtmlEntry recordResolveAngularComponentTemplateTaskResults(ResolveAngularCompo nentTemplateTask task) {
6606 Source source = task.source; 6525 Source source = task.source;
6607 AnalysisException thrownException = task.exception; 6526 AnalysisException thrownException = task.exception;
6608 HtmlEntry htmlEntry = null; 6527 HtmlEntry htmlEntry = null;
6609 { 6528 SourceEntry sourceEntry = _cache.get(source);
6610 SourceEntry sourceEntry = _cache.get(source); 6529 if (sourceEntry == null) {
6611 if (sourceEntry == null) { 6530 throw new ObsoleteSourceAnalysisException(source);
6612 throw new ObsoleteSourceAnalysisException(source); 6531 } else if (sourceEntry is! HtmlEntry) {
6613 } else if (sourceEntry is! HtmlEntry) { 6532 // This shouldn't be possible because we should never have performed the t ask if the source
6614 // This shouldn't be possible because we should never have performed the task if the source 6533 // didn't represent an HTML file, but check to be safe.
6615 // didn't represent an HTML file, but check to be safe. 6534 throw new AnalysisException.con1("Internal error: attempting to resolve no n-HTML file as an HTML file: ${source.fullName}");
6616 throw new AnalysisException.con1("Internal error: attempting to resolve non-HTML file as an HTML file: ${source.fullName}"); 6535 }
6536 htmlEntry = sourceEntry as HtmlEntry;
6537 int sourceTime = getModificationStamp(source);
6538 int resultTime = task.modificationTime;
6539 if (sourceTime == resultTime) {
6540 if (htmlEntry.modificationTime != sourceTime) {
6541 // The source has changed without the context being notified. Simulate n otification.
6542 sourceChanged(source);
6543 htmlEntry = getReadableHtmlEntry(source);
6544 if (htmlEntry == null) {
6545 throw new AnalysisException.con1("An HTML file became a non-HTML file: ${source.fullName}");
6546 }
6617 } 6547 }
6618 htmlEntry = sourceEntry as HtmlEntry; 6548 HtmlEntryImpl htmlCopy = htmlEntry.writableCopy;
6619 int sourceTime = getModificationStamp(source); 6549 if (thrownException == null) {
6620 int resultTime = task.modificationTime; 6550 htmlCopy.setValue(HtmlEntry.ANGULAR_ERRORS, task.resolutionErrors);
6621 if (sourceTime == resultTime) { 6551 // notify about errors
6622 if (htmlEntry.modificationTime != sourceTime) { 6552 ChangeNoticeImpl notice = getNotice(source);
6623 // The source has changed without the context being notified. Simulate notification. 6553 notice.htmlUnit = task.resolvedUnit;
6624 sourceChanged(source); 6554 notice.setErrors(htmlCopy.allErrors, htmlCopy.getValue(SourceEntry.LINE_ INFO));
6625 htmlEntry = getReadableHtmlEntry(source);
6626 if (htmlEntry == null) {
6627 throw new AnalysisException.con1("An HTML file became a non-HTML fil e: ${source.fullName}");
6628 }
6629 }
6630 HtmlEntryImpl htmlCopy = htmlEntry.writableCopy;
6631 if (thrownException == null) {
6632 htmlCopy.setValue(HtmlEntry.ANGULAR_ERRORS, task.resolutionErrors);
6633 // notify about errors
6634 ChangeNoticeImpl notice = getNotice(source);
6635 notice.htmlUnit = task.resolvedUnit;
6636 notice.setErrors(htmlCopy.allErrors, htmlCopy.getValue(SourceEntry.LIN E_INFO));
6637 } else {
6638 htmlCopy.recordResolutionError();
6639 }
6640 htmlCopy.exception = thrownException;
6641 _cache.put(source, htmlCopy);
6642 htmlEntry = htmlCopy;
6643 } else { 6555 } else {
6644 HtmlEntryImpl htmlCopy = htmlEntry.writableCopy; 6556 htmlCopy.recordResolutionError();
6645 if (thrownException == null || resultTime >= 0) {
6646 //
6647 // The analysis was performed on out-of-date sources. Mark the cache s o that the sources
6648 // will be re-analyzed using the up-to-date sources.
6649 //
6650 // if (htmlCopy.getState(HtmlEntry.ANGULAR_ERRORS) == CacheSt ate.IN_PROCESS) {
6651 // htmlCopy.setState(HtmlEntry.ANGULAR_ERRORS, CacheState.I NVALID);
6652 // }
6653 // if (htmlCopy.getState(HtmlEntry.ELEMENT) == CacheState.IN_ PROCESS) {
6654 // htmlCopy.setState(HtmlEntry.ELEMENT, CacheState.INVALID) ;
6655 // }
6656 // if (htmlCopy.getState(HtmlEntry.RESOLUTION_ERRORS) == Cach eState.IN_PROCESS) {
6657 // htmlCopy.setState(HtmlEntry.RESOLUTION_ERRORS, CacheStat e.INVALID);
6658 // }
6659 htmlCopy.invalidateAllInformation();
6660 htmlCopy.modificationTime = sourceTime;
6661 _cache.removedAst(source);
6662 } else {
6663 //
6664 // We could not determine whether the sources were up-to-date or out-o f-date. Mark the
6665 // cache so that we won't attempt to re-analyze the sources until ther e's a good chance
6666 // that we'll be able to do so without error.
6667 //
6668 htmlCopy.recordResolutionError();
6669 }
6670 htmlCopy.exception = thrownException;
6671 _cache.put(source, htmlCopy);
6672 htmlEntry = htmlCopy;
6673 } 6557 }
6558 htmlCopy.exception = thrownException;
6559 _cache.put(source, htmlCopy);
6560 htmlEntry = htmlCopy;
6561 } else {
6562 HtmlEntryImpl htmlCopy = htmlEntry.writableCopy;
6563 if (thrownException == null || resultTime >= 0) {
6564 //
6565 // The analysis was performed on out-of-date sources. Mark the cache so that the sources
6566 // will be re-analyzed using the up-to-date sources.
6567 //
6568 // if (htmlCopy.getState(HtmlEntry.ANGULAR_ERRORS) == CacheStat e.IN_PROCESS) {
6569 // htmlCopy.setState(HtmlEntry.ANGULAR_ERRORS, CacheState.INV ALID);
6570 // }
6571 // if (htmlCopy.getState(HtmlEntry.ELEMENT) == CacheState.IN_PR OCESS) {
6572 // htmlCopy.setState(HtmlEntry.ELEMENT, CacheState.INVALID);
6573 // }
6574 // if (htmlCopy.getState(HtmlEntry.RESOLUTION_ERRORS) == CacheS tate.IN_PROCESS) {
6575 // htmlCopy.setState(HtmlEntry.RESOLUTION_ERRORS, CacheState. INVALID);
6576 // }
6577 htmlCopy.invalidateAllInformation();
6578 htmlCopy.modificationTime = sourceTime;
6579 _cache.removedAst(source);
6580 } else {
6581 //
6582 // We could not determine whether the sources were up-to-date or out-of- date. Mark the
6583 // cache so that we won't attempt to re-analyze the sources until there' s a good chance
6584 // that we'll be able to do so without error.
6585 //
6586 htmlCopy.recordResolutionError();
6587 }
6588 htmlCopy.exception = thrownException;
6589 _cache.put(source, htmlCopy);
6590 htmlEntry = htmlCopy;
6674 } 6591 }
6675 if (thrownException != null) { 6592 if (thrownException != null) {
6676 throw thrownException; 6593 throw thrownException;
6677 } 6594 }
6678 return htmlEntry; 6595 return htmlEntry;
6679 } 6596 }
6680 6597
6681 /** 6598 /**
6682 * Record the results produced by performing a [ResolveAngularEntryHtmlTask]. If the results 6599 * Record the results produced by performing a [ResolveAngularEntryHtmlTask]. If the results
6683 * were computed from data that is now out-of-date, then the results will not be recorded. 6600 * were computed from data that is now out-of-date, then the results will not be recorded.
6684 * 6601 *
6685 * @param task the task that was performed 6602 * @param task the task that was performed
6686 * @throws AnalysisException if the results could not be recorded 6603 * @throws AnalysisException if the results could not be recorded
6687 */ 6604 */
6688 HtmlEntry recordResolveAngularEntryHtmlTaskResults(ResolveAngularEntryHtmlTask task) { 6605 HtmlEntry recordResolveAngularEntryHtmlTaskResults(ResolveAngularEntryHtmlTask task) {
6689 Source source = task.source; 6606 Source source = task.source;
6690 AnalysisException thrownException = task.exception; 6607 AnalysisException thrownException = task.exception;
6691 HtmlEntry htmlEntry = null; 6608 HtmlEntry htmlEntry = null;
6692 { 6609 SourceEntry sourceEntry = _cache.get(source);
6693 SourceEntry sourceEntry = _cache.get(source); 6610 if (sourceEntry == null) {
6694 if (sourceEntry == null) { 6611 throw new ObsoleteSourceAnalysisException(source);
6695 throw new ObsoleteSourceAnalysisException(source); 6612 } else if (sourceEntry is! HtmlEntry) {
6696 } else if (sourceEntry is! HtmlEntry) { 6613 // This shouldn't be possible because we should never have performed the t ask if the source
6697 // This shouldn't be possible because we should never have performed the task if the source 6614 // didn't represent an HTML file, but check to be safe.
6698 // didn't represent an HTML file, but check to be safe. 6615 throw new AnalysisException.con1("Internal error: attempting to resolve no n-HTML file as an HTML file: ${source.fullName}");
6699 throw new AnalysisException.con1("Internal error: attempting to resolve non-HTML file as an HTML file: ${source.fullName}"); 6616 }
6617 htmlEntry = sourceEntry as HtmlEntry;
6618 int sourceTime = getModificationStamp(source);
6619 int resultTime = task.modificationTime;
6620 if (sourceTime == resultTime) {
6621 if (htmlEntry.modificationTime != sourceTime) {
6622 // The source has changed without the context being notified. Simulate n otification.
6623 sourceChanged(source);
6624 htmlEntry = getReadableHtmlEntry(source);
6625 if (htmlEntry == null) {
6626 throw new AnalysisException.con1("An HTML file became a non-HTML file: ${source.fullName}");
6627 }
6700 } 6628 }
6701 htmlEntry = sourceEntry as HtmlEntry; 6629 HtmlEntryImpl htmlCopy = htmlEntry.writableCopy;
6702 int sourceTime = getModificationStamp(source); 6630 if (thrownException == null) {
6703 int resultTime = task.modificationTime; 6631 htmlCopy.setValue(HtmlEntry.RESOLVED_UNIT, task.resolvedUnit);
6704 if (sourceTime == resultTime) { 6632 recordAngularEntryPoint(htmlCopy, task);
6705 if (htmlEntry.modificationTime != sourceTime) { 6633 _cache.storedAst(source);
6706 // The source has changed without the context being notified. Simulate notification. 6634 ChangeNoticeImpl notice = getNotice(source);
6707 sourceChanged(source); 6635 notice.htmlUnit = task.resolvedUnit;
6708 htmlEntry = getReadableHtmlEntry(source); 6636 notice.setErrors(htmlCopy.allErrors, htmlCopy.getValue(SourceEntry.LINE_ INFO));
6709 if (htmlEntry == null) {
6710 throw new AnalysisException.con1("An HTML file became a non-HTML fil e: ${source.fullName}");
6711 }
6712 }
6713 HtmlEntryImpl htmlCopy = htmlEntry.writableCopy;
6714 if (thrownException == null) {
6715 htmlCopy.setValue(HtmlEntry.RESOLVED_UNIT, task.resolvedUnit);
6716 recordAngularEntryPoint(htmlCopy, task);
6717 _cache.storedAst(source);
6718 ChangeNoticeImpl notice = getNotice(source);
6719 notice.htmlUnit = task.resolvedUnit;
6720 notice.setErrors(htmlCopy.allErrors, htmlCopy.getValue(SourceEntry.LIN E_INFO));
6721 } else {
6722 htmlCopy.recordResolutionError();
6723 }
6724 htmlCopy.exception = thrownException;
6725 _cache.put(source, htmlCopy);
6726 htmlEntry = htmlCopy;
6727 } else { 6637 } else {
6728 HtmlEntryImpl htmlCopy = htmlEntry.writableCopy; 6638 htmlCopy.recordResolutionError();
6729 if (thrownException == null || resultTime >= 0) {
6730 //
6731 // The analysis was performed on out-of-date sources. Mark the cache s o that the sources
6732 // will be re-analyzed using the up-to-date sources.
6733 //
6734 // if (htmlCopy.getState(HtmlEntry.ANGULAR_ERRORS) == CacheSt ate.IN_PROCESS) {
6735 // htmlCopy.setState(HtmlEntry.ANGULAR_ERRORS, CacheState.I NVALID);
6736 // }
6737 // if (htmlCopy.getState(HtmlEntry.ELEMENT) == CacheState.IN_ PROCESS) {
6738 // htmlCopy.setState(HtmlEntry.ELEMENT, CacheState.INVALID) ;
6739 // }
6740 // if (htmlCopy.getState(HtmlEntry.RESOLUTION_ERRORS) == Cach eState.IN_PROCESS) {
6741 // htmlCopy.setState(HtmlEntry.RESOLUTION_ERRORS, CacheStat e.INVALID);
6742 // }
6743 htmlCopy.invalidateAllInformation();
6744 htmlCopy.modificationTime = sourceTime;
6745 _cache.removedAst(source);
6746 } else {
6747 //
6748 // We could not determine whether the sources were up-to-date or out-o f-date. Mark the
6749 // cache so that we won't attempt to re-analyze the sources until ther e's a good chance
6750 // that we'll be able to do so without error.
6751 //
6752 htmlCopy.recordResolutionError();
6753 }
6754 htmlCopy.exception = thrownException;
6755 _cache.put(source, htmlCopy);
6756 htmlEntry = htmlCopy;
6757 } 6639 }
6640 htmlCopy.exception = thrownException;
6641 _cache.put(source, htmlCopy);
6642 htmlEntry = htmlCopy;
6643 } else {
6644 HtmlEntryImpl htmlCopy = htmlEntry.writableCopy;
6645 if (thrownException == null || resultTime >= 0) {
6646 //
6647 // The analysis was performed on out-of-date sources. Mark the cache so that the sources
6648 // will be re-analyzed using the up-to-date sources.
6649 //
6650 // if (htmlCopy.getState(HtmlEntry.ANGULAR_ERRORS) == CacheStat e.IN_PROCESS) {
6651 // htmlCopy.setState(HtmlEntry.ANGULAR_ERRORS, CacheState.INV ALID);
6652 // }
6653 // if (htmlCopy.getState(HtmlEntry.ELEMENT) == CacheState.IN_PR OCESS) {
6654 // htmlCopy.setState(HtmlEntry.ELEMENT, CacheState.INVALID);
6655 // }
6656 // if (htmlCopy.getState(HtmlEntry.RESOLUTION_ERRORS) == CacheS tate.IN_PROCESS) {
6657 // htmlCopy.setState(HtmlEntry.RESOLUTION_ERRORS, CacheState. INVALID);
6658 // }
6659 htmlCopy.invalidateAllInformation();
6660 htmlCopy.modificationTime = sourceTime;
6661 _cache.removedAst(source);
6662 } else {
6663 //
6664 // We could not determine whether the sources were up-to-date or out-of- date. Mark the
6665 // cache so that we won't attempt to re-analyze the sources until there' s a good chance
6666 // that we'll be able to do so without error.
6667 //
6668 htmlCopy.recordResolutionError();
6669 }
6670 htmlCopy.exception = thrownException;
6671 _cache.put(source, htmlCopy);
6672 htmlEntry = htmlCopy;
6758 } 6673 }
6759 if (thrownException != null) { 6674 if (thrownException != null) {
6760 throw thrownException; 6675 throw thrownException;
6761 } 6676 }
6762 return htmlEntry; 6677 return htmlEntry;
6763 } 6678 }
6764 6679
6765 /** 6680 /**
6766 * Record the results produced by performing a [ResolveDartDependenciesTask]. If the results 6681 * Record the results produced by performing a [ResolveDartDependenciesTask]. If the results
6767 * were computed from data that is now out-of-date, then the results will not be recorded. 6682 * were computed from data that is now out-of-date, then the results will not be recorded.
6768 * 6683 *
6769 * @param task the task that was performed 6684 * @param task the task that was performed
6770 * @return an entry containing the computed results 6685 * @return an entry containing the computed results
6771 * @throws AnalysisException if the results could not be recorded 6686 * @throws AnalysisException if the results could not be recorded
6772 */ 6687 */
6773 DartEntry recordResolveDartDependenciesTaskResults(ResolveDartDependenciesTask task) { 6688 DartEntry recordResolveDartDependenciesTaskResults(ResolveDartDependenciesTask task) {
6774 Source source = task.source; 6689 Source source = task.source;
6775 AnalysisException thrownException = task.exception; 6690 AnalysisException thrownException = task.exception;
6776 DartEntry dartEntry = null; 6691 DartEntry dartEntry = null;
6777 { 6692 SourceEntry sourceEntry = _cache.get(source);
6778 SourceEntry sourceEntry = _cache.get(source); 6693 if (sourceEntry == null) {
6779 if (sourceEntry == null) { 6694 throw new ObsoleteSourceAnalysisException(source);
6780 throw new ObsoleteSourceAnalysisException(source); 6695 } else if (sourceEntry is! DartEntry) {
6781 } else if (sourceEntry is! DartEntry) { 6696 // This shouldn't be possible because we should never have performed the t ask if the source
6782 // This shouldn't be possible because we should never have performed the task if the source 6697 // didn't represent a Dart file, but check to be safe.
6783 // didn't represent a Dart file, but check to be safe. 6698 throw new AnalysisException.con1("Internal error: attempting to resolve Da rt dependencies in a non-Dart file: ${source.fullName}");
6784 throw new AnalysisException.con1("Internal error: attempting to resolve Dart dependencies in a non-Dart file: ${source.fullName}"); 6699 }
6700 dartEntry = sourceEntry as DartEntry;
6701 int sourceTime = getModificationStamp(source);
6702 int resultTime = task.modificationTime;
6703 if (sourceTime == resultTime) {
6704 if (dartEntry.modificationTime != sourceTime) {
6705 // The source has changed without the context being notified. Simulate n otification.
6706 sourceChanged(source);
6707 dartEntry = getReadableDartEntry(source);
6708 if (dartEntry == null) {
6709 throw new AnalysisException.con1("A Dart file became a non-Dart file: ${source.fullName}");
6710 }
6785 } 6711 }
6786 dartEntry = sourceEntry as DartEntry; 6712 removeFromParts(source, dartEntry);
6787 int sourceTime = getModificationStamp(source); 6713 DartEntryImpl dartCopy = dartEntry.writableCopy;
6788 int resultTime = task.modificationTime; 6714 if (thrownException == null) {
6789 if (sourceTime == resultTime) { 6715 List<Source> newParts = task.includedSources;
6790 if (dartEntry.modificationTime != sourceTime) { 6716 for (int i = 0; i < newParts.length; i++) {
6791 // The source has changed without the context being notified. Simulate notification. 6717 Source partSource = newParts[i];
6792 sourceChanged(source); 6718 DartEntry partEntry = getReadableDartEntry(partSource);
6793 dartEntry = getReadableDartEntry(source); 6719 if (partEntry != null && partEntry != dartEntry) {
6794 if (dartEntry == null) { 6720 DartEntryImpl partCopy = partEntry.writableCopy;
6795 throw new AnalysisException.con1("A Dart file became a non-Dart file : ${source.fullName}"); 6721 partCopy.addContainingLibrary(source);
6722 _cache.put(partSource, partCopy);
6796 } 6723 }
6797 } 6724 }
6725 dartCopy.setValue(DartEntry.EXPORTED_LIBRARIES, task.exportedSources);
6726 dartCopy.setValue(DartEntry.IMPORTED_LIBRARIES, task.importedSources);
6727 dartCopy.setValue(DartEntry.INCLUDED_PARTS, newParts);
6728 } else {
6729 dartCopy.recordDependencyError();
6730 }
6731 dartCopy.exception = thrownException;
6732 _cache.put(source, dartCopy);
6733 dartEntry = dartCopy;
6734 } else {
6735 logInformation2("Dependency resolution results discarded for ${debuggingSt ring(source)}; sourceTime = ${sourceTime}, resultTime = ${resultTime}, cacheTime = ${dartEntry.modificationTime}", thrownException);
6736 DartEntryImpl dartCopy = dartEntry.writableCopy;
6737 if (thrownException == null || resultTime >= 0) {
6738 //
6739 // The analysis was performed on out-of-date sources. Mark the cache so that the sources
6740 // will be re-analyzed using the up-to-date sources.
6741 //
6742 // dartCopy.recordDependencyNotInProcess();
6798 removeFromParts(source, dartEntry); 6743 removeFromParts(source, dartEntry);
6799 DartEntryImpl dartCopy = dartEntry.writableCopy; 6744 dartCopy.invalidateAllInformation();
6800 if (thrownException == null) { 6745 dartCopy.modificationTime = sourceTime;
6801 List<Source> newParts = task.includedSources; 6746 _cache.removedAst(source);
6802 for (int i = 0; i < newParts.length; i++) { 6747 _workManager.add(source, SourcePriority.UNKNOWN);
6803 Source partSource = newParts[i];
6804 DartEntry partEntry = getReadableDartEntry(partSource);
6805 if (partEntry != null && partEntry != dartEntry) {
6806 DartEntryImpl partCopy = partEntry.writableCopy;
6807 partCopy.addContainingLibrary(source);
6808 _cache.put(partSource, partCopy);
6809 }
6810 }
6811 dartCopy.setValue(DartEntry.EXPORTED_LIBRARIES, task.exportedSources);
6812 dartCopy.setValue(DartEntry.IMPORTED_LIBRARIES, task.importedSources);
6813 dartCopy.setValue(DartEntry.INCLUDED_PARTS, newParts);
6814 } else {
6815 dartCopy.recordDependencyError();
6816 }
6817 dartCopy.exception = thrownException;
6818 _cache.put(source, dartCopy);
6819 dartEntry = dartCopy;
6820 } else { 6748 } else {
6821 logInformation2("Dependency resolution results discarded for ${debugging String(source)}; sourceTime = ${sourceTime}, resultTime = ${resultTime}, cacheTi me = ${dartEntry.modificationTime}", thrownException); 6749 //
6822 DartEntryImpl dartCopy = dartEntry.writableCopy; 6750 // We could not determine whether the sources were up-to-date or out-of- date. Mark the
6823 if (thrownException == null || resultTime >= 0) { 6751 // cache so that we won't attempt to re-analyze the sources until there' s a good chance
6824 // 6752 // that we'll be able to do so without error.
6825 // The analysis was performed on out-of-date sources. Mark the cache s o that the sources 6753 //
6826 // will be re-analyzed using the up-to-date sources. 6754 dartCopy.setState(DartEntry.EXPORTED_LIBRARIES, CacheState.ERROR);
6827 // 6755 dartCopy.setState(DartEntry.IMPORTED_LIBRARIES, CacheState.ERROR);
6828 // dartCopy.recordDependencyNotInProcess(); 6756 dartCopy.setState(DartEntry.INCLUDED_PARTS, CacheState.ERROR);
6829 removeFromParts(source, dartEntry);
6830 dartCopy.invalidateAllInformation();
6831 dartCopy.modificationTime = sourceTime;
6832 _cache.removedAst(source);
6833 _workManager.add(source, SourcePriority.UNKNOWN);
6834 } else {
6835 //
6836 // We could not determine whether the sources were up-to-date or out-o f-date. Mark the
6837 // cache so that we won't attempt to re-analyze the sources until ther e's a good chance
6838 // that we'll be able to do so without error.
6839 //
6840 dartCopy.setState(DartEntry.EXPORTED_LIBRARIES, CacheState.ERROR);
6841 dartCopy.setState(DartEntry.IMPORTED_LIBRARIES, CacheState.ERROR);
6842 dartCopy.setState(DartEntry.INCLUDED_PARTS, CacheState.ERROR);
6843 }
6844 dartCopy.exception = thrownException;
6845 _cache.put(source, dartCopy);
6846 dartEntry = dartCopy;
6847 } 6757 }
6758 dartCopy.exception = thrownException;
6759 _cache.put(source, dartCopy);
6760 dartEntry = dartCopy;
6848 } 6761 }
6849 if (thrownException != null) { 6762 if (thrownException != null) {
6850 throw thrownException; 6763 throw thrownException;
6851 } 6764 }
6852 return dartEntry; 6765 return dartEntry;
6853 } 6766 }
6854 6767
6855 /** 6768 /**
6856 * Record the results produced by performing a [ResolveDartUnitTask]. If the r esults were 6769 * Record the results produced by performing a [ResolveDartUnitTask]. If the r esults were
6857 * computed from data that is now out-of-date, then the results will not be re corded. 6770 * computed from data that is now out-of-date, then the results will not be re corded.
6858 * 6771 *
6859 * @param task the task that was performed 6772 * @param task the task that was performed
6860 * @return an entry containing the computed results 6773 * @return an entry containing the computed results
6861 * @throws AnalysisException if the results could not be recorded 6774 * @throws AnalysisException if the results could not be recorded
6862 */ 6775 */
6863 DartEntry recordResolveDartUnitTaskResults(ResolveDartUnitTask task) { 6776 DartEntry recordResolveDartUnitTaskResults(ResolveDartUnitTask task) {
6864 Source unitSource = task.source; 6777 Source unitSource = task.source;
6865 Source librarySource = task.librarySource; 6778 Source librarySource = task.librarySource;
6866 AnalysisException thrownException = task.exception; 6779 AnalysisException thrownException = task.exception;
6867 DartEntry dartEntry = null; 6780 DartEntry dartEntry = null;
6868 { 6781 SourceEntry sourceEntry = _cache.get(unitSource);
6869 SourceEntry sourceEntry = _cache.get(unitSource); 6782 if (sourceEntry == null) {
6870 if (sourceEntry == null) { 6783 throw new ObsoleteSourceAnalysisException(unitSource);
6871 throw new ObsoleteSourceAnalysisException(unitSource); 6784 } else if (sourceEntry is! DartEntry) {
6872 } else if (sourceEntry is! DartEntry) { 6785 // This shouldn't be possible because we should never have performed the t ask if the source
6873 // This shouldn't be possible because we should never have performed the task if the source 6786 // didn't represent a Dart file, but check to be safe.
6874 // didn't represent a Dart file, but check to be safe. 6787 throw new AnalysisException.con1("Internal error: attempting to resolve no n-Dart file as a Dart file: ${unitSource.fullName}");
6875 throw new AnalysisException.con1("Internal error: attempting to resolve non-Dart file as a Dart file: ${unitSource.fullName}"); 6788 }
6789 dartEntry = sourceEntry as DartEntry;
6790 int sourceTime = getModificationStamp(unitSource);
6791 int resultTime = task.modificationTime;
6792 if (sourceTime == resultTime) {
6793 if (dartEntry.modificationTime != sourceTime) {
6794 // The source has changed without the context being notified. Simulate n otification.
6795 sourceChanged(unitSource);
6796 dartEntry = getReadableDartEntry(unitSource);
6797 if (dartEntry == null) {
6798 throw new AnalysisException.con1("A Dart file became a non-Dart file: ${unitSource.fullName}");
6799 }
6876 } 6800 }
6877 dartEntry = sourceEntry as DartEntry; 6801 DartEntryImpl dartCopy = dartEntry.writableCopy;
6878 int sourceTime = getModificationStamp(unitSource); 6802 if (thrownException == null) {
6879 int resultTime = task.modificationTime; 6803 dartCopy.setValue2(DartEntry.RESOLVED_UNIT, librarySource, task.resolved Unit);
6880 if (sourceTime == resultTime) { 6804 _cache.storedAst(unitSource);
6881 if (dartEntry.modificationTime != sourceTime) {
6882 // The source has changed without the context being notified. Simulate notification.
6883 sourceChanged(unitSource);
6884 dartEntry = getReadableDartEntry(unitSource);
6885 if (dartEntry == null) {
6886 throw new AnalysisException.con1("A Dart file became a non-Dart file : ${unitSource.fullName}");
6887 }
6888 }
6889 DartEntryImpl dartCopy = dartEntry.writableCopy;
6890 if (thrownException == null) {
6891 dartCopy.setValue2(DartEntry.RESOLVED_UNIT, librarySource, task.resolv edUnit);
6892 _cache.storedAst(unitSource);
6893 } else {
6894 dartCopy.setState2(DartEntry.RESOLVED_UNIT, librarySource, CacheState. ERROR);
6895 _cache.removedAst(unitSource);
6896 }
6897 dartCopy.exception = thrownException;
6898 _cache.put(unitSource, dartCopy);
6899 dartEntry = dartCopy;
6900 } else { 6805 } else {
6901 logInformation2("Resolution results discarded for ${debuggingString(unit Source)}; sourceTime = ${sourceTime}, resultTime = ${resultTime}, cacheTime = ${ dartEntry.modificationTime}", thrownException); 6806 dartCopy.setState2(DartEntry.RESOLVED_UNIT, librarySource, CacheState.ER ROR);
6902 DartEntryImpl dartCopy = dartEntry.writableCopy; 6807 _cache.removedAst(unitSource);
6903 if (thrownException == null || resultTime >= 0) {
6904 //
6905 // The analysis was performed on out-of-date sources. Mark the cache s o that the sources
6906 // will be re-analyzed using the up-to-date sources.
6907 //
6908 // if (dartCopy.getState(DartEntry.RESOLVED_UNIT) == CacheSta te.IN_PROCESS) {
6909 // dartCopy.setState(DartEntry.RESOLVED_UNIT, librarySource , CacheState.INVALID);
6910 // }
6911 removeFromParts(unitSource, dartEntry);
6912 dartCopy.invalidateAllInformation();
6913 dartCopy.modificationTime = sourceTime;
6914 _cache.removedAst(unitSource);
6915 _workManager.add(unitSource, SourcePriority.UNKNOWN);
6916 } else {
6917 //
6918 // We could not determine whether the sources were up-to-date or out-o f-date. Mark the
6919 // cache so that we won't attempt to re-analyze the sources until ther e's a good chance
6920 // that we'll be able to do so without error.
6921 //
6922 dartCopy.setState2(DartEntry.RESOLVED_UNIT, librarySource, CacheState. ERROR);
6923 }
6924 dartCopy.exception = thrownException;
6925 _cache.put(unitSource, dartCopy);
6926 dartEntry = dartCopy;
6927 } 6808 }
6809 dartCopy.exception = thrownException;
6810 _cache.put(unitSource, dartCopy);
6811 dartEntry = dartCopy;
6812 } else {
6813 logInformation2("Resolution results discarded for ${debuggingString(unitSo urce)}; sourceTime = ${sourceTime}, resultTime = ${resultTime}, cacheTime = ${da rtEntry.modificationTime}", thrownException);
6814 DartEntryImpl dartCopy = dartEntry.writableCopy;
6815 if (thrownException == null || resultTime >= 0) {
6816 //
6817 // The analysis was performed on out-of-date sources. Mark the cache so that the sources
6818 // will be re-analyzed using the up-to-date sources.
6819 //
6820 // if (dartCopy.getState(DartEntry.RESOLVED_UNIT) == CacheState .IN_PROCESS) {
6821 // dartCopy.setState(DartEntry.RESOLVED_UNIT, librarySource, CacheState.INVALID);
6822 // }
6823 removeFromParts(unitSource, dartEntry);
6824 dartCopy.invalidateAllInformation();
6825 dartCopy.modificationTime = sourceTime;
6826 _cache.removedAst(unitSource);
6827 _workManager.add(unitSource, SourcePriority.UNKNOWN);
6828 } else {
6829 //
6830 // We could not determine whether the sources were up-to-date or out-of- date. Mark the
6831 // cache so that we won't attempt to re-analyze the sources until there' s a good chance
6832 // that we'll be able to do so without error.
6833 //
6834 dartCopy.setState2(DartEntry.RESOLVED_UNIT, librarySource, CacheState.ER ROR);
6835 }
6836 dartCopy.exception = thrownException;
6837 _cache.put(unitSource, dartCopy);
6838 dartEntry = dartCopy;
6928 } 6839 }
6929 if (thrownException != null) { 6840 if (thrownException != null) {
6930 throw thrownException; 6841 throw thrownException;
6931 } 6842 }
6932 return dartEntry; 6843 return dartEntry;
6933 } 6844 }
6934 6845
6935 /** 6846 /**
6936 * Record the results produced by performing a [ResolveHtmlTask]. If the resul ts were 6847 * Record the results produced by performing a [ResolveHtmlTask]. If the resul ts were
6937 * computed from data that is now out-of-date, then the results will not be re corded. 6848 * computed from data that is now out-of-date, then the results will not be re corded.
6938 * 6849 *
6939 * @param task the task that was performed 6850 * @param task the task that was performed
6940 * @return an entry containing the computed results 6851 * @return an entry containing the computed results
6941 * @throws AnalysisException if the results could not be recorded 6852 * @throws AnalysisException if the results could not be recorded
6942 */ 6853 */
6943 HtmlEntry recordResolveHtmlTaskResults(ResolveHtmlTask task) { 6854 HtmlEntry recordResolveHtmlTaskResults(ResolveHtmlTask task) {
6944 Source source = task.source; 6855 Source source = task.source;
6945 AnalysisException thrownException = task.exception; 6856 AnalysisException thrownException = task.exception;
6946 HtmlEntry htmlEntry = null; 6857 HtmlEntry htmlEntry = null;
6947 { 6858 SourceEntry sourceEntry = _cache.get(source);
6948 SourceEntry sourceEntry = _cache.get(source); 6859 if (sourceEntry == null) {
6949 if (sourceEntry == null) { 6860 throw new ObsoleteSourceAnalysisException(source);
6950 throw new ObsoleteSourceAnalysisException(source); 6861 } else if (sourceEntry is! HtmlEntry) {
6951 } else if (sourceEntry is! HtmlEntry) { 6862 // This shouldn't be possible because we should never have performed the t ask if the source
6952 // This shouldn't be possible because we should never have performed the task if the source 6863 // didn't represent an HTML file, but check to be safe.
6953 // didn't represent an HTML file, but check to be safe. 6864 throw new AnalysisException.con1("Internal error: attempting to resolve no n-HTML file as an HTML file: ${source.fullName}");
6954 throw new AnalysisException.con1("Internal error: attempting to resolve non-HTML file as an HTML file: ${source.fullName}"); 6865 }
6866 htmlEntry = sourceEntry as HtmlEntry;
6867 int sourceTime = getModificationStamp(source);
6868 int resultTime = task.modificationTime;
6869 if (sourceTime == resultTime) {
6870 if (htmlEntry.modificationTime != sourceTime) {
6871 // The source has changed without the context being notified. Simulate n otification.
6872 sourceChanged(source);
6873 htmlEntry = getReadableHtmlEntry(source);
6874 if (htmlEntry == null) {
6875 throw new AnalysisException.con1("An HTML file became a non-HTML file: ${source.fullName}");
6876 }
6955 } 6877 }
6956 htmlEntry = sourceEntry as HtmlEntry; 6878 HtmlEntryImpl htmlCopy = htmlEntry.writableCopy;
6957 int sourceTime = getModificationStamp(source); 6879 if (thrownException == null) {
6958 int resultTime = task.modificationTime; 6880 htmlCopy.setState(HtmlEntry.PARSED_UNIT, CacheState.FLUSHED);
6959 if (sourceTime == resultTime) { 6881 htmlCopy.setValue(HtmlEntry.RESOLVED_UNIT, task.resolvedUnit);
6960 if (htmlEntry.modificationTime != sourceTime) { 6882 htmlCopy.setValue(HtmlEntry.ELEMENT, task.element);
6961 // The source has changed without the context being notified. Simulate notification. 6883 htmlCopy.setValue(HtmlEntry.RESOLUTION_ERRORS, task.resolutionErrors);
6962 sourceChanged(source); 6884 _cache.storedAst(source);
6963 htmlEntry = getReadableHtmlEntry(source); 6885 ChangeNoticeImpl notice = getNotice(source);
6964 if (htmlEntry == null) { 6886 notice.htmlUnit = task.resolvedUnit;
6965 throw new AnalysisException.con1("An HTML file became a non-HTML fil e: ${source.fullName}"); 6887 notice.setErrors(htmlCopy.allErrors, htmlCopy.getValue(SourceEntry.LINE_ INFO));
6966 }
6967 }
6968 HtmlEntryImpl htmlCopy = htmlEntry.writableCopy;
6969 if (thrownException == null) {
6970 htmlCopy.setState(HtmlEntry.PARSED_UNIT, CacheState.FLUSHED);
6971 htmlCopy.setValue(HtmlEntry.RESOLVED_UNIT, task.resolvedUnit);
6972 htmlCopy.setValue(HtmlEntry.ELEMENT, task.element);
6973 htmlCopy.setValue(HtmlEntry.RESOLUTION_ERRORS, task.resolutionErrors);
6974 _cache.storedAst(source);
6975 ChangeNoticeImpl notice = getNotice(source);
6976 notice.htmlUnit = task.resolvedUnit;
6977 notice.setErrors(htmlCopy.allErrors, htmlCopy.getValue(SourceEntry.LIN E_INFO));
6978 } else {
6979 htmlCopy.recordResolutionError();
6980 _cache.removedAst(source);
6981 }
6982 htmlCopy.exception = thrownException;
6983 _cache.put(source, htmlCopy);
6984 htmlEntry = htmlCopy;
6985 } else { 6888 } else {
6986 logInformation2("Resolution results discarded for ${debuggingString(sour ce)}; sourceTime = ${sourceTime}, resultTime = ${resultTime}, cacheTime = ${html Entry.modificationTime}", thrownException); 6889 htmlCopy.recordResolutionError();
6987 HtmlEntryImpl htmlCopy = htmlEntry.writableCopy; 6890 _cache.removedAst(source);
6988 if (thrownException == null || resultTime >= 0) {
6989 //
6990 // The analysis was performed on out-of-date sources. Mark the cache s o that the sources
6991 // will be re-analyzed using the up-to-date sources.
6992 //
6993 // if (htmlCopy.getState(HtmlEntry.ELEMENT) == CacheState.IN_ PROCESS) {
6994 // htmlCopy.setState(HtmlEntry.ELEMENT, CacheState.INVALID) ;
6995 // }
6996 // if (htmlCopy.getState(HtmlEntry.RESOLUTION_ERRORS) == Cach eState.IN_PROCESS) {
6997 // htmlCopy.setState(HtmlEntry.RESOLUTION_ERRORS, CacheStat e.INVALID);
6998 // }
6999 htmlCopy.invalidateAllInformation();
7000 htmlCopy.modificationTime = sourceTime;
7001 _cache.removedAst(source);
7002 } else {
7003 //
7004 // We could not determine whether the sources were up-to-date or out-o f-date. Mark the
7005 // cache so that we won't attempt to re-analyze the sources until ther e's a good chance
7006 // that we'll be able to do so without error.
7007 //
7008 htmlCopy.recordResolutionError();
7009 }
7010 htmlCopy.exception = thrownException;
7011 _cache.put(source, htmlCopy);
7012 htmlEntry = htmlCopy;
7013 } 6891 }
6892 htmlCopy.exception = thrownException;
6893 _cache.put(source, htmlCopy);
6894 htmlEntry = htmlCopy;
6895 } else {
6896 logInformation2("Resolution results discarded for ${debuggingString(source )}; sourceTime = ${sourceTime}, resultTime = ${resultTime}, cacheTime = ${htmlEn try.modificationTime}", thrownException);
6897 HtmlEntryImpl htmlCopy = htmlEntry.writableCopy;
6898 if (thrownException == null || resultTime >= 0) {
6899 //
6900 // The analysis was performed on out-of-date sources. Mark the cache so that the sources
6901 // will be re-analyzed using the up-to-date sources.
6902 //
6903 // if (htmlCopy.getState(HtmlEntry.ELEMENT) == CacheState.IN_PR OCESS) {
6904 // htmlCopy.setState(HtmlEntry.ELEMENT, CacheState.INVALID);
6905 // }
6906 // if (htmlCopy.getState(HtmlEntry.RESOLUTION_ERRORS) == CacheS tate.IN_PROCESS) {
6907 // htmlCopy.setState(HtmlEntry.RESOLUTION_ERRORS, CacheState. INVALID);
6908 // }
6909 htmlCopy.invalidateAllInformation();
6910 htmlCopy.modificationTime = sourceTime;
6911 _cache.removedAst(source);
6912 } else {
6913 //
6914 // We could not determine whether the sources were up-to-date or out-of- date. Mark the
6915 // cache so that we won't attempt to re-analyze the sources until there' s a good chance
6916 // that we'll be able to do so without error.
6917 //
6918 htmlCopy.recordResolutionError();
6919 }
6920 htmlCopy.exception = thrownException;
6921 _cache.put(source, htmlCopy);
6922 htmlEntry = htmlCopy;
7014 } 6923 }
7015 if (thrownException != null) { 6924 if (thrownException != null) {
7016 throw thrownException; 6925 throw thrownException;
7017 } 6926 }
7018 return htmlEntry; 6927 return htmlEntry;
7019 } 6928 }
7020 6929
7021 /** 6930 /**
7022 * Record the results produced by performing a [ScanDartTask]. If the results were computed 6931 * Record the results produced by performing a [ScanDartTask]. If the results were computed
7023 * from data that is now out-of-date, then the results will not be recorded. 6932 * from data that is now out-of-date, then the results will not be recorded.
7024 * 6933 *
7025 * @param task the task that was performed 6934 * @param task the task that was performed
7026 * @return an entry containing the computed results 6935 * @return an entry containing the computed results
7027 * @throws AnalysisException if the results could not be recorded 6936 * @throws AnalysisException if the results could not be recorded
7028 */ 6937 */
7029 DartEntry recordScanDartTaskResults(ScanDartTask task) { 6938 DartEntry recordScanDartTaskResults(ScanDartTask task) {
7030 Source source = task.source; 6939 Source source = task.source;
7031 AnalysisException thrownException = task.exception; 6940 AnalysisException thrownException = task.exception;
7032 DartEntry dartEntry = null; 6941 DartEntry dartEntry = null;
7033 { 6942 SourceEntry sourceEntry = _cache.get(source);
7034 SourceEntry sourceEntry = _cache.get(source); 6943 if (sourceEntry == null) {
7035 if (sourceEntry == null) { 6944 throw new ObsoleteSourceAnalysisException(source);
7036 throw new ObsoleteSourceAnalysisException(source); 6945 } else if (sourceEntry is! DartEntry) {
7037 } else if (sourceEntry is! DartEntry) { 6946 // This shouldn't be possible because we should never have performed the t ask if the source
7038 // This shouldn't be possible because we should never have performed the task if the source 6947 // didn't represent a Dart file, but check to be safe.
7039 // didn't represent a Dart file, but check to be safe. 6948 throw new AnalysisException.con1("Internal error: attempting to parse non- Dart file as a Dart file: ${source.fullName}");
7040 throw new AnalysisException.con1("Internal error: attempting to parse no n-Dart file as a Dart file: ${source.fullName}"); 6949 }
6950 dartEntry = sourceEntry as DartEntry;
6951 int sourceTime = getModificationStamp(source);
6952 int resultTime = task.modificationTime;
6953 if (sourceTime == resultTime) {
6954 if (dartEntry.modificationTime != sourceTime) {
6955 // The source has changed without the context being notified. Simulate n otification.
6956 sourceChanged(source);
6957 dartEntry = getReadableDartEntry(source);
6958 if (dartEntry == null) {
6959 throw new AnalysisException.con1("A Dart file became a non-Dart file: ${source.fullName}");
6960 }
7041 } 6961 }
7042 dartEntry = sourceEntry as DartEntry; 6962 DartEntryImpl dartCopy = dartEntry.writableCopy;
7043 int sourceTime = getModificationStamp(source); 6963 if (thrownException == null) {
7044 int resultTime = task.modificationTime; 6964 LineInfo lineInfo = task.lineInfo;
7045 if (sourceTime == resultTime) { 6965 dartCopy.setValue(SourceEntry.LINE_INFO, lineInfo);
7046 if (dartEntry.modificationTime != sourceTime) { 6966 dartCopy.setValue(DartEntry.TOKEN_STREAM, task.tokenStream);
7047 // The source has changed without the context being notified. Simulate notification. 6967 dartCopy.setValue(DartEntry.SCAN_ERRORS, task.errors);
7048 sourceChanged(source); 6968 _cache.storedAst(source);
7049 dartEntry = getReadableDartEntry(source); 6969 _workManager.add(source, SourcePriority.NORMAL_PART);
7050 if (dartEntry == null) { 6970 ChangeNoticeImpl notice = getNotice(source);
7051 throw new AnalysisException.con1("A Dart file became a non-Dart file : ${source.fullName}"); 6971 notice.setErrors(dartEntry.allErrors, lineInfo);
7052 }
7053 }
7054 DartEntryImpl dartCopy = dartEntry.writableCopy;
7055 if (thrownException == null) {
7056 LineInfo lineInfo = task.lineInfo;
7057 dartCopy.setValue(SourceEntry.LINE_INFO, lineInfo);
7058 dartCopy.setValue(DartEntry.TOKEN_STREAM, task.tokenStream);
7059 dartCopy.setValue(DartEntry.SCAN_ERRORS, task.errors);
7060 _cache.storedAst(source);
7061 _workManager.add(source, SourcePriority.NORMAL_PART);
7062 ChangeNoticeImpl notice = getNotice(source);
7063 notice.setErrors(dartEntry.allErrors, lineInfo);
7064 } else {
7065 removeFromParts(source, dartEntry);
7066 dartCopy.recordScanError();
7067 _cache.removedAst(source);
7068 }
7069 dartCopy.exception = thrownException;
7070 _cache.put(source, dartCopy);
7071 dartEntry = dartCopy;
7072 } else { 6972 } else {
7073 logInformation2("Scan results discarded for ${debuggingString(source)}; sourceTime = ${sourceTime}, resultTime = ${resultTime}, cacheTime = ${dartEntry. modificationTime}", thrownException); 6973 removeFromParts(source, dartEntry);
7074 DartEntryImpl dartCopy = dartEntry.writableCopy; 6974 dartCopy.recordScanError();
7075 if (thrownException == null || resultTime >= 0) { 6975 _cache.removedAst(source);
7076 //
7077 // The analysis was performed on out-of-date sources. Mark the cache s o that the sources
7078 // will be re-analyzed using the up-to-date sources.
7079 //
7080 // dartCopy.recordScanNotInProcess();
7081 removeFromParts(source, dartEntry);
7082 dartCopy.invalidateAllInformation();
7083 dartCopy.modificationTime = sourceTime;
7084 _cache.removedAst(source);
7085 _workManager.add(source, SourcePriority.UNKNOWN);
7086 } else {
7087 //
7088 // We could not determine whether the sources were up-to-date or out-o f-date. Mark the
7089 // cache so that we won't attempt to re-analyze the sources until ther e's a good chance
7090 // that we'll be able to do so without error.
7091 //
7092 dartCopy.recordScanError();
7093 }
7094 dartCopy.exception = thrownException;
7095 _cache.put(source, dartCopy);
7096 dartEntry = dartCopy;
7097 } 6976 }
6977 dartCopy.exception = thrownException;
6978 _cache.put(source, dartCopy);
6979 dartEntry = dartCopy;
6980 } else {
6981 logInformation2("Scan results discarded for ${debuggingString(source)}; so urceTime = ${sourceTime}, resultTime = ${resultTime}, cacheTime = ${dartEntry.mo dificationTime}", thrownException);
6982 DartEntryImpl dartCopy = dartEntry.writableCopy;
6983 if (thrownException == null || resultTime >= 0) {
6984 //
6985 // The analysis was performed on out-of-date sources. Mark the cache so that the sources
6986 // will be re-analyzed using the up-to-date sources.
6987 //
6988 // dartCopy.recordScanNotInProcess();
6989 removeFromParts(source, dartEntry);
6990 dartCopy.invalidateAllInformation();
6991 dartCopy.modificationTime = sourceTime;
6992 _cache.removedAst(source);
6993 _workManager.add(source, SourcePriority.UNKNOWN);
6994 } else {
6995 //
6996 // We could not determine whether the sources were up-to-date or out-of- date. Mark the
6997 // cache so that we won't attempt to re-analyze the sources until there' s a good chance
6998 // that we'll be able to do so without error.
6999 //
7000 dartCopy.recordScanError();
7001 }
7002 dartCopy.exception = thrownException;
7003 _cache.put(source, dartCopy);
7004 dartEntry = dartCopy;
7098 } 7005 }
7099 if (thrownException != null) { 7006 if (thrownException != null) {
7100 throw thrownException; 7007 throw thrownException;
7101 } 7008 }
7102 return dartEntry; 7009 return dartEntry;
7103 } 7010 }
7104 7011
7105 /** 7012 /**
7106 * Remove the given library from the list of containing libraries for all of t he parts referenced 7013 * Remove the given library from the list of containing libraries for all of t he parts referenced
7107 * by the given entry. 7014 * by the given entry.
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
7266 * invalid so that the source will be re-analyzed. 7173 * invalid so that the source will be re-analyzed.
7267 * 7174 *
7268 * <b>Note:</b> This method must only be invoked while we are synchronized on [cacheLock]. 7175 * <b>Note:</b> This method must only be invoked while we are synchronized on [cacheLock].
7269 * 7176 *
7270 * @return `true` if at least one entry was invalid 7177 * @return `true` if at least one entry was invalid
7271 */ 7178 */
7272 bool validateCacheConsistency() { 7179 bool validateCacheConsistency() {
7273 int consistencyCheckStart = JavaSystem.nanoTime(); 7180 int consistencyCheckStart = JavaSystem.nanoTime();
7274 List<Source> missingSources = new List<Source>(); 7181 List<Source> missingSources = new List<Source>();
7275 int inconsistentCount = 0; 7182 int inconsistentCount = 0;
7276 { 7183 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) {
7277 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) { 7184 Source source = entry.getKey();
7278 Source source = entry.getKey(); 7185 SourceEntry sourceEntry = entry.getValue();
7279 SourceEntry sourceEntry = entry.getValue(); 7186 int sourceTime = getModificationStamp(source);
7280 int sourceTime = getModificationStamp(source); 7187 if (sourceTime != sourceEntry.modificationTime) {
7281 if (sourceTime != sourceEntry.modificationTime) { 7188 sourceChanged(source);
7282 sourceChanged(source); 7189 inconsistentCount++;
7283 inconsistentCount++; 7190 }
7284 } 7191 if (sourceEntry.exception != null) {
7285 if (sourceEntry.exception != null) { 7192 if (!exists(source)) {
7286 if (!exists(source)) { 7193 missingSources.add(source);
7287 missingSources.add(source);
7288 }
7289 } 7194 }
7290 } 7195 }
7291 } 7196 }
7292 int consistencyCheckEnd = JavaSystem.nanoTime(); 7197 int consistencyCheckEnd = JavaSystem.nanoTime();
7293 PrintStringWriter writer = new PrintStringWriter(); 7198 PrintStringWriter writer = new PrintStringWriter();
7294 writer.print("Consistency check took "); 7199 writer.print("Consistency check took ");
7295 writer.print((consistencyCheckEnd - consistencyCheckStart) / 1000000.0); 7200 writer.print((consistencyCheckEnd - consistencyCheckStart) / 1000000.0);
7296 writer.println(" ms and found"); 7201 writer.println(" ms and found");
7297 writer.print(" "); 7202 writer.print(" ");
7298 writer.print(inconsistentCount); 7203 writer.print(inconsistentCount);
(...skipping 4752 matching lines...) Expand 10 before | Expand all | Expand 10 after
12051 11956
12052 void logError2(String message, Exception exception) { 11957 void logError2(String message, Exception exception) {
12053 } 11958 }
12054 11959
12055 void logInformation(String message) { 11960 void logInformation(String message) {
12056 } 11961 }
12057 11962
12058 void logInformation3(String message, Exception exception) { 11963 void logInformation3(String message, Exception exception) {
12059 } 11964 }
12060 } 11965 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698