| 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 |
| 11 import '../entrypoint.dart'; | 12 import '../entrypoint.dart'; |
| 12 import '../io.dart'; | 13 import '../io.dart'; |
| 13 import '../utils.dart'; | 14 import '../utils.dart'; |
| 14 import '../validator.dart'; | 15 import '../validator.dart'; |
| 15 | 16 |
| 16 /// Dart reserved words, from the Dart spec. | 17 /// Dart reserved words, from the Dart spec. |
| 17 final _RESERVED_WORDS = [ | 18 final _RESERVED_WORDS = [ |
| 18 "abstract", "as", "dynamic", "export", "external", "factory", "get", | 19 "abstract", "as", "dynamic", "export", "external", "factory", "get", |
| 19 "implements", "import", "library", "operator", "part", "set", "static", | 20 "implements", "import", "library", "operator", "part", "set", "static", |
| 20 "typedef" | 21 "typedef" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 46 | 47 |
| 47 /// Returns a list of all libraries in the current package as paths relative | 48 /// Returns a list of all libraries in the current package as paths relative |
| 48 /// to the package's root directory. | 49 /// to the package's root directory. |
| 49 Future<List<String>> get _libraries { | 50 Future<List<String>> get _libraries { |
| 50 var libDir = join(entrypoint.root.dir, "lib"); | 51 var libDir = join(entrypoint.root.dir, "lib"); |
| 51 return defer(() { | 52 return defer(() { |
| 52 if (!dirExists(libDir)) return []; | 53 if (!dirExists(libDir)) return []; |
| 53 return listDir(libDir, recursive: true); | 54 return listDir(libDir, recursive: true); |
| 54 }).then((files) { | 55 }).then((files) { |
| 55 return files | 56 return files |
| 56 .map((file) => relativeTo(file, dirname(libDir))) | 57 .map((file) => path.relative(file, from: path.dirname(libDir))) |
| 57 .where((file) => !splitPath(file).contains("src") && | 58 .where((file) => !splitPath(file).contains("src") && |
| 58 path.extension(file) == '.dart') | 59 path.extension(file) == '.dart') |
| 59 .toList(); | 60 .toList(); |
| 60 }); | 61 }); |
| 61 } | 62 } |
| 62 | 63 |
| 63 void _checkName(String name, String description) { | 64 void _checkName(String name, String description) { |
| 64 if (name == "") { | 65 if (name == "") { |
| 65 errors.add("$description may not be empty."); | 66 errors.add("$description may not be empty."); |
| 66 } else if (!new RegExp(r"^[a-zA-Z0-9_]*$").hasMatch(name)) { | 67 } else if (!new RegExp(r"^[a-zA-Z0-9_]*$").hasMatch(name)) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 86 builder | 87 builder |
| 87 ..add(source.substring(lastMatchEnd, match.start + 1)) | 88 ..add(source.substring(lastMatchEnd, match.start + 1)) |
| 88 ..add("_") | 89 ..add("_") |
| 89 ..add(match.group(1).toLowerCase()); | 90 ..add(match.group(1).toLowerCase()); |
| 90 lastMatchEnd = match.end; | 91 lastMatchEnd = match.end; |
| 91 } | 92 } |
| 92 builder.add(source.substring(lastMatchEnd)); | 93 builder.add(source.substring(lastMatchEnd)); |
| 93 return builder.toString().toLowerCase(); | 94 return builder.toString().toLowerCase(); |
| 94 } | 95 } |
| 95 } | 96 } |
| OLD | NEW |