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 analysis_server.src.services.correction.fix_internal; | 5 library analysis_server.src.services.correction.fix_internal; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:collection'; | 8 import 'dart:collection'; |
9 import 'dart:core' hide Resource; | 9 import 'dart:core' hide Resource; |
10 | 10 |
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 SimpleIdentifier methodName = invocation.methodName; | 421 SimpleIdentifier methodName = invocation.methodName; |
422 Element targetElement = methodName.bestElement; | 422 Element targetElement = methodName.bestElement; |
423 List<Expression> arguments = argumentList.arguments; | 423 List<Expression> arguments = argumentList.arguments; |
424 if (targetElement is ExecutableElement) { | 424 if (targetElement is ExecutableElement) { |
425 List<ParameterElement> parameters = targetElement.parameters; | 425 List<ParameterElement> parameters = targetElement.parameters; |
426 int numParameters = parameters.length; | 426 int numParameters = parameters.length; |
427 Iterable<ParameterElement> requiredParameters = parameters | 427 Iterable<ParameterElement> requiredParameters = parameters |
428 .takeWhile((p) => p.parameterKind == ParameterKind.REQUIRED); | 428 .takeWhile((p) => p.parameterKind == ParameterKind.REQUIRED); |
429 Iterable<ParameterElement> optionalParameters = parameters | 429 Iterable<ParameterElement> optionalParameters = parameters |
430 .skipWhile((p) => p.parameterKind == ParameterKind.REQUIRED); | 430 .skipWhile((p) => p.parameterKind == ParameterKind.REQUIRED); |
| 431 // prepare the argument to add a new parameter for |
431 int numRequired = requiredParameters.length; | 432 int numRequired = requiredParameters.length; |
| 433 if (numRequired >= arguments.length) { |
| 434 return; |
| 435 } |
432 Expression argument = arguments[numRequired]; | 436 Expression argument = arguments[numRequired]; |
433 // prepare target | 437 // prepare target |
434 int targetOffset; | 438 int targetOffset; |
435 if (numRequired != 0) { | 439 if (numRequired != 0) { |
436 AstNode parameterNode = requiredParameters.last.computeNode(); | 440 AstNode parameterNode = requiredParameters.last.computeNode(); |
437 targetOffset = parameterNode.end; | 441 targetOffset = parameterNode.end; |
438 } else { | 442 } else { |
439 AstNode targetNode = targetElement.computeNode(); | 443 AstNode targetNode = targetElement.computeNode(); |
440 if (targetNode is FunctionDeclaration) { | 444 if (targetNode is FunctionDeclaration) { |
441 FunctionExpression function = targetNode.functionExpression; | 445 FunctionExpression function = targetNode.functionExpression; |
(...skipping 2529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2971 /** | 2975 /** |
2972 * Describes the location for a newly created [FieldDeclaration]. | 2976 * Describes the location for a newly created [FieldDeclaration]. |
2973 */ | 2977 */ |
2974 class _FieldLocation { | 2978 class _FieldLocation { |
2975 final String prefix; | 2979 final String prefix; |
2976 final int offset; | 2980 final int offset; |
2977 final String suffix; | 2981 final String suffix; |
2978 | 2982 |
2979 _FieldLocation(this.prefix, this.offset, this.suffix); | 2983 _FieldLocation(this.prefix, this.offset, this.suffix); |
2980 } | 2984 } |
OLD | NEW |