| 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 'common.dart'; | 5 import 'common.dart'; |
| 6 import 'elements/elements.dart' show LibraryElement; | 6 import 'elements/elements.dart' show LibraryElement; |
| 7 import 'util/emptyset.dart'; | 7 import 'util/emptyset.dart'; |
| 8 | 8 |
| 9 /// API used by the library loader to translate internal SDK URIs into file | 9 /// API used by the library loader to translate internal SDK URIs into file |
| 10 /// system readable URIs. | 10 /// system readable URIs. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 /// | 28 /// |
| 29 /// The [importingLibrary] holds the library importing [uri] or `null` if | 29 /// The [importingLibrary] holds the library importing [uri] or `null` if |
| 30 /// [uri] is loaded as the main library. The [importingLibrary] is used to | 30 /// [uri] is loaded as the main library. The [importingLibrary] is used to |
| 31 /// grant access to internal libraries from platform libraries and patch | 31 /// grant access to internal libraries from platform libraries and patch |
| 32 /// libraries. | 32 /// libraries. |
| 33 /// | 33 /// |
| 34 /// If the [uri] is not accessible from [importingLibrary], this method is | 34 /// If the [uri] is not accessible from [importingLibrary], this method is |
| 35 /// responsible for reporting errors. | 35 /// responsible for reporting errors. |
| 36 /// | 36 /// |
| 37 /// See [LibraryLoader] for terminology on URIs. | 37 /// See [LibraryLoader] for terminology on URIs. |
| 38 Uri translate(LibraryElement importingLibrary, Uri uri, | 38 Uri translate(LibraryElement importingLibrary, Uri uri, Spannable spannable); |
| 39 [Spannable spannable]); | |
| 40 } | 39 } |
| 41 | 40 |
| 42 /// A translator that forwards all methods to an internal | 41 /// A translator that forwards all methods to an internal |
| 43 /// [ResolvedUriTranslator]. | 42 /// [ResolvedUriTranslator]. |
| 44 /// | 43 /// |
| 45 /// The translator to forward to may be set after the instance is constructed. | 44 /// The translator to forward to may be set after the instance is constructed. |
| 46 /// This is useful for the compiler because some tasks that are instantiated at | 45 /// This is useful for the compiler because some tasks that are instantiated at |
| 47 /// compiler construction time need a [ResolvedUriTranslator], but the data | 46 /// compiler construction time need a [ResolvedUriTranslator], but the data |
| 48 /// required to instantiate it cannot be obtained at construction time. So a | 47 /// required to instantiate it cannot be obtained at construction time. So a |
| 49 /// [ForwardingResolvedUriTranslator] may be passed instead, and the translator | 48 /// [ForwardingResolvedUriTranslator] may be passed instead, and the translator |
| 50 /// to forward to can be set once the required data has been retrieved. | 49 /// to forward to can be set once the required data has been retrieved. |
| 51 class ForwardingResolvedUriTranslator implements ResolvedUriTranslator { | 50 class ForwardingResolvedUriTranslator implements ResolvedUriTranslator { |
| 52 ResolvedUriTranslator resolvedUriTranslator; | 51 ResolvedUriTranslator resolvedUriTranslator; |
| 53 | 52 |
| 54 /// Returns `true` if [resolvedUriTranslator] is not `null`. | 53 /// Returns `true` if [resolvedUriTranslator] is not `null`. |
| 55 bool get isSet => resolvedUriTranslator != null; | 54 bool get isSet => resolvedUriTranslator != null; |
| 56 | 55 |
| 57 /// The opposite of [isSet]. | 56 /// The opposite of [isSet]. |
| 58 bool get isNotSet => resolvedUriTranslator == null; | 57 bool get isNotSet => resolvedUriTranslator == null; |
| 59 | 58 |
| 60 @override | 59 @override |
| 61 Uri translate(LibraryElement importingLibrary, Uri resolvedUri, | 60 Uri translate(LibraryElement importingLibrary, Uri resolvedUri, |
| 62 [Spannable spannable]) => | 61 Spannable spannable) => |
| 63 resolvedUriTranslator.translate(importingLibrary, resolvedUri, spannable); | 62 resolvedUriTranslator.translate(importingLibrary, resolvedUri, spannable); |
| 64 | 63 |
| 65 @override | 64 @override |
| 66 Set<Uri> get disallowedLibraryUris => | 65 Set<Uri> get disallowedLibraryUris => |
| 67 resolvedUriTranslator?.disallowedLibraryUris ?? | 66 resolvedUriTranslator?.disallowedLibraryUris ?? |
| 68 const ImmutableEmptySet<Uri>(); | 67 const ImmutableEmptySet<Uri>(); |
| 69 | 68 |
| 70 @override | 69 @override |
| 71 bool get mockableLibraryUsed => resolvedUriTranslator.mockableLibraryUsed; | 70 bool get mockableLibraryUsed => resolvedUriTranslator.mockableLibraryUsed; |
| 72 | 71 |
| 73 @override | 72 @override |
| 74 Map<String, Uri> get sdkLibraries => resolvedUriTranslator.sdkLibraries; | 73 Map<String, Uri> get sdkLibraries => resolvedUriTranslator.sdkLibraries; |
| 75 } | 74 } |
| 76 | 75 |
| 77 class _ResolvedUriTranslator implements ResolvedUriTranslator { | 76 class _ResolvedUriTranslator implements ResolvedUriTranslator { |
| 78 final Map<String, Uri> _sdkLibraries; | 77 final Map<String, Uri> _sdkLibraries; |
| 79 final DiagnosticReporter _reporter; | 78 final DiagnosticReporter _reporter; |
| 80 | 79 |
| 81 Set<Uri> disallowedLibraryUris = new Set<Uri>(); | 80 Set<Uri> disallowedLibraryUris = new Set<Uri>(); |
| 82 bool mockableLibraryUsed = false; | 81 bool mockableLibraryUsed = false; |
| 83 | 82 |
| 84 _ResolvedUriTranslator(this._sdkLibraries, this._reporter); | 83 _ResolvedUriTranslator(this._sdkLibraries, this._reporter); |
| 85 | 84 |
| 86 Map<String, Uri> get sdkLibraries => _sdkLibraries; | 85 Map<String, Uri> get sdkLibraries => _sdkLibraries; |
| 87 | 86 |
| 88 @override | 87 @override |
| 89 Uri translate(LibraryElement importingLibrary, Uri uri, | 88 Uri translate(LibraryElement importingLibrary, Uri uri, Spannable spannable) { |
| 90 [Spannable spannable]) { | |
| 91 if (uri.scheme == 'dart') { | 89 if (uri.scheme == 'dart') { |
| 92 return translateDartUri(importingLibrary, uri, spannable); | 90 return translateDartUri(importingLibrary, uri, spannable); |
| 93 } | 91 } |
| 94 return uri; | 92 return uri; |
| 95 } | 93 } |
| 96 | 94 |
| 97 /// Translates "resolvedUri" with scheme "dart" to a [uri] resolved relative | 95 /// Translates "resolvedUri" with scheme "dart" to a [uri] resolved relative |
| 98 /// to `options.platformConfigUri` according to the information in the file at | 96 /// to `options.platformConfigUri` according to the information in the file at |
| 99 /// `options.platformConfigUri`. | 97 /// `options.platformConfigUri`. |
| 100 /// | 98 /// |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 } | 150 } |
| 153 | 151 |
| 154 void registerDisallowedLibraryUse(Uri uri) { | 152 void registerDisallowedLibraryUse(Uri uri) { |
| 155 disallowedLibraryUris.add(uri); | 153 disallowedLibraryUris.add(uri); |
| 156 } | 154 } |
| 157 | 155 |
| 158 Uri lookupLibraryUri(String libraryName) { | 156 Uri lookupLibraryUri(String libraryName) { |
| 159 return _sdkLibraries[libraryName]; | 157 return _sdkLibraries[libraryName]; |
| 160 } | 158 } |
| 161 } | 159 } |
| OLD | NEW |