| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 script to assist in documenting the difference between the dart:html API | 6 * A script to assist in documenting the difference between the dart:html API |
| 7 * and the old DOM API. | 7 * and the old DOM API. |
| 8 */ | 8 */ |
| 9 #library('html_diff'); | 9 #library('html_diff'); |
| 10 | 10 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 * [HtmlDiff.initialize] should be called. | 96 * [HtmlDiff.initialize] should be called. |
| 97 */ | 97 */ |
| 98 void run() { | 98 void run() { |
| 99 LibraryMirror htmlLib = _mirrors.libraries[HTML_DECLARED_NAME]; | 99 LibraryMirror htmlLib = _mirrors.libraries[HTML_DECLARED_NAME]; |
| 100 if (htmlLib === null) { | 100 if (htmlLib === null) { |
| 101 warn('Could not find $HTML_LIBRARY_NAME'); | 101 warn('Could not find $HTML_LIBRARY_NAME'); |
| 102 return; | 102 return; |
| 103 } | 103 } |
| 104 for (InterfaceMirror htmlType in htmlLib.types.getValues()) { | 104 for (InterfaceMirror htmlType in htmlLib.types.getValues()) { |
| 105 final domTypes = htmlToDomTypes(htmlType); | 105 final domTypes = htmlToDomTypes(htmlType); |
| 106 if (domTypes.isEmpty()) continue; | 106 if (domTypes.isEmpty) continue; |
| 107 | 107 |
| 108 htmlTypesToDom.putIfAbsent(htmlType.qualifiedName, | 108 htmlTypesToDom.putIfAbsent(htmlType.qualifiedName, |
| 109 () => new Set()).addAll(domTypes); | 109 () => new Set()).addAll(domTypes); |
| 110 | 110 |
| 111 htmlType.declaredMembers.forEach( | 111 htmlType.declaredMembers.forEach( |
| 112 (_, m) => _addMemberDiff(m, domTypes)); | 112 (_, m) => _addMemberDiff(m, domTypes)); |
| 113 } | 113 } |
| 114 } | 114 } |
| 115 | 115 |
| 116 /** | 116 /** |
| 117 * Records the `@domName` to `dart:html` mapping for | 117 * Records the `@domName` to `dart:html` mapping for |
| 118 * [htmlMember] (from `dart:html`). [domTypes] are the | 118 * [htmlMember] (from `dart:html`). [domTypes] are the |
| 119 * `@domName` type values that correspond to [htmlMember]'s | 119 * `@domName` type values that correspond to [htmlMember]'s |
| 120 * defining type. | 120 * defining type. |
| 121 */ | 121 */ |
| 122 void _addMemberDiff(MemberMirror htmlMember, List<String> domTypes) { | 122 void _addMemberDiff(MemberMirror htmlMember, List<String> domTypes) { |
| 123 var domMembers = htmlToDomMembers(htmlMember, domTypes); | 123 var domMembers = htmlToDomMembers(htmlMember, domTypes); |
| 124 if (htmlMember == null && !domMembers.isEmpty()) { | 124 if (htmlMember == null && !domMembers.isEmpty) { |
| 125 warn('$HTML_LIBRARY_NAME member ' | 125 warn('$HTML_LIBRARY_NAME member ' |
| 126 '${htmlMember.surroundingDeclaration.simpleName}.' | 126 '${htmlMember.surroundingDeclaration.simpleName}.' |
| 127 '${htmlMember.simpleName} has no corresponding ' | 127 '${htmlMember.simpleName} has no corresponding ' |
| 128 '$HTML_LIBRARY_NAME member.'); | 128 '$HTML_LIBRARY_NAME member.'); |
| 129 } | 129 } |
| 130 | 130 |
| 131 if (htmlMember == null) return; | 131 if (htmlMember == null) return; |
| 132 if (!domMembers.isEmpty()) { | 132 if (!domMembers.isEmpty) { |
| 133 htmlToDom[htmlMember.qualifiedName] = domMembers; | 133 htmlToDom[htmlMember.qualifiedName] = domMembers; |
| 134 } | 134 } |
| 135 } | 135 } |
| 136 | 136 |
| 137 /** | 137 /** |
| 138 * Returns the `@domName` type values that correspond to | 138 * Returns the `@domName` type values that correspond to |
| 139 * [htmlType] from `dart:html`. This can be the empty list if no | 139 * [htmlType] from `dart:html`. This can be the empty list if no |
| 140 * correspondence is found. | 140 * correspondence is found. |
| 141 */ | 141 */ |
| 142 List<String> htmlToDomTypes(InterfaceMirror htmlType) { | 142 List<String> htmlToDomTypes(InterfaceMirror htmlType) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 165 final tags = _getTags(comments.find(htmlMember.location)); | 165 final tags = _getTags(comments.find(htmlMember.location)); |
| 166 if (tags.containsKey('domName')) { | 166 if (tags.containsKey('domName')) { |
| 167 var domNames = <String>[]; | 167 var domNames = <String>[]; |
| 168 for (var s in tags['domName'].split(',')) { | 168 for (var s in tags['domName'].split(',')) { |
| 169 domNames.add(s.trim()); | 169 domNames.add(s.trim()); |
| 170 } | 170 } |
| 171 if (domNames.length == 1 && domNames[0] == 'none') return new Set(); | 171 if (domNames.length == 1 && domNames[0] == 'none') return new Set(); |
| 172 final members = new Set(); | 172 final members = new Set(); |
| 173 domNames.forEach((name) { | 173 domNames.forEach((name) { |
| 174 var nameMembers = _membersFromName(name, domTypes); | 174 var nameMembers = _membersFromName(name, domTypes); |
| 175 if (nameMembers.isEmpty()) { | 175 if (nameMembers.isEmpty) { |
| 176 if (name.contains('.')) { | 176 if (name.contains('.')) { |
| 177 warn('no member $name'); | 177 warn('no member $name'); |
| 178 } else { | 178 } else { |
| 179 final options = <String>[]; | 179 final options = <String>[]; |
| 180 for (var t in domTypes) { | 180 for (var t in domTypes) { |
| 181 options.add('$t.$name'); | 181 options.add('$t.$name'); |
| 182 } | 182 } |
| 183 Strings.join(options, ' or '); | 183 Strings.join(options, ' or '); |
| 184 warn('no member $options'); | 184 warn('no member $options'); |
| 185 } | 185 } |
| 186 } | 186 } |
| 187 members.addAll(nameMembers); | 187 members.addAll(nameMembers); |
| 188 }); | 188 }); |
| 189 return members; | 189 return members; |
| 190 } | 190 } |
| 191 | 191 |
| 192 return new Set(); | 192 return new Set(); |
| 193 } | 193 } |
| 194 | 194 |
| 195 /** | 195 /** |
| 196 * Returns the `@domName` strings that are indicated by | 196 * Returns the `@domName` strings that are indicated by |
| 197 * [name]. [name] can be either an unqualified member name | 197 * [name]. [name] can be either an unqualified member name |
| 198 * (e.g. `createElement`), in which case it's treated as the name of | 198 * (e.g. `createElement`), in which case it's treated as the name of |
| 199 * a member of one of [defaultTypes], or a fully-qualified member | 199 * a member of one of [defaultTypes], or a fully-qualified member |
| 200 * name (e.g. `Document.createElement`), in which case it's treated as a | 200 * name (e.g. `Document.createElement`), in which case it's treated as a |
| 201 * member of the @domName element (`Document` in this case). | 201 * member of the @domName element (`Document` in this case). |
| 202 */ | 202 */ |
| 203 Set<String> _membersFromName(String name, List<String> defaultTypes) { | 203 Set<String> _membersFromName(String name, List<String> defaultTypes) { |
| 204 if (!name.contains('.', 0)) { | 204 if (!name.contains('.', 0)) { |
| 205 if (defaultTypes.isEmpty()) { | 205 if (defaultTypes.isEmpty) { |
| 206 warn('no default type for $name'); | 206 warn('no default type for $name'); |
| 207 return new Set(); | 207 return new Set(); |
| 208 } | 208 } |
| 209 final members = new Set<String>(); | 209 final members = new Set<String>(); |
| 210 defaultTypes.forEach((t) { members.add('$t.$name'); }); | 210 defaultTypes.forEach((t) { members.add('$t.$name'); }); |
| 211 return members; | 211 return members; |
| 212 } | 212 } |
| 213 | 213 |
| 214 if (name.split('.').length != 2) { | 214 if (name.split('.').length != 2) { |
| 215 warn('invalid member name ${name}'); | 215 warn('invalid member name ${name}'); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 229 Map<String, String> _getTags(String comment) { | 229 Map<String, String> _getTags(String comment) { |
| 230 if (comment == null) return const <String, String>{}; | 230 if (comment == null) return const <String, String>{}; |
| 231 final re = const RegExp("@([a-zA-Z]+) ([^;]+)(?:;|\$)"); | 231 final re = const RegExp("@([a-zA-Z]+) ([^;]+)(?:;|\$)"); |
| 232 final tags = <String, String>{}; | 232 final tags = <String, String>{}; |
| 233 for (var m in re.allMatches(comment.trim())) { | 233 for (var m in re.allMatches(comment.trim())) { |
| 234 tags[m[1]] = m[2]; | 234 tags[m[1]] = m[2]; |
| 235 } | 235 } |
| 236 return tags; | 236 return tags; |
| 237 } | 237 } |
| 238 } | 238 } |
| OLD | NEW |