OLD | NEW |
1 import 'dart:io' as io; | 1 import 'dart:io' as io; |
2 | 2 |
3 import 'package:analyzer/dart/element/element.dart'; | 3 import 'package:analyzer/dart/element/element.dart'; |
4 import 'package:analyzer/src/context/cache.dart'; | 4 import 'package:analyzer/src/context/cache.dart'; |
5 import 'package:analyzer/src/context/context.dart'; | 5 import 'package:analyzer/src/context/context.dart'; |
6 import 'package:analyzer/src/generated/engine.dart'; | 6 import 'package:analyzer/src/generated/engine.dart'; |
| 7 import 'package:analyzer/src/generated/java_io.dart'; |
7 import 'package:analyzer/src/generated/resolver.dart'; | 8 import 'package:analyzer/src/generated/resolver.dart'; |
8 import 'package:analyzer/src/generated/source.dart'; | 9 import 'package:analyzer/src/generated/source.dart'; |
| 10 import 'package:analyzer/src/generated/source_io.dart'; |
9 import 'package:analyzer/src/summary/idl.dart'; | 11 import 'package:analyzer/src/summary/idl.dart'; |
10 import 'package:analyzer/src/summary/resynthesize.dart'; | 12 import 'package:analyzer/src/summary/resynthesize.dart'; |
11 import 'package:analyzer/src/summary/summary_sdk.dart'; | 13 import 'package:analyzer/src/summary/summary_sdk.dart'; |
12 import 'package:analyzer/src/task/dart.dart'; | 14 import 'package:analyzer/src/task/dart.dart'; |
13 import 'package:analyzer/task/dart.dart'; | 15 import 'package:analyzer/task/dart.dart'; |
14 import 'package:analyzer/task/model.dart'; | 16 import 'package:analyzer/task/model.dart'; |
15 import 'package:path/path.dart' as pathos; | 17 import 'package:path/path.dart' as pathos; |
16 | 18 |
17 /** | 19 /** |
18 * The [ResultProvider] that provides results from input package summaries. | 20 * The [ResultProvider] that provides results from input package summaries. |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 * summaries. | 95 * summaries. |
94 */ | 96 */ |
95 class InSummaryPackageUriResolver extends UriResolver { | 97 class InSummaryPackageUriResolver extends UriResolver { |
96 final SummaryDataStore _dataStore; | 98 final SummaryDataStore _dataStore; |
97 | 99 |
98 InSummaryPackageUriResolver(this._dataStore); | 100 InSummaryPackageUriResolver(this._dataStore); |
99 | 101 |
100 @override | 102 @override |
101 Source resolveAbsolute(Uri uri, [Uri actualUri]) { | 103 Source resolveAbsolute(Uri uri, [Uri actualUri]) { |
102 actualUri ??= uri; | 104 actualUri ??= uri; |
103 if (_dataStore.unlinkedMap.containsKey(uri.toString())) { | 105 UnlinkedUnit unit = _dataStore.unlinkedMap[uri.toString()]; |
104 return new InSummarySource( | 106 if (unit != null) { |
105 actualUri, _dataStore.uriToSummaryPath[uri.toString()]); | 107 String summaryPath = _dataStore.uriToSummaryPath[uri.toString()]; |
| 108 if (unit.fallbackModePath.isNotEmpty) { |
| 109 return new _InSummaryFallbackSource( |
| 110 new JavaFile(unit.fallbackModePath), actualUri, summaryPath); |
| 111 } else { |
| 112 return new InSummarySource(actualUri, summaryPath); |
| 113 } |
106 } | 114 } |
107 return null; | 115 return null; |
108 } | 116 } |
109 } | 117 } |
110 | 118 |
111 /** | 119 /** |
| 120 * A placeholder of a source that is part of a package whose analysis results |
| 121 * are served from its summary. This source uses its URI as [fullName] and has |
| 122 * empty contents. |
| 123 */ |
| 124 class InSummarySource extends Source { |
| 125 final Uri uri; |
| 126 |
| 127 /** |
| 128 * The summary file where this source was defined. |
| 129 */ |
| 130 final String summaryPath; |
| 131 |
| 132 InSummarySource(this.uri, this.summaryPath); |
| 133 |
| 134 @override |
| 135 TimestampedData<String> get contents => new TimestampedData<String>(0, ''); |
| 136 |
| 137 @override |
| 138 String get encoding => uri.toString(); |
| 139 |
| 140 @override |
| 141 String get fullName => encoding; |
| 142 |
| 143 @override |
| 144 int get hashCode => uri.hashCode; |
| 145 |
| 146 @override |
| 147 bool get isInSystemLibrary => false; |
| 148 |
| 149 @override |
| 150 int get modificationStamp => 0; |
| 151 |
| 152 @override |
| 153 String get shortName => pathos.basename(fullName); |
| 154 |
| 155 @override |
| 156 UriKind get uriKind => UriKind.PACKAGE_URI; |
| 157 |
| 158 @override |
| 159 bool operator ==(Object object) => |
| 160 object is InSummarySource && object.uri == uri; |
| 161 |
| 162 @override |
| 163 bool exists() => true; |
| 164 |
| 165 @override |
| 166 Uri resolveRelativeUri(Uri relativeUri) { |
| 167 Uri baseUri = uri; |
| 168 return baseUri.resolveUri(relativeUri); |
| 169 } |
| 170 |
| 171 @override |
| 172 String toString() => uri.toString(); |
| 173 } |
| 174 |
| 175 /** |
112 * A [SummaryDataStore] is a container for the data extracted from a set of | 176 * A [SummaryDataStore] is a container for the data extracted from a set of |
113 * summary package bundles. It contains maps which can be used to find linked | 177 * summary package bundles. It contains maps which can be used to find linked |
114 * and unlinked summaries by URI. | 178 * and unlinked summaries by URI. |
115 */ | 179 */ |
116 class SummaryDataStore { | 180 class SummaryDataStore { |
117 /** | 181 /** |
118 * Map from the URI of a compilation unit to the unlinked summary of that | 182 * Map from the URI of a compilation unit to the unlinked summary of that |
119 * compilation unit. | 183 * compilation unit. |
120 */ | 184 */ |
121 final Map<String, UnlinkedUnit> unlinkedMap = <String, UnlinkedUnit>{}; | 185 final Map<String, UnlinkedUnit> unlinkedMap = <String, UnlinkedUnit>{}; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 return _dataStore.linkedMap[uri]; | 234 return _dataStore.linkedMap[uri]; |
171 } | 235 } |
172 | 236 |
173 @override | 237 @override |
174 UnlinkedUnit getUnlinkedSummary(String uri) { | 238 UnlinkedUnit getUnlinkedSummary(String uri) { |
175 return _dataStore.unlinkedMap[uri]; | 239 return _dataStore.unlinkedMap[uri]; |
176 } | 240 } |
177 | 241 |
178 @override | 242 @override |
179 bool hasLibrarySummary(String uri) { | 243 bool hasLibrarySummary(String uri) { |
180 return _dataStore.linkedMap.containsKey(uri); | 244 LinkedLibrary linkedLibrary = _dataStore.linkedMap[uri]; |
| 245 return linkedLibrary != null && !linkedLibrary.fallbackMode; |
181 } | 246 } |
182 } | 247 } |
183 | 248 |
184 /** | 249 /** |
185 * A placeholder of a source that is part of a package whose analysis results | 250 * A source that is part of a package whose summary was generated in fallback |
186 * are served from its summary. This source uses its URI as [fullName] and has | 251 * mode. This source behaves identically to a [FileBasedSource] except that it |
187 * empty contents. | 252 * also provides [summaryPath]. |
188 */ | 253 */ |
189 class InSummarySource extends Source { | 254 class _InSummaryFallbackSource extends FileBasedSource |
190 final Uri uri; | 255 implements InSummarySource { |
191 | 256 @override |
192 /** | |
193 * The summary file where this source was defined. | |
194 */ | |
195 final String summaryPath; | 257 final String summaryPath; |
196 | 258 |
197 InSummarySource(this.uri, this.summaryPath); | 259 _InSummaryFallbackSource(JavaFile file, Uri uri, this.summaryPath) |
198 | 260 : super(file, uri); |
199 @override | |
200 TimestampedData<String> get contents => new TimestampedData<String>(0, ''); | |
201 | |
202 @override | |
203 String get encoding => uri.toString(); | |
204 | |
205 @override | |
206 String get fullName => encoding; | |
207 | |
208 @override | |
209 int get hashCode => uri.hashCode; | |
210 | |
211 @override | |
212 bool get isInSystemLibrary => false; | |
213 | |
214 @override | |
215 int get modificationStamp => 0; | |
216 | |
217 @override | |
218 String get shortName => pathos.basename(fullName); | |
219 | |
220 @override | |
221 UriKind get uriKind => UriKind.PACKAGE_URI; | |
222 | |
223 @override | |
224 bool operator ==(Object object) => | |
225 object is InSummarySource && object.uri == uri; | |
226 | |
227 @override | |
228 bool exists() => true; | |
229 | |
230 @override | |
231 Uri resolveRelativeUri(Uri relativeUri) { | |
232 Uri baseUri = uri; | |
233 return baseUri.resolveUri(relativeUri); | |
234 } | |
235 | |
236 @override | |
237 String toString() => uri.toString(); | |
238 } | 261 } |
OLD | NEW |