Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(181)

Side by Side Diff: utils/apidoc/html_diff.dart

Issue 119913002: Align source mirrors with runtime mirrors. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated cf. comments + small fix. Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « utils/apidoc/apidoc.dart ('k') | utils/apidoc/lib/metadata.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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:async'; 11 import 'dart:async';
12 import 'dart:io';
13 12
14 import 'lib/metadata.dart'; 13 import 'lib/metadata.dart';
15 14
16 // TODO(rnystrom): Use "package:" URL (#4968). 15 // TODO(rnystrom): Use "package:" URL (#4968).
17 import '../../sdk/lib/_internal/compiler/implementation/mirrors/dart2js_mirror.d art'; 16 import '../../sdk/lib/_internal/compiler/implementation/mirrors/analyze.dart';
18 import '../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors.dart'; 17 import '../../sdk/lib/_internal/compiler/implementation/mirrors/source_mirrors.d art';
19 import '../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors_util.dar t'; 18 import '../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors_util.dar t';
20 import '../../sdk/lib/_internal/compiler/implementation/source_file_provider.dar t'; 19 import '../../sdk/lib/_internal/compiler/implementation/source_file_provider.dar t';
21 import '../../sdk/lib/_internal/dartdoc/lib/dartdoc.dart';
22 import '../../sdk/lib/html/html_common/metadata.dart';
23 20
24 // TODO(amouravski): There is currently magic that looks at dart:* libraries 21 // TODO(amouravski): There is currently magic that looks at dart:* libraries
25 // 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
26 // changes. We should only need to look at the library 'html'. 23 // changes. We should only need to look at the library 'html'.
27 final List<Uri> HTML_LIBRARY_URIS = [ 24 final List<Uri> HTML_LIBRARY_URIS = [
28 new Uri(scheme: 'dart', path: 'html'), 25 new Uri(scheme: 'dart', path: 'html'),
29 new Uri(scheme: 'dart', path: 'indexed_db'), 26 new Uri(scheme: 'dart', path: 'indexed_db'),
30 new Uri(scheme: 'dart', path: 'svg'), 27 new Uri(scheme: 'dart', path: 'svg'),
31 new Uri(scheme: 'dart', path: 'web_audio')]; 28 new Uri(scheme: 'dart', path: 'web_audio')];
32 29
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 HTML_LIBRARY_URIS, libraryRoot, null, 93 HTML_LIBRARY_URIS, libraryRoot, null,
97 provider.readStringFromUri, 94 provider.readStringFromUri,
98 handler.diagnosticHandler); 95 handler.diagnosticHandler);
99 analysis.then((MirrorSystem mirrors) { 96 analysis.then((MirrorSystem mirrors) {
100 for (var libraryUri in HTML_LIBRARY_URIS) { 97 for (var libraryUri in HTML_LIBRARY_URIS) {
101 var library = mirrors.libraries[libraryUri]; 98 var library = mirrors.libraries[libraryUri];
102 if (library == null) { 99 if (library == null) {
103 warn('Could not find $libraryUri'); 100 warn('Could not find $libraryUri');
104 result.complete(false); 101 result.complete(false);
105 } 102 }
106 for (ClassMirror type in library.classes.values) { 103 for (ClassMirror type in classesOf(library.declarations)) {
107 final domTypes = htmlToDomTypes(type); 104 final domTypes = htmlToDomTypes(type);
108 if (domTypes.isEmpty) continue; 105 if (domTypes.isEmpty) continue;
109 106
110 htmlTypesToDom.putIfAbsent(type.qualifiedName, 107 htmlTypesToDom.putIfAbsent(qualifiedNameOf(type),
111 () => new Set()).addAll(domTypes); 108 () => new Set()).addAll(domTypes);
112 109
113 type.members.forEach( 110 membersOf(type.declarations).forEach(
114 (_, m) => _addMemberDiff(m, domTypes, library.simpleName)); 111 (m) => _addMemberDiff(m, domTypes, nameOf(library)));
115 } 112 }
116 } 113 }
117 result.complete(true); 114 result.complete(true);
118 }); 115 });
119 return result.future; 116 return result.future;
120 } 117 }
121 118
122 /** 119 /**
123 * Records the `@DomName` to `dart:html` mapping for 120 * Records the `@DomName` to `dart:html` mapping for
124 * [htmlMember] (from `dart:html`). [domTypes] are the 121 * [htmlMember] (from `dart:html`). [domTypes] are the
125 * `@DomName` type values that correspond to [htmlMember]'s 122 * `@DomName` type values that correspond to [htmlMember]'s
126 * defining type. 123 * defining type.
127 */ 124 */
128 void _addMemberDiff(MemberMirror htmlMember, List<String> domTypes, 125 void _addMemberDiff(DeclarationMirror htmlMember, List<String> domTypes,
129 String libraryName) { 126 String libraryName) {
130 var domMembers = htmlToDomMembers(htmlMember, domTypes); 127 var domMembers = htmlToDomMembers(htmlMember, domTypes);
131 if (htmlMember == null && !domMembers.isEmpty) { 128 if (htmlMember == null && !domMembers.isEmpty) {
132 warn('$libraryName member ' 129 warn('$libraryName member '
133 '${htmlMember.owner.simpleName}.' 130 '${htmlMember.owner.simpleName}.'
134 '${htmlMember.simpleName} has no corresponding ' 131 '${htmlMember.simpleName} has no corresponding '
135 '$libraryName member.'); 132 '$libraryName member.');
136 } 133 }
137 134
138 if (htmlMember == null) return; 135 if (htmlMember == null) return;
139 if (!domMembers.isEmpty) { 136 if (!domMembers.isEmpty) {
140 htmlToDom[htmlMember.qualifiedName] = domMembers; 137 htmlToDom[qualifiedNameOf(htmlMember)] = domMembers;
141 } 138 }
142 } 139 }
143 140
144 /** 141 /**
145 * Returns the `@DomName` type values that correspond to 142 * Returns the `@DomName` type values that correspond to
146 * [htmlType] from `dart:html`. This can be the empty list if no 143 * [htmlType] from `dart:html`. This can be the empty list if no
147 * correspondence is found. 144 * correspondence is found.
148 */ 145 */
149 List<String> htmlToDomTypes(ClassMirror htmlType) { 146 List<String> htmlToDomTypes(ClassMirror htmlType) {
150 if (htmlType.simpleName == null) return <String>[]; 147 if (htmlType.simpleName == null) return <String>[];
151 148
152 final domNameMetadata = findMetadata(htmlType.metadata, 'DomName'); 149 final domNameMetadata = findMetadata(htmlType.metadata, 'DomName');
153 if (domNameMetadata != null) { 150 if (domNameMetadata != null) {
154 var domNames = <String>[]; 151 var domNames = <String>[];
155 var names = domNameMetadata.getField('name'); 152 var names = domNameMetadata.getField(symbolOf('name'));
156 for (var s in names.reflectee.split(',')) { 153 for (var s in names.reflectee.split(',')) {
157 domNames.add(s.trim()); 154 domNames.add(s.trim());
158 } 155 }
159 156
160 if (domNames.length == 1 && domNames[0] == 'none') return <String>[]; 157 if (domNames.length == 1 && domNames[0] == 'none') return <String>[];
161 return domNames; 158 return domNames;
162 } 159 }
163 return <String>[]; 160 return <String>[];
164 } 161 }
165 162
166 /** 163 /**
167 * Returns the `@DomName` member values that correspond to 164 * Returns the `@DomName` member values that correspond to
168 * [htmlMember] from `dart:html`. This can be the empty set if no 165 * [htmlMember] from `dart:html`. This can be the empty set if no
169 * correspondence is found. [domTypes] are the 166 * correspondence is found. [domTypes] are the
170 * `@DomName` type values that correspond to [htmlMember]'s 167 * `@DomName` type values that correspond to [htmlMember]'s
171 * defining type. 168 * defining type.
172 */ 169 */
173 Set<String> htmlToDomMembers(MemberMirror htmlMember, List<String> domTypes) { 170 Set<String> htmlToDomMembers(DeclarationMirror htmlMember,
171 List<String> domTypes) {
174 if (htmlMember.isPrivate) return new Set(); 172 if (htmlMember.isPrivate) return new Set();
175 173
176 final domNameMetadata = findMetadata(htmlMember.metadata, 'DomName'); 174 final domNameMetadata = findMetadata(htmlMember.metadata, 'DomName');
177 if (domNameMetadata != null) { 175 if (domNameMetadata != null) {
178 var domNames = <String>[]; 176 var domNames = <String>[];
179 var names = domNameMetadata.getField('name'); 177 var names = domNameMetadata.getField(symbolOf('name'));
180 for (var s in names.reflectee.split(',')) { 178 for (var s in names.reflectee.split(',')) {
181 domNames.add(s.trim()); 179 domNames.add(s.trim());
182 } 180 }
183 181
184 if (domNames.length == 1 && domNames[0] == 'none') return new Set(); 182 if (domNames.length == 1 && domNames[0] == 'none') return new Set();
185 final members = new Set(); 183 final members = new Set();
186 domNames.forEach((name) { 184 domNames.forEach((name) {
187 var nameMembers = _membersFromName(name, domTypes); 185 var nameMembers = _membersFromName(name, domTypes);
188 if (nameMembers.isEmpty) { 186 if (nameMembers.isEmpty) {
189 if (name.contains('.')) { 187 if (name.contains('.')) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 return members; 222 return members;
225 } 223 }
226 224
227 if (name.split('.').length != 2) { 225 if (name.split('.').length != 2) {
228 warn('invalid member name ${name}'); 226 warn('invalid member name ${name}');
229 return new Set(); 227 return new Set();
230 } 228 }
231 return new Set.from([name]); 229 return new Set.from([name]);
232 } 230 }
233 } 231 }
OLDNEW
« no previous file with comments | « utils/apidoc/apidoc.dart ('k') | utils/apidoc/lib/metadata.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698