Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(173)

Side by Side Diff: pkg/fasta/lib/src/translate_uri.dart

Issue 2634453004: Fasta infrastructure. (Closed)
Patch Set: Address review comments. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/fasta/lib/src/ticker.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library fasta.translate_uri;
6
7 import 'dart:async' show
8 Future;
9
10 import 'dart:io' show
11 File;
12
13 import 'package:package_config/packages_file.dart' as packages_file show
14 parse;
15
16 import 'errors.dart' show
17 internalError;
18
19 class TranslateUri {
20 final Map<String, Uri> packages;
21
22 TranslateUri(this.packages);
23
24 Uri translate(Uri uri) {
25 if (uri.scheme == "dart") return translateDartUri(uri);
26 if (uri.scheme == "package") return translatePackageUri(uri);
27 return null;
28 }
29
30 Uri translateDartUri(Uri uri) {
31 throw internalError("dart: URIs not implemented yet.");
32 }
33
34 Uri translatePackageUri(Uri uri) {
35 int index = uri.path.indexOf("/");
36 if (index == -1) return null;
37 String name = uri.path.substring(0, index);
38 String path = uri.path.substring(index + 1);
39 Uri root = packages[name];
40 if (root == null) return null;
41 return root.resolve(path);
42 }
43
44 static Future<TranslateUri> parse([Uri uri]) async {
45 uri ??= Uri.base.resolve(".packages");
46 File file = new File.fromUri(uri);
47 List<int> bytes = await file.readAsBytes();
48 Map<String, Uri> packages = packages_file.parse(bytes, uri);
49 return new TranslateUri(packages);
50 }
51 }
OLDNEW
« no previous file with comments | « pkg/fasta/lib/src/ticker.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698