| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 * This provides classes to represent the internal structure of the | 6 * This provides classes to represent the internal structure of the |
| 7 * arguments to `Intl.message`. It is used when parsing sources to extract | 7 * arguments to `Intl.message`. It is used when parsing sources to extract |
| 8 * messages or to generate code for message substitution. Normal programs | 8 * messages or to generate code for message substitution. Normal programs |
| 9 * using Intl would not import this library. | 9 * using Intl would not import this library. |
| 10 * | 10 * |
| (...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 * The name of the main argument, which is expected to have the value | 452 * The name of the main argument, which is expected to have the value |
| 453 * which is one of [attributeNames] and is used to decide which clause to use. | 453 * which is one of [attributeNames] and is used to decide which clause to use. |
| 454 */ | 454 */ |
| 455 String mainArgument; | 455 String mainArgument; |
| 456 | 456 |
| 457 /** | 457 /** |
| 458 * Return the arguments that affect this SubMessage as a map of | 458 * Return the arguments that affect this SubMessage as a map of |
| 459 * argument names and values. | 459 * argument names and values. |
| 460 */ | 460 */ |
| 461 Map argumentsOfInterestFor(MethodInvocation node) { | 461 Map argumentsOfInterestFor(MethodInvocation node) { |
| 462 var basicArguments = node.argumentList.arguments.elements; | 462 var basicArguments = node.argumentList.arguments; |
| 463 var others = basicArguments.where((each) => each is NamedExpression); | 463 var others = basicArguments.where((each) => each is NamedExpression); |
| 464 return new Map.fromIterable(others, | 464 return new Map.fromIterable(others, |
| 465 key: (node) => node.name.label.token.value(), | 465 key: (node) => node.name.label.token.value(), |
| 466 value: (node) => node.expression); | 466 value: (node) => node.expression); |
| 467 } | 467 } |
| 468 | 468 |
| 469 /** | 469 /** |
| 470 * Return the list of attribute names to use when generating code. This | 470 * Return the list of attribute names to use when generating code. This |
| 471 * may be different from [attributeNames] if there are multiple aliases | 471 * may be different from [attributeNames] if there are multiple aliases |
| 472 * that map to the same clause. | 472 * that map to the same clause. |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 636 var exact = cases[attributeName]; | 636 var exact = cases[attributeName]; |
| 637 return exact == null ? cases["other"] : exact; | 637 return exact == null ? cases["other"] : exact; |
| 638 } | 638 } |
| 639 | 639 |
| 640 /** | 640 /** |
| 641 * Return the arguments that we care about for the select. In this | 641 * Return the arguments that we care about for the select. In this |
| 642 * case they will all be passed in as a Map rather than as the named | 642 * case they will all be passed in as a Map rather than as the named |
| 643 * arguments used in Plural/Gender. | 643 * arguments used in Plural/Gender. |
| 644 */ | 644 */ |
| 645 Map argumentsOfInterestFor(MethodInvocation node) { | 645 Map argumentsOfInterestFor(MethodInvocation node) { |
| 646 var casesArgument = node.argumentList.arguments.elements[1]; | 646 var casesArgument = node.argumentList.arguments[1]; |
| 647 return new Map.fromIterable(casesArgument.entries, | 647 return new Map.fromIterable(casesArgument.entries, |
| 648 key: (node) => node.key.value, | 648 key: (node) => node.key.value, |
| 649 value: (node) => node.value); | 649 value: (node) => node.value); |
| 650 } | 650 } |
| 651 | 651 |
| 652 /** | 652 /** |
| 653 * Write out the generated representation of this message. This differs | 653 * Write out the generated representation of this message. This differs |
| 654 * from Plural/Gender in that it prints a literal map rather than | 654 * from Plural/Gender in that it prints a literal map rather than |
| 655 * named arguments. | 655 * named arguments. |
| 656 */ | 656 */ |
| 657 String toCode() { | 657 String toCode() { |
| 658 var out = new StringBuffer(); | 658 var out = new StringBuffer(); |
| 659 out.write('\${'); | 659 out.write('\${'); |
| 660 out.write(dartMessageName); | 660 out.write(dartMessageName); |
| 661 out.write('('); | 661 out.write('('); |
| 662 out.write(mainArgument); | 662 out.write(mainArgument); |
| 663 var args = codeAttributeNames; | 663 var args = codeAttributeNames; |
| 664 out.write(", {"); | 664 out.write(", {"); |
| 665 args.fold(out, (buffer, arg) => buffer..write( | 665 args.fold(out, (buffer, arg) => buffer..write( |
| 666 "'$arg': '${this[arg].toCode()}', ")); | 666 "'$arg': '${this[arg].toCode()}', ")); |
| 667 out.write("})}"); | 667 out.write("})}"); |
| 668 return out.toString(); | 668 return out.toString(); |
| 669 } | 669 } |
| 670 } | 670 } |
| OLD | NEW |