Chromium Code Reviews| 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/resolver.dart'; | 7 import 'package:analyzer/src/generated/resolver.dart'; |
| 8 import 'package:analyzer/src/generated/source.dart'; | 8 import 'package:analyzer/src/generated/source.dart'; |
| 9 import 'package:analyzer/src/summary/idl.dart'; | 9 import 'package:analyzer/src/summary/idl.dart'; |
| 10 import 'package:analyzer/src/summary/resynthesize.dart'; | 10 import 'package:analyzer/src/summary/resynthesize.dart'; |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 94 */ | 94 */ |
| 95 class InSummaryPackageUriResolver extends UriResolver { | 95 class InSummaryPackageUriResolver extends UriResolver { |
| 96 final SummaryDataStore _dataStore; | 96 final SummaryDataStore _dataStore; |
| 97 | 97 |
| 98 InSummaryPackageUriResolver(this._dataStore); | 98 InSummaryPackageUriResolver(this._dataStore); |
| 99 | 99 |
| 100 @override | 100 @override |
| 101 Source resolveAbsolute(Uri uri, [Uri actualUri]) { | 101 Source resolveAbsolute(Uri uri, [Uri actualUri]) { |
| 102 actualUri ??= uri; | 102 actualUri ??= uri; |
| 103 if (_dataStore.unlinkedMap.containsKey(uri.toString())) { | 103 if (_dataStore.unlinkedMap.containsKey(uri.toString())) { |
| 104 return new _InSummarySource(actualUri); | 104 return new InSummarySource( |
| 105 actualUri, _dataStore.uriToSummary[uri.toString()]); | |
| 105 } | 106 } |
| 106 return null; | 107 return null; |
| 107 } | 108 } |
| 108 } | 109 } |
| 109 | 110 |
| 110 /** | 111 /** |
| 111 * A [SummaryDataStore] is a container for the data extracted from a set of | 112 * A [SummaryDataStore] is a container for the data extracted from a set of |
| 112 * summary package bundles. It contains maps which can be used to find linked | 113 * summary package bundles. It contains maps which can be used to find linked |
| 113 * and unlinked summaries by URI. | 114 * and unlinked summaries by URI. |
| 114 */ | 115 */ |
| 115 class SummaryDataStore { | 116 class SummaryDataStore { |
| 116 /** | 117 /** |
| 117 * Map from the URI of a compilation unit to the unlinked summary of that | 118 * Map from the URI of a compilation unit to the unlinked summary of that |
| 118 * compilation unit. | 119 * compilation unit. |
| 119 */ | 120 */ |
| 120 final Map<String, UnlinkedUnit> unlinkedMap = <String, UnlinkedUnit>{}; | 121 final Map<String, UnlinkedUnit> unlinkedMap = <String, UnlinkedUnit>{}; |
| 121 | 122 |
| 122 /** | 123 /** |
| 123 * Map from the URI of a library to the linked summary of that library. | 124 * Map from the URI of a library to the linked summary of that library. |
| 124 */ | 125 */ |
| 125 final Map<String, LinkedLibrary> linkedMap = <String, LinkedLibrary>{}; | 126 final Map<String, LinkedLibrary> linkedMap = <String, LinkedLibrary>{}; |
| 126 | 127 |
| 128 /** | |
| 129 * Map from the URI of a library to the summary path that contained it. | |
| 130 */ | |
| 131 final Map<String, String> uriToSummary = <String, String>{}; | |
|
scheglov
2016/03/23 19:22:42
uriToSummaryPath maybe?
Jennifer Messerly
2016/03/23 19:25:56
good idea! done
| |
| 132 | |
| 127 SummaryDataStore(Iterable<String> summaryPaths) { | 133 SummaryDataStore(Iterable<String> summaryPaths) { |
| 128 summaryPaths.forEach(_fillMaps); | 134 summaryPaths.forEach(_fillMaps); |
| 129 } | 135 } |
| 130 | 136 |
| 131 void _fillMaps(String path) { | 137 void _fillMaps(String path) { |
| 132 io.File file = new io.File(path); | 138 io.File file = new io.File(path); |
| 133 List<int> buffer = file.readAsBytesSync(); | 139 List<int> buffer = file.readAsBytesSync(); |
| 134 PackageBundle bundle = new PackageBundle.fromBuffer(buffer); | 140 PackageBundle bundle = new PackageBundle.fromBuffer(buffer); |
| 135 for (int i = 0; i < bundle.unlinkedUnitUris.length; i++) { | 141 for (int i = 0; i < bundle.unlinkedUnitUris.length; i++) { |
| 136 unlinkedMap[bundle.unlinkedUnitUris[i]] = bundle.unlinkedUnits[i]; | 142 String uri = bundle.unlinkedUnitUris[i]; |
| 143 uriToSummary[uri] = path; | |
| 144 unlinkedMap[uri] = bundle.unlinkedUnits[i]; | |
| 137 } | 145 } |
| 138 for (int i = 0; i < bundle.linkedLibraryUris.length; i++) { | 146 for (int i = 0; i < bundle.linkedLibraryUris.length; i++) { |
| 139 linkedMap[bundle.linkedLibraryUris[i]] = bundle.linkedLibraries[i]; | 147 String uri = bundle.linkedLibraryUris[i]; |
| 148 linkedMap[uri] = bundle.linkedLibraries[i]; | |
| 140 } | 149 } |
| 141 } | 150 } |
| 142 } | 151 } |
| 143 | 152 |
| 144 /** | 153 /** |
| 145 * A concrete resynthesizer that serves summaries from given file paths. | 154 * A concrete resynthesizer that serves summaries from given file paths. |
| 146 */ | 155 */ |
| 147 class _FileBasedSummaryResynthesizer extends SummaryResynthesizer { | 156 class _FileBasedSummaryResynthesizer extends SummaryResynthesizer { |
| 148 final SummaryDataStore _dataStore; | 157 final SummaryDataStore _dataStore; |
| 149 | 158 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 170 bool hasLibrarySummary(String uri) { | 179 bool hasLibrarySummary(String uri) { |
| 171 return _dataStore.linkedMap.containsKey(uri); | 180 return _dataStore.linkedMap.containsKey(uri); |
| 172 } | 181 } |
| 173 } | 182 } |
| 174 | 183 |
| 175 /** | 184 /** |
| 176 * A placeholder of a source that is part of a package whose analysis results | 185 * A placeholder of a source that is part of a package whose analysis results |
| 177 * are served from its summary. This source uses its URI as [fullName] and has | 186 * are served from its summary. This source uses its URI as [fullName] and has |
| 178 * empty contents. | 187 * empty contents. |
| 179 */ | 188 */ |
| 180 class _InSummarySource extends Source { | 189 class InSummarySource extends Source { |
| 181 final Uri uri; | 190 final Uri uri; |
| 182 | 191 |
| 183 _InSummarySource(this.uri); | 192 /** |
| 193 * The summary file where this source file was defined. | |
|
scheglov
2016/03/23 19:22:42
"source file" -> "source"
Jennifer Messerly
2016/03/23 19:25:56
Done.
| |
| 194 */ | |
| 195 final String summaryPath; | |
| 196 | |
| 197 InSummarySource(this.uri, this.summaryPath); | |
| 184 | 198 |
| 185 @override | 199 @override |
| 186 TimestampedData<String> get contents => new TimestampedData<String>(0, ''); | 200 TimestampedData<String> get contents => new TimestampedData<String>(0, ''); |
| 187 | 201 |
| 188 @override | 202 @override |
| 189 String get encoding => uri.toString(); | 203 String get encoding => uri.toString(); |
| 190 | 204 |
| 191 @override | 205 @override |
| 192 String get fullName => encoding; | 206 String get fullName => encoding; |
| 193 | 207 |
| 194 @override | 208 @override |
| 195 int get hashCode => uri.hashCode; | 209 int get hashCode => uri.hashCode; |
| 196 | 210 |
| 197 @override | 211 @override |
| 198 bool get isInSystemLibrary => false; | 212 bool get isInSystemLibrary => false; |
| 199 | 213 |
| 200 @override | 214 @override |
| 201 int get modificationStamp => 0; | 215 int get modificationStamp => 0; |
| 202 | 216 |
| 203 @override | 217 @override |
| 204 String get shortName => pathos.basename(fullName); | 218 String get shortName => pathos.basename(fullName); |
| 205 | 219 |
| 206 @override | 220 @override |
| 207 UriKind get uriKind => UriKind.PACKAGE_URI; | 221 UriKind get uriKind => UriKind.PACKAGE_URI; |
| 208 | 222 |
| 209 @override | 223 @override |
| 210 bool operator ==(Object object) => | 224 bool operator ==(Object object) => |
| 211 object is _InSummarySource && object.uri == uri; | 225 object is InSummarySource && object.uri == uri; |
| 212 | 226 |
| 213 @override | 227 @override |
| 214 bool exists() => true; | 228 bool exists() => true; |
| 215 | 229 |
| 216 @override | 230 @override |
| 217 Uri resolveRelativeUri(Uri relativeUri) { | 231 Uri resolveRelativeUri(Uri relativeUri) { |
| 218 Uri baseUri = uri; | 232 Uri baseUri = uri; |
| 219 return baseUri.resolveUri(relativeUri); | 233 return baseUri.resolveUri(relativeUri); |
| 220 } | 234 } |
| 221 | 235 |
| 222 @override | 236 @override |
| 223 String toString() => uri.toString(); | 237 String toString() => uri.toString(); |
| 224 } | 238 } |
| OLD | NEW |