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

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

Issue 11398002: Splitting SVG types out of dart:html. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Passing dartc. Created 8 years, 1 month 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
« tests/html/svgelement2_test.dart ('K') | « utils/apidoc/apidoc.dart ('k') | no next file » | 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:coreimpl'; 11 import 'dart:coreimpl';
12 import 'dart:io'; 12 import 'dart:io';
13 13
14 // TODO(rnystrom): Use "package:" URL (#4968). 14 // TODO(rnystrom): Use "package:" URL (#4968).
15 import '../../sdk/lib/_internal/dartdoc/lib/dartdoc.dart'; 15 import '../../sdk/lib/_internal/dartdoc/lib/dartdoc.dart';
16 import '../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors.dart'; 16 import '../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors.dart';
17 import '../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors_util.dar t'; 17 import '../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors_util.dar t';
18 18
19 // TODO(amouravski): There is currently magic that looks at dart:* libraries 19 // TODO(amouravski): There is currently magic that looks at dart:* libraries
20 // rather than the declared library names. This changed due to recent syntax 20 // rather than the declared library names. This changed due to recent syntax
21 // changes. We should only need to look at the library 'html'. 21 // changes. We should only need to look at the library 'html'.
22 const HTML_LIBRARY_NAME = 'dart:html'; 22 const List<String> HTML_LIBRARY_NAMES = const ['dart:html', 'dart:svg'];
23 const HTML_DECLARED_NAME = 'html'; 23 const List<String> HTML_DECLARED_NAMES = const ['html', 'svg'];
24 24
25 /** 25 /**
26 * A class for computing a many-to-many mapping between the types and 26 * A class for computing a many-to-many mapping between the types and
27 * members in `dart:html` and the MDN DOM types. This mapping is 27 * members in `dart:html` and the MDN DOM types. This mapping is
28 * based on two indicators: 28 * based on two indicators:
29 * 29 *
30 * 1. Auto-detected wrappers. Most `dart:html` types correspond 30 * 1. Auto-detected wrappers. Most `dart:html` types correspond
31 * straightforwardly to a single `@domName` type, and 31 * straightforwardly to a single `@domName` type, and
32 * have the same name. In addition, most `dart:html` methods 32 * have the same name. In addition, most `dart:html` methods
33 * just call a single `@domName` method. This class 33 * just call a single `@domName` method. This class
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 65
66 static Compilation _compilation; 66 static Compilation _compilation;
67 static MirrorSystem _mirrors; 67 static MirrorSystem _mirrors;
68 static LibraryMirror dom; 68 static LibraryMirror dom;
69 69
70 /** 70 /**
71 * Perform static initialization of [world]. This should be run before 71 * Perform static initialization of [world]. This should be run before
72 * calling [HtmlDiff.run]. 72 * calling [HtmlDiff.run].
73 */ 73 */
74 static void initialize(Path libDir) { 74 static void initialize(Path libDir) {
75 _compilation = new Compilation.library(<Path>[new Path(HTML_LIBRARY_NAME)], 75 var paths = <Path>[];
76 libDir); 76 for (var libraryName in HTML_LIBRARY_NAMES) {
77 paths.add(new Path(libraryName));
78 }
79 _compilation = new Compilation.library(paths, libDir);
77 _mirrors = _compilation.mirrors; 80 _mirrors = _compilation.mirrors;
78 } 81 }
79 82
80 HtmlDiff({bool printWarnings: false}) : 83 HtmlDiff({bool printWarnings: false}) :
81 _printWarnings = printWarnings, 84 _printWarnings = printWarnings,
82 htmlToDom = new Map<String, Set<String>>(), 85 htmlToDom = new Map<String, Set<String>>(),
83 htmlTypesToDom = new Map<String, Set<String>>(), 86 htmlTypesToDom = new Map<String, Set<String>>(),
84 comments = new CommentMap(); 87 comments = new CommentMap();
85 88
86 void warn(String s) { 89 void warn(String s) {
87 if (_printWarnings) { 90 if (_printWarnings) {
88 print('Warning: $s'); 91 print('Warning: $s');
89 } 92 }
90 } 93 }
91 94
92 /** 95 /**
93 * Computes the `@domName` to `dart:html` mapping, and 96 * Computes the `@domName` to `dart:html` mapping, and
94 * places it in [htmlToDom] and [htmlTypesToDom]. Before this is run, dart2js 97 * places it in [htmlToDom] and [htmlTypesToDom]. Before this is run, dart2js
95 * should be initialized (via [parseOptions] and [initializeWorld]) and 98 * should be initialized (via [parseOptions] and [initializeWorld]) and
96 * [HtmlDiff.initialize] should be called. 99 * [HtmlDiff.initialize] should be called.
97 */ 100 */
98 void run() { 101 void run() {
99 LibraryMirror htmlLib = _mirrors.libraries[HTML_DECLARED_NAME]; 102 for (var libraryName in HTML_DECLARED_NAMES) {
100 if (htmlLib === null) { 103 var library = _mirrors.libraries[libraryName];
101 warn('Could not find $HTML_LIBRARY_NAME'); 104 if (library == null) {
102 return; 105 warn('Could not find $libraryName');
103 } 106 return;
104 for (ClassMirror htmlType in htmlLib.classes.values) { 107 }
105 final domTypes = htmlToDomTypes(htmlType); 108 _processLibrary(library);
106 if (domTypes.isEmpty) continue;
107
108 htmlTypesToDom.putIfAbsent(htmlType.qualifiedName,
109 () => new Set()).addAll(domTypes);
110
111 htmlType.members.forEach(
112 (_, m) => _addMemberDiff(m, domTypes));
113 } 109 }
114 } 110 }
115 111
112 void _processLibrary(LibraryMirror library) {
Anton Muhin 2012/11/09 13:13:23 why a helper method? can it be inline or a closur
blois 2012/11/09 18:21:56 Done.
113 for (ClassMirror type in library.classes.values) {
114 final domTypes = htmlToDomTypes(type);
115 if (domTypes.isEmpty) continue;
116
117 htmlTypesToDom.putIfAbsent(type.qualifiedName,
118 () => new Set()).addAll(domTypes);
119
120 type.members.forEach(
121 (_, m) => _addMemberDiff(m, domTypes, library.simpleName));
122 }
123 }
124
116 /** 125 /**
117 * Records the `@domName` to `dart:html` mapping for 126 * Records the `@domName` to `dart:html` mapping for
118 * [htmlMember] (from `dart:html`). [domTypes] are the 127 * [htmlMember] (from `dart:html`). [domTypes] are the
119 * `@domName` type values that correspond to [htmlMember]'s 128 * `@domName` type values that correspond to [htmlMember]'s
120 * defining type. 129 * defining type.
121 */ 130 */
122 void _addMemberDiff(MemberMirror htmlMember, List<String> domTypes) { 131 void _addMemberDiff(MemberMirror htmlMember, List<String> domTypes,
132 String libraryName) {
123 var domMembers = htmlToDomMembers(htmlMember, domTypes); 133 var domMembers = htmlToDomMembers(htmlMember, domTypes);
124 if (htmlMember == null && !domMembers.isEmpty) { 134 if (htmlMember == null && !domMembers.isEmpty) {
125 warn('$HTML_LIBRARY_NAME member ' 135 warn('$libraryName member '
126 '${htmlMember.owner.simpleName}.' 136 '${htmlMember.owner.simpleName}.'
127 '${htmlMember.simpleName} has no corresponding ' 137 '${htmlMember.simpleName} has no corresponding '
128 '$HTML_LIBRARY_NAME member.'); 138 '$libraryName member.');
129 } 139 }
130 140
131 if (htmlMember == null) return; 141 if (htmlMember == null) return;
132 if (!domMembers.isEmpty) { 142 if (!domMembers.isEmpty) {
133 htmlToDom[htmlMember.qualifiedName] = domMembers; 143 htmlToDom[htmlMember.qualifiedName] = domMembers;
134 } 144 }
135 } 145 }
136 146
137 /** 147 /**
138 * Returns the `@domName` type values that correspond to 148 * Returns the `@domName` type values that correspond to
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 Map<String, String> _getTags(String comment) { 239 Map<String, String> _getTags(String comment) {
230 if (comment == null) return const <String, String>{}; 240 if (comment == null) return const <String, String>{};
231 final re = const RegExp("@([a-zA-Z]+) ([^;]+)(?:;|\$)"); 241 final re = const RegExp("@([a-zA-Z]+) ([^;]+)(?:;|\$)");
232 final tags = <String, String>{}; 242 final tags = <String, String>{};
233 for (var m in re.allMatches(comment.trim())) { 243 for (var m in re.allMatches(comment.trim())) {
234 tags[m[1]] = m[2]; 244 tags[m[1]] = m[2];
235 } 245 }
236 return tags; 246 return tags;
237 } 247 }
238 } 248 }
OLDNEW
« tests/html/svgelement2_test.dart ('K') | « utils/apidoc/apidoc.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698