| 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 |
| 11 import 'dart:io'; | 11 import 'dart:io'; |
| 12 import 'dart:async'; | 12 import 'dart:async'; |
| 13 import '../../sdk/lib/html/html_common/metadata.dart'; | 13 import '../../sdk/lib/html/html_common/metadata.dart'; |
| 14 import 'lib/metadata.dart'; |
| 14 | 15 |
| 15 // TODO(rnystrom): Use "package:" URL (#4968). | 16 // TODO(rnystrom): Use "package:" URL (#4968). |
| 16 import '../../sdk/lib/_internal/dartdoc/lib/dartdoc.dart'; | 17 import '../../sdk/lib/_internal/dartdoc/lib/dartdoc.dart'; |
| 17 import '../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors.dart'; | 18 import '../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors.dart'; |
| 18 import '../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors_util.dar
t'; | 19 import '../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors_util.dar
t'; |
| 19 | 20 |
| 20 // TODO(amouravski): There is currently magic that looks at dart:* libraries | 21 // TODO(amouravski): There is currently magic that looks at dart:* libraries |
| 21 // rather than the declared library names. This changed due to recent syntax | 22 // rather than the declared library names. This changed due to recent syntax |
| 22 // changes. We should only need to look at the library 'html'. | 23 // changes. We should only need to look at the library 'html'. |
| 23 const List<String> HTML_LIBRARY_NAMES = const [ | 24 const List<String> HTML_LIBRARY_NAMES = const [ |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 } | 146 } |
| 146 | 147 |
| 147 /** | 148 /** |
| 148 * Returns the `@DomName` type values that correspond to | 149 * Returns the `@DomName` type values that correspond to |
| 149 * [htmlType] from `dart:html`. This can be the empty list if no | 150 * [htmlType] from `dart:html`. This can be the empty list if no |
| 150 * correspondence is found. | 151 * correspondence is found. |
| 151 */ | 152 */ |
| 152 List<String> htmlToDomTypes(ClassMirror htmlType) { | 153 List<String> htmlToDomTypes(ClassMirror htmlType) { |
| 153 if (htmlType.simpleName == null) return <String>[]; | 154 if (htmlType.simpleName == null) return <String>[]; |
| 154 | 155 |
| 155 final domNameMetadata = _findMetadata(htmlType.metadata, 'DomName'); | 156 final domNameMetadata = findMetadata(htmlType.metadata, 'DomName'); |
| 156 if (domNameMetadata != null) { | 157 if (domNameMetadata != null) { |
| 157 var domNames = <String>[]; | 158 var domNames = <String>[]; |
| 158 var tags = deprecatedFutureValue(domNameMetadata.getField('name')); | 159 var tags = deprecatedFutureValue(domNameMetadata.getField('name')); |
| 159 for (var s in tags.reflectee.split(',')) { | 160 for (var s in tags.reflectee.split(',')) { |
| 160 domNames.add(s.trim()); | 161 domNames.add(s.trim()); |
| 161 } | 162 } |
| 162 | 163 |
| 163 if (domNames.length == 1 && domNames[0] == 'none') return <String>[]; | 164 if (domNames.length == 1 && domNames[0] == 'none') return <String>[]; |
| 164 return domNames; | 165 return domNames; |
| 165 } | 166 } |
| 166 return <String>[]; | 167 return <String>[]; |
| 167 } | 168 } |
| 168 | 169 |
| 169 /** | 170 /** |
| 170 * Returns the `@DomName` member values that correspond to | 171 * Returns the `@DomName` member values that correspond to |
| 171 * [htmlMember] from `dart:html`. This can be the empty set if no | 172 * [htmlMember] from `dart:html`. This can be the empty set if no |
| 172 * correspondence is found. [domTypes] are the | 173 * correspondence is found. [domTypes] are the |
| 173 * `@DomName` type values that correspond to [htmlMember]'s | 174 * `@DomName` type values that correspond to [htmlMember]'s |
| 174 * defining type. | 175 * defining type. |
| 175 */ | 176 */ |
| 176 Set<String> htmlToDomMembers(MemberMirror htmlMember, List<String> domTypes) { | 177 Set<String> htmlToDomMembers(MemberMirror htmlMember, List<String> domTypes) { |
| 177 if (htmlMember.isPrivate) return new Set(); | 178 if (htmlMember.isPrivate) return new Set(); |
| 178 | 179 |
| 179 final domNameMetadata = _findMetadata(htmlMember.metadata, 'DomName'); | 180 final domNameMetadata = findMetadata(htmlMember.metadata, 'DomName'); |
| 180 if (domNameMetadata != null) { | 181 if (domNameMetadata != null) { |
| 181 var domNames = <String>[]; | 182 var domNames = <String>[]; |
| 182 var tags = deprecatedFutureValue(domNameMetadata.getField('name')); | 183 var tags = deprecatedFutureValue(domNameMetadata.getField('name')); |
| 183 for (var s in tags.reflectee.split(',')) { | 184 for (var s in tags.reflectee.split(',')) { |
| 184 domNames.add(s.trim()); | 185 domNames.add(s.trim()); |
| 185 } | 186 } |
| 186 | 187 |
| 187 if (domNames.length == 1 && domNames[0] == 'none') return new Set(); | 188 if (domNames.length == 1 && domNames[0] == 'none') return new Set(); |
| 188 final members = new Set(); | 189 final members = new Set(); |
| 189 domNames.forEach((name) { | 190 domNames.forEach((name) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 defaultTypes.forEach((t) { members.add('$t.$name'); }); | 227 defaultTypes.forEach((t) { members.add('$t.$name'); }); |
| 227 return members; | 228 return members; |
| 228 } | 229 } |
| 229 | 230 |
| 230 if (name.split('.').length != 2) { | 231 if (name.split('.').length != 2) { |
| 231 warn('invalid member name ${name}'); | 232 warn('invalid member name ${name}'); |
| 232 return new Set(); | 233 return new Set(); |
| 233 } | 234 } |
| 234 return new Set.from([name]); | 235 return new Set.from([name]); |
| 235 } | 236 } |
| 236 | 237 } |
| 237 } | |
| 238 | |
| 239 /// Returns the metadata for the given string or null if not found. | |
| 240 InstanceMirror _findMetadata(List<InstanceMirror> metadataList, String find) { | |
| 241 return metadataList.firstMatching( | |
| 242 (metadata) => metadata.type.simpleName == find, | |
| 243 orElse: () => null); | |
| 244 } | |
| OLD | NEW |