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/dart/ast/token.dart'; | 10 import 'package:analyzer/dart/ast/token.dart'; |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 this._arguments, | 146 this._arguments, |
147 this._functions, | 147 this._functions, |
148 this._argumentsAfterFunctions); | 148 this._argumentsAfterFunctions); |
149 | 149 |
150 /// Builds chunks for the argument list. | 150 /// Builds chunks for the argument list. |
151 void visit() { | 151 void visit() { |
152 // If there is just one positional argument, it tends to look weird to | 152 // If there is just one positional argument, it tends to look weird to |
153 // split before it, so try not to. | 153 // split before it, so try not to. |
154 if (_isSingle) _visitor.builder.startSpan(); | 154 if (_isSingle) _visitor.builder.startSpan(); |
155 | 155 |
156 // Nest around the parentheses in case there are comments before or after | |
157 // them. | |
158 _visitor.builder.nestExpression(); | |
159 _visitor.builder.startSpan(); | 156 _visitor.builder.startSpan(); |
160 _visitor.token(_leftParenthesis); | 157 _visitor.token(_leftParenthesis); |
161 | 158 |
162 _arguments.visit(_visitor); | 159 _arguments.visit(_visitor); |
163 | 160 |
164 _visitor.builder.endSpan(); | 161 _visitor.builder.endSpan(); |
165 | 162 |
166 if (_functions != null) { | 163 if (_functions != null) { |
167 // TODO(rnystrom): It might look better to treat the parameter list of the | 164 // TODO(rnystrom): It might look better to treat the parameter list of the |
168 // first function as if it were an argument in the preceding argument list | 165 // first function as if it were an argument in the preceding argument list |
(...skipping 17 matching lines...) Expand all Loading... |
186 } | 183 } |
187 } | 184 } |
188 | 185 |
189 _visitor.builder.startSpan(); | 186 _visitor.builder.startSpan(); |
190 _argumentsAfterFunctions.visit(_visitor); | 187 _argumentsAfterFunctions.visit(_visitor); |
191 _visitor.builder.endSpan(); | 188 _visitor.builder.endSpan(); |
192 } | 189 } |
193 | 190 |
194 _visitor.token(_rightParenthesis); | 191 _visitor.token(_rightParenthesis); |
195 | 192 |
196 _visitor.builder.unnest(); | |
197 | |
198 if (_isSingle) _visitor.builder.endSpan(); | 193 if (_isSingle) _visitor.builder.endSpan(); |
199 } | 194 } |
200 | 195 |
201 /// Returns `true` if [expression] is a [FunctionExpression] with a non-empty | 196 /// Returns `true` if [expression] is a [FunctionExpression] with a non-empty |
202 /// block body. | 197 /// block body. |
203 static bool _isBlockFunction(Expression expression) { | 198 static bool _isBlockFunction(Expression expression) { |
204 if (expression is NamedExpression) { | 199 if (expression is NamedExpression) { |
205 expression = (expression as NamedExpression).expression; | 200 expression = (expression as NamedExpression).expression; |
206 } | 201 } |
207 | 202 |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 | 458 |
464 // TODO(rnystrom): Should we step into parenthesized expressions? | 459 // TODO(rnystrom): Should we step into parenthesized expressions? |
465 | 460 |
466 if (expression is ListLiteral) return expression.leftBracket; | 461 if (expression is ListLiteral) return expression.leftBracket; |
467 if (expression is MapLiteral) return expression.leftBracket; | 462 if (expression is MapLiteral) return expression.leftBracket; |
468 | 463 |
469 // Not a collection literal. | 464 // Not a collection literal. |
470 return null; | 465 return null; |
471 } | 466 } |
472 } | 467 } |
OLD | NEW |