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

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

Issue 12446003: Support full dart2js output for dartdoc/apidoc. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebased Created 7 years, 9 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') | 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: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 import 'lib/metadata.dart';
15 15
16 // TODO(rnystrom): Use "package:" URL (#4968). 16 // TODO(rnystrom): Use "package:" URL (#4968).
17 import '../../sdk/lib/_internal/dartdoc/lib/dartdoc.dart'; 17 import '../../sdk/lib/_internal/dartdoc/lib/dartdoc.dart';
18 import '../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors.dart'; 18 import '../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors.dart';
19 import '../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors_util.dar t'; 19 import '../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors_util.dar t';
20 import '../../sdk/lib/_internal/compiler/implementation/mirrors/dart2js_mirror.d art';
20 21
21 // TODO(amouravski): There is currently magic that looks at dart:* libraries 22 // TODO(amouravski): There is currently magic that looks at dart:* libraries
22 // rather than the declared library names. This changed due to recent syntax 23 // rather than the declared library names. This changed due to recent syntax
23 // changes. We should only need to look at the library 'html'. 24 // changes. We should only need to look at the library 'html'.
24 const List<String> HTML_LIBRARY_NAMES = const [ 25 const List<String> HTML_LIBRARY_NAMES = const [
25 'dart:html', 26 'dart:html',
26 'dart:svg', 27 'dart:svg',
27 'dart:web_audio']; 28 'dart:web_audio'];
28 const List<String> HTML_DECLARED_NAMES = const [ 29 const List<String> HTML_DECLARED_NAMES = const [
29 'dart.dom.html', 30 'dart.dom.html',
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 * `@DomName` member(s). 63 * `@DomName` member(s).
63 */ 64 */
64 final Map<String, Set<String>> htmlToDom; 65 final Map<String, Set<String>> htmlToDom;
65 66
66 /** A map from `dart:html` types to corresponding `@DomName` types. */ 67 /** A map from `dart:html` types to corresponding `@DomName` types. */
67 final Map<String, Set<String>> htmlTypesToDom; 68 final Map<String, Set<String>> htmlTypesToDom;
68 69
69 /** If true, then print warning messages. */ 70 /** If true, then print warning messages. */
70 final bool _printWarnings; 71 final bool _printWarnings;
71 72
72 static Compilation _compilation;
73 static MirrorSystem _mirrors;
74 static LibraryMirror dom; 73 static LibraryMirror dom;
75 74
76 /**
77 * Perform static initialization of [world]. This should be run before
78 * calling [HtmlDiff.run].
79 */
80 static void initialize(Path libDir) {
81 var paths = <Path>[];
82 for (var libraryName in HTML_LIBRARY_NAMES) {
83 paths.add(new Path(libraryName));
84 }
85 _compilation = new Compilation.library(paths, libDir);
86 _mirrors = _compilation.mirrors;
87 }
88
89 HtmlDiff({bool printWarnings: false}) : 75 HtmlDiff({bool printWarnings: false}) :
90 _printWarnings = printWarnings, 76 _printWarnings = printWarnings,
91 htmlToDom = new Map<String, Set<String>>(), 77 htmlToDom = new Map<String, Set<String>>(),
92 htmlTypesToDom = new Map<String, Set<String>>(); 78 htmlTypesToDom = new Map<String, Set<String>>();
93 79
94 void warn(String s) { 80 void warn(String s) {
95 if (_printWarnings) { 81 if (_printWarnings) {
96 print('Warning: $s'); 82 print('Warning: $s');
97 } 83 }
98 } 84 }
99 85
100 /** 86 /**
101 * Computes the `@DomName` to `dart:html` mapping, and 87 * Computes the `@DomName` to `dart:html` mapping, and
102 * places it in [htmlToDom] and [htmlTypesToDom]. Before this is run, dart2js 88 * places it in [htmlToDom] and [htmlTypesToDom]. Before this is run, dart2js
103 * should be initialized (via [parseOptions] and [initializeWorld]) and 89 * should be initialized (via [parseOptions] and [initializeWorld]) and
104 * [HtmlDiff.initialize] should be called. 90 * [HtmlDiff.initialize] should be called.
105 */ 91 */
106 void run() { 92 Future run(Path libDir) {
107 for (var libraryName in HTML_DECLARED_NAMES) { 93 var result = new Completer();
108 var library = _mirrors.libraries[libraryName]; 94 var paths = <Path>[];
109 if (library == null) { 95 for (var libraryName in HTML_LIBRARY_NAMES) {
110 warn('Could not find $libraryName'); 96 paths.add(new Path(libraryName));
111 return; 97 }
98 analyze(paths, libDir).then((MirrorSystem mirrors) {
99 for (var libraryName in HTML_DECLARED_NAMES) {
100 var library = mirrors.libraries[libraryName];
101 if (library == null) {
102 warn('Could not find $libraryName');
103 result.complete(false);
104 }
105 for (ClassMirror type in library.classes.values) {
106 final domTypes = htmlToDomTypes(type);
107 if (domTypes.isEmpty) continue;
108
109 htmlTypesToDom.putIfAbsent(type.qualifiedName,
110 () => new Set()).addAll(domTypes);
111
112 type.members.forEach(
113 (_, m) => _addMemberDiff(m, domTypes, library.simpleName));
114 }
112 } 115 }
113 for (ClassMirror type in library.classes.values) { 116 result.complete(true);
114 final domTypes = htmlToDomTypes(type); 117 });
115 if (domTypes.isEmpty) continue; 118 return result.future;
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 } 119 }
125 120
126 /** 121 /**
127 * Records the `@DomName` to `dart:html` mapping for 122 * Records the `@DomName` to `dart:html` mapping for
128 * [htmlMember] (from `dart:html`). [domTypes] are the 123 * [htmlMember] (from `dart:html`). [domTypes] are the
129 * `@DomName` type values that correspond to [htmlMember]'s 124 * `@DomName` type values that correspond to [htmlMember]'s
130 * defining type. 125 * defining type.
131 */ 126 */
132 void _addMemberDiff(MemberMirror htmlMember, List<String> domTypes, 127 void _addMemberDiff(MemberMirror htmlMember, List<String> domTypes,
133 String libraryName) { 128 String libraryName) {
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 return members; 223 return members;
229 } 224 }
230 225
231 if (name.split('.').length != 2) { 226 if (name.split('.').length != 2) {
232 warn('invalid member name ${name}'); 227 warn('invalid member name ${name}');
233 return new Set(); 228 return new Set();
234 } 229 }
235 return new Set.from([name]); 230 return new Set.from([name]);
236 } 231 }
237 } 232 }
OLDNEW
« no previous file with comments | « utils/apidoc/apidoc.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698