checkArgs method
Verify that the args argument matches the method parameters and isn't, e.g. passing string names instead of the argument values.
Implementation
bool checkArgs(NamedExpression? args, List<String> parameterNames) {
if (args == null) return true;
// Detect cases where args passes invalid names, either literal strings
// instead of identifiers, or in the wrong order, missing values, etc.
ListLiteral identifiers = args.childEntities.last as ListLiteral;
if (!identifiers.elements.every((each) => each is SimpleIdentifier)) {
return false;
}
var names = identifiers.elements
.map((each) => (each as SimpleIdentifier).name)
.toList();
var both;
try {
both = new Map.fromIterables(names, parameterNames);
} catch (e) {
// Most likely because sizes don't match.
return false;
}
var everythingMatches = true;
both.forEach((name, parameterName) {
if (name != parameterName) everythingMatches = false;
});
return everythingMatches;
}