OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 * [typeDeclFromHtml]. | 386 * [typeDeclFromHtml]. |
387 * | 387 * |
388 * Child elements can occur in any order. | 388 * Child elements can occur in any order. |
389 */ | 389 */ |
390 Request requestFromHtml(dom.Element html, String context) { | 390 Request requestFromHtml(dom.Element html, String context) { |
391 String domainName = getAncestor(html, 'domain', context).attributes['name']; | 391 String domainName = getAncestor(html, 'domain', context).attributes['name']; |
392 checkName(html, 'request', context); | 392 checkName(html, 'request', context); |
393 String method = html.attributes['method']; | 393 String method = html.attributes['method']; |
394 context = '$context.${method != null ? method : 'method'}'; | 394 context = '$context.${method != null ? method : 'method'}'; |
395 checkAttributes(html, ['method'], context, | 395 checkAttributes(html, ['method'], context, |
396 optionalAttributes: ['experimental']); | 396 optionalAttributes: ['experimental', 'deprecated']); |
397 bool experimental = html.attributes['experimental'] == 'true'; | 397 bool experimental = html.attributes['experimental'] == 'true'; |
| 398 bool deprecated = html.attributes['deprecated'] == 'true'; |
398 TypeDecl params; | 399 TypeDecl params; |
399 TypeDecl result; | 400 TypeDecl result; |
400 recurse(html, context, { | 401 recurse(html, context, { |
401 'params': (dom.Element child) { | 402 'params': (dom.Element child) { |
402 params = typeObjectFromHtml(child, '$context.params'); | 403 params = typeObjectFromHtml(child, '$context.params'); |
403 }, | 404 }, |
404 'result': (dom.Element child) { | 405 'result': (dom.Element child) { |
405 result = typeObjectFromHtml(child, '$context.result'); | 406 result = typeObjectFromHtml(child, '$context.result'); |
406 } | 407 } |
407 }); | 408 }); |
408 return new Request(domainName, method, params, result, html, | 409 return new Request(domainName, method, params, result, html, |
409 experimental: experimental); | 410 experimental: experimental, deprecated: deprecated); |
410 } | 411 } |
411 | 412 |
412 /** | 413 /** |
413 * Create a [TypeDefinition] object from an HTML representation such as: | 414 * Create a [TypeDefinition] object from an HTML representation such as: |
414 * | 415 * |
415 * <type name="typeName"> | 416 * <type name="typeName"> |
416 * TYPE | 417 * TYPE |
417 * </type> | 418 * </type> |
418 * | 419 * |
419 * Where TYPE is any HTML that can be parsed by [typeDeclFromHtml]. | 420 * Where TYPE is any HTML that can be parsed by [typeDeclFromHtml]. |
420 * | 421 * |
421 * Child elements can occur in any order. | 422 * Child elements can occur in any order. |
422 */ | 423 */ |
423 TypeDefinition typeDefinitionFromHtml(dom.Element html) { | 424 TypeDefinition typeDefinitionFromHtml(dom.Element html) { |
424 checkName(html, 'type'); | 425 checkName(html, 'type'); |
425 String name = html.attributes['name']; | 426 String name = html.attributes['name']; |
426 String context = name != null ? name : 'type'; | 427 String context = name != null ? name : 'type'; |
427 checkAttributes(html, ['name'], context, | 428 checkAttributes(html, ['name'], context, |
428 optionalAttributes: ['experimental']); | 429 optionalAttributes: ['experimental', 'deprecated']); |
429 TypeDecl type = processContentsAsType(html, context); | 430 TypeDecl type = processContentsAsType(html, context); |
430 bool experimental = html.attributes['experimental'] == 'true'; | 431 bool experimental = html.attributes['experimental'] == 'true'; |
431 return new TypeDefinition(name, type, html, experimental: experimental); | 432 bool deprecated = html.attributes['deprecated'] == 'true'; |
| 433 return new TypeDefinition(name, type, html, |
| 434 experimental: experimental, deprecated: deprecated); |
432 } | 435 } |
433 | 436 |
434 /** | 437 /** |
435 * Create a [TypeEnum] from an HTML description. | 438 * Create a [TypeEnum] from an HTML description. |
436 */ | 439 */ |
437 TypeEnum typeEnumFromHtml(dom.Element html, String context) { | 440 TypeEnum typeEnumFromHtml(dom.Element html, String context) { |
438 checkName(html, 'enum', context); | 441 checkName(html, 'enum', context); |
439 checkAttributes(html, [], context); | 442 checkAttributes(html, [], context); |
440 List<TypeEnumValue> values = <TypeEnumValue>[]; | 443 List<TypeEnumValue> values = <TypeEnumValue>[]; |
441 recurse(html, context, { | 444 recurse(html, context, { |
(...skipping 10 matching lines...) Expand all Loading... |
452 * <enum> | 455 * <enum> |
453 * <code>VALUE</code> | 456 * <code>VALUE</code> |
454 * </enum> | 457 * </enum> |
455 * | 458 * |
456 * Where VALUE is the text of the enumerated value. | 459 * Where VALUE is the text of the enumerated value. |
457 * | 460 * |
458 * Child elements can occur in any order. | 461 * Child elements can occur in any order. |
459 */ | 462 */ |
460 TypeEnumValue typeEnumValueFromHtml(dom.Element html, String context) { | 463 TypeEnumValue typeEnumValueFromHtml(dom.Element html, String context) { |
461 checkName(html, 'value', context); | 464 checkName(html, 'value', context); |
462 checkAttributes(html, [], context); | 465 checkAttributes(html, [], context, optionalAttributes: ['deprecated']); |
| 466 bool deprecated = html.attributes['deprecated'] == 'true'; |
463 List<String> values = <String>[]; | 467 List<String> values = <String>[]; |
464 recurse(html, context, { | 468 recurse(html, context, { |
465 'code': (dom.Element child) { | 469 'code': (dom.Element child) { |
466 String text = innerText(child).trim(); | 470 String text = innerText(child).trim(); |
467 values.add(text); | 471 values.add(text); |
468 } | 472 } |
469 }); | 473 }); |
470 if (values.length != 1) { | 474 if (values.length != 1) { |
471 throw new Exception('$context: Exactly one value must be specified'); | 475 throw new Exception('$context: Exactly one value must be specified'); |
472 } | 476 } |
473 return new TypeEnumValue(values[0], html); | 477 return new TypeEnumValue(values[0], html, deprecated: deprecated); |
474 } | 478 } |
475 | 479 |
476 /** | 480 /** |
477 * Create a [TypeObjectField] from an HTML description such as: | 481 * Create a [TypeObjectField] from an HTML description such as: |
478 * | 482 * |
479 * <field name="fieldName"> | 483 * <field name="fieldName"> |
480 * TYPE | 484 * TYPE |
481 * </field> | 485 * </field> |
482 * | 486 * |
483 * Where TYPE is any HTML that can be parsed by [typeDeclFromHtml]. | 487 * Where TYPE is any HTML that can be parsed by [typeDeclFromHtml]. |
484 * | 488 * |
485 * In addition, the attribute optional="true" may be used to specify that the | 489 * In addition, the attribute optional="true" may be used to specify that the |
486 * field is optional, and the attribute value="..." may be used to specify that | 490 * field is optional, and the attribute value="..." may be used to specify that |
487 * the field is required to have a certain value. | 491 * the field is required to have a certain value. |
488 * | 492 * |
489 * Child elements can occur in any order. | 493 * Child elements can occur in any order. |
490 */ | 494 */ |
491 TypeObjectField typeObjectFieldFromHtml(dom.Element html, String context) { | 495 TypeObjectField typeObjectFieldFromHtml(dom.Element html, String context) { |
492 checkName(html, 'field', context); | 496 checkName(html, 'field', context); |
493 String name = html.attributes['name']; | 497 String name = html.attributes['name']; |
494 context = '$context.${name != null ? name : 'field'}'; | 498 context = '$context.${name != null ? name : 'field'}'; |
495 checkAttributes(html, ['name'], context, | 499 checkAttributes(html, ['name'], context, |
496 optionalAttributes: ['optional', 'value']); | 500 optionalAttributes: ['optional', 'value', 'deprecated']); |
| 501 bool deprecated = html.attributes['deprecated'] == 'true'; |
497 bool optional = false; | 502 bool optional = false; |
498 String optionalString = html.attributes['optional']; | 503 String optionalString = html.attributes['optional']; |
499 if (optionalString != null) { | 504 if (optionalString != null) { |
500 switch (optionalString) { | 505 switch (optionalString) { |
501 case 'true': | 506 case 'true': |
502 optional = true; | 507 optional = true; |
503 break; | 508 break; |
504 case 'false': | 509 case 'false': |
505 optional = false; | 510 optional = false; |
506 break; | 511 break; |
507 default: | 512 default: |
508 throw new Exception( | 513 throw new Exception( |
509 '$context: field contains invalid "optional" attribute: "$optionalSt
ring"'); | 514 '$context: field contains invalid "optional" attribute: "$optionalSt
ring"'); |
510 } | 515 } |
511 } | 516 } |
512 String value = html.attributes['value']; | 517 String value = html.attributes['value']; |
513 TypeDecl type = processContentsAsType(html, context); | 518 TypeDecl type = processContentsAsType(html, context); |
514 return new TypeObjectField(name, type, html, | 519 return new TypeObjectField(name, type, html, |
515 optional: optional, value: value); | 520 optional: optional, value: value, deprecated: deprecated); |
516 } | 521 } |
517 | 522 |
518 /** | 523 /** |
519 * Create a [TypeObject] from an HTML description. | 524 * Create a [TypeObject] from an HTML description. |
520 */ | 525 */ |
521 TypeObject typeObjectFromHtml(dom.Element html, String context) { | 526 TypeObject typeObjectFromHtml(dom.Element html, String context) { |
522 checkAttributes(html, [], context, optionalAttributes: ['experimental']); | 527 checkAttributes(html, [], context, optionalAttributes: ['experimental']); |
523 List<TypeObjectField> fields = <TypeObjectField>[]; | 528 List<TypeObjectField> fields = <TypeObjectField>[]; |
524 recurse(html, context, { | 529 recurse(html, context, { |
525 'field': (dom.Element child) { | 530 'field': (dom.Element child) { |
(...skipping 21 matching lines...) Expand all Loading... |
547 TypeDefinition typeDefinition = typeDefinitionFromHtml(child); | 552 TypeDefinition typeDefinition = typeDefinitionFromHtml(child); |
548 types[typeDefinition.name] = typeDefinition; | 553 types[typeDefinition.name] = typeDefinition; |
549 } | 554 } |
550 }); | 555 }); |
551 return new Types(types, html); | 556 return new Types(types, html); |
552 } | 557 } |
553 | 558 |
554 typedef void ElementProcessor(dom.Element element); | 559 typedef void ElementProcessor(dom.Element element); |
555 | 560 |
556 typedef void TextProcessor(dom.Text text); | 561 typedef void TextProcessor(dom.Text text); |
OLD | NEW |