OLD | NEW |
---|---|
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 path.context; | 5 library path.context; |
6 | 6 |
7 import 'internal_style.dart'; | 7 import 'internal_style.dart'; |
8 import 'style.dart'; | 8 import 'style.dart'; |
9 import 'parsed_path.dart'; | 9 import 'parsed_path.dart'; |
10 import 'path_exception.dart'; | 10 import 'path_exception.dart'; |
(...skipping 23 matching lines...) Expand all Loading... | |
34 if (style == null) { | 34 if (style == null) { |
35 style = Style.platform; | 35 style = Style.platform; |
36 } else if (style is! InternalStyle) { | 36 } else if (style is! InternalStyle) { |
37 throw new ArgumentError("Only styles defined by the path package are " | 37 throw new ArgumentError("Only styles defined by the path package are " |
38 "allowed."); | 38 "allowed."); |
39 } | 39 } |
40 | 40 |
41 return new Context._(style, current); | 41 return new Context._(style, current); |
42 } | 42 } |
43 | 43 |
44 Context._(this.style, this.current); | 44 /// Create a [Context] to be used internally within path. |
45 Context.internal() : style = Style.platform; | |
Bob Nystrom
2014/08/01 16:32:07
Since _current is final, don't you need to initial
Anders Johnsen
2014/08/04 06:33:14
It's auto-initialized to null.
Anders Johnsen
2014/08/04 06:58:07
Ha, nice one Anders... You are of cause right - fi
| |
46 | |
47 Context._(this.style, this._current); | |
45 | 48 |
46 /// The style of path that this context works with. | 49 /// The style of path that this context works with. |
47 final InternalStyle style; | 50 final InternalStyle style; |
48 | 51 |
49 /// The current directory that relative paths will be relative to. | 52 /// The current directory given when Context was created. If null, current |
50 final String current; | 53 /// directory is evaluated from 'p.current'. |
54 final String _current; | |
55 | |
56 /// The current directory that relative paths are relative to. | |
57 String get current => _current != null ? _current : p.current; | |
51 | 58 |
52 /// Gets the path separator for the context's [style]. On Mac and Linux, | 59 /// Gets the path separator for the context's [style]. On Mac and Linux, |
53 /// this is `/`. On Windows, it's `\`. | 60 /// this is `/`. On Windows, it's `\`. |
54 String get separator => style.separator; | 61 String get separator => style.separator; |
55 | 62 |
56 /// Creates a new path by appending the given path parts to [current]. | 63 /// Creates a new path by appending the given path parts to [current]. |
57 /// Equivalent to [join()] with [current] as the first argument. Example: | 64 /// Equivalent to [join()] with [current] as the first argument. Example: |
58 /// | 65 /// |
59 /// var context = new Context(current: '/root'); | 66 /// var context = new Context(current: '/root'); |
60 /// context.absolute('path', 'to', 'foo'); // -> '/root/path/to/foo' | 67 /// context.absolute('path', 'to', 'foo'); // -> '/root/path/to/foo' |
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
538 // Show the arguments. | 545 // Show the arguments. |
539 var message = new StringBuffer(); | 546 var message = new StringBuffer(); |
540 message.write("$method("); | 547 message.write("$method("); |
541 message.write(args.take(numArgs) | 548 message.write(args.take(numArgs) |
542 .map((arg) => arg == null ? "null" : '"$arg"') | 549 .map((arg) => arg == null ? "null" : '"$arg"') |
543 .join(", ")); | 550 .join(", ")); |
544 message.write("): part ${i - 1} was null, but part $i was not."); | 551 message.write("): part ${i - 1} was null, but part $i was not."); |
545 throw new ArgumentError(message.toString()); | 552 throw new ArgumentError(message.toString()); |
546 } | 553 } |
547 } | 554 } |
OLD | NEW |