OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 import 'dart:convert'; | 5 import 'dart:convert'; |
6 import 'dart:core' hide Resource; | 6 import 'dart:core' hide Resource; |
7 | 7 |
8 import 'package:analyzer/dart/element/element.dart'; | 8 import 'package:analyzer/dart/element/element.dart'; |
9 import 'package:analyzer/file_system/file_system.dart'; | 9 import 'package:analyzer/file_system/file_system.dart'; |
10 import 'package:analyzer/src/generated/engine.dart'; | 10 import 'package:analyzer/src/generated/engine.dart'; |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 * [LibraryBundleWithId]s were already returned as a part of the closure of | 133 * [LibraryBundleWithId]s were already returned as a part of the closure of |
134 * another library, they are still included - it is up to the client to | 134 * another library, they are still included - it is up to the client to |
135 * decide whether a bundle should be used or not, but it is easy to do | 135 * decide whether a bundle should be used or not, but it is easy to do |
136 * using [LibraryBundleWithId.id]. | 136 * using [LibraryBundleWithId.id]. |
137 */ | 137 */ |
138 List<LibraryBundleWithId> getLibraryClosureBundles(Source librarySource) { | 138 List<LibraryBundleWithId> getLibraryClosureBundles(Source librarySource) { |
139 try { | 139 try { |
140 List<Source> closureSources = _getLibraryClosure(librarySource); | 140 List<Source> closureSources = _getLibraryClosure(librarySource); |
141 List<LibraryBundleWithId> closureBundles = <LibraryBundleWithId>[]; | 141 List<LibraryBundleWithId> closureBundles = <LibraryBundleWithId>[]; |
142 for (Source source in closureSources) { | 142 for (Source source in closureSources) { |
143 if (source.isInSystemLibrary) { | |
144 continue; | |
145 } | |
146 if (getSourceKind(source) == SourceKind.PART) { | 143 if (getSourceKind(source) == SourceKind.PART) { |
147 continue; | 144 continue; |
148 } | 145 } |
149 String key = _getLibraryBundleKey(source); | 146 String key = _getLibraryBundleKey(source); |
150 PackageBundle bundle = _getLibraryBundle(key); | 147 PackageBundle bundle = _getLibraryBundle(key); |
151 if (bundle == null) { | 148 if (bundle == null) { |
152 return null; | 149 return null; |
153 } | 150 } |
154 closureBundles.add(new LibraryBundleWithId(source, key, bundle)); | 151 closureBundles.add(new LibraryBundleWithId(source, key, bundle)); |
155 } | 152 } |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 List<int> bytes = builder.toBuffer(); | 240 List<int> bytes = builder.toBuffer(); |
244 storage.put(key, bytes); | 241 storage.put(key, bytes); |
245 } | 242 } |
246 | 243 |
247 /** | 244 /** |
248 * Fill the whole source closure of the library with the given | 245 * Fill the whole source closure of the library with the given |
249 * [librarySource]. It includes defining units and parts of the library and | 246 * [librarySource]. It includes defining units and parts of the library and |
250 * all its directly or indirectly imported or exported libraries. | 247 * all its directly or indirectly imported or exported libraries. |
251 */ | 248 */ |
252 void _appendLibraryClosure(Set<Source> closure, Source librarySource) { | 249 void _appendLibraryClosure(Set<Source> closure, Source librarySource) { |
| 250 if (librarySource.isInSystemLibrary) { |
| 251 return; |
| 252 } |
253 if (closure.add(librarySource)) { | 253 if (closure.add(librarySource)) { |
254 CacheSourceContent contentSource = _getCacheSourceContent(librarySource); | 254 CacheSourceContent contentSource = _getCacheSourceContent(librarySource); |
255 if (contentSource == null) { | 255 if (contentSource == null) { |
256 throw new StateError('No structure for $librarySource'); | 256 throw new StateError('No structure for $librarySource'); |
257 } | 257 } |
258 // Append parts. | 258 // Append parts. |
259 for (String partUri in contentSource.partUris) { | 259 for (String partUri in contentSource.partUris) { |
260 Source partSource = _resolveUri(librarySource, partUri); | 260 Source partSource = _resolveUri(librarySource, partUri); |
261 if (partSource == null) { | 261 if (partSource == null) { |
262 throw new StateError('Unable to resolve $partUri in $librarySource'); | 262 throw new StateError('Unable to resolve $partUri in $librarySource'); |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 }); | 450 }); |
451 } | 451 } |
452 // Resolve relative URIs without caching. | 452 // Resolve relative URIs without caching. |
453 return context.sourceFactory.resolveUri(containingSource, containedUri); | 453 return context.sourceFactory.resolveUri(containingSource, containedUri); |
454 } | 454 } |
455 | 455 |
456 /** | 456 /** |
457 * Write the content based information about the given [source]. | 457 * Write the content based information about the given [source]. |
458 */ | 458 */ |
459 void _writeCacheSourceContent(Source source, CacheSourceContentBuilder b) { | 459 void _writeCacheSourceContent(Source source, CacheSourceContentBuilder b) { |
460 String key = _getCacheSourceContentKey(source); | 460 if (!_sourceContentMap.containsKey(source)) { |
461 List<int> bytes = b.toBuffer(); | 461 String key = _getCacheSourceContentKey(source); |
462 storage.put(key, bytes); | 462 List<int> bytes = b.toBuffer(); |
463 // Put into the cache to avoid reading it later. | 463 storage.put(key, bytes); |
464 _sourceContentMap[source] = new CacheSourceContent.fromBuffer(bytes); | 464 // Put into the cache to avoid reading it later. |
| 465 _sourceContentMap[source] = new CacheSourceContent.fromBuffer(bytes); |
| 466 } |
465 } | 467 } |
466 | 468 |
467 /** | 469 /** |
468 * Write [CacheSourceContent] for every unit of the given [library] and its | 470 * Write [CacheSourceContent] for every unit of the given [library] and its |
469 * direct and indirect imports/exports. | 471 * direct and indirect imports/exports. |
470 */ | 472 */ |
471 void _writeCacheSourceContents(LibraryElement library, | 473 void _writeCacheSourceContents(LibraryElement library, |
472 [Set<LibraryElement> writtenLibraries]) { | 474 [Set<LibraryElement> writtenLibraries]) { |
473 Source librarySource = library.source; | 475 Source librarySource = library.source; |
474 // Do nothing if already cached. | |
475 if (_sourceContentMap.containsKey(librarySource)) { | |
476 return; | |
477 } | |
478 // Stop recursion cycle. | 476 // Stop recursion cycle. |
479 writtenLibraries ??= new Set<LibraryElement>(); | 477 writtenLibraries ??= new Set<LibraryElement>(); |
480 if (!writtenLibraries.add(library)) { | 478 if (!writtenLibraries.add(library)) { |
481 return; | 479 return; |
482 } | 480 } |
483 // Write parts. | 481 // Write parts. |
484 List<String> partUris = <String>[]; | 482 List<String> partUris = <String>[]; |
485 for (CompilationUnitElement part in library.parts) { | 483 for (CompilationUnitElement part in library.parts) { |
486 partUris.add(part.uri); | 484 partUris.add(part.uri); |
487 Source partSource = part.source; | 485 Source partSource = part.source; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 */ | 531 */ |
534 final String id; | 532 final String id; |
535 | 533 |
536 /** | 534 /** |
537 * The payload bundle. | 535 * The payload bundle. |
538 */ | 536 */ |
539 final PackageBundle bundle; | 537 final PackageBundle bundle; |
540 | 538 |
541 LibraryBundleWithId(this.source, this.id, this.bundle); | 539 LibraryBundleWithId(this.source, this.id, this.bundle); |
542 } | 540 } |
OLD | NEW |