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

Unified Diff: lib/src/argument_list_visitor.dart

Issue 1258203006: Handle function arguments inside function calls. (Closed) Base URL: https://github.com/dart-lang/dart_style.git@master
Patch Set: Reformat self. 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 | « CHANGELOG.md ('k') | lib/src/line_splitting/solve_state.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/argument_list_visitor.dart
diff --git a/lib/src/argument_list_visitor.dart b/lib/src/argument_list_visitor.dart
index 4acb3b450cea00bff44c82b294a422e1a7ee18cf..c45b73724827255098d99f0f86c7a0c6a4045d40 100644
--- a/lib/src/argument_list_visitor.dart
+++ b/lib/src/argument_list_visitor.dart
@@ -97,12 +97,8 @@ class ArgumentListVisitor {
new ArgumentSublist(node.arguments, argumentsAfter));
}
- ArgumentListVisitor._(
- this._visitor,
- this._node,
- this._arguments,
- this._functions,
- this._argumentsAfterFunctions);
+ ArgumentListVisitor._(this._visitor, this._node, this._arguments,
+ this._functions, this._argumentsAfterFunctions);
/// Builds chunks for the call chain.
void visit() {
@@ -162,11 +158,36 @@ class ArgumentListVisitor {
expression = (expression as NamedExpression).expression;
}
+ // Allow functions wrapped in dotted method calls like "a.b.c(() { ... })".
+ if (expression is MethodInvocation) {
+ if (!_isValidWrappingTarget(expression.target)) return false;
+ if (expression.argumentList.arguments.length != 1) return false;
+
+ return _isBlockFunction(expression.argumentList.arguments.single);
+ }
+
// Curly body functions are.
if (expression is! FunctionExpression) return false;
var function = expression as FunctionExpression;
return function.body is BlockFunctionBody;
}
+
+ /// Returns `true` if [expression] is a valid method invocation target for
+ /// an invocation that wraps a function literal argument.
+ static bool _isValidWrappingTarget(Expression expression) {
+ // Allow bare function calls.
+ if (expression == null) return true;
+
+ // Allow property accesses.
+ while (expression is PropertyAccess) {
+ expression = (expression as PropertyAccess).target;
+ }
+
+ if (expression is PrefixedIdentifier) return true;
+ if (expression is SimpleIdentifier) return true;
+
+ return false;
+ }
}
/// A range of arguments from a complete argument list.
@@ -333,8 +354,8 @@ class ArgumentSublist {
}
// Split before the first named argument.
- namedRule.beforeArguments(visitor.builder.split(
- space: !_isFirstArgument(_named.first)));
+ namedRule.beforeArguments(
+ visitor.builder.split(space: !_isFirstArgument(_named.first)));
for (var argument in _named) {
_visitArgument(visitor, namedRule, argument);
@@ -346,7 +367,8 @@ class ArgumentSublist {
visitor.builder.endRule();
}
- void _visitArgument(SourceVisitor visitor, ArgumentRule rule, Expression argument) {
+ void _visitArgument(
+ SourceVisitor visitor, ArgumentRule rule, Expression argument) {
// If we're about to write a collection argument, handle it specially.
if (_collections.contains(argument)) {
if (rule != null) rule.beforeCollection();
@@ -394,4 +416,4 @@ class ArgumentSublist {
return expression is ListLiteral || expression is MapLiteral;
}
-}
+}
« no previous file with comments | « CHANGELOG.md ('k') | lib/src/line_splitting/solve_state.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698