OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 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 | 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 /// Holds a couple utility functions used at various places in the system. | 5 /// Holds a couple utility functions used at various places in the system. |
6 library dev_compiler.src.utils; | 6 library dev_compiler.src.utils; |
7 | 7 |
8 import 'dart:io'; | 8 import 'dart:io'; |
9 | 9 |
10 import 'package:path/path.dart' as path; | 10 import 'package:path/path.dart' as path; |
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 | 431 |
432 bool isDartMathMinMax(Element e) => | 432 bool isDartMathMinMax(Element e) => |
433 e is FunctionElement && | 433 e is FunctionElement && |
434 e.library.source.uri.toString() == 'dart:math' && | 434 e.library.source.uri.toString() == 'dart:math' && |
435 (e.name == 'min' || e.name == 'max'); | 435 (e.name == 'min' || e.name == 'max'); |
436 | 436 |
437 /// Parses an enum value out of a string. | 437 /// Parses an enum value out of a string. |
438 // TODO(ochafik): generic signature. | 438 // TODO(ochafik): generic signature. |
439 dynamic parseEnum(String s, List enumValues) => | 439 dynamic parseEnum(String s, List enumValues) => |
440 enumValues.firstWhere((v) => s == getEnumName(v), | 440 enumValues.firstWhere((v) => s == getEnumName(v), |
441 orElse: () => throw new ArgumentError( | 441 orElse: () => throw new ArgumentError('Unknown enum value: $s ' |
442 'Unknown enum value: $s ' | |
443 '(expected one of ${enumValues.map(getEnumName)})')); | 442 '(expected one of ${enumValues.map(getEnumName)})')); |
444 | 443 |
445 /// Gets the "simple" name of an enum value. | 444 /// Gets the "simple" name of an enum value. |
446 getEnumName(v) { | 445 getEnumName(v) { |
447 var parts = '$v'.split('.'); | 446 var parts = '$v'.split('.'); |
448 if (parts.length != 2 || !parts.every((p) => p.isNotEmpty)) { | 447 if (parts.length != 2 || !parts.every((p) => p.isNotEmpty)) { |
449 throw new ArgumentError('Invalid enum value: $v'); | 448 throw new ArgumentError('Invalid enum value: $v'); |
450 } | 449 } |
451 return parts[1]; | 450 return parts[1]; |
452 } | 451 } |
OLD | NEW |