Chromium Code Reviews| 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 83 void _setCommandLineArguments(ArgResults argResults) { | 83 void _setCommandLineArguments(ArgResults argResults) { |
| 84 outputToYaml = argResults['yaml'] || argResults['output-format'] == 'yaml'; | 84 outputToYaml = argResults['yaml'] || argResults['output-format'] == 'yaml'; |
| 85 outputToJson = argResults['json'] || argResults['output-format'] == 'json'; | 85 outputToJson = argResults['json'] || argResults['output-format'] == 'json'; |
| 86 if (outputToYaml && outputToJson) { | 86 if (outputToYaml && outputToJson) { |
| 87 throw new ArgumentError('Cannot have contradictory output flags.'); | 87 throw new ArgumentError('Cannot have contradictory output flags.'); |
| 88 } | 88 } |
| 89 outputToYaml = outputToYaml || !outputToJson; | 89 outputToYaml = outputToYaml || !outputToJson; |
| 90 includePrivate = argResults['include-private']; | 90 includePrivate = argResults['include-private']; |
| 91 parseSdk = argResults['parse-sdk']; | 91 parseSdk = argResults['parse-sdk']; |
| 92 includeSdk = parseSdk || argResults['include-sdk']; | 92 includeSdk = parseSdk || argResults['include-sdk']; |
| 93 packageDir = argResults['package-root']; | |
| 94 if (packageDir != null) logger.info('Package Root: ${packageDir}'); | |
| 93 } | 95 } |
| 94 | 96 |
| 95 List<String> _listLibraries(List<String> args) { | 97 List<String> _listLibraries(List<String> args) { |
| 96 // TODO(janicejl): At the moment, only have support to have either one file, | 98 // TODO(janicejl): At the moment, only have support to have either one file, |
| 97 // or one directory. This is because there can only be one package directory | 99 // or one directory. This is because there can only be one package directory |
| 98 // since only one docgen is created per run. | 100 // since only one docgen is created per run. |
| 99 if (args.length != 1) throw new UnsupportedError(USAGE); | 101 if (args.length != 1) throw new UnsupportedError(USAGE); |
| 100 var libraries = new List<String>(); | 102 var libraries = new List<String>(); |
| 101 var type = FileSystemEntity.typeSync(args[0]); | 103 var type = FileSystemEntity.typeSync(args[0]); |
| 102 | 104 |
| 103 if (type == FileSystemEntityType.FILE) { | 105 if (type == FileSystemEntityType.FILE) { |
| 104 libraries.add(path.absolute(args[0])); | 106 libraries.add(path.absolute(args[0])); |
| 105 logger.info('Added to libraries: ${libraries.last}'); | 107 logger.info('Added to libraries: ${libraries.last}'); |
| 106 } else { | 108 } else { |
| 107 libraries.addAll(_listDartFromDir(args[0])); | 109 libraries.addAll(_listDartFromDir(args[0])); |
| 108 } | 110 } |
| 109 logger.info('Package Directory: $packageDir'); | |
| 110 return libraries; | 111 return libraries; |
| 111 } | 112 } |
| 112 | 113 |
| 113 List<String> _listDartFromDir(String args) { | 114 List<String> _listDartFromDir(String args) { |
| 114 var files = listDir(args, recursive: true); | 115 var files = listDir(args, recursive: true); |
| 115 packageDir = files.firstWhere((f) => | 116 if (packageDir == null) { |
| 116 f.endsWith('/pubspec.yaml'), orElse: () => ''); | 117 packageDir = files.firstWhere((f) => |
| 117 if (packageDir != '') packageDir = path.dirname(packageDir) + '/packages'; | 118 f.endsWith('/pubspec.yaml'), orElse: () => ''); |
| 118 return files.where((f) => | 119 if (packageDir != '') packageDir = path.dirname(packageDir) + '/packages'; |
| 119 f.endsWith('.dart') && !f.contains('/packages')).toList() | 120 logger.info('Package Directory: $packageDir'); |
| 121 } | |
| 122 // files with paths not containing '/packages' to avoid analyzing them twice, | |
|
Emily Fortuna
2013/07/01 18:51:57
files -> Files
also make this an actual sentence
janicejl
2013/07/01 18:59:23
Done.
| |
| 123 // unless the file to analyze already has a /package in its path. | |
| 124 return files.where((f) => f.endsWith('.dart') && | |
| 125 (!f.contains('/packages') || args.contains('/packages'))).toList() | |
| 120 ..forEach((lib) => logger.info('Added to libraries: $lib')); | 126 ..forEach((lib) => logger.info('Added to libraries: $lib')); |
| 121 } | 127 } |
| 122 | 128 |
| 123 List<String> _listSdk() { | 129 List<String> _listSdk() { |
| 124 var sdk = new List<String>(); | 130 var sdk = new List<String>(); |
| 125 LIBRARIES.forEach((String name, LibraryInfo info) { | 131 LIBRARIES.forEach((String name, LibraryInfo info) { |
| 126 if (info.documented) { | 132 if (info.documented) { |
| 127 sdk.add('dart:$name'); | 133 sdk.add('dart:$name'); |
| 128 logger.info('Add to SDK: ${sdk.last}'); | 134 logger.info('Add to SDK: ${sdk.last}'); |
| 129 } | 135 } |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 145 } else { | 151 } else { |
| 146 // If DART_SDK is not defined in the environment, | 152 // If DART_SDK is not defined in the environment, |
| 147 // assuming the dart executable is from the Dart SDK folder inside bin. | 153 // assuming the dart executable is from the Dart SDK folder inside bin. |
| 148 sdkRoot = path.dirname(path.dirname(new Options().executable)); | 154 sdkRoot = path.dirname(path.dirname(new Options().executable)); |
| 149 logger.info('SDK Root: ${sdkRoot}'); | 155 logger.info('SDK Root: ${sdkRoot}'); |
| 150 } | 156 } |
| 151 | 157 |
| 152 return _getMirrorSystemHelper(libraries, sdkRoot, packageRoot: packageDir); | 158 return _getMirrorSystemHelper(libraries, sdkRoot, packageRoot: packageDir); |
| 153 } | 159 } |
| 154 | 160 |
| 161 // TODO(janicejl): Should make docgen fail gracefully, or output a friendly | |
| 162 // error message letting them know why it is failing to create a mirror system. | |
| 163 // If there is conflicting library names, should modify it with a hash at the | |
| 164 // end of it's library name. | |
| 155 /** | 165 /** |
| 156 * Analyzes set of libraries and provides a mirror system which can be used | 166 * Analyzes set of libraries and provides a mirror system which can be used |
| 157 * for static inspection of the source code. | 167 * for static inspection of the source code. |
| 158 */ | 168 */ |
| 159 Future<MirrorSystem> _getMirrorSystemHelper(List<String> libraries, | 169 Future<MirrorSystem> _getMirrorSystemHelper(List<String> libraries, |
| 160 String libraryRoot, {String packageRoot}) { | 170 String libraryRoot, {String packageRoot}) { |
| 161 SourceFileProvider provider = new SourceFileProvider(); | 171 SourceFileProvider provider = new SourceFileProvider(); |
| 162 api.DiagnosticHandler diagnosticHandler = | 172 api.DiagnosticHandler diagnosticHandler = |
| 163 new FormattingDiagnosticHandler(provider).diagnosticHandler; | 173 new FormattingDiagnosticHandler(provider).diagnosticHandler; |
| 164 Uri libraryUri = currentDirectory.resolve(appendSlash('$libraryRoot')); | 174 Uri libraryUri = currentDirectory.resolve(appendSlash('$libraryRoot')); |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 536 parameterMap['qualifiedname'] = qualifiedName; | 546 parameterMap['qualifiedname'] = qualifiedName; |
| 537 parameterMap['optional'] = isOptional.toString(); | 547 parameterMap['optional'] = isOptional.toString(); |
| 538 parameterMap['named'] = isNamed.toString(); | 548 parameterMap['named'] = isNamed.toString(); |
| 539 parameterMap['default'] = hasDefaultValue.toString(); | 549 parameterMap['default'] = hasDefaultValue.toString(); |
| 540 parameterMap['type'] = type; | 550 parameterMap['type'] = type; |
| 541 parameterMap['value'] = defaultValue; | 551 parameterMap['value'] = defaultValue; |
| 542 parameterMap['annotations'] = new List.from(annotations); | 552 parameterMap['annotations'] = new List.from(annotations); |
| 543 return parameterMap; | 553 return parameterMap; |
| 544 } | 554 } |
| 545 } | 555 } |
| OLD | NEW |