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

Unified Diff: lib/src/intl_message.dart

Issue 1244843002: Allow ClassName_methodName for a message name, easier to disambiguate duplicates (Closed) Base URL: https://github.com/dart-lang/intl.git@master
Patch Set: Created 5 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/intl.dart ('k') | pubspec.yaml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/intl_message.dart
diff --git a/lib/src/intl_message.dart b/lib/src/intl_message.dart
index 28a118acbf1ec5e7ddc4e61e04b26191c5992cf5..3df4a6194965cd19377aa7175b27d36793a8c97d 100644
--- a/lib/src/intl_message.dart
+++ b/lib/src/intl_message.dart
@@ -93,10 +93,23 @@ abstract class Message {
return "The 'name' argument for Intl.message must be a simple string "
"literal.";
}
- if (outerName != null && outerName != messageName.expression.value) {
- return "The 'name' argument for Intl.message must match "
- "the name of the containing function ("
- "'${messageName.expression.value}' vs. '$outerName')";
+ var hasOuterName = outerName != null;
+ var givenName = messageName.expression.value;
+ var simpleMatch = outerName == givenName;
+ ClassDeclaration classNode(n) {
+ if (n == null) return null;
+ if (n is ClassDeclaration) return n;
+ return classNode(n.parent);
+ }
+ var classDeclaration = classNode(node);
+ var classPlusMethod = classDeclaration == null
+ ? null
+ : "${classDeclaration.name.token.toString()}_$outerName";
+ var classMatch = classPlusMethod != null && (givenName == classPlusMethod);
+ if (!(hasOuterName && (simpleMatch || classMatch))) {
+ return "The 'name' argument for Intl.message must match either"
+ "the name of the containing function or <className>_<methodName> ("
+ "'$givenName' vs. '$outerName')";
}
var simpleArguments = arguments.where((each) => each is NamedExpression &&
["desc", "name"].contains(each.name.label.name));
« no previous file with comments | « lib/intl.dart ('k') | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698