| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 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 library dart_style.src.argument_list_visitor; | 5 library dart_style.src.argument_list_visitor; |
| 6 | 6 |
| 7 import 'dart:math' as math; | 7 import 'dart:math' as math; |
| 8 | 8 |
| 9 import 'package:analyzer/analyzer.dart'; | 9 import 'package:analyzer/analyzer.dart'; |
| 10 import 'package:analyzer/src/generated/scanner.dart'; | 10 import 'package:analyzer/src/generated/scanner.dart'; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 if (functionsEnd != null && functionsEnd != i) { | 61 if (functionsEnd != null && functionsEnd != i) { |
| 62 functionsStart = null; | 62 functionsStart = null; |
| 63 functionsEnd = null; | 63 functionsEnd = null; |
| 64 break; | 64 break; |
| 65 } | 65 } |
| 66 | 66 |
| 67 functionsEnd = i + 1; | 67 functionsEnd = i + 1; |
| 68 } | 68 } |
| 69 } | 69 } |
| 70 | 70 |
| 71 // Edge case: If all of the arguments are named, but they aren't all |
| 72 // functions, then don't handle the functions specially. A function with a |
| 73 // bunch of named arguments tends to look best when they are all lined up, |
| 74 // even the function ones (unless they are all functions). |
| 75 // |
| 76 // Prefers: |
| 77 // |
| 78 // function( |
| 79 // named: () { |
| 80 // something(); |
| 81 // }, |
| 82 // another: argument); |
| 83 // |
| 84 // Over: |
| 85 // |
| 86 // function(named: () { |
| 87 // something(); |
| 88 // } |
| 89 // another: argument); |
| 90 if (functionsStart != null && |
| 91 node.arguments[0] is NamedExpression && |
| 92 (functionsStart > 0 || functionsEnd < node.arguments.length)) { |
| 93 functionsStart = null; |
| 94 } |
| 95 |
| 71 if (functionsStart == null) { | 96 if (functionsStart == null) { |
| 72 // No functions, so there is just a single argument list. | 97 // No functions, so there is just a single argument list. |
| 73 return new ArgumentListVisitor._(visitor, node, | 98 return new ArgumentListVisitor._(visitor, node, |
| 74 new ArgumentSublist(node.arguments, node.arguments), null, null); | 99 new ArgumentSublist(node.arguments, node.arguments), null, null); |
| 75 } | 100 } |
| 76 | 101 |
| 77 // Split the arguments into two independent argument lists with the | 102 // Split the arguments into two independent argument lists with the |
| 78 // functions in the middle. | 103 // functions in the middle. |
| 79 var argumentsBefore = node.arguments.take(functionsStart).toList(); | 104 var argumentsBefore = node.arguments.take(functionsStart).toList(); |
| 80 var functions = node.arguments.sublist(functionsStart, functionsEnd); | 105 var functions = node.arguments.sublist(functionsStart, functionsEnd); |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 | 437 |
| 413 // TODO(rnystrom): Should we step into parenthesized expressions? | 438 // TODO(rnystrom): Should we step into parenthesized expressions? |
| 414 | 439 |
| 415 if (expression is ListLiteral) return expression.leftBracket; | 440 if (expression is ListLiteral) return expression.leftBracket; |
| 416 if (expression is MapLiteral) return expression.leftBracket; | 441 if (expression is MapLiteral) return expression.leftBracket; |
| 417 | 442 |
| 418 // Not a collection literal. | 443 // Not a collection literal. |
| 419 return null; | 444 return null; |
| 420 } | 445 } |
| 421 } | 446 } |
| OLD | NEW |