Chromium Code Reviews| 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 11 matching lines...) Expand all Loading... | |
| 22 * Converts the libraries in [HTML_LIBRARY_NAMES] to a json file at [jsonPath] | 22 * Converts the libraries in [HTML_LIBRARY_NAMES] to a json file at [jsonPath] |
| 23 * given the library path at [libPath]. | 23 * given the library path at [libPath]. |
| 24 * | 24 * |
| 25 * The json output looks like: | 25 * The json output looks like: |
| 26 * { | 26 * { |
| 27 * $library_name: { | 27 * $library_name: { |
| 28 * $interface_name: { | 28 * $interface_name: { |
| 29 * comment: "$comment" | 29 * comment: "$comment" |
| 30 * members: { | 30 * members: { |
| 31 * $member: [ | 31 * $member: [ |
| 32 * $comment1, | 32 * [$comment1line1, |
| 33 * $comment1line2, | |
| 34 * ...], | |
| 33 * ... | 35 * ... |
| 34 * ], | 36 * ], |
| 35 * ... | 37 * ... |
| 36 * } | 38 * } |
| 37 * }, | 39 * }, |
| 38 * ... | 40 * ... |
| 39 * }, | 41 * }, |
| 40 * ... | 42 * ... |
| 41 * } | 43 * } |
| 42 * | 44 * |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 libMirror.classes.values.toList(), ignoreDocsEditable: true); | 90 libMirror.classes.values.toList(), ignoreDocsEditable: true); |
| 89 | 91 |
| 90 for (ClassMirror classMirror in sortedClasses) { | 92 for (ClassMirror classMirror in sortedClasses) { |
| 91 var classJson = {}; | 93 var classJson = {}; |
| 92 var sortedMembers = _sortAndFilterMirrors( | 94 var sortedMembers = _sortAndFilterMirrors( |
| 93 classMirror.members.values.toList()); | 95 classMirror.members.values.toList()); |
| 94 | 96 |
| 95 var membersJson = {}; | 97 var membersJson = {}; |
| 96 for (var memberMirror in sortedMembers) { | 98 for (var memberMirror in sortedMembers) { |
| 97 var memberDomName = domNames(memberMirror)[0]; | 99 var memberDomName = domNames(memberMirror)[0]; |
| 98 var memberComment = computeUntrimmedCommentAsList(memberMirror); | 100 var memberComment = _splitCommentsByNewline( |
| 101 computeUntrimmedCommentAsList(memberMirror)); | |
| 99 | 102 |
| 100 // Remove interface name from Dom Name. | 103 // Remove interface name from Dom Name. |
| 101 if (memberDomName.indexOf('.') >= 0) { | 104 if (memberDomName.indexOf('.') >= 0) { |
| 102 memberDomName = memberDomName.slice(memberDomName.indexOf('.') + 1); | 105 memberDomName = memberDomName.slice(memberDomName.indexOf('.') + 1); |
| 103 } | 106 } |
| 104 | 107 |
| 105 if (!memberComment.isEmpty) { | 108 if (!memberComment.isEmpty) { |
| 106 membersJson.putIfAbsent(memberDomName, () => memberComment); | 109 membersJson.putIfAbsent(memberDomName, () => memberComment); |
| 107 } | 110 } |
| 108 } | 111 } |
| 109 | 112 |
| 110 // Only include the comment if DocsEditable is set. | 113 // Only include the comment if DocsEditable is set. |
| 111 var classComment = computeUntrimmedCommentAsList(classMirror); | 114 var classComment = _splitCommentsByNewline( |
| 115 computeUntrimmedCommentAsList(classMirror)); | |
| 112 if (!classComment.isEmpty && | 116 if (!classComment.isEmpty && |
| 113 findMetadata(classMirror.metadata, 'DocsEditable') != null) { | 117 findMetadata(classMirror.metadata, 'DocsEditable') != null) { |
| 114 classJson.putIfAbsent('comment', () => classComment); | 118 classJson.putIfAbsent('comment', () => classComment); |
| 115 } | 119 } |
| 116 if (!membersJson.isEmpty) { | 120 if (!membersJson.isEmpty) { |
| 117 classJson.putIfAbsent('members', () => | 121 classJson.putIfAbsent('members', () => |
| 118 membersJson); | 122 membersJson); |
| 119 } | 123 } |
| 120 | 124 |
| 121 if (!classJson.isEmpty) { | 125 if (!classJson.isEmpty) { |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 148 : true)) | 152 : true)) |
| 149 .toList(); | 153 .toList(); |
| 150 | 154 |
| 151 filteredMirrors.sort((x, y) => | 155 filteredMirrors.sort((x, y) => |
| 152 domNames(x)[0].toUpperCase().compareTo( | 156 domNames(x)[0].toUpperCase().compareTo( |
| 153 domNames(y)[0].toUpperCase())); | 157 domNames(y)[0].toUpperCase())); |
| 154 | 158 |
| 155 return filteredMirrors; | 159 return filteredMirrors; |
| 156 } | 160 } |
| 157 | 161 |
| 162 List<String> _splitCommentsByNewline(List<String> comments) { | |
| 163 var out = []; | |
| 164 | |
| 165 comments.forEach((c) { | |
|
blois
2013/01/29 16:53:31
nit- I prefer for () loops over forEach for standa
| |
| 166 out.addAll(c.split(new RegExp('\n'))); | |
| 167 }); | |
| 168 | |
| 169 return out; | |
| 170 } | |
| 171 | |
| 158 /// Given the class mirror, returns the names found or an empty list. | 172 /// Given the class mirror, returns the names found or an empty list. |
| 159 List<String> domNames(DeclarationMirror mirror) { | 173 List<String> domNames(DeclarationMirror mirror) { |
| 160 var domNameMetadata = findMetadata(mirror.metadata, 'DomName'); | 174 var domNameMetadata = findMetadata(mirror.metadata, 'DomName'); |
| 161 | 175 |
| 162 if (domNameMetadata != null) { | 176 if (domNameMetadata != null) { |
| 163 var domNames = <String>[]; | 177 var domNames = <String>[]; |
| 164 var tags = deprecatedFutureValue(domNameMetadata.getField('name')); | 178 var tags = deprecatedFutureValue(domNameMetadata.getField('name')); |
| 165 for (var s in tags.reflectee.split(',')) { | 179 for (var s in tags.reflectee.split(',')) { |
| 166 domNames.add(s.trim()); | 180 domNames.add(s.trim()); |
| 167 } | 181 } |
| 168 | 182 |
| 169 if (domNames.length == 1 && domNames[0] == 'none') return <String>[]; | 183 if (domNames.length == 1 && domNames[0] == 'none') return <String>[]; |
| 170 return domNames; | 184 return domNames; |
| 171 } else { | 185 } else { |
| 172 return <String>[]; | 186 return <String>[]; |
| 173 } | 187 } |
| 174 } | 188 } |
| OLD | NEW |