| 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..eb45caf2cef0f283d9080d42817a773264135a60 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) {
|
| + _addFix_addMissingRequiredArgument();
|
| + }
|
| if (errorCode == StaticWarningCode.FUNCTION_WITHOUT_CALL) {
|
| _addFix_addMissingMethodCall();
|
| }
|
| @@ -549,6 +552,57 @@ class FixProcessor {
|
| }
|
| }
|
|
|
| + void _addFix_addMissingRequiredArgument() {
|
| + Element targetElement;
|
| + ArgumentList argumentList;
|
| +
|
| + if (node is SimpleIdentifier) {
|
| + AstNode invocation = node.parent;
|
| + if (invocation is MethodInvocation) {
|
| + targetElement = invocation.methodName.bestElement;
|
| + argumentList = invocation.argumentList;
|
| + } else {
|
| + AstNode ancestor =
|
| + invocation.getAncestor((p) => p is InstanceCreationExpression);
|
| + if (ancestor is InstanceCreationExpression) {
|
| + targetElement = ancestor.staticElement;
|
| + argumentList = ancestor.argumentList;
|
| + }
|
| + }
|
| + }
|
| +
|
| + if (targetElement is ExecutableElement) {
|
| + List<Expression> args = argumentList.arguments;
|
| + List<String> namedArgs = args
|
| + .where((e) => e is NamedExpression)
|
| + .map((e) => (e as NamedExpression).name.label.name)
|
| + .toList(growable: false);
|
| +
|
| + List<ParameterElement> missingParams = targetElement.parameters
|
| + .where((p) => p.isRequired && !namedArgs.contains(p.name))
|
| + .toList(growable: false);
|
| + if (missingParams.isEmpty) {
|
| + return;
|
| + }
|
| +
|
| + // add proposal
|
| +
|
| + SourceBuilder sb;
|
| +
|
| + if (args.isEmpty) {
|
| + sb = new SourceBuilder(file, argumentList.leftParenthesis.end);
|
| + } else {
|
| + sb = new SourceBuilder(file, args.last.end);
|
| + sb.append(', ');
|
| + }
|
| +
|
| + sb.append(missingParams.map((p) => '${p.name}: null').join(', '));
|
| +
|
| + _insertBuilder(sb, targetElement);
|
| + _addFix(DartFixKind.ADD_MISSING_REQUIRED_ARGUMENT, []);
|
| + }
|
| + }
|
| +
|
| void _addFix_boolInsteadOfBoolean() {
|
| SourceRange range = rf.rangeError(error);
|
| _addReplaceEdit(range, 'bool');
|
|
|