Chromium Code Reviews| Index: pkg/analysis_server/lib/src/services/correction/fix_internal.dart |
| diff --git a/pkg/analysis_server/lib/src/services/correction/fix_internal.dart b/pkg/analysis_server/lib/src/services/correction/fix_internal.dart |
| index c823e4ebee013b703d53a1ab20670908d52e2da6..c42cf926be45776d0f1592967cefa9b7439314e1 100644 |
| --- a/pkg/analysis_server/lib/src/services/correction/fix_internal.dart |
| +++ b/pkg/analysis_server/lib/src/services/correction/fix_internal.dart |
| @@ -267,6 +267,9 @@ class FixProcessor { |
| _addFix_createConstructor_insteadOfSyntheticDefault(); |
| await _addFix_addMissingParameter(); |
| } |
| + if (errorCode == HintCode.MISSING_REQUIRED_PARAM) { |
|
Brian Wilkerson
2017/02/14 22:23:12
We might want to fix the hint code too.
pquitslund
2017/02/14 23:41:37
Probably. Unfortunately, this will break options
|
| + _addFix_addMissingRequiredParameter(); |
| + } |
| if (errorCode == StaticWarningCode.FUNCTION_WITHOUT_CALL) { |
| _addFix_addMissingMethodCall(); |
| } |
| @@ -549,6 +552,44 @@ class FixProcessor { |
| } |
| } |
| + void _addFix_addMissingRequiredParameter() { |
| + if (node is SimpleIdentifier && node.parent is MethodInvocation) { |
|
scheglov
2017/02/14 22:06:07
Do we need this functionality for constructors?
pquitslund
2017/02/14 23:41:37
Yes! Case added and a test.
|
| + MethodInvocation invocation = node.parent; |
|
scheglov
2017/02/14 22:06:07
I prefer speculatively name "AstNode invocation =
pquitslund
2017/02/14 23:41:37
Done.
|
| + Element targetElement = invocation.methodName.bestElement; |
| + if (targetElement is ExecutableElement) { |
| + List<ParameterElement> parameters = targetElement.parameters; |
| + List<Expression> arguments = invocation.argumentList.arguments; |
| + Iterable<String> namedArgs = arguments |
| + .where((e) => e is NamedExpression) |
| + .map((e) => (e as NamedExpression).name.label.name); |
| + |
| + Iterable<ParameterElement> missingParams = parameters |
| + .where((p) => p.isRequired && !namedArgs.contains(p.name)); |
|
scheglov
2017/02/14 22:06:07
Maybe materialize using toList().
pquitslund
2017/02/14 23:41:37
Done.
|
| + if (missingParams.isEmpty) { |
| + return; |
| + } |
| + |
| + // add proposal |
| + |
| + SourceBuilder sb; |
| + NodeList<Expression> args = invocation.argumentList.arguments; |
|
scheglov
2017/02/14 22:06:07
You already have "arguments" above.
pquitslund
2017/02/14 23:41:37
Ah. Good catch!
|
| + |
| + if (args.isEmpty) { |
| + sb = new SourceBuilder( |
| + file, invocation.argumentList.leftParenthesis.offset + 1); |
| + } else { |
| + sb = new SourceBuilder(file, args.last.endToken.offset + 1); |
|
scheglov
2017/02/14 22:06:07
I think this would work only for single character
pquitslund
2017/02/14 23:41:37
Good catch. Fixed!
|
| + sb.append(', '); |
| + } |
| + |
| + sb.append(missingParams.map((p) => '${p.name}: null').join(', ')); |
| + |
| + _insertBuilder(sb, targetElement); |
| + _addFix(DartFixKind.ADD_MISSING_REQUIRED_PARAMETER, []); |
|
scheglov
2017/02/14 22:06:07
Should we use different kinds for adding one, and
Brian Wilkerson
2017/02/14 22:23:12
Is there any reason not to always add all argument
pquitslund
2017/02/14 23:41:37
My thinking was to always just add them all. If t
|
| + } |
| + } |
| + } |
| + |
| void _addFix_boolInsteadOfBoolean() { |
| SourceRange range = rf.rangeError(error); |
| _addReplaceEdit(range, 'bool'); |