OLD | NEW |
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 name_validator; | 5 library name_validator; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:io'; | 8 import 'dart:io'; |
9 | 9 |
10 import '../../../pkg/path/lib/path.dart' as path; | 10 import '../../../pkg/path/lib/path.dart' as path; |
11 import '../entrypoint.dart'; | 11 import '../entrypoint.dart'; |
12 import '../io.dart'; | 12 import '../io.dart'; |
| 13 import '../utils.dart'; |
13 import '../validator.dart'; | 14 import '../validator.dart'; |
14 | 15 |
15 /// Dart reserved words, from the Dart spec. | 16 /// Dart reserved words, from the Dart spec. |
16 final _RESERVED_WORDS = [ | 17 final _RESERVED_WORDS = [ |
17 "abstract", "as", "dynamic", "export", "external", "factory", "get", | 18 "abstract", "as", "dynamic", "export", "external", "factory", "get", |
18 "implements", "import", "library", "operator", "part", "set", "static", | 19 "implements", "import", "library", "operator", "part", "set", "static", |
19 "typedef" | 20 "typedef" |
20 ]; | 21 ]; |
21 | 22 |
22 /// A validator that validates the name of the package and its libraries. | 23 /// A validator that validates the name of the package and its libraries. |
(...skipping 17 matching lines...) Expand all Loading... |
40 'the name of the package, "${entrypoint.root.name}".\n' | 41 'the name of the package, "${entrypoint.root.name}".\n' |
41 'This helps users know what library to import.'); | 42 'This helps users know what library to import.'); |
42 } | 43 } |
43 }); | 44 }); |
44 } | 45 } |
45 | 46 |
46 /// Returns a list of all libraries in the current package as paths relative | 47 /// Returns a list of all libraries in the current package as paths relative |
47 /// to the package's root directory. | 48 /// to the package's root directory. |
48 Future<List<String>> get _libraries { | 49 Future<List<String>> get _libraries { |
49 var libDir = join(entrypoint.root.dir, "lib"); | 50 var libDir = join(entrypoint.root.dir, "lib"); |
50 return dirExists(libDir).then((libDirExists) { | 51 return defer(() { |
51 if (!libDirExists) return []; | 52 if (!dirExists(libDir)) return []; |
52 return listDir(libDir, recursive: true); | 53 return listDir(libDir, recursive: true); |
53 }).then((files) { | 54 }).then((files) { |
54 return files | 55 return files |
55 .map((file) => relativeTo(file, dirname(libDir))) | 56 .map((file) => relativeTo(file, dirname(libDir))) |
56 .where((file) => !splitPath(file).contains("src") && | 57 .where((file) => !splitPath(file).contains("src") && |
57 path.extension(file) == '.dart') | 58 path.extension(file) == '.dart') |
58 .toList(); | 59 .toList(); |
59 }); | 60 }); |
60 } | 61 } |
61 | 62 |
(...skipping 23 matching lines...) Expand all Loading... |
85 builder | 86 builder |
86 ..add(source.substring(lastMatchEnd, match.start + 1)) | 87 ..add(source.substring(lastMatchEnd, match.start + 1)) |
87 ..add("_") | 88 ..add("_") |
88 ..add(match.group(1).toLowerCase()); | 89 ..add(match.group(1).toLowerCase()); |
89 lastMatchEnd = match.end; | 90 lastMatchEnd = match.end; |
90 } | 91 } |
91 builder.add(source.substring(lastMatchEnd)); | 92 builder.add(source.substring(lastMatchEnd)); |
92 return builder.toString().toLowerCase(); | 93 return builder.toString().toLowerCase(); |
93 } | 94 } |
94 } | 95 } |
OLD | NEW |