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

Side by Side Diff: pkg/front_end/lib/src/base/uri_kind.dart

Issue 2486923007: Create pkg/front_end/src/base and begin populating with general use classes. (Closed)
Patch Set: Fix formatting Created 4 years, 1 month 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
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 /**
6 * The enumeration `UriKind` defines the different kinds of URI's that are known to the
7 * analysis engine. These are used to keep track of the kind of URI associated w ith a given source.
8 */
9 class UriKind implements Comparable<UriKind> {
10 /**
11 * A 'dart:' URI.
12 */
13 static const UriKind DART_URI = const UriKind('DART_URI', 0, 0x64);
14
15 /**
16 * A 'file:' URI.
17 */
18 static const UriKind FILE_URI = const UriKind('FILE_URI', 1, 0x66);
19
20 /**
21 * A 'package:' URI.
22 */
23 static const UriKind PACKAGE_URI = const UriKind('PACKAGE_URI', 2, 0x70);
24
25 static const List<UriKind> values = const [DART_URI, FILE_URI, PACKAGE_URI];
26
27 /**
28 * The name of this URI kind.
29 */
30 final String name;
31
32 /**
33 * The ordinal value of the URI kind.
34 */
35 final int ordinal;
36
37 /**
38 * The single character encoding used to identify this kind of URI.
39 */
40 final int encoding;
41
42 /**
43 * Initialize a newly created URI kind to have the given encoding.
44 */
45 const UriKind(this.name, this.ordinal, this.encoding);
46
47 @override
48 int get hashCode => ordinal;
49
50 @override
51 int compareTo(UriKind other) => ordinal - other.ordinal;
52
53 @override
54 String toString() => name;
55
56 /**
57 * Return the URI kind represented by the given [encoding], or `null` if there
58 * is no kind with the given encoding.
59 */
60 static UriKind fromEncoding(int encoding) {
61 while (true) {
62 if (encoding == 0x64) {
63 return DART_URI;
64 } else if (encoding == 0x66) {
65 return FILE_URI;
66 } else if (encoding == 0x70) {
67 return PACKAGE_URI;
68 }
69 break;
70 }
71 return null;
72 }
73
74 /**
75 * Return the URI kind corresponding to the given scheme string.
76 */
77 static UriKind fromScheme(String scheme) {
78 if (scheme == 'package') {
79 return UriKind.PACKAGE_URI;
80 } else if (scheme == 'dart') {
81 return UriKind.DART_URI;
82 } else if (scheme == 'file') {
83 return UriKind.FILE_URI;
84 }
85 return UriKind.FILE_URI;
86 }
87 }
OLDNEW
« no previous file with comments | « pkg/front_end/lib/src/base/timestamped_data.dart ('k') | pkg/front_end/lib/src/scanner/errors.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698