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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 /// Choose a canonical name from the library element. This is safe to use as a | 42 /// Choose a canonical name from the library element. This is safe to use as a |
43 /// namespace in JS and Dart code generation. This never uses the library's | 43 /// namespace in JS and Dart code generation. This never uses the library's |
44 /// name (the identifier in the `library` declaration) as it doesn't have any | 44 /// name (the identifier in the `library` declaration) as it doesn't have any |
45 /// meaningful rules enforced. | 45 /// meaningful rules enforced. |
46 String canonicalLibraryName(LibraryElement library) { | 46 String canonicalLibraryName(LibraryElement library) { |
47 var uri = library.source.uri; | 47 var uri = library.source.uri; |
48 var name = path.basenameWithoutExtension(uri.pathSegments.last); | 48 var name = path.basenameWithoutExtension(uri.pathSegments.last); |
49 return _toIdentifier(name); | 49 return _toIdentifier(name); |
50 } | 50 } |
51 | 51 |
| 52 String canonicalLibraryUri(LibraryElement library) { |
| 53 return '${library.source.uri}'; |
| 54 } |
| 55 |
52 /// Escape [name] to make it into a valid identifier. | 56 /// Escape [name] to make it into a valid identifier. |
53 String _toIdentifier(String name) { | 57 String _toIdentifier(String name) { |
54 if (name.length == 0) return r'$'; | 58 if (name.length == 0) return r'$'; |
55 | 59 |
56 // Escape any invalid characters | 60 // Escape any invalid characters |
57 StringBuffer buffer = null; | 61 StringBuffer buffer = null; |
58 for (int i = 0; i < name.length; i++) { | 62 for (int i = 0; i < name.length; i++) { |
59 var ch = name[i]; | 63 var ch = name[i]; |
60 var needsEscape = ch == r'$' || _invalidCharInIdentifier.hasMatch(ch); | 64 var needsEscape = ch == r'$' || _invalidCharInIdentifier.hasMatch(ch); |
61 if (needsEscape && buffer == null) { | 65 if (needsEscape && buffer == null) { |
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
461 int lineEnd = endLoc.offset; | 465 int lineEnd = endLoc.offset; |
462 int unitEnd = unit.endToken.end; | 466 int unitEnd = unit.endToken.end; |
463 int lineNum = lineInfo.getLocation(lineEnd).lineNumber; | 467 int lineNum = lineInfo.getLocation(lineEnd).lineNumber; |
464 while (lineEnd < unitEnd && | 468 while (lineEnd < unitEnd && |
465 lineInfo.getLocation(++lineEnd).lineNumber == lineNum); | 469 lineInfo.getLocation(++lineEnd).lineNumber == lineNum); |
466 | 470 |
467 var text = content.substring(start, end); | 471 var text = content.substring(start, end); |
468 var lineText = content.substring(lineStart, lineEnd); | 472 var lineText = content.substring(lineStart, lineEnd); |
469 return new SourceSpanWithContext(startLoc, endLoc, text, lineText); | 473 return new SourceSpanWithContext(startLoc, endLoc, text, lineText); |
470 } | 474 } |
OLD | NEW |