| 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 * A library for extracting the documentation from the various HTML libraries | 6 * A library for extracting the documentation from the various HTML libraries |
| 7 * ([dart:html], [dart:svg], [dart:web_audio], [dart:indexed_db]) and saving | 7 * ([dart:html], [dart:svg], [dart:web_audio], [dart:indexed_db]) and saving |
| 8 * those documentation comments to a JSON file. | 8 * those documentation comments to a JSON file. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 library docs; | 11 library docs; |
| 12 | 12 |
| 13 import '../../../../sdk/lib/_internal/dartdoc/lib/src/dart2js_mirrors.dart'; | 13 import '../../../../sdk/lib/_internal/dartdoc/lib/src/dart2js_mirrors.dart'; |
| 14 import '../../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors.da
rt'; | 14 import '../../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors.da
rt'; |
| 15 import '../../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors_ut
il.dart'; |
| 15 import '../../../../sdk/lib/_internal/dartdoc/lib/dartdoc.dart'; | 16 import '../../../../sdk/lib/_internal/dartdoc/lib/dartdoc.dart'; |
| 16 import '../../../../sdk/lib/_internal/dartdoc/lib/src/json_serializer.dart'; | 17 import '../../../../sdk/lib/_internal/dartdoc/lib/src/json_serializer.dart'; |
| 17 import '../../../../utils/apidoc/lib/metadata.dart'; | 18 import '../../../../utils/apidoc/lib/metadata.dart'; |
| 18 import 'dart:async'; | 19 import 'dart:async'; |
| 19 import 'dart:io'; | 20 import 'dart:io'; |
| 20 | 21 |
| 21 /// The various HTML libraries. | 22 /// The various HTML libraries. |
| 22 const List<String> HTML_LIBRARY_NAMES = const ['dart:html', | 23 const List<String> HTML_LIBRARY_NAMES = const ['dart:html', |
| 23 'dart:indexed_db', | 24 'dart:indexed_db', |
| 24 'dart:svg', | 25 'dart:svg', |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 | 81 |
| 81 // Sort the libraries by name (not key). | 82 // Sort the libraries by name (not key). |
| 82 var sortedLibraries = new List<LibraryMirror>.from( | 83 var sortedLibraries = new List<LibraryMirror>.from( |
| 83 mirrors.libraries.values.where( | 84 mirrors.libraries.values.where( |
| 84 (e) => HTML_LIBRARY_NAMES.indexOf(e.uri.toString()) >= 0)) | 85 (e) => HTML_LIBRARY_NAMES.indexOf(e.uri.toString()) >= 0)) |
| 85 ..sort((x, y) => | 86 ..sort((x, y) => |
| 86 x.uri.toString().toUpperCase().compareTo( | 87 x.uri.toString().toUpperCase().compareTo( |
| 87 y.uri.toString().toUpperCase())); | 88 y.uri.toString().toUpperCase())); |
| 88 | 89 |
| 89 for (LibraryMirror libMirror in sortedLibraries) { | 90 for (LibraryMirror libMirror in sortedLibraries) { |
| 90 print('Extracting documentation from ${libMirror.displayName}.'); | 91 print('Extracting documentation from ${libMirror.simpleName}.'); |
| 91 | 92 |
| 92 var libraryJson = {}; | 93 var libraryJson = {}; |
| 93 var sortedClasses = _sortAndFilterMirrors( | 94 var sortedClasses = _sortAndFilterMirrors( |
| 94 libMirror.classes.values.toList(), ignoreDocsEditable: true); | 95 libMirror.classes.values.toList(), ignoreDocsEditable: true); |
| 95 | 96 |
| 96 for (ClassMirror classMirror in sortedClasses) { | 97 for (ClassMirror classMirror in sortedClasses) { |
| 97 var classJson = {}; | 98 var classJson = {}; |
| 98 var sortedMembers = _sortAndFilterMirrors( | 99 var sortedMembers = _sortAndFilterMirrors( |
| 99 classMirror.members.values.toList()); | 100 classMirror.members.values.toList()); |
| 100 | 101 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 127 membersJson); | 128 membersJson); |
| 128 } | 129 } |
| 129 | 130 |
| 130 if (!classJson.isEmpty) { | 131 if (!classJson.isEmpty) { |
| 131 libraryJson.putIfAbsent(domNames(classMirror)[0], () => | 132 libraryJson.putIfAbsent(domNames(classMirror)[0], () => |
| 132 classJson); | 133 classJson); |
| 133 } | 134 } |
| 134 } | 135 } |
| 135 | 136 |
| 136 if (!libraryJson.isEmpty) { | 137 if (!libraryJson.isEmpty) { |
| 137 convertedJson.putIfAbsent(libMirror.displayName, () => | 138 convertedJson.putIfAbsent(libMirror.simpleName, () => |
| 138 libraryJson); | 139 libraryJson); |
| 139 } | 140 } |
| 140 } | 141 } |
| 141 | 142 |
| 142 return convertedJson; | 143 return convertedJson; |
| 143 } | 144 } |
| 144 | 145 |
| 145 /// Filter out mirrors that are private, or which are not part of this docs | 146 /// Filter out mirrors that are private, or which are not part of this docs |
| 146 /// process. That is, ones without the DocsEditable annotation. | 147 /// process. That is, ones without the DocsEditable annotation. |
| 147 /// If [ignoreDocsEditable] is true, relax the restriction on @DocsEditable. | 148 /// If [ignoreDocsEditable] is true, relax the restriction on @DocsEditable. |
| 148 /// This is to account for classes that are defined in a template, but whose | 149 /// This is to account for classes that are defined in a template, but whose |
| 149 /// members are generated. | 150 /// members are generated. |
| 150 List<DeclarationMirror> _sortAndFilterMirrors(List<DeclarationMirror> mirrors, | 151 List<DeclarationMirror> _sortAndFilterMirrors(List<DeclarationMirror> mirrors, |
| 151 {ignoreDocsEditable: false}) { | 152 {ignoreDocsEditable: false}) { |
| 152 | 153 |
| 153 var filteredMirrors = mirrors.where((DeclarationMirror c) => | 154 var filteredMirrors = mirrors.where((DeclarationMirror c) => |
| 154 !domNames(c).isEmpty && | 155 !domNames(c).isEmpty && |
| 155 !c.displayName.startsWith('_') && | 156 !displayName(c).startsWith('_') && |
| 156 (!ignoreDocsEditable ? (findMetadata(c.metadata, 'DocsEditable') != null) | 157 (!ignoreDocsEditable ? (findMetadata(c.metadata, 'DocsEditable') != null) |
| 157 : true)) | 158 : true)) |
| 158 .toList(); | 159 .toList(); |
| 159 | 160 |
| 160 filteredMirrors.sort((x, y) => | 161 filteredMirrors.sort((x, y) => |
| 161 domNames(x)[0].toUpperCase().compareTo( | 162 domNames(x)[0].toUpperCase().compareTo( |
| 162 domNames(y)[0].toUpperCase())); | 163 domNames(y)[0].toUpperCase())); |
| 163 | 164 |
| 164 return filteredMirrors; | 165 return filteredMirrors; |
| 165 } | 166 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 184 for (var s in tags.reflectee.split(',')) { | 185 for (var s in tags.reflectee.split(',')) { |
| 185 domNames.add(s.trim()); | 186 domNames.add(s.trim()); |
| 186 } | 187 } |
| 187 | 188 |
| 188 if (domNames.length == 1 && domNames[0] == 'none') return <String>[]; | 189 if (domNames.length == 1 && domNames[0] == 'none') return <String>[]; |
| 189 return domNames; | 190 return domNames; |
| 190 } else { | 191 } else { |
| 191 return <String>[]; | 192 return <String>[]; |
| 192 } | 193 } |
| 193 } | 194 } |
| OLD | NEW |