Chromium Code Reviews| 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 |
|
Johnni Winther
2014/02/03 08:21:27
The changes in this file fix warnings introduced i
| |
| 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 is for use in extracting messages from a Dart program | 6 * This is for use in extracting messages from a Dart program |
| 7 * using the Intl.message() mechanism and writing them to a file for | 7 * using the Intl.message() mechanism and writing them to a file for |
| 8 * translation. This provides only the stub of a mechanism, because it | 8 * translation. This provides only the stub of a mechanism, because it |
| 9 * doesn't define how the file should be written. It provides an | 9 * doesn't define how the file should be written. It provides an |
| 10 * [IntlMessage] class that holds the extracted data and [parseString] | 10 * [IntlMessage] class that holds the extracted data and [parseString] |
| 11 * and [parseFile] methods which | 11 * and [parseFile] methods which |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 * as that will be the nearest parent of the Intl.message invocation. | 105 * as that will be the nearest parent of the Intl.message invocation. |
| 106 */ | 106 */ |
| 107 FormalParameterList parameters; | 107 FormalParameterList parameters; |
| 108 String name; | 108 String name; |
| 109 | 109 |
| 110 /** Return true if [node] matches the pattern we expect for Intl.message() */ | 110 /** Return true if [node] matches the pattern we expect for Intl.message() */ |
| 111 bool looksLikeIntlMessage(MethodInvocation node) { | 111 bool looksLikeIntlMessage(MethodInvocation node) { |
| 112 const validNames = const ["message", "plural", "gender", "select"]; | 112 const validNames = const ["message", "plural", "gender", "select"]; |
| 113 if (!validNames.contains(node.methodName.name)) return false; | 113 if (!validNames.contains(node.methodName.name)) return false; |
| 114 if (!(node.target is SimpleIdentifier)) return false; | 114 if (!(node.target is SimpleIdentifier)) return false; |
| 115 return node.target.token.toString() == "Intl"; | 115 SimpleIdentifier target = node.target; |
| 116 return target.token.toString() == "Intl"; | |
| 116 } | 117 } |
| 117 | 118 |
| 118 Message _expectedInstance(String type) { | 119 Message _expectedInstance(String type) { |
| 119 switch (type) { | 120 switch (type) { |
| 120 case 'message' : return new MainMessage(); | 121 case 'message' : return new MainMessage(); |
| 121 case 'plural' : return new Plural(); | 122 case 'plural' : return new Plural(); |
| 122 case 'gender' : return new Gender(); | 123 case 'gender' : return new Gender(); |
| 123 case 'select' : return new Select(); | 124 case 'select' : return new Select(); |
| 124 default: return null; | 125 default: return null; |
| 125 } | 126 } |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 397 pieces.add(messageFromMethodInvocation(node)); | 398 pieces.add(messageFromMethodInvocation(node)); |
| 398 super.visitMethodInvocation(node); | 399 super.visitMethodInvocation(node); |
| 399 } | 400 } |
| 400 | 401 |
| 401 /** Return true if [node] matches the pattern for plural or gender message.*/ | 402 /** Return true if [node] matches the pattern for plural or gender message.*/ |
| 402 bool looksLikePluralOrGender(MethodInvocation node) { | 403 bool looksLikePluralOrGender(MethodInvocation node) { |
| 403 if (!["plural", "gender", "select"].contains(node.methodName.name)) { | 404 if (!["plural", "gender", "select"].contains(node.methodName.name)) { |
| 404 return false; | 405 return false; |
| 405 } | 406 } |
| 406 if (!(node.target is SimpleIdentifier)) return false; | 407 if (!(node.target is SimpleIdentifier)) return false; |
| 407 return node.target.token.toString() == "Intl"; | 408 SimpleIdentifier target = node.target; |
| 409 return target.token.toString() == "Intl"; | |
| 408 } | 410 } |
| 409 | 411 |
| 410 /** | 412 /** |
| 411 * Returns a String describing why the node is invalid, or null if no | 413 * Returns a String describing why the node is invalid, or null if no |
| 412 * reason is found, so it's presumed valid. | 414 * reason is found, so it's presumed valid. |
| 413 */ | 415 */ |
| 414 String checkValidity(MethodInvocation node) { | 416 String checkValidity(MethodInvocation node) { |
| 415 // TODO(alanknight): Add reasonable validity checks. | 417 // TODO(alanknight): Add reasonable validity checks. |
| 416 } | 418 } |
| 417 | 419 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 433 | 435 |
| 434 var arguments = message.argumentsOfInterestFor(node); | 436 var arguments = message.argumentsOfInterestFor(node); |
| 435 arguments.forEach((key, value) { | 437 arguments.forEach((key, value) { |
| 436 try { | 438 try { |
| 437 var interpolation = new InterpolationVisitor(message); | 439 var interpolation = new InterpolationVisitor(message); |
| 438 value.accept(interpolation); | 440 value.accept(interpolation); |
| 439 message[key] = interpolation.pieces; | 441 message[key] = interpolation.pieces; |
| 440 } on IntlMessageExtractionException catch (e) { | 442 } on IntlMessageExtractionException catch (e) { |
| 441 message = null; | 443 message = null; |
| 442 var err = new StringBuffer() | 444 var err = new StringBuffer() |
| 443 ..writeAll(["Error ", $e, "\nProcessing <", node, ">"]) | 445 ..writeAll(["Error ", e, "\nProcessing <", node, ">"]) |
| 444 ..write(_reportErrorLocation(node)); | 446 ..write(_reportErrorLocation(node)); |
| 445 print(err); | 447 print(err); |
| 446 warnings.add(err); | 448 warnings.add(err); |
| 447 } | 449 } |
| 448 }); | 450 }); |
| 449 var mainArg = node.argumentList.arguments.firstWhere( | 451 var mainArg = node.argumentList.arguments.firstWhere( |
| 450 (each) => each is! NamedExpression); | 452 (each) => each is! NamedExpression); |
| 451 if (mainArg is SimpleStringLiteral) { | 453 if (mainArg is SimpleStringLiteral) { |
| 452 message.mainArgument = mainArg.toString(); | 454 message.mainArgument = mainArg.toString(); |
| 453 } else { | 455 } else { |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 466 */ | 468 */ |
| 467 final String message; | 469 final String message; |
| 468 | 470 |
| 469 /** | 471 /** |
| 470 * Creates a new exception with an optional error [message]. | 472 * Creates a new exception with an optional error [message]. |
| 471 */ | 473 */ |
| 472 const IntlMessageExtractionException([this.message = ""]); | 474 const IntlMessageExtractionException([this.message = ""]); |
| 473 | 475 |
| 474 String toString() => "IntlMessageExtractionException: $message"; | 476 String toString() => "IntlMessageExtractionException: $message"; |
| 475 } | 477 } |
| OLD | NEW |