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

Side by Side Diff: pkg/analysis_server/tool/spec/from_html.dart

Issue 1310263003: Reformat code to minimize churn (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 3 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
OLDNEW
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 library from.html; 8 library from.html;
9 9
10 import 'dart:io'; 10 import 'dart:io';
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 */ 116 */
117 void checkName(dom.Element element, String expectedName, [String context]) { 117 void checkName(dom.Element element, String expectedName, [String context]) {
118 if (element.localName != expectedName) { 118 if (element.localName != expectedName) {
119 if (context == null) { 119 if (context == null) {
120 context = element.localName; 120 context = element.localName;
121 } 121 }
122 throw new Exception( 122 throw new Exception(
123 '$context: Expected $expectedName, found ${element.localName}'); 123 '$context: Expected $expectedName, found ${element.localName}');
124 } 124 }
125 } 125 }
126
126 /** 127 /**
127 * Create a [Domain] object from an HTML representation such as: 128 * Create a [Domain] object from an HTML representation such as:
128 * 129 *
129 * <domain name="domainName"> 130 * <domain name="domainName">
130 * <request method="...">...</request> <!-- zero or more --> 131 * <request method="...">...</request> <!-- zero or more -->
131 * <notification event="...">...</notification> <!-- zero or more --> 132 * <notification event="...">...</notification> <!-- zero or more -->
132 * </domain> 133 * </domain>
133 * 134 *
134 * Child elements can occur in any order. 135 * Child elements can occur in any order.
135 */ 136 */
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 * Child elements can occur in any order. 413 * Child elements can occur in any order.
413 */ 414 */
414 TypeDefinition typeDefinitionFromHtml(dom.Element html) { 415 TypeDefinition typeDefinitionFromHtml(dom.Element html) {
415 checkName(html, 'type'); 416 checkName(html, 'type');
416 String name = html.attributes['name']; 417 String name = html.attributes['name'];
417 String context = name != null ? name : 'type'; 418 String context = name != null ? name : 'type';
418 checkAttributes(html, ['name'], context); 419 checkAttributes(html, ['name'], context);
419 TypeDecl type = processContentsAsType(html, context); 420 TypeDecl type = processContentsAsType(html, context);
420 return new TypeDefinition(name, type, html); 421 return new TypeDefinition(name, type, html);
421 } 422 }
423
422 /** 424 /**
423 * Create a [TypeEnum] from an HTML description. 425 * Create a [TypeEnum] from an HTML description.
424 */ 426 */
425 TypeEnum typeEnumFromHtml(dom.Element html, String context) { 427 TypeEnum typeEnumFromHtml(dom.Element html, String context) {
426 checkName(html, 'enum', context); 428 checkName(html, 'enum', context);
427 checkAttributes(html, [], context); 429 checkAttributes(html, [], context);
428 List<TypeEnumValue> values = <TypeEnumValue>[]; 430 List<TypeEnumValue> values = <TypeEnumValue>[];
429 recurse(html, context, { 431 recurse(html, context, {
430 'value': (dom.Element child) { 432 'value': (dom.Element child) {
431 values.add(typeEnumValueFromHtml(child, context)); 433 values.add(typeEnumValueFromHtml(child, context));
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 * In addition, the attribute optional="true" may be used to specify that the 475 * In addition, the attribute optional="true" may be used to specify that the
474 * field is optional, and the attribute value="..." may be used to specify that 476 * field is optional, and the attribute value="..." may be used to specify that
475 * the field is required to have a certain value. 477 * the field is required to have a certain value.
476 * 478 *
477 * Child elements can occur in any order. 479 * Child elements can occur in any order.
478 */ 480 */
479 TypeObjectField typeObjectFieldFromHtml(dom.Element html, String context) { 481 TypeObjectField typeObjectFieldFromHtml(dom.Element html, String context) {
480 checkName(html, 'field', context); 482 checkName(html, 'field', context);
481 String name = html.attributes['name']; 483 String name = html.attributes['name'];
482 context = '$context.${name != null ? name : 'field'}'; 484 context = '$context.${name != null ? name : 'field'}';
483 checkAttributes( 485 checkAttributes(html, ['name'], context,
484 html, ['name'], context, optionalAttributes: ['optional', 'value']); 486 optionalAttributes: ['optional', 'value']);
485 bool optional = false; 487 bool optional = false;
486 String optionalString = html.attributes['optional']; 488 String optionalString = html.attributes['optional'];
487 if (optionalString != null) { 489 if (optionalString != null) {
488 switch (optionalString) { 490 switch (optionalString) {
489 case 'true': 491 case 'true':
490 optional = true; 492 optional = true;
491 break; 493 break;
492 case 'false': 494 case 'false':
493 optional = false; 495 optional = false;
494 break; 496 break;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 TypeDefinition typeDefinition = typeDefinitionFromHtml(child); 536 TypeDefinition typeDefinition = typeDefinitionFromHtml(child);
535 types[typeDefinition.name] = typeDefinition; 537 types[typeDefinition.name] = typeDefinition;
536 } 538 }
537 }); 539 });
538 return new Types(types, html); 540 return new Types(types, html);
539 } 541 }
540 542
541 typedef void ElementProcessor(dom.Element element); 543 typedef void ElementProcessor(dom.Element element);
542 544
543 typedef void TextProcessor(dom.Text text); 545 typedef void TextProcessor(dom.Text text);
OLDNEW
« no previous file with comments | « pkg/analysis_server/tool/spec/codegen_tools.dart ('k') | pkg/analysis_server/tool/spec/text_formatter.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698