diff --git a/pkg/analysis_server/analyzer_use_new_elements.txt b/pkg/analysis_server/analyzer_use_new_elements.txt index f0ca359f3d9e..44dea5770781 100644 --- a/pkg/analysis_server/analyzer_use_new_elements.txt +++ b/pkg/analysis_server/analyzer_use_new_elements.txt @@ -213,6 +213,7 @@ lib/src/services/correction/dart/add_key_to_constructors.dart lib/src/services/correction/dart/add_late.dart lib/src/services/correction/dart/add_leading_newline_to_string.dart lib/src/services/correction/dart/add_missing_enum_like_case_clauses.dart +lib/src/services/correction/dart/add_missing_parameter.dart lib/src/services/correction/dart/add_missing_parameter_named.dart lib/src/services/correction/dart/add_missing_required_argument.dart lib/src/services/correction/dart/add_ne_null.dart diff --git a/pkg/analysis_server/lib/src/services/correction/dart/add_missing_parameter.dart b/pkg/analysis_server/lib/src/services/correction/dart/add_missing_parameter.dart index 1ab5eb2e1558..c3eaabc729e7 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/add_missing_parameter.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/add_missing_parameter.dart @@ -31,8 +31,8 @@ class AddMissingParameter extends MultiCorrectionProducer { return const []; } - var includeOptional = executableParameters.optionalPositional.isEmpty && - executableParameters.named.isEmpty; + var includeOptional = executableParameters.optionalPositional2.isEmpty && + executableParameters.named2.isEmpty; return [ _AddMissingRequiredPositionalParameter(executableParameters, context: context), @@ -56,10 +56,11 @@ class _AddMissingOptionalPositionalParameter extends _AddMissingParameter { @override Future compute(ChangeBuilder builder) async { - var prefix = _executableParameters.required.isNotEmpty ? ', [' : '['; - if (_executableParameters.required.isNotEmpty) { + var prefix = _executableParameters.required2.isNotEmpty ? ', [' : '['; + if (_executableParameters.required2.isNotEmpty) { + var lastElement = _executableParameters.required2.last; var prevNode = await _executableParameters - .getParameterNode(_executableParameters.required.last); + .getParameterNode2(lastElement.firstFragment!); await _addParameter(builder, prevNode?.end, prefix, ']'); } else { var parameterList = await _executableParameters.getParameterList(); @@ -89,7 +90,7 @@ abstract class _AddMissingParameter extends ResolvedCorrectionProducer { return; } List arguments = argumentList.arguments; - var numRequired = _executableParameters.required.length; + var numRequired = _executableParameters.required2.length; if (numRequired >= arguments.length) { return; } @@ -118,15 +119,17 @@ class _AddMissingRequiredPositionalParameter extends _AddMissingParameter { @override Future compute(ChangeBuilder builder) async { - if (_executableParameters.required.isNotEmpty) { + if (_executableParameters.required2.isNotEmpty) { + var lastElement = _executableParameters.required2.last; var prevNode = await _executableParameters - .getParameterNode(_executableParameters.required.last); + .getParameterNode2(lastElement.firstFragment!); await _addParameter(builder, prevNode?.end, ', ', ''); } else { var parameterList = await _executableParameters.getParameterList(); var offset = parameterList?.leftParenthesis.end; - var suffix = - _executableParameters.executable.parameters.isNotEmpty ? ', ' : ''; + var suffix = _executableParameters.executable2.formalParameters.isNotEmpty + ? ', ' + : ''; await _addParameter(builder, offset, '', suffix); } } diff --git a/pkg/analysis_server/lib/src/services/correction/executable_parameters.dart b/pkg/analysis_server/lib/src/services/correction/executable_parameters.dart index c81d271e1318..1826cd924c55 100644 --- a/pkg/analysis_server/lib/src/services/correction/executable_parameters.dart +++ b/pkg/analysis_server/lib/src/services/correction/executable_parameters.dart @@ -11,6 +11,7 @@ import 'package:analyzer/src/dart/analysis/session_helper.dart'; class ExecutableParameters { final AnalysisSessionHelper sessionHelper; final ExecutableElement executable; + final ExecutableElement2 executable2; final List required = []; final List optionalPositional = []; @@ -20,7 +21,11 @@ class ExecutableParameters { final List optionalPositional2 = []; final List named2 = []; - ExecutableParameters._(this.sessionHelper, this.executable) { + ExecutableParameters._( + this.sessionHelper, + this.executable, + this.executable2, + ) { for (var parameter in executable.parameters) { if (parameter.isRequiredPositional) { required.add(parameter); @@ -89,18 +94,26 @@ class ExecutableParameters { static ExecutableParameters? forInvocation( AnalysisSessionHelper sessionHelper, AstNode? invocation) { Element? element; + Element2? element2; // This doesn't handle FunctionExpressionInvocation. if (invocation is Annotation) { element = invocation.element; + element2 = invocation.element2; } else if (invocation is InstanceCreationExpression) { element = invocation.constructorName.staticElement; + element2 = invocation.constructorName.element; } else if (invocation is MethodInvocation) { element = invocation.methodName.staticElement; + element2 = invocation.methodName.element; } else if (invocation is ConstructorReferenceNode) { element = invocation.staticElement; + element2 = invocation.element; } - if (element is ExecutableElement && !element.isSynthetic) { - return ExecutableParameters._(sessionHelper, element); + if (element is ExecutableElement && + !element.isSynthetic && + element2 is ExecutableElement2 && + !element2.isSynthetic) { + return ExecutableParameters._(sessionHelper, element, element2); } else { return null; }