| 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 /** | 5 /** |
| 6 * **docgen** is a tool for creating machine readable representations of Dart | 6 * **docgen** is a tool for creating machine readable representations of Dart |
| 7 * code metadata, including: classes, members, comments and annotations. | 7 * code metadata, including: classes, members, comments and annotations. |
| 8 * | 8 * |
| 9 * docgen is run on a `.dart` file or a directory containing `.dart` files. | 9 * docgen is run on a `.dart` file or a directory containing `.dart` files. |
| 10 * | 10 * |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 return true; | 106 return true; |
| 107 }); | 107 }); |
| 108 } | 108 } |
| 109 | 109 |
| 110 List<String> _listLibraries(List<String> args) { | 110 List<String> _listLibraries(List<String> args) { |
| 111 if (args.length != 1) throw new UnsupportedError(USAGE); | 111 if (args.length != 1) throw new UnsupportedError(USAGE); |
| 112 var libraries = new List<String>(); | 112 var libraries = new List<String>(); |
| 113 var type = FileSystemEntity.typeSync(args[0]); | 113 var type = FileSystemEntity.typeSync(args[0]); |
| 114 | 114 |
| 115 if (type == FileSystemEntityType.FILE) { | 115 if (type == FileSystemEntityType.FILE) { |
| 116 libraries.add(path.absolute(args[0])); | 116 if (args[0].endsWith('.dart')) { |
| 117 logger.info('Added to libraries: ${libraries.last}'); | 117 libraries.add(path.absolute(args[0])); |
| 118 logger.info('Added to libraries: ${libraries.last}'); |
| 119 } |
| 118 } else { | 120 } else { |
| 119 libraries.addAll(_listDartFromDir(args[0])); | 121 libraries.addAll(_listDartFromDir(args[0])); |
| 120 } | 122 } |
| 121 return libraries; | 123 return libraries; |
| 122 } | 124 } |
| 123 | 125 |
| 124 List<String> _listDartFromDir(String args) { | 126 List<String> _listDartFromDir(String args) { |
| 125 var files = listDir(args, recursive: true); | 127 var libraries = []; |
| 126 // To avoid anaylzing package files twice, only files with paths not | 128 // To avoid anaylzing package files twice, only files with paths not |
| 127 // containing '/packages' will be added. The only exception is if the file to | 129 // containing '/packages' will be added. The only exception is if the file to |
| 128 // analyze already has a '/package' in its path. | 130 // analyze already has a '/package' in its path. |
| 129 return files.where((f) => f.endsWith('.dart') && | 131 var files = listDir(args, recursive: true).where((f) => f.endsWith('.dart') && |
| 130 (!f.contains('${path.separator}packages') || | 132 (!f.contains('${path.separator}packages') || |
| 131 args.contains('${path.separator}packages'))).toList() | 133 args.contains('${path.separator}packages'))).toList(); |
| 132 ..forEach((lib) => logger.info('Added to libraries: $lib')); | 134 |
| 135 files.forEach((f) { |
| 136 // Only add the file if it does not contain 'part of' |
| 137 // TODO(janicejl): Remove when Issue(12406) is resolved. |
| 138 var contents = new File(f).readAsStringSync(); |
| 139 if (!(contents.contains(new RegExp('\npart of ')) || |
| 140 contents.startsWith(new RegExp('part of ')))) { |
| 141 libraries.add(f); |
| 142 logger.info('Added to libraries: $f'); |
| 143 } |
| 144 }); |
| 145 return libraries; |
| 133 } | 146 } |
| 134 | 147 |
| 135 String _findPackageRoot(String directory) { | 148 String _findPackageRoot(String directory) { |
| 136 var files = listDir(directory, recursive: true); | 149 var files = listDir(directory, recursive: true); |
| 137 // Return '' means that there was no pubspec.yaml and therefor no packageRoot. | 150 // Return '' means that there was no pubspec.yaml and therefor no packageRoot. |
| 138 String packageRoot = files.firstWhere((f) => | 151 String packageRoot = files.firstWhere((f) => |
| 139 f.endsWith('${path.separator}pubspec.yaml'), orElse: () => ''); | 152 f.endsWith('${path.separator}pubspec.yaml'), orElse: () => ''); |
| 140 if (packageRoot != '') { | 153 if (packageRoot != '') { |
| 141 packageRoot = path.join(path.dirname(packageRoot), 'packages'); | 154 packageRoot = path.join(path.dirname(packageRoot), 'packages'); |
| 142 } | 155 } |
| (...skipping 918 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1061 String qualifiedName; | 1074 String qualifiedName; |
| 1062 List<String> parameters; | 1075 List<String> parameters; |
| 1063 | 1076 |
| 1064 Annotation(this.qualifiedName, this.parameters); | 1077 Annotation(this.qualifiedName, this.parameters); |
| 1065 | 1078 |
| 1066 Map toMap() => { | 1079 Map toMap() => { |
| 1067 'name': qualifiedName, | 1080 'name': qualifiedName, |
| 1068 'parameters': parameters | 1081 'parameters': parameters |
| 1069 }; | 1082 }; |
| 1070 } | 1083 } |
| OLD | NEW |