| OLD | NEW |
| 1 /** | 1 /** |
| 2 * A library for extracting the documentation from the various HTML libraries | 2 * A library for extracting the documentation from the various HTML libraries |
| 3 * ([dart:html], [dart:svg], [dart:web_audio], [dart:indexed_db]) and saving | 3 * ([dart:html], [dart:svg], [dart:web_audio], [dart:indexed_db]) and saving |
| 4 * those documentation comments to a JSON file. | 4 * those documentation comments to a JSON file. |
| 5 */ | 5 */ |
| 6 | 6 |
| 7 library docs; | 7 library docs; |
| 8 | 8 |
| 9 import '../../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors.da
rt'; | 9 import '../../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors.da
rt'; |
| 10 import '../../../../sdk/lib/_internal/dartdoc/lib/src/json_serializer.dart'; | 10 import '../../../../sdk/lib/_internal/dartdoc/lib/src/json_serializer.dart'; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 (e) => HTML_LIBRARY_NAMES.indexOf(e.uri.toString()) >= 0)) | 78 (e) => HTML_LIBRARY_NAMES.indexOf(e.uri.toString()) >= 0)) |
| 79 ..sort((x, y) => | 79 ..sort((x, y) => |
| 80 x.uri.toString().toUpperCase().compareTo( | 80 x.uri.toString().toUpperCase().compareTo( |
| 81 y.uri.toString().toUpperCase())); | 81 y.uri.toString().toUpperCase())); |
| 82 | 82 |
| 83 for (LibraryMirror libMirror in sortedLibraries) { | 83 for (LibraryMirror libMirror in sortedLibraries) { |
| 84 print('Extracting documentation from ${libMirror.displayName}.'); | 84 print('Extracting documentation from ${libMirror.displayName}.'); |
| 85 | 85 |
| 86 var libraryJson = {}; | 86 var libraryJson = {}; |
| 87 var sortedClasses = _sortAndFilterMirrors( | 87 var sortedClasses = _sortAndFilterMirrors( |
| 88 libMirror.classes.values.toList()); | 88 libMirror.classes.values.toList(), ignoreDocsEditable: true); |
| 89 | 89 |
| 90 for (ClassMirror classMirror in sortedClasses) { | 90 for (ClassMirror classMirror in sortedClasses) { |
| 91 var classJson = {}; | 91 var classJson = {}; |
| 92 var sortedMembers = _sortAndFilterMirrors( | 92 var sortedMembers = _sortAndFilterMirrors( |
| 93 classMirror.members.values.toList()); | 93 classMirror.members.values.toList()); |
| 94 | 94 |
| 95 var membersJson = {}; | 95 var membersJson = {}; |
| 96 for (var memberMirror in sortedMembers) { | 96 for (var memberMirror in sortedMembers) { |
| 97 var memberDomName = domNames(memberMirror)[0]; | 97 var memberDomName = domNames(memberMirror)[0]; |
| 98 var memberComment = computeUntrimmedCommentAsList(memberMirror); | 98 var memberComment = computeUntrimmedCommentAsList(memberMirror); |
| 99 | 99 |
| 100 // Remove interface name from Dom Name. | 100 // Remove interface name from Dom Name. |
| 101 if (memberDomName.indexOf('.') >= 0) { | 101 if (memberDomName.indexOf('.') >= 0) { |
| 102 memberDomName = memberDomName.slice(memberDomName.indexOf('.') + 1); | 102 memberDomName = memberDomName.slice(memberDomName.indexOf('.') + 1); |
| 103 } | 103 } |
| 104 | 104 |
| 105 if (!memberComment.isEmpty) { | 105 if (!memberComment.isEmpty) { |
| 106 membersJson.putIfAbsent(memberDomName, () => memberComment); | 106 membersJson.putIfAbsent(memberDomName, () => memberComment); |
| 107 } | 107 } |
| 108 } | 108 } |
| 109 | 109 |
| 110 // Only include the comment if DocsEditable is set. |
| 110 var classComment = computeUntrimmedCommentAsList(classMirror); | 111 var classComment = computeUntrimmedCommentAsList(classMirror); |
| 111 if (!classComment.isEmpty) { | 112 if (!classComment.isEmpty && |
| 113 findMetadata(classMirror.metadata, 'DocsEditable') != null) { |
| 112 classJson.putIfAbsent('comment', () => classComment); | 114 classJson.putIfAbsent('comment', () => classComment); |
| 113 } | 115 } |
| 114 if (!membersJson.isEmpty) { | 116 if (!membersJson.isEmpty) { |
| 115 classJson.putIfAbsent('members', () => | 117 classJson.putIfAbsent('members', () => |
| 116 membersJson); | 118 membersJson); |
| 117 } | 119 } |
| 118 | 120 |
| 119 if (!classJson.isEmpty) { | 121 if (!classJson.isEmpty) { |
| 120 libraryJson.putIfAbsent(domNames(classMirror)[0], () => | 122 libraryJson.putIfAbsent(domNames(classMirror)[0], () => |
| 121 classJson); | 123 classJson); |
| 122 } | 124 } |
| 123 } | 125 } |
| 124 | 126 |
| 125 if (!libraryJson.isEmpty) { | 127 if (!libraryJson.isEmpty) { |
| 126 convertedJson.putIfAbsent(libMirror.displayName, () => | 128 convertedJson.putIfAbsent(libMirror.displayName, () => |
| 127 libraryJson); | 129 libraryJson); |
| 128 } | 130 } |
| 129 } | 131 } |
| 130 | 132 |
| 131 return convertedJson; | 133 return convertedJson; |
| 132 } | 134 } |
| 133 | 135 |
| 134 List<DeclarationMirror> _sortAndFilterMirrors(List<DeclarationMirror> mirrors) { | 136 /// Filter out mirrors that are private, or which are not part of this docs |
| 135 // Filter out mirrors that are private, or which are not part of this docs | 137 /// process. That is, ones without the DocsEditable annotation. |
| 136 // process. That is, ones without the DocsEditable annotation. | 138 /// If [ignoreDocsEditable] is true, relax the restriction on @DocsEditable. |
| 139 /// This is to account for classes that are defined in a template, but whose |
| 140 /// members are generated. |
| 141 List<DeclarationMirror> _sortAndFilterMirrors(List<DeclarationMirror> mirrors, |
| 142 {ignoreDocsEditable: false}) { |
| 143 |
| 137 var filteredMirrors = mirrors.where((DeclarationMirror c) => | 144 var filteredMirrors = mirrors.where((DeclarationMirror c) => |
| 138 !domNames(c).isEmpty && | 145 !domNames(c).isEmpty && |
| 139 !c.displayName.startsWith('_') && | 146 !c.displayName.startsWith('_') && |
| 140 (findMetadata(c.metadata, 'DocsEditable') != null)) | 147 (!ignoreDocsEditable ? (findMetadata(c.metadata, 'DocsEditable') != null) |
| 148 : true)) |
| 141 .toList(); | 149 .toList(); |
| 142 | 150 |
| 143 filteredMirrors.sort((x, y) => | 151 filteredMirrors.sort((x, y) => |
| 144 domNames(x)[0].toUpperCase().compareTo( | 152 domNames(x)[0].toUpperCase().compareTo( |
| 145 domNames(y)[0].toUpperCase())); | 153 domNames(y)[0].toUpperCase())); |
| 146 | 154 |
| 147 return filteredMirrors; | 155 return filteredMirrors; |
| 148 } | 156 } |
| 149 | 157 |
| 150 /// Given the class mirror, returns the names found or an empty list. | 158 /// Given the class mirror, returns the names found or an empty list. |
| 151 List<String> domNames(DeclarationMirror mirror) { | 159 List<String> domNames(DeclarationMirror mirror) { |
| 152 var domNameMetadata = findMetadata(mirror.metadata, 'DomName'); | 160 var domNameMetadata = findMetadata(mirror.metadata, 'DomName'); |
| 153 | 161 |
| 154 if (domNameMetadata != null) { | 162 if (domNameMetadata != null) { |
| 155 var domNames = <String>[]; | 163 var domNames = <String>[]; |
| 156 var tags = deprecatedFutureValue(domNameMetadata.getField('name')); | 164 var tags = deprecatedFutureValue(domNameMetadata.getField('name')); |
| 157 for (var s in tags.reflectee.split(',')) { | 165 for (var s in tags.reflectee.split(',')) { |
| 158 domNames.add(s.trim()); | 166 domNames.add(s.trim()); |
| 159 } | 167 } |
| 160 | 168 |
| 161 if (domNames.length == 1 && domNames[0] == 'none') return <String>[]; | 169 if (domNames.length == 1 && domNames[0] == 'none') return <String>[]; |
| 162 return domNames; | 170 return domNames; |
| 163 } else { | 171 } else { |
| 164 return <String>[]; | 172 return <String>[]; |
| 165 } | 173 } |
| 166 } | 174 } |
| OLD | NEW |