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

Unified Diff: build/gen_html_setters.dart

Issue 11315020: Add attribute information table so we generate correct setters. (Closed) Base URL: https://github.com/dart-lang/dart-web-components.git@master
Patch Set: better todo comments 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « .gitignore ('k') | build/gen_html_setters.sh » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/gen_html_setters.dart
diff --git a/build/gen_html_setters.dart b/build/gen_html_setters.dart
new file mode 100644
index 0000000000000000000000000000000000000000..24d7b88998b03066572f2e74b5253ad22fdc0136
--- /dev/null
+++ b/build/gen_html_setters.dart
@@ -0,0 +1,119 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import 'dart:io';
+
+// TODO(jmesserly): should be importing a compiler mirrors package.
+// This is currently generated by the shell script.
+import 'compile_mirrors.dart';
+
+// TODO(jmesserly): pub is not creating a "packages" for us.
+import '../lib/src/html5_utils.dart' show htmlElementNames;
+
+const MY_NAME = 'build/gen_html_setters.sh';
+const OUTPUT_NAME = 'lib/src/html5_setters.g.dart';
+
+/**
+ * Given a field name in `dart:html` gets the HTML attribute name.
+ */
+const fieldToAttribute = const {
+ 'acceptCharset': 'accept-charset',
+ 'defaultValue': 'default',
+ // Yuck. http://dartbug.com/4550
+ 'webkitdropzone': 'dropzone',
+ 'htmlFor': 'for',
+ 'httpEquiv': 'http-equiv',
+};
+
+
+main() {
+ print('''
+This script uses compile time mirrors to get information from dart:html.
+The information is used to create "$OUTPUT_NAME".
+''');
+
+ var sdk = Platform.environment['DART_SDK'];
+ if (sdk == null) {
+ print('DART_SDK path must be set. Use gen_html_setters.sh.');
+ exit(1);
+ }
+
+ var htmlPath = new Path('dart:html');
+ var libPath = new Path(sdk).append('lib');
+ var pkgPath = new Path(sdk).append('pkg');
+
+ var mirrors = new Compilation.library([htmlPath], libPath, pkgPath).mirrors;
+ var html = mirrors.libraries['html'];
+
+
+ var extendsCode = new StringBuffer();
+ extendsCode.add('var htmlElementExtends = const {\n');
+
+ var code = new StringBuffer();
+ code.add('// This file is autogenerated by $MY_NAME. Do not edit.\n');
+ code.add('library html5_setters;\n');
+
+ var elemSet = new Set();
+ void addSuperInterfaces(ClassMirror cls) {
+ var name = cls.displayName;
+ if (name.endsWith('Element') && !elemSet.contains(name)) {
+ elemSet.add(name);
+ cls.superinterfaces.forEach(addSuperInterfaces);
+ }
+ }
+ for (var name in htmlElementNames.values) {
+ addSuperInterfaces(html.classes[name]);
+ }
+ addSuperInterfaces(html.classes['UnknownElement']);
+
+ code.add('var htmlElementFields = const {\n');
+ var elements = new List.from(elemSet);
+ elements.sort();
+ for (var element in elements) {
+ var cls = html.classes[element];
+ var setters = [];
+
+ var interfaces = cls.superinterfaces.filter(
+ (i) => i.displayName.endsWith('Element'));
+
+ if (interfaces.length > 1) {
+ print('ERROR: $element has more than one Element superinterface:\n'
+ ' $interfaces');
+ exit(2);
+ } else if (interfaces.length > 0) {
+ extendsCode.add(" '$element': '${interfaces[0].displayName}',\n");
+ }
+
+ // TODO(jmesserly): using "cls.setters" does not seem to work
+ for (var member in cls.members.values) {
+ if (member.simpleName.startsWith(r'$')) continue;
+ if (member is! VariableMirror) continue;
+ if (member.isFinal || member.isConst) continue;
+ setters.add(member.displayName);
+ }
+
+ if (setters.length == 0) continue;
+
+ code.add(" '$element': const {\n");
+ for (var setter in setters) {
+ var attr = fieldToAttribute[setter];
+ if (attr == null) attr = setter.toLowerCase();
+ code.add(" '$attr': '$setter',\n");
+ }
+ code.add(' },\n');
+ }
+ code.add('};\n\n');
+ extendsCode.add('};\n');
+ code.add(extendsCode.toString());
+
+ var outPath = new Path(new Options().script).directoryPath
+ .append('..').append(OUTPUT_NAME);
+
+ new File.fromPath(outPath)
+ .openSync(FileMode.WRITE)
+ ..writeStringSync(code.toString())
+ ..closeSync();
+
+ print('Wrote $outPath.');
+}
« no previous file with comments | « .gitignore ('k') | build/gen_html_setters.sh » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698