messageFromMethodInvocation method
Create a MainMessage from node
using the name and
parameters of the last function/method declaration we encountered
and the parameters to the Intl.message call.
Implementation
Message? messageFromMethodInvocation(MethodInvocation node) {
var message;
switch (node.methodName.name) {
case "gender":
message = new Gender();
break;
case "plural":
message = new Plural();
break;
case "select":
message = new Select();
break;
default:
throw new IntlMessageExtractionException(
"Invalid plural/gender/select message ${node.methodName.name} "
"in $node");
}
message.parent = parent;
var arguments = message.argumentsOfInterestFor(node);
arguments.forEach((key, value) {
try {
var interpolation = new InterpolationVisitor(message, extraction);
value.accept(interpolation);
// Might be null due to previous errors.
// Continue collecting errors, but don't build message.
if (message != null) {
message[key] = interpolation.pieces;
}
} on IntlMessageExtractionException catch (e) {
message = null;
var err = new StringBuffer()
..writeAll(["Error ", e, "\nProcessing <", node, ">"])
..write(extraction._reportErrorLocation(node));
var errString = err.toString();
extraction.onMessage(errString);
extraction.warnings.add(errString);
}
});
var mainArg = node.argumentList.arguments
.firstWhere((each) => each is! NamedExpression);
if (mainArg is SimpleStringLiteral) {
message?.mainArgument = mainArg.toString();
} else if (mainArg is SimpleIdentifier) {
message?.mainArgument = mainArg.name;
} else {
var err = new StringBuffer()
..write("Error (Invalid argument to plural/gender/select, "
"must be simple variable reference) "
"\nProcessing <$node>")
..write(extraction._reportErrorLocation(node));
var errString = err.toString();
extraction.onMessage(errString);
extraction.warnings.add(errString);
}
return message;
}