Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f8ce36d

Browse files
committedJun 26, 2015
Add Resource class. Currently unimplemented.
[email protected], [email protected] Committed: 2890a7a Review URL: https://codereview.chromium.org//1181663002.
1 parent 3a0edfb commit f8ce36d

File tree

9 files changed

+275
-2
lines changed

9 files changed

+275
-2
lines changed
 

‎pkg/analyzer/lib/file_system/file_system.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ abstract class File extends Resource {
1818
* Watch for changes to this file
1919
*/
2020
Stream<WatchEvent> get changes;
21-
21+
2222
/**
2323
* Return the last-modified stamp of the file.
2424
* Throws [FileSystemException] if the file does not exist.

‎pkg/pkg.status

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,3 +196,125 @@ typed_data/test/typed_buffers_test/01: Crash # Invalid argument(s)
196196
typed_data/test/typed_buffers_test/none: Crash # Invalid argument(s)
197197
typed_mock/test/typed_mock_test: Crash # Invalid argument(s)
198198
analyzer/test/generated/source_factory_test : Crash # Invalid argument(s)
199+
200+
[ $compiler == dart2analyzer ]
201+
analysis_server/test/analysis/get_errors_test: StaticWarning
202+
analysis_server/test/analysis/get_hover_test: StaticWarning
203+
analysis_server/test/analysis/notification_errors_test: StaticWarning
204+
analysis_server/test/analysis/notification_highlights_test: StaticWarning
205+
analysis_server/test/analysis/notification_navigation_test: StaticWarning
206+
analysis_server/test/analysis/notification_occurrences_test: StaticWarning
207+
analysis_server/test/analysis/notification_outline_test: StaticWarning
208+
analysis_server/test/analysis/notification_overrides_test: StaticWarning
209+
analysis_server/test/analysis/reanalyze_test: StaticWarning
210+
analysis_server/test/analysis/update_content_test: StaticWarning
211+
analysis_server/test/analysis_server_test: StaticWarning
212+
analysis_server/test/channel/byte_stream_channel_test: StaticWarning
213+
analysis_server/test/channel/web_socket_channel_test: StaticWarning
214+
analysis_server/test/completion_test: StaticWarning
215+
analysis_server/test/context_manager_test: StaticWarning
216+
analysis_server/test/domain_analysis_test: StaticWarning
217+
analysis_server/test/domain_completion_test: StaticWarning
218+
analysis_server/test/domain_execution_test: StaticWarning
219+
analysis_server/test/domain_server_test: StaticWarning
220+
analysis_server/test/edit/assists_test: StaticWarning
221+
analysis_server/test/edit/fixes_test: StaticWarning
222+
analysis_server/test/edit/format_test: StaticWarning
223+
analysis_server/test/edit/refactoring_test: StaticWarning
224+
analysis_server/test/edit/sort_members_test: StaticWarning
225+
analysis_server/test/operation/operation_queue_test: StaticWarning
226+
analysis_server/test/operation/operation_test: StaticWarning
227+
analysis_server/test/protocol_server_test: StaticWarning
228+
analysis_server/test/search/element_references_test: StaticWarning
229+
analysis_server/test/search/member_declarations_test: StaticWarning
230+
analysis_server/test/search/member_references_test: StaticWarning
231+
analysis_server/test/search/search_result_test: StaticWarning
232+
analysis_server/test/search/top_level_declarations_test: StaticWarning
233+
analysis_server/test/search/type_hierarchy_test: StaticWarning
234+
analysis_server/test/services/completion/arglist_contributor_test: StaticWarning
235+
analysis_server/test/services/completion/combinator_contributor_test: StaticWarning
236+
analysis_server/test/services/completion/common_usage_computer_test: StaticWarning
237+
analysis_server/test/services/completion/completion_computer_test: StaticWarning
238+
analysis_server/test/services/completion/completion_manager_test: StaticWarning
239+
analysis_server/test/services/completion/completion_target_test: StaticWarning
240+
ng
241+
analysis_server/test/services/completion/imported_reference_contributor_test: StaticWarning
242+
analysis_server/test/services/completion/import_uri_contributor_test: StaticWarning
243+
analysis_server/test/services/completion/keyword_contributor_test: StaticWarning
244+
analysis_server/test/services/completion/local_declaration_visitor_test: StaticWarning
245+
analysis_server/test/services/completion/local_reference_contributor_test: StaticWarning
246+
analysis_server/test/services/completion/optype_test: StaticWarning
247+
analysis_server/test/services/completion/prefixed_element_contributor_test: StaticWarning
248+
analysis_server/test/services/correction/assist_test: StaticWarning
249+
analysis_server/test/services/correction/change_test: StaticWarning
250+
analysis_server/test/services/correction/fix_test: StaticWarning
251+
analysis_server/test/services/correction/name_suggestion_test: StaticWarning
252+
analysis_server/test/services/correction/sort_members_test: StaticWarning
253+
analysis_server/test/services/correction/source_range_test: StaticWarning
254+
analysis_server/test/services/correction/status_test: StaticWarning
255+
analysis_server/test/services/dependencies/library_dependencies_test: StaticWarning
256+
analysis_server/test/services/index/dart_index_contributor_test: StaticWarning
257+
analysis_server/test/services/index/local_file_index_test: StaticWarning
258+
analysis_server/test/services/index/local_index_test: StaticWarning
259+
analysis_server/test/services/index/store/codec_test: StaticWarning
260+
analysis_server/test/services/index/store/split_store_test: StaticWarning
261+
analysis_server/test/services/index/store/temporary_folder_file_manager_test: StaticWarning
262+
analysis_server/test/services/refactoring/convert_getter_to_method_test: StaticWarning
263+
analysis_server/test/services/refactoring/convert_method_to_getter_test: StaticWarning
264+
analysis_server/test/services/refactoring/extract_local_test: StaticWarning
265+
analysis_server/test/services/refactoring/extract_method_test: StaticWarning
266+
analysis_server/test/services/refactoring/inline_local_test: StaticWarning
267+
analysis_server/test/services/refactoring/inline_method_test: StaticWarning
268+
analysis_server/test/services/refactoring/move_file_test: StaticWarning
269+
analysis_server/test/services/refactoring/naming_conventions_test: StaticWarning
270+
analysis_server/test/services/refactoring/rename_class_member_test: StaticWarning
271+
analysis_server/test/services/refactoring/rename_constructor_test: StaticWarning
272+
analysis_server/test/services/refactoring/rename_import_test: StaticWarning
273+
analysis_server/test/services/refactoring/rename_label_test: StaticWarning
274+
analysis_server/test/services/refactoring/rename_library_test: StaticWarning
275+
analysis_server/test/services/refactoring/rename_local_test: StaticWarning
276+
analysis_server/test/services/refactoring/rename_unit_member_test: StaticWarning
277+
analysis_server/test/services/search/hierarchy_test: StaticWarning
278+
analysis_server/test/services/search/search_engine_test: StaticWarning
279+
analysis_server/test/socket_server_test: StaticWarning
280+
analysis_server/test/source/caching_put_package_map_provider_test: StaticWarning
281+
analysis_server/test/source/optimizing_pub_package_map_provider_test: StaticWarning
282+
analysis_server/test/src/utilities/change_builder_core_test: StaticWarning
283+
analysis_server/test/src/utilities/change_builder_dart_test: StaticWarning
284+
analyzer/test/enum_test: StaticWarning
285+
analyzer/test/file_system/memory_file_system_test: StaticWarning
286+
analyzer/test/file_system/physical_resource_provider_test: StaticWarning
287+
analyzer/test/file_system/resource_uri_resolver_test: StaticWarning
288+
analyzer/test/generated/all_the_rest_test: StaticWarning
289+
analyzer/test/generated/ast_test: StaticWarning
290+
analyzer/test/generated/compile_time_error_code_test: StaticWarning
291+
analyzer/test/generated/element_test: StaticWarning
292+
analyzer/test/generated/engine_test: StaticWarning
293+
analyzer/test/generated/incremental_resolver_test: StaticWarning
294+
analyzer/test/generated/incremental_scanner_test: StaticWarning
295+
analyzer/test/generated/non_error_resolver_test: StaticWarning
296+
analyzer/test/generated/parser_test: StaticWarning
297+
analyzer/test/generated/resolver_test: StaticWarning
298+
analyzer/test/generated/scanner_test: StaticWarning
299+
analyzer/test/generated/source_factory_test: StaticWarning
300+
analyzer/test/generated/static_type_warning_code_test: StaticWarning
301+
analyzer/test/generated/static_warning_code_test: StaticWarning
302+
analyzer/test/generated/type_system_test: StaticWarning
303+
analyzer/test/generated/utilities_test: StaticWarning
304+
analyzer/test/instrumentation/instrumentation_test: StaticWarning
305+
analyzer/test/parse_compilation_unit_test: StaticWarning
306+
analyzer/test/source/package_map_provider_test: StaticWarning
307+
analyzer/test/source/package_map_resolver_test: StaticWarning
308+
analyzer/test/src/context/cache_test: StaticWarning
309+
analyzer/test/src/context/context_test: StaticWarning
310+
analyzer/test/src/task/dart_test: StaticWarning
311+
analyzer/test/src/task/dart_work_manager_test: StaticWarning
312+
analyzer/test/src/task/driver_test: StaticWarning
313+
analyzer/test/src/task/general_test: StaticWarning
314+
analyzer/test/src/task/html_test: StaticWarning
315+
analyzer/test/src/task/html_work_manager_test: StaticWarning
316+
analyzer/test/src/task/incremental_element_builder_test: StaticWarning
317+
analyzer/test/src/task/inputs_test: StaticWarning
318+
analyzer/test/src/task/manager_test: StaticWarning
319+
analyzer/test/src/task/model_test: StaticWarning
320+
analyzer/test/task/task_dart_test: StaticWarning

‎runtime/lib/core_patch.dart

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,3 +205,27 @@ class _SyncIterator implements Iterator {
205205
}
206206
}
207207
}
208+
209+
patch class Resource {
210+
/* patch */ const factory Resource(String uri) = _Resource;
211+
}
212+
213+
class _Resource implements Resource {
214+
final String _location;
215+
216+
const _Resource(String uri) : _location = uri;
217+
218+
Uri get uri => Uri.base.resolve(_location);
219+
220+
Stream<List<int>> openRead() {
221+
throw new UnimplementedError("openRead");
222+
}
223+
224+
Future<List<int>> readAsBytes() {
225+
throw new UnimplementedError("readAsBytes");
226+
}
227+
228+
Future<String> readAsString({Encoding encoding}) {
229+
throw new UnimplementedError("readAsString");
230+
}
231+
}

‎runtime/lib/internal_patch.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ patch class CodeUnits {
2121

2222
final bool is64Bit = _inquireIs64Bit();
2323

24-
bool _inquireIs64Bit() native "Internal_inquireIs64Bit";
24+
bool _inquireIs64Bit() native "Internal_inquireIs64Bit";

‎sdk/lib/_internal/compiler/js_lib/core_patch.dart

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,3 +510,71 @@ class Uri {
510510
throw new UnsupportedError("'Uri.base' is not supported");
511511
}
512512
}
513+
514+
@patch
515+
class Resource {
516+
@patch
517+
const factory Resource(String uri) = _Resource;
518+
}
519+
520+
Uri _resolvePackageUri(Uri packageUri) {
521+
assert(packageUri.scheme == "package");
522+
if (packageUri.hasAuthority) {
523+
throw new ArgumentError("Package-URI must not have a host: $packageUri");
524+
}
525+
var resolved = Uri.base.resolve("packages/${packageUri.path}");
526+
return resolved;
527+
}
528+
529+
class _Resource implements Resource {
530+
final String _location;
531+
532+
const _Resource(String uri) : _location = uri;
533+
534+
Uri get uri => Uri.base.resolve(_location);
535+
536+
Stream<List<int>> openRead() {
537+
Uri uri = this.uri;
538+
if (uri.scheme == "package") {
539+
uri = _resolvePackageUri(uri);
540+
}
541+
if (uri.scheme == "http" || uri.scheme == "https") {
542+
return _readAsStream(uri);
543+
}
544+
throw new StateError("Unable to find resource, unknown scheme: $_location");
545+
}
546+
547+
Future<List<int>> readAsBytes() {
548+
Uri uri = this.uri;
549+
if (uri.scheme == "package") {
550+
uri = _resolvePackageUri(uri);
551+
}
552+
if (uri.scheme == "http" || uri.scheme == "https") {
553+
return _readAsBytes(uri);
554+
}
555+
throw new StateError("Unable to find resource, unknown scheme: $_location");
556+
}
557+
558+
Future<String> readAsString({Encoding encoding: UTF8}) {
559+
Uri uri = this.uri;
560+
if (uri.scheme == "package") {
561+
uri = _resolvePackageUri(uri);
562+
}
563+
if (uri.scheme == "http" || uri.scheme == "https") {
564+
return _readAsString(uri);
565+
}
566+
throw new StateError("Unable to find resource, unknown scheme: $_location");
567+
}
568+
569+
Stream<List<int>> _readAsStream(Uri uri) {
570+
throw new UnimplementedError("Streaming bytes via HTTP");
571+
}
572+
573+
Future<List<int>> _readAsBytes(Uri uri) {
574+
throw new UnimplementedError("Reading bytes via HTTP");
575+
}
576+
577+
Future<String> _readAsString(Uri uri) {
578+
throw new UnimplementedError("Reading string via HTTP");
579+
}
580+
}

‎sdk/lib/core/core.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ import "dart:_internal" hide Symbol;
157157
import "dart:_internal" as internal show Symbol;
158158
import "dart:convert" show UTF8, LATIN1, Encoding;
159159
import "dart:math" show Random; // Used by List.shuffle.
160+
import "dart:async" show Stream, Future; // Used by Resource.
160161

161162
part "annotations.dart";
162163
part "bool.dart";
@@ -181,6 +182,7 @@ part "object.dart";
181182
part "pattern.dart";
182183
part "print.dart";
183184
part "regexp.dart";
185+
part "resource.dart";
184186
part "set.dart";
185187
part "sink.dart";
186188
part "stacktrace.dart";

‎sdk/lib/core/core_sources.gypi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
'pattern.dart',
3030
'print.dart',
3131
'regexp.dart',
32+
'resource.dart',
3233
'set.dart',
3334
'sink.dart',
3435
'stacktrace.dart',

‎sdk/lib/core/resource.dart

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
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.
4+
5+
part of dart.core;
6+
7+
/**
8+
* A resource that can be read into the program.
9+
*
10+
* A resource is data that can be located using a URI and read into
11+
* the program at runtime.
12+
* The URI may use the `package` scheme to read resources provided
13+
* along with package sources.
14+
*/
15+
abstract class Resource {
16+
/**
17+
* Creates a resource object with the given [uri] as location.
18+
*
19+
* The `uri` is a string containing a valid URI.
20+
* If the string is not a valid URI, using any of the functions on
21+
* the resource object will fail.
22+
*
23+
* The URI may be relative, in which case it will be resolved
24+
* against [Uri.base] before being used.
25+
*
26+
* The URI may use the `package` scheme, which is always supported.
27+
* Other schemes may also be supported where possible.
28+
*/
29+
external const factory Resource(String uri);
30+
31+
/**
32+
* The location `uri` of this resource.
33+
*
34+
* This is a [Uri] of the `uri` parameter given to the constructor.
35+
* If the parameter was not a valid URI, reading `uri` may fail.
36+
*/
37+
Uri get uri;
38+
39+
/** Read the resource content as a stream of bytes. */
40+
Stream<List<int>> openRead();
41+
42+
/** Read the resource content. */
43+
Future<List<int>> readAsBytes();
44+
45+
/**
46+
* Read the resource content as a string.
47+
*
48+
* The content is decoded into a string using an [Encoding].
49+
* If no other encoding is provided, it defaults to UTF-8.
50+
*/
51+
Future<String> readAsString({Encoding encoding});
52+
}

‎tests/try/poi/serialize_test.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,10 @@ final coreImports = [
531531
"name": "RegExp",
532532
"kind": "class"
533533
},
534+
{
535+
"name": "Resource",
536+
"kind": "class"
537+
},
534538
{
535539
"name": "Set",
536540
"kind": "class"

0 commit comments

Comments
 (0)
Please sign in to comment.