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

Side by Side Diff: utils/pub/source_registry.dart

Issue 11638010: Convert /** comments to /// in pub. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Respond to review. Created 8 years 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 | Annotate | Revision Log
« no previous file with comments | « utils/pub/source.dart ('k') | utils/pub/system_cache.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 library source_registry; 5 library source_registry;
6 6
7 import 'source.dart'; 7 import 'source.dart';
8 8
9 /** 9 /// A class that keeps track of [Source]s used for installing packages.
10 * A class that keeps track of [Source]s used for installing packages.
11 */
12 class SourceRegistry { 10 class SourceRegistry {
13 final Map<String, Source> _map; 11 final Map<String, Source> _map;
14 Source _default; 12 Source _default;
15 13
16 /** 14 /// Creates a new registry with no packages registered.
17 * Creates a new registry with no packages registered.
18 */
19 SourceRegistry() : _map = <String, Source>{}; 15 SourceRegistry() : _map = <String, Source>{};
20 16
21 /** 17 /// Returns the default source, which is used when no source is specified.
22 * Returns the default source, which is used when no source is specified.
23 */
24 Source get defaultSource => _default; 18 Source get defaultSource => _default;
25 19
26 /** 20 /// Sets the default source. This takes a string, which must be the name of a
27 * Sets the default source. This takes a string, which must be the name of a 21 /// registered source.
28 * registered source.
29 */
30 void setDefault(String name) { 22 void setDefault(String name) {
31 if (!_map.containsKey(name)) { 23 if (!_map.containsKey(name)) {
32 // TODO(nweiz): Real error-handling system 24 // TODO(nweiz): Real error-handling system
33 throw 'Default source $name is not in the registry'; 25 throw 'Default source $name is not in the registry';
34 } 26 }
35 27
36 _default = _map[name]; 28 _default = _map[name];
37 } 29 }
38 30
39 /** 31 /// Registers a new source. This source may not have the same name as a source
40 * Registers a new source. This source may not have the same name as a source 32 /// that's already been registered.
41 * that's already been registered.
42 */
43 void register(Source source) { 33 void register(Source source) {
44 if (_map.containsKey(source.name)) { 34 if (_map.containsKey(source.name)) {
45 // TODO(nweiz): Real error-handling system 35 // TODO(nweiz): Real error-handling system
46 throw 'Source registry already has a source named ${source.name}'; 36 throw 'Source registry already has a source named ${source.name}';
47 } 37 }
48 38
49 _map[source.name] = source; 39 _map[source.name] = source;
50 } 40 }
51 41
52 /** 42 /// Returns `true` if there is a source named [name].
53 * Returns `true` if there is a source named [name].
54 */
55 bool contains(String name) => _map.containsKey(name); 43 bool contains(String name) => _map.containsKey(name);
56 44
57 /** 45 /// Returns the source named [name]. Throws an error if no such source has
58 * Returns the source named [name]. Throws an error if no such source has been 46 /// been registered. If [name] is null, returns the default source.
59 * registered. If [name] is null, returns the default source.
60 */
61 Source operator[](String name) { 47 Source operator[](String name) {
62 if (name == null) { 48 if (name == null) {
63 if (defaultSource != null) return defaultSource; 49 if (defaultSource != null) return defaultSource;
64 // TODO(nweiz): Real error-handling system 50 // TODO(nweiz): Real error-handling system
65 throw 'No default source has been registered'; 51 throw 'No default source has been registered';
66 } 52 }
67 if (_map.containsKey(name)) return _map[name]; 53 if (_map.containsKey(name)) return _map[name];
68 throw 'No source named $name is registered'; 54 throw 'No source named $name is registered';
69 } 55 }
70 } 56 }
OLDNEW
« no previous file with comments | « utils/pub/source.dart ('k') | utils/pub/system_cache.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698