| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 * Code for reading an HTML API description. | 6 * Code for reading an HTML API description. |
| 7 */ | 7 */ |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 | 9 |
| 10 import 'package:analyzer/src/codegen/html.dart'; | 10 import 'package:analyzer/src/codegen/html.dart'; |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 element.attributes.forEach((String name, String value) { | 124 element.attributes.forEach((String name, String value) { |
| 125 if (!requiredAttributes.contains(name) && | 125 if (!requiredAttributes.contains(name) && |
| 126 !optionalAttributes.contains(name)) { | 126 !optionalAttributes.contains(name)) { |
| 127 throw new Exception( | 127 throw new Exception( |
| 128 '$context: Unexpected attribute in ${element.localName}: $name'); | 128 '$context: Unexpected attribute in ${element.localName}: $name'); |
| 129 } | 129 } |
| 130 attributesFound.add(name); | 130 attributesFound.add(name); |
| 131 }); | 131 }); |
| 132 for (String expectedAttribute in requiredAttributes) { | 132 for (String expectedAttribute in requiredAttributes) { |
| 133 if (!attributesFound.contains(expectedAttribute)) { | 133 if (!attributesFound.contains(expectedAttribute)) { |
| 134 throw new Exception( | 134 throw new Exception('$context: ${element |
| 135 '$context: ${element.localName} must contain attribute $expectedAttr
ibute'); | 135 .localName} must contain attribute $expectedAttribute'); |
| 136 } | 136 } |
| 137 } | 137 } |
| 138 } | 138 } |
| 139 | 139 |
| 140 /** | 140 /** |
| 141 * Check that the given [element] has the given [expectedName]. | 141 * Check that the given [element] has the given [expectedName]. |
| 142 */ | 142 */ |
| 143 void checkName(dom.Element element, String expectedName, [String context]) { | 143 void checkName(dom.Element element, String expectedName, [String context]) { |
| 144 if (element.localName != expectedName) { | 144 if (element.localName != expectedName) { |
| 145 if (context == null) { | 145 if (context == null) { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 * | 204 * |
| 205 * <params> has the same form as <object>, as described in [typeDeclFromHtml]. | 205 * <params> has the same form as <object>, as described in [typeDeclFromHtml]. |
| 206 * | 206 * |
| 207 * Child elements can occur in any order. | 207 * Child elements can occur in any order. |
| 208 */ | 208 */ |
| 209 Notification notificationFromHtml(dom.Element html, String context) { | 209 Notification notificationFromHtml(dom.Element html, String context) { |
| 210 String domainName = getAncestor(html, 'domain', context).attributes['name']; | 210 String domainName = getAncestor(html, 'domain', context).attributes['name']; |
| 211 checkName(html, 'notification', context); | 211 checkName(html, 'notification', context); |
| 212 String event = html.attributes['event']; | 212 String event = html.attributes['event']; |
| 213 context = '$context.${event != null ? event : 'event'}'; | 213 context = '$context.${event != null ? event : 'event'}'; |
| 214 checkAttributes(html, ['event'], context); | 214 checkAttributes(html, ['event'], context, |
| 215 optionalAttributes: ['experimental']); |
| 216 bool experimental = html.attributes['experimental'] == 'true'; |
| 215 TypeDecl params; | 217 TypeDecl params; |
| 216 recurse(html, context, { | 218 recurse(html, context, { |
| 217 'params': (dom.Element child) { | 219 'params': (dom.Element child) { |
| 218 params = typeObjectFromHtml(child, '$context.params'); | 220 params = typeObjectFromHtml(child, '$context.params'); |
| 219 } | 221 } |
| 220 }); | 222 }); |
| 221 return new Notification(domainName, event, params, html); | 223 return new Notification(domainName, event, params, html, |
| 224 experimental: experimental); |
| 222 } | 225 } |
| 223 | 226 |
| 224 /** | 227 /** |
| 225 * Create a single of [TypeDecl] corresponding to the type defined inside the | 228 * Create a single of [TypeDecl] corresponding to the type defined inside the |
| 226 * given HTML element. | 229 * given HTML element. |
| 227 */ | 230 */ |
| 228 TypeDecl processContentsAsType(dom.Element html, String context) { | 231 TypeDecl processContentsAsType(dom.Element html, String context) { |
| 229 List<TypeDecl> types = processContentsAsTypes(html, context); | 232 List<TypeDecl> types = processContentsAsTypes(html, context); |
| 230 if (types.length != 1) { | 233 if (types.length != 1) { |
| 231 throw new Exception('$context: Exactly one type must be specified'); | 234 throw new Exception('$context: Exactly one type must be specified'); |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 597 } | 600 } |
| 598 }); | 601 }); |
| 599 for (dom.Element element in childElements) { | 602 for (dom.Element element in childElements) { |
| 600 html.append(element); | 603 html.append(element); |
| 601 } | 604 } |
| 602 Types types = new Types(typeMap, html); | 605 Types types = new Types(typeMap, html); |
| 603 types.importUris.addAll(importUris); | 606 types.importUris.addAll(importUris); |
| 604 return types; | 607 return types; |
| 605 } | 608 } |
| 606 } | 609 } |
| OLD | NEW |