Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(514)

Side by Side Diff: pkg/docgen/lib/src/generator.dart

Issue 237343002: pkg/docgen: sort output files (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/docgen/bin/docgen.dart ('k') | pkg/docgen/lib/src/model_helpers.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 docgen.generator; 5 library docgen.generator;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection';
8 import 'dart:convert'; 9 import 'dart:convert';
9 import 'dart:io'; 10 import 'dart:io';
10 11
11 import 'package:markdown/markdown.dart' as markdown; 12 import 'package:markdown/markdown.dart' as markdown;
12 import 'package:path/path.dart' as path; 13 import 'package:path/path.dart' as path;
13 14
14 import '../../../../sdk/lib/_internal/compiler/compiler.dart' as api; 15 import '../../../../sdk/lib/_internal/compiler/compiler.dart' as api;
15 import '../../../../sdk/lib/_internal/compiler/implementation/filenames.dart'; 16 import '../../../../sdk/lib/_internal/compiler/implementation/filenames.dart';
16 import '../../../../sdk/lib/_internal/compiler/implementation/mirrors/analyze.da rt' 17 import '../../../../sdk/lib/_internal/compiler/implementation/mirrors/analyze.da rt'
17 as dart2js; 18 as dart2js;
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 var introText = defaultText; 165 var introText = defaultText;
165 if (fileName.isNotEmpty) { 166 if (fileName.isNotEmpty) {
166 var introFile = new File(fileName); 167 var introFile = new File(fileName);
167 introText = introFile.existsSync() ? introFile.readAsStringSync() : 168 introText = introFile.existsSync() ? introFile.readAsStringSync() :
168 defaultText; 169 defaultText;
169 } 170 }
170 return markdown.markdownToHtml(introText, linkResolver: linkResolver, 171 return markdown.markdownToHtml(introText, linkResolver: linkResolver,
171 inlineSyntaxes: MARKDOWN_SYNTAXES); 172 inlineSyntaxes: MARKDOWN_SYNTAXES);
172 } 173 }
173 174
175 int _indexableComparer(Indexable a, Indexable b) {
176 if (a is Library && b is Library) {
177 var compare = a.packageName.compareTo(b.packageName);
178 if (compare == 0) {
179 compare = a.name.compareTo(b.name);
180 }
181 return compare;
182 }
183
184 if (a is Library) return -1;
185 if (b is Library) return 1;
186
187 return a.qualifiedName.compareTo(b.qualifiedName);
188 }
Alan Knight 2014/04/14 17:33:30 Why can't we just compare the qualified name of li
kevmoo 2014/04/14 17:35:37 Because core libraries don't have a qualified pref
189
174 /// Creates documentation for filtered libraries. 190 /// Creates documentation for filtered libraries.
175 void _documentLibraries(List<LibraryMirror> libs, {bool includeSdk: false, bool 191 void _documentLibraries(List<LibraryMirror> libs, {bool includeSdk: false, bool
176 outputToYaml: true, bool append: false, bool parseSdk: false, String 192 outputToYaml: true, bool append: false, bool parseSdk: false, String
177 introFileName: '', String startPage}) { 193 introFileName: '', String startPage}) {
178 libs.forEach((lib) { 194 libs.forEach((lib) {
179 // Files belonging to the SDK have a uri that begins with 'dart:'. 195 // Files belonging to the SDK have a uri that begins with 'dart:'.
180 if (includeSdk || !lib.uri.toString().startsWith('dart:')) { 196 if (includeSdk || !lib.uri.toString().startsWith('dart:')) {
181 generateLibrary(lib); 197 generateLibrary(lib);
182 } 198 }
183 }); 199 });
184 200
185 var filteredEntities = new Set<Indexable>(); 201 var filteredEntities = new SplayTreeSet<Indexable>(_indexableComparer);
186 for (Map<String, Set<Indexable>> firstLevel in mirrorToDocgen.values) { 202 for (Map<String, Set<Indexable>> firstLevel in mirrorToDocgen.values) {
187 for (Set<Indexable> items in firstLevel.values) { 203 for (Set<Indexable> items in firstLevel.values) {
188 for (Indexable item in items) { 204 for (Indexable item in items) {
189 if (isFullChainVisible(item)) { 205 if (isFullChainVisible(item)) {
190 if (item is! Method || 206 if (item is! Method ||
191 (item is Method && item.methodInheritedFrom == null)) { 207 (item is Method && item.methodInheritedFrom == null)) {
192 filteredEntities.add(item); 208 filteredEntities.add(item);
193 } 209 }
194 } 210 }
195 } 211 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 filteredEntities.where((e) => e is Class || e is Library).forEach((output) { 254 filteredEntities.where((e) => e is Class || e is Library).forEach((output) {
239 _writeIndexableToFile(output, outputToYaml); 255 _writeIndexableToFile(output, outputToYaml);
240 }); 256 });
241 257
242 // Outputs all the qualified names documented with their type. 258 // Outputs all the qualified names documented with their type.
243 // This will help generate search results. 259 // This will help generate search results.
244 var sortedEntities = filteredEntities.map((e) => 260 var sortedEntities = filteredEntities.map((e) =>
245 '${e.qualifiedName} ${e.typeName}').toList()..sort(); 261 '${e.qualifiedName} ${e.typeName}').toList()..sort();
246 262
247 _writeToFile(sortedEntities.join('\n') + '\n', 'index.txt', append: append); 263 _writeToFile(sortedEntities.join('\n') + '\n', 'index.txt', append: append);
248 var index = new Map.fromIterables(filteredEntities.map((e) => e.qualifiedName 264 var index = new SplayTreeMap.fromIterable(filteredEntities,
249 ), filteredEntities.map((e) => e.typeName)); 265 key: (e) => e.qualifiedName, value: (e) => e.typeName);
266
250 if (append) { 267 if (append) {
251 var previousIndex = JSON.decode(new File('$_outputDirectory/index.json' 268 var previousIndex = JSON.decode(new File('$_outputDirectory/index.json'
252 ).readAsStringSync()); 269 ).readAsStringSync());
253 index.addAll(previousIndex); 270 index.addAll(previousIndex);
254 } 271 }
255 _writeToFile(JSON.encode(index), 'index.json'); 272 _writeToFile(JSON.encode(index), 'index.json');
256 } 273 }
257 274
258 /// Helper method to serialize the given Indexable out to a file. 275 /// Helper method to serialize the given Indexable out to a file.
259 void _writeIndexableToFile(Indexable result, bool outputToYaml) { 276 void _writeIndexableToFile(Indexable result, bool outputToYaml) {
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 return sdk; 448 return sdk;
432 } 449 }
433 450
434 /// Currently left public for testing purposes. :-/ 451 /// Currently left public for testing purposes. :-/
435 void generateLibrary(dart2js_mirrors.Dart2JsLibraryMirror library) { 452 void generateLibrary(dart2js_mirrors.Dart2JsLibraryMirror library) {
436 var result = new Library(library); 453 var result = new Library(library);
437 result.updateLibraryPackage(library); 454 result.updateLibraryPackage(library);
438 logger.fine('Generated library for ${result.name}'); 455 logger.fine('Generated library for ${result.name}');
439 } 456 }
440 457
441
442 /// If we can't find the SDK introduction text, which will happen if running 458 /// If we can't find the SDK introduction text, which will happen if running
443 /// from a snapshot and using --parse-sdk or --include-sdk, then use this 459 /// from a snapshot and using --parse-sdk or --include-sdk, then use this
444 /// hard-coded version. This should be updated to be consistent with the text 460 /// hard-coded version. This should be updated to be consistent with the text
445 /// in docgen/doc/sdk-introduction.md 461 /// in docgen/doc/sdk-introduction.md
446 const _DEFAULT_SDK_INTRODUCTION = 462 const _DEFAULT_SDK_INTRODUCTION =
447 """ 463 """
448 Welcome to the Dart API reference documentation, 464 Welcome to the Dart API reference documentation,
449 covering the official Dart API libraries. 465 covering the official Dart API libraries.
450 Some of the most fundamental Dart libraries include: 466 Some of the most fundamental Dart libraries include:
451 467
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 * [Samples](http://www.dartlang.org/samples/) 499 * [Samples](http://www.dartlang.org/samples/)
484 * [A Tour of the Dart Libraries](http://www.dartlang.org/docs/dart-up-and-runn ing/contents/ch03.html) 500 * [A Tour of the Dart Libraries](http://www.dartlang.org/docs/dart-up-and-runn ing/contents/ch03.html)
485 501
486 This API reference is automatically generated from the source code in the 502 This API reference is automatically generated from the source code in the
487 [Dart project](https://code.google.com/p/dart/). 503 [Dart project](https://code.google.com/p/dart/).
488 If you'd like to contribute to this documentation, see 504 If you'd like to contribute to this documentation, see
489 [Contributing](https://code.google.com/p/dart/wiki/Contributing) 505 [Contributing](https://code.google.com/p/dart/wiki/Contributing)
490 and 506 and
491 [Writing API Documentation](https://code.google.com/p/dart/wiki/WritingApiDocume ntation). 507 [Writing API Documentation](https://code.google.com/p/dart/wiki/WritingApiDocume ntation).
492 """; 508 """;
OLDNEW
« no previous file with comments | « pkg/docgen/bin/docgen.dart ('k') | pkg/docgen/lib/src/model_helpers.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698