From 1ad68b9b16bc583dd1024ccd51683c35e28c142b Mon Sep 17 00:00:00 2001 From: Brian Wilkerson Date: Sat, 24 Apr 2021 18:12:07 +0000 Subject: [PATCH] Make local variables that hide fields be final (analysis_server) As per our earlier conversation, I looked for places where a local variable was introduced to overcome field promotion and has the same name as the field. Where possible I made them final; where not possible I changed the name. Change-Id: Iad3d2139693ca66f1eb22a3926c3b84a4115f13d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/196552 Reviewed-by: Konstantin Shcheglov Commit-Queue: Brian Wilkerson --- .../instrumentation_input_converter.dart | 2 +- .../lib/protocol/protocol.dart | 8 ++--- .../lib/src/edit/edit_domain.dart | 6 ++-- .../lib/src/plugin/plugin_manager.dart | 2 +- .../completion/dart/arglist_contributor.dart | 10 +++--- .../completion/dart/completion_manager.dart | 3 +- .../completion/dart/feature_computer.dart | 2 +- .../completion/dart/keyword_contributor.dart | 8 ++--- .../correction/dart/abstract_producer.dart | 2 +- .../services/correction/dart/add_async.dart | 2 +- .../services/correction/dart/add_const.dart | 24 ++++++------- .../services/correction/dart/add_late.dart | 2 +- .../dart/add_missing_parameter_named.dart | 2 +- .../dart/add_missing_required_argument.dart | 2 +- .../services/correction/dart/add_ne_null.dart | 2 +- .../correction/dart/add_null_check.dart | 2 +- .../correction/dart/add_type_annotation.dart | 2 +- .../correction/dart/change_argument_name.dart | 2 +- .../services/correction/dart/change_to.dart | 8 ++--- .../correction/dart/convert_into_is_not.dart | 2 +- .../correction/dart/convert_quotes.dart | 2 +- .../correction/dart/convert_to_if_null.dart | 2 +- .../dart/convert_to_multiline_string.dart | 10 +++--- .../dart/convert_to_null_aware.dart | 22 ++++++------ .../dart/convert_to_package_import.dart | 10 +++--- .../dart/convert_to_relative_import.dart | 14 ++++---- .../correction/dart/create_class.dart | 24 ++++++------- .../correction/dart/create_method.dart | 7 ++-- .../correction/dart/create_mixin.dart | 2 +- .../services/correction/dart/data_driven.dart | 2 +- .../dart/extend_class_for_mixin.dart | 2 +- .../dart/flutter_convert_to_children.dart | 2 +- .../correction/dart/import_library.dart | 36 +++++++++---------- .../correction/dart/inline_invocation.dart | 2 +- .../correction/dart/insert_semicolon.dart | 4 +-- .../dart/join_variable_declaration.dart | 2 +- .../correction/dart/make_field_not_final.dart | 2 +- .../services/correction/dart/make_final.dart | 2 +- .../dart/make_return_type_nullable.dart | 2 +- .../dart/make_variable_not_final.dart | 2 +- .../correction/dart/remove_dead_code.dart | 2 +- .../dart/remove_interpolation_braces.dart | 2 +- ...move_parameters_in_getter_declaration.dart | 2 +- .../correction/dart/remove_question_mark.dart | 12 +++---- .../dart/remove_this_expression.dart | 2 +- .../dart/replace_new_with_const.dart | 10 +++--- .../replace_with_conditional_assignment.dart | 2 +- .../correction/dart/shadow_field.dart | 1 + .../correction/dart/wrap_in_future.dart | 2 +- .../fix/data_driven/add_type_parameter.dart | 4 +-- .../fix/data_driven/rename_parameter.dart | 2 +- .../correction/statement_analyzer.dart | 10 +++--- .../lib/src/services/correction/status.dart | 2 +- .../src/services/pub/pub_package_service.dart | 10 +++--- .../services/refactoring/extract_local.dart | 6 ++-- .../services/refactoring/rename_local.dart | 2 +- .../lib/src/utilities/extensions/ast.dart | 4 +-- .../lib/src/utilities/request_statistics.dart | 2 +- .../support/integration_tests.dart | 4 +-- .../test/search/element_references_test.dart | 2 +- .../refactoring/inline_method_test.dart | 4 +-- .../test/stress/utilities/git.dart | 4 +-- .../test/utils/test_support.dart | 2 +- .../code_completion/completion_metrics.dart | 4 +-- .../tool/instrumentation/page/log_page.dart | 2 +- pkg/analysis_server/tool/spec/api.dart | 6 ++-- 66 files changed, 176 insertions(+), 173 deletions(-) diff --git a/pkg/analysis_server/benchmark/integration/instrumentation_input_converter.dart b/pkg/analysis_server/benchmark/integration/instrumentation_input_converter.dart index 037c9b0233d..a70184052d0 100644 --- a/pkg/analysis_server/benchmark/integration/instrumentation_input_converter.dart +++ b/pkg/analysis_server/benchmark/integration/instrumentation_input_converter.dart @@ -32,7 +32,7 @@ class InstrumentationInputConverter extends CommonInputConverter { try { fields = _parseFields(line); if (fields.length < 2) { - var readBuffer = this.readBuffer; + final readBuffer = this.readBuffer; if (readBuffer != null) { readBuffer.writeln(fields.length == 1 ? fields[0] : ''); return null; diff --git a/pkg/analysis_server/lib/protocol/protocol.dart b/pkg/analysis_server/lib/protocol/protocol.dart index e9d5c9d361c..9d15dac4640 100644 --- a/pkg/analysis_server/lib/protocol/protocol.dart +++ b/pkg/analysis_server/lib/protocol/protocol.dart @@ -46,7 +46,7 @@ class Notification { Map toJson() { var jsonObject = {}; jsonObject[EVENT] = event; - var params = this.params; + final params = this.params; if (params != null) { jsonObject[PARAMS] = params; } @@ -114,7 +114,7 @@ class Request { if (params.isNotEmpty) { jsonObject[PARAMS] = params; } - var clientRequestTime = this.clientRequestTime; + final clientRequestTime = this.clientRequestTime; if (clientRequestTime != null) { jsonObject[CLIENT_REQUEST_TIME] = clientRequestTime; } @@ -505,11 +505,11 @@ class Response { Map toJson() { var jsonObject = {}; jsonObject[ID] = id; - var error = this.error; + final error = this.error; if (error != null) { jsonObject[ERROR] = error.toJson(); } - var result = this.result; + final result = this.result; if (result != null) { jsonObject[RESULT] = result; } diff --git a/pkg/analysis_server/lib/src/edit/edit_domain.dart b/pkg/analysis_server/lib/src/edit/edit_domain.dart index 4c5becb059c..57d87fe6434 100644 --- a/pkg/analysis_server/lib/src/edit/edit_domain.dart +++ b/pkg/analysis_server/lib/src/edit/edit_domain.dart @@ -1227,7 +1227,7 @@ class _RefactoringManager { initStatus = await refactoring.checkInitialConditions(); _checkForReset_afterInitialConditions(); if (refactoring is ExtractLocalRefactoring) { - var feedback = this.feedback as ExtractLocalVariableFeedback; + final feedback = this.feedback as ExtractLocalVariableFeedback; feedback.names = refactoring.names; feedback.offsets = refactoring.offsets; feedback.lengths = refactoring.lengths; @@ -1236,7 +1236,7 @@ class _RefactoringManager { feedback.coveringExpressionLengths = refactoring.coveringExpressionLengths; } else if (refactoring is ExtractMethodRefactoring) { - var feedback = this.feedback as ExtractMethodFeedback; + final feedback = this.feedback as ExtractMethodFeedback; feedback.canCreateGetter = refactoring.canCreateGetter; feedback.returnType = refactoring.returnType; feedback.names = refactoring.names; @@ -1255,7 +1255,7 @@ class _RefactoringManager { className: refactoring.className); } } else if (refactoring is RenameRefactoring) { - var feedback = this.feedback as RenameFeedback; + final feedback = this.feedback as RenameFeedback; feedback.elementKindName = refactoring.elementKindName; feedback.oldName = refactoring.oldName; } diff --git a/pkg/analysis_server/lib/src/plugin/plugin_manager.dart b/pkg/analysis_server/lib/src/plugin/plugin_manager.dart index 08f8fb6f198..07c49560cc0 100644 --- a/pkg/analysis_server/lib/src/plugin/plugin_manager.dart +++ b/pkg/analysis_server/lib/src/plugin/plugin_manager.dart @@ -901,7 +901,7 @@ class PluginSession { /// Send a request, based on the given [parameters]. Return a future that will /// complete when a response is received. Future sendRequest(RequestParams parameters) { - var channel = this.channel; + final channel = this.channel; if (channel == null) { throw StateError('Cannot send a request to a plugin that has stopped.'); } diff --git a/pkg/analysis_server/lib/src/services/completion/dart/arglist_contributor.dart b/pkg/analysis_server/lib/src/services/completion/dart/arglist_contributor.dart index e47f4f0eb01..05f75924afe 100644 --- a/pkg/analysis_server/lib/src/services/completion/dart/arglist_contributor.dart +++ b/pkg/analysis_server/lib/src/services/completion/dart/arglist_contributor.dart @@ -133,7 +133,7 @@ class ArgListContributor extends DartCompletionContributor { /// Return the number of arguments in the argument list. int _argCount() { - var argumentList = this.argumentList; + final argumentList = this.argumentList; if (argumentList != null) { var paren = argumentList.rightParenthesis; if (request.target.entity == paren) { @@ -159,7 +159,7 @@ class ArgListContributor extends DartCompletionContributor { /// Return `true` if the caret is preceding an arg where a name could be added /// (turning a positional arg into a named arg). bool _isAddingLabelToPositional() { - var argumentList = this.argumentList; + final argumentList = this.argumentList; if (argumentList != null) { var entity = request.target.entity; if (entity is! Expression) { @@ -194,7 +194,7 @@ class ArgListContributor extends DartCompletionContributor { /// Return `true` if the completion target is at the end of the list of /// arguments. bool _isAppendingToArgList() { - var argumentList = this.argumentList; + final argumentList = this.argumentList; if (argumentList != null) { var entity = request.target.entity; if (entity == argumentList.rightParenthesis) { @@ -275,7 +275,7 @@ class ArgListContributor extends DartCompletionContributor { /// [_isInsertingToArgListWithNoSynthetic] have been called and both returned /// `false`. bool _isInsertingToArgListWithSynthetic() { - var argumentList = this.argumentList; + final argumentList = this.argumentList; if (argumentList != null) { var entity = request.target.entity; if (entity is SimpleIdentifier) { @@ -295,7 +295,7 @@ class ArgListContributor extends DartCompletionContributor { /// Return a list containing the currently specified named arguments. List _namedArgs() { var namedArgs = []; - var argumentList = this.argumentList; + final argumentList = this.argumentList; if (argumentList != null) { for (var arg in argumentList.arguments) { if (arg is NamedExpression) { diff --git a/pkg/analysis_server/lib/src/services/completion/dart/completion_manager.dart b/pkg/analysis_server/lib/src/services/completion/dart/completion_manager.dart index 66989f9755c..1ea7a5a203d 100644 --- a/pkg/analysis_server/lib/src/services/completion/dart/completion_manager.dart +++ b/pkg/analysis_server/lib/src/services/completion/dart/completion_manager.dart @@ -199,7 +199,8 @@ class DartCompletionManager { } void _addIncludedSuggestionRelevanceTags(DartCompletionRequestImpl request) { - var includedSuggestionRelevanceTags = this.includedSuggestionRelevanceTags!; + final includedSuggestionRelevanceTags = + this.includedSuggestionRelevanceTags!; var location = request.opType.completionLocation; if (location != null) { var locationTable = elementKindRelevance[location]; diff --git a/pkg/analysis_server/lib/src/services/completion/dart/feature_computer.dart b/pkg/analysis_server/lib/src/services/completion/dart/feature_computer.dart index f6d226309a1..7da38ea4981 100644 --- a/pkg/analysis_server/lib/src/services/completion/dart/feature_computer.dart +++ b/pkg/analysis_server/lib/src/services/completion/dart/feature_computer.dart @@ -1015,7 +1015,7 @@ extension on AstNode { extension on ArgumentList { /// Return the [FunctionType], if there is one, for this [ArgumentList]. FunctionType? get functionType { - var parent = this.parent; + final parent = this.parent; if (parent is InstanceCreationExpression) { return parent.constructorName.staticElement?.type; } else if (parent is MethodInvocation) { diff --git a/pkg/analysis_server/lib/src/services/completion/dart/keyword_contributor.dart b/pkg/analysis_server/lib/src/services/completion/dart/keyword_contributor.dart index dafe115c73c..d44cb1a1803 100644 --- a/pkg/analysis_server/lib/src/services/completion/dart/keyword_contributor.dart +++ b/pkg/analysis_server/lib/src/services/completion/dart/keyword_contributor.dart @@ -56,7 +56,7 @@ class _KeywordVisitor extends GeneralizingAstVisitor { return; } } - var entity = this.entity; + final entity = this.entity; if (entity == node.rightParenthesis) { _addExpressionKeywords(node); var previous = node.findPrevious(entity as Token); @@ -142,7 +142,7 @@ class _KeywordVisitor extends GeneralizingAstVisitor { @override void visitClassDeclaration(ClassDeclaration node) { - var entity = this.entity; + final entity = this.entity; // Don't suggest class name if (entity == node.name) { return; @@ -544,7 +544,7 @@ class _KeywordVisitor extends GeneralizingAstVisitor { @override void visitMixinDeclaration(MixinDeclaration node) { - var entity = this.entity; + final entity = this.entity; // Don't suggest mixin name if (entity == node.name) { return; @@ -906,7 +906,7 @@ class _KeywordVisitor extends GeneralizingAstVisitor { if (block == null) { return false; } - var entity = this.entity; + final entity = this.entity; if (entity is Statement) { var entityIndex = block.statements.indexOf(entity); if (entityIndex > 0) { diff --git a/pkg/analysis_server/lib/src/services/correction/dart/abstract_producer.dart b/pkg/analysis_server/lib/src/services/correction/dart/abstract_producer.dart index c21bf0b7ace..0c52fb4ead6 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/abstract_producer.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/abstract_producer.dart @@ -373,7 +373,7 @@ abstract class _AbstractCorrectionProducer { AstNode? get coveredNode { // TODO(brianwilkerson) Consider renaming this to `coveringNode`. if (_coveredNode == null) { - var diagnostic = this.diagnostic; + final diagnostic = this.diagnostic; if (diagnostic == null) { return null; } diff --git a/pkg/analysis_server/lib/src/services/correction/dart/add_async.dart b/pkg/analysis_server/lib/src/services/correction/dart/add_async.dart index 289a5375d62..32499c04819 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/add_async.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/add_async.dart @@ -46,7 +46,7 @@ class AddAsync extends CorrectionProducer { } else { var body = node.thisOrAncestorOfType(); if (body != null && body.keyword == null) { - var typeProvider = this.typeProvider; + final typeProvider = this.typeProvider; await builder.addDartFileEdit(file, (builder) { builder.convertFunctionFromSyncToAsync(body, typeProvider); }); diff --git a/pkg/analysis_server/lib/src/services/correction/dart/add_const.dart b/pkg/analysis_server/lib/src/services/correction/dart/add_const.dart index 84311ad1044..cd0bf2acfba 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/add_const.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/add_const.dart @@ -17,27 +17,27 @@ class AddConst extends CorrectionProducer { @override Future compute(ChangeBuilder builder) async { - AstNode? node = this.node; - if (node is SimpleIdentifier) { - node = node.parent; + AstNode? targetNode = node; + if (targetNode is SimpleIdentifier) { + targetNode = targetNode.parent; } - if (node is ConstructorDeclaration) { - var node_final = node; + if (targetNode is ConstructorDeclaration) { + var node_final = targetNode; await builder.addDartFileEdit(file, (builder) { final offset = node_final.firstTokenAfterCommentAndMetadata.offset; builder.addSimpleInsertion(offset, 'const '); }); return; } - if (node is TypeName) { - node = node.parent; + if (targetNode is TypeName) { + targetNode = targetNode.parent; } - if (node is ConstructorName) { - node = node.parent; + if (targetNode is ConstructorName) { + targetNode = targetNode.parent; } - if (node is InstanceCreationExpression) { - if (node.keyword == null) { - var node_final = node; + if (targetNode is InstanceCreationExpression) { + if (targetNode.keyword == null) { + var node_final = targetNode; await builder.addDartFileEdit(file, (builder) { builder.addSimpleInsertion(node_final.offset, 'const '); }); diff --git a/pkg/analysis_server/lib/src/services/correction/dart/add_late.dart b/pkg/analysis_server/lib/src/services/correction/dart/add_late.dart index cc3293beb84..733d4ea19c4 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/add_late.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/add_late.dart @@ -21,7 +21,7 @@ class AddLate extends CorrectionProducer { if (!libraryElement.isNonNullableByDefault) { return; } - var node = this.node; + final node = this.node; if (node is SimpleIdentifier) { var variable = node.parent; var variableList = variable?.parent; diff --git a/pkg/analysis_server/lib/src/services/correction/dart/add_missing_parameter_named.dart b/pkg/analysis_server/lib/src/services/correction/dart/add_missing_parameter_named.dart index da82a33bd93..0dd82a129ce 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/add_missing_parameter_named.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/add_missing_parameter_named.dart @@ -21,7 +21,7 @@ class AddMissingParameterNamed extends CorrectionProducer { @override Future compute(ChangeBuilder builder) async { // Prepare the name of the missing parameter. - var node = this.node; + final node = this.node; if (node is! SimpleIdentifier) { return; } diff --git a/pkg/analysis_server/lib/src/services/correction/dart/add_missing_required_argument.dart b/pkg/analysis_server/lib/src/services/correction/dart/add_missing_required_argument.dart index c3aa42d63c6..84d563cc5ff 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/add_missing_required_argument.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/add_missing_required_argument.dart @@ -42,7 +42,7 @@ class AddMissingRequiredArgument extends CorrectionProducer { } } - var diagnostic = this.diagnostic; + final diagnostic = this.diagnostic; if (diagnostic == null) { return; } diff --git a/pkg/analysis_server/lib/src/services/correction/dart/add_ne_null.dart b/pkg/analysis_server/lib/src/services/correction/dart/add_ne_null.dart index d5facaf52c0..970dedfbd77 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/add_ne_null.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/add_ne_null.dart @@ -20,7 +20,7 @@ class AddNeNull extends CorrectionProducerWithDiagnostic { @override Future compute(ChangeBuilder builder) async { if (unit.featureSet.isEnabled(Feature.non_nullable)) { - var node = this.node; + final node = this.node; if (node is Expression && node.staticType?.nullabilitySuffix == NullabilitySuffix.none) { return; diff --git a/pkg/analysis_server/lib/src/services/correction/dart/add_null_check.dart b/pkg/analysis_server/lib/src/services/correction/dart/add_null_check.dart index 11bf7842e80..33c5944d9db 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/add_null_check.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/add_null_check.dart @@ -23,7 +23,7 @@ class AddNullCheck extends CorrectionProducer { return; } Expression? target; - var coveredNode = this.coveredNode; + final coveredNode = this.coveredNode; var coveredNodeParent = coveredNode?.parent; if (coveredNode is SimpleIdentifier) { if (coveredNodeParent is MethodInvocation) { diff --git a/pkg/analysis_server/lib/src/services/correction/dart/add_type_annotation.dart b/pkg/analysis_server/lib/src/services/correction/dart/add_type_annotation.dart index 08bd321f23d..8a89c1f62c9 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/add_type_annotation.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/add_type_annotation.dart @@ -27,7 +27,7 @@ class AddTypeAnnotation extends CorrectionProducer { @override Future compute(ChangeBuilder builder) async { - var node = this.node; + final node = this.node; if (node is SimpleIdentifier) { var parent = node.parent; if (parent is SimpleFormalParameter) { diff --git a/pkg/analysis_server/lib/src/services/correction/dart/change_argument_name.dart b/pkg/analysis_server/lib/src/services/correction/dart/change_argument_name.dart index 75c187fb470..0442afb05c6 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/change_argument_name.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/change_argument_name.dart @@ -53,7 +53,7 @@ class ChangeArgumentName extends MultiCorrectionProducer { } _NamedExpressionContext? _getNamedParameterNames() { - var node = this.node; + final node = this.node; var namedExpression = node.parent?.parent; if (node is SimpleIdentifier && namedExpression is NamedExpression && diff --git a/pkg/analysis_server/lib/src/services/correction/dart/change_to.dart b/pkg/analysis_server/lib/src/services/correction/dart/change_to.dart index 0f81d936b1a..0ec47fc5675 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/change_to.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/change_to.dart @@ -53,7 +53,7 @@ class ChangeTo extends CorrectionProducer { } Future _proposeAnnotation(ChangeBuilder builder) async { - var node = this.node; + final node = this.node; if (node is Annotation) { var name = node.name; if (name.staticElement == null) { @@ -105,7 +105,7 @@ class ChangeTo extends CorrectionProducer { Future _proposeClassOrMixinMember(ChangeBuilder builder, Expression? target, _ElementPredicate predicate) async { - var node = this.node; + final node = this.node; var targetIdentifierElement = target is Identifier ? target.staticElement : null; if (node is SimpleIdentifier) { @@ -139,7 +139,7 @@ class ChangeTo extends CorrectionProducer { } Future _proposeFunction(ChangeBuilder builder) async { - var node = this.node; + final node = this.node; if (node is SimpleIdentifier) { // Prepare the optional import prefix name. String? prefixName; @@ -181,7 +181,7 @@ class ChangeTo extends CorrectionProducer { } Future _proposeGetterOrSetter(ChangeBuilder builder) async { - var node = this.node; + final node = this.node; if (node is SimpleIdentifier) { // prepare target Expression? target; diff --git a/pkg/analysis_server/lib/src/services/correction/dart/convert_into_is_not.dart b/pkg/analysis_server/lib/src/services/correction/dart/convert_into_is_not.dart index e84c81f6da3..b81db266408 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/convert_into_is_not.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/convert_into_is_not.dart @@ -21,7 +21,7 @@ class ConvertIntoIsNot extends CorrectionProducer { // Find the is expression var isExpression = node.thisOrAncestorOfType(); if (isExpression == null) { - var node = this.node; + final node = this.node; if (node is PrefixExpression) { var operand = node.operand; if (operand is ParenthesizedExpression) { diff --git a/pkg/analysis_server/lib/src/services/correction/dart/convert_quotes.dart b/pkg/analysis_server/lib/src/services/correction/dart/convert_quotes.dart index 5e45165c621..67cfb7dfc2d 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/convert_quotes.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/convert_quotes.dart @@ -20,7 +20,7 @@ abstract class ConvertQuotes extends CorrectionProducer { @override Future compute(ChangeBuilder builder) async { - var node = this.node; + final node = this.node; if (node is SimpleStringLiteral) { await _simpleStringLiteral(builder, node); } else if (node is StringInterpolation) { diff --git a/pkg/analysis_server/lib/src/services/correction/dart/convert_to_if_null.dart b/pkg/analysis_server/lib/src/services/correction/dart/convert_to_if_null.dart index d8ca1d223a8..24ba7dd48e7 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/convert_to_if_null.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/convert_to_if_null.dart @@ -19,7 +19,7 @@ class ConvertToIfNull extends CorrectionProducer { @override Future compute(ChangeBuilder builder) async { - var node = this.node; + final node = this.node; if (node is ConditionalExpression && node.offset == errorOffset && node.length == errorLength) { diff --git a/pkg/analysis_server/lib/src/services/correction/dart/convert_to_multiline_string.dart b/pkg/analysis_server/lib/src/services/correction/dart/convert_to_multiline_string.dart index 51861d9d999..08070765b36 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/convert_to_multiline_string.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/convert_to_multiline_string.dart @@ -15,12 +15,12 @@ class ConvertToMultilineString extends CorrectionProducer { @override Future compute(ChangeBuilder builder) async { - var node = this.node; - if (node is InterpolationElement) { - node = node.parent!; + var targetNode = node; + if (targetNode is InterpolationElement) { + targetNode = targetNode.parent!; } - if (node is SingleStringLiteral) { - var literal = node; + if (targetNode is SingleStringLiteral) { + var literal = targetNode; if (!literal.isSynthetic && !literal.isMultiline) { await builder.addDartFileEdit(file, (builder) { var newQuote = literal.isSingleQuoted ? "'''" : '"""'; diff --git a/pkg/analysis_server/lib/src/services/correction/dart/convert_to_null_aware.dart b/pkg/analysis_server/lib/src/services/correction/dart/convert_to_null_aware.dart index 013e4fef8ae..da0f2695711 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/convert_to_null_aware.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/convert_to_null_aware.dart @@ -25,18 +25,18 @@ class ConvertToNullAware extends CorrectionProducer { @override Future compute(ChangeBuilder builder) async { - var node = this.node; - var parent = node.parent; + var targetNode = node; + var parent = targetNode.parent; if (parent is BinaryExpression) { var grandParent = parent.parent; if (grandParent is ConditionalExpression) { - node = grandParent; + targetNode = grandParent; } } - if (node is! ConditionalExpression) { + if (targetNode is! ConditionalExpression) { return; } - var condition = node.condition.unParenthesized; + var condition = targetNode.condition.unParenthesized; SimpleIdentifier identifier; Expression nullExpression; Expression nonNullExpression; @@ -67,11 +67,11 @@ class ConvertToNullAware extends CorrectionProducer { // is the save variable being compared to `null`. // if (condition.operator.type == TokenType.EQ_EQ) { - nullExpression = node.thenExpression; - nonNullExpression = node.elseExpression; + nullExpression = targetNode.thenExpression; + nonNullExpression = targetNode.elseExpression; } else if (condition.operator.type == TokenType.BANG_EQ) { - nonNullExpression = node.thenExpression; - nullExpression = node.elseExpression; + nonNullExpression = targetNode.thenExpression; + nullExpression = targetNode.elseExpression; } else { return; } @@ -100,9 +100,9 @@ class ConvertToNullAware extends CorrectionProducer { periodOffset = operator.offset; await builder.addDartFileEdit(file, (builder) { - builder.addDeletion(range.startStart(node, nonNullExpression)); + builder.addDeletion(range.startStart(targetNode, nonNullExpression)); builder.addSimpleInsertion(periodOffset, '?'); - builder.addDeletion(range.endEnd(nonNullExpression, node)); + builder.addDeletion(range.endEnd(nonNullExpression, targetNode)); }); } } diff --git a/pkg/analysis_server/lib/src/services/correction/dart/convert_to_package_import.dart b/pkg/analysis_server/lib/src/services/correction/dart/convert_to_package_import.dart index a40b1b2a4c5..b9020ea3001 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/convert_to_package_import.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/convert_to_package_import.dart @@ -23,12 +23,12 @@ class ConvertToPackageImport extends CorrectionProducer { @override Future compute(ChangeBuilder builder) async { - var node = this.node; - if (node is StringLiteral) { - node = node.parent!; + var targetNode = node; + if (targetNode is StringLiteral) { + targetNode = targetNode.parent!; } - if (node is ImportDirective) { - var importDirective = node; + if (targetNode is ImportDirective) { + var importDirective = targetNode; var uriSource = importDirective.uriSource; // Ignore if invalid URI. diff --git a/pkg/analysis_server/lib/src/services/correction/dart/convert_to_relative_import.dart b/pkg/analysis_server/lib/src/services/correction/dart/convert_to_relative_import.dart index 48a99d728ae..7b97d0914d3 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/convert_to_relative_import.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/convert_to_relative_import.dart @@ -24,16 +24,16 @@ class ConvertToRelativeImport extends CorrectionProducer { @override Future compute(ChangeBuilder builder) async { - var node = this.node; - if (node is StringLiteral) { - node = node.parent!; + var targetNode = node; + if (targetNode is StringLiteral) { + targetNode = targetNode.parent!; } - if (node is! ImportDirective) { + if (targetNode is! ImportDirective) { return; } // Ignore if invalid URI. - if (node.uriSource == null) { + if (targetNode.uriSource == null) { return; } @@ -45,7 +45,7 @@ class ConvertToRelativeImport extends CorrectionProducer { Uri importUri; try { - var uriContent = node.uriContent; + var uriContent = targetNode.uriContent; if (uriContent == null) { return; } @@ -75,7 +75,7 @@ class ConvertToRelativeImport extends CorrectionProducer { from: path.dirname(sourceUri.path), ); - final node_final = node; + final node_final = targetNode; await builder.addDartFileEdit(file, (builder) { builder.addSimpleReplacement( range.node(node_final.uri).getExpanded(-1), diff --git a/pkg/analysis_server/lib/src/services/correction/dart/create_class.dart b/pkg/analysis_server/lib/src/services/correction/dart/create_class.dart index 833a8dbd80a..9c01f356aa8 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/create_class.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/create_class.dart @@ -22,29 +22,29 @@ class CreateClass extends CorrectionProducer { @override Future compute(ChangeBuilder builder) async { - var node = this.node; + var targetNode = node; Element? prefixElement; SimpleIdentifier nameNode; ArgumentList? arguments; - if (node is Annotation) { - var name = node.name; - arguments = node.arguments; + if (targetNode is Annotation) { + var name = targetNode.name; + arguments = targetNode.arguments; if (name.staticElement != null || arguments == null) { // TODO(brianwilkerson) Consider supporting creating a class when the // arguments are missing by also adding an empty argument list. return; } - node = name; + targetNode = name; } - if (node is SimpleIdentifier) { - nameNode = node; - } else if (node is PrefixedIdentifier) { - prefixElement = node.prefix.staticElement; + if (targetNode is SimpleIdentifier) { + nameNode = targetNode; + } else if (targetNode is PrefixedIdentifier) { + prefixElement = targetNode.prefix.staticElement; if (prefixElement == null) { return; } - nameNode = node.identifier; + nameNode = targetNode.identifier; } else { return; } @@ -60,7 +60,7 @@ class CreateClass extends CorrectionProducer { String? filePath; if (prefixElement == null) { targetUnit = unit.declaredElement!; - var enclosingMember = node.thisOrAncestorMatching((node) => + var enclosingMember = targetNode.thisOrAncestorMatching((node) => node is CompilationUnitMember && node.parent is CompilationUnit); if (enclosingMember == null) { return; @@ -111,7 +111,7 @@ class CreateClass extends CorrectionProducer { builder.write(suffix); }); if (prefixElement == null) { - builder.addLinkedPosition(range.node(node), 'NAME'); + builder.addLinkedPosition(range.node(targetNode), 'NAME'); } }); } diff --git a/pkg/analysis_server/lib/src/services/correction/dart/create_method.dart b/pkg/analysis_server/lib/src/services/correction/dart/create_method.dart index a76ce2acf3f..2edd32e24a0 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/create_method.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/create_method.dart @@ -95,7 +95,7 @@ class CreateMethod extends CorrectionProducer { CompilationUnitMember? targetNode; var target = invocation.realTarget; - var utils = this.utils; + var utilsForTargetNode = utils; if (target is ExtensionOverride) { targetElement = target.staticElement; if (targetElement is ExtensionElement) { @@ -152,12 +152,13 @@ class CreateMethod extends CorrectionProducer { if (targetResolveResult is! ResolvedUnitResult) { return; } - utils = CorrectionUtils(targetResolveResult); + utilsForTargetNode = CorrectionUtils(targetResolveResult); } if (targetElement == null || targetNode == null) { return; } - var targetLocation = utils.prepareNewMethodLocation(targetNode); + var targetLocation = + utilsForTargetNode.prepareNewMethodLocation(targetNode); if (targetLocation == null) { return; } diff --git a/pkg/analysis_server/lib/src/services/correction/dart/create_mixin.dart b/pkg/analysis_server/lib/src/services/correction/dart/create_mixin.dart index 14c4598cb30..dbc902071a8 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/create_mixin.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/create_mixin.dart @@ -24,7 +24,7 @@ class CreateMixin extends CorrectionProducer { Future compute(ChangeBuilder builder) async { Element? prefixElement; SimpleIdentifier nameNode; - var node = this.node; + final node = this.node; if (node is SimpleIdentifier) { var parent = node.parent; var grandParent = parent?.parent; diff --git a/pkg/analysis_server/lib/src/services/correction/dart/data_driven.dart b/pkg/analysis_server/lib/src/services/correction/dart/data_driven.dart index 5261db324c0..ed399acc4fd 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/data_driven.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/data_driven.dart @@ -54,7 +54,7 @@ class DataDriven extends MultiCorrectionProducer { return setsForTests; } var transformSets = TransformSetManager.instance.forLibrary(library); - var overrideSet = this.overrideSet; + final overrideSet = this.overrideSet; if (overrideSet != null) { transformSets = transformSets.map((set) => set.applyOverrides(overrideSet)).toList(); diff --git a/pkg/analysis_server/lib/src/services/correction/dart/extend_class_for_mixin.dart b/pkg/analysis_server/lib/src/services/correction/dart/extend_class_for_mixin.dart index 52ed499440d..b9557d00e56 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/extend_class_for_mixin.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/extend_class_for_mixin.dart @@ -19,7 +19,7 @@ class ExtendClassForMixin extends CorrectionProducer { @override Future compute(ChangeBuilder builder) async { - var diagnostic = this.diagnostic; + final diagnostic = this.diagnostic; if (diagnostic == null) { return; } diff --git a/pkg/analysis_server/lib/src/services/correction/dart/flutter_convert_to_children.dart b/pkg/analysis_server/lib/src/services/correction/dart/flutter_convert_to_children.dart index 1c0f0ca623a..755c644ca81 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/flutter_convert_to_children.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/flutter_convert_to_children.dart @@ -18,7 +18,7 @@ class FlutterConvertToChildren extends CorrectionProducer { // Find "child: widget" under selection. NamedExpression namedExp; { - var node = this.node; + final node = this.node; var parent = node.parent; var parent2 = parent?.parent; if (node is SimpleIdentifier && diff --git a/pkg/analysis_server/lib/src/services/correction/dart/import_library.dart b/pkg/analysis_server/lib/src/services/correction/dart/import_library.dart index 2274c6e7302..1499ae62d7b 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/import_library.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/import_library.dart @@ -52,44 +52,44 @@ class ImportLibrary extends MultiCorrectionProducer { ]); } } else if (_importKind == _ImportKind.forTopLevelVariable) { - var node = this.node; - if (node is Annotation) { - var name = node.name; + var targetNode = node; + if (targetNode is Annotation) { + var name = targetNode.name; if (name.staticElement == null) { - if (node.arguments != null) { + if (targetNode.arguments != null) { return; } - node = name; + targetNode = name; } } - if (node is SimpleIdentifier) { - var name = node.name; + if (targetNode is SimpleIdentifier) { + var name = targetNode.name; yield* _importLibraryForElement( name, const [ElementKind.TOP_LEVEL_VARIABLE], const [TopLevelDeclarationKind.variable]); } } else if (_importKind == _ImportKind.forType) { - var node = this.node; - if (node is Annotation) { - var name = node.name; + var targetNode = node; + if (targetNode is Annotation) { + var name = targetNode.name; if (name.staticElement == null) { - if (node.arguments == null) { + if (targetNode.arguments == null) { return; } - node = name; + targetNode = name; } } - if (mightBeTypeIdentifier(node)) { - var typeName = (node is SimpleIdentifier) - ? node.name - : (node as PrefixedIdentifier).prefix.name; + if (mightBeTypeIdentifier(targetNode)) { + var typeName = (targetNode is SimpleIdentifier) + ? targetNode.name + : (targetNode as PrefixedIdentifier).prefix.name; yield* _importLibraryForElement( typeName, const [ElementKind.CLASS, ElementKind.FUNCTION_TYPE_ALIAS], const [TopLevelDeclarationKind.type]); - } else if (mightBeImplicitConstructor(node)) { - var typeName = (node as SimpleIdentifier).name; + } else if (mightBeImplicitConstructor(targetNode)) { + var typeName = (targetNode as SimpleIdentifier).name; yield* _importLibraryForElement(typeName, const [ElementKind.CLASS], const [TopLevelDeclarationKind.type]); } diff --git a/pkg/analysis_server/lib/src/services/correction/dart/inline_invocation.dart b/pkg/analysis_server/lib/src/services/correction/dart/inline_invocation.dart index c2e071149df..c784ce4c58c 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/inline_invocation.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/inline_invocation.dart @@ -29,7 +29,7 @@ class InlineInvocation extends CorrectionProducer { @override Future compute(ChangeBuilder builder) async { - var node = this.node; + final node = this.node; if (node is! SimpleIdentifier || node.name != 'add') { return; } diff --git a/pkg/analysis_server/lib/src/services/correction/dart/insert_semicolon.dart b/pkg/analysis_server/lib/src/services/correction/dart/insert_semicolon.dart index b50d526b499..c2bf057bf95 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/insert_semicolon.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/insert_semicolon.dart @@ -14,7 +14,7 @@ class InsertSemicolon extends CorrectionProducer { @override Future compute(ChangeBuilder builder) async { - var diagnostic = this.diagnostic; + final diagnostic = this.diagnostic; if (diagnostic == null) { return; } @@ -32,7 +32,7 @@ class InsertSemicolon extends CorrectionProducer { } bool _isAwaitNode() { - var node = this.node; + final node = this.node; return node is SimpleIdentifier && node.name == 'await'; } diff --git a/pkg/analysis_server/lib/src/services/correction/dart/join_variable_declaration.dart b/pkg/analysis_server/lib/src/services/correction/dart/join_variable_declaration.dart index 015acb8792c..8b97a1df56b 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/join_variable_declaration.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/join_variable_declaration.dart @@ -16,7 +16,7 @@ class JoinVariableDeclaration extends CorrectionProducer { @override Future compute(ChangeBuilder builder) async { - var node = this.node; + final node = this.node; if (node is SimpleIdentifier) { var parent = node.parent; if (parent is AssignmentExpression && diff --git a/pkg/analysis_server/lib/src/services/correction/dart/make_field_not_final.dart b/pkg/analysis_server/lib/src/services/correction/dart/make_field_not_final.dart index a2c636aa320..374d184e81d 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/make_field_not_final.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/make_field_not_final.dart @@ -23,7 +23,7 @@ class MakeFieldNotFinal extends CorrectionProducer { @override Future compute(ChangeBuilder builder) async { - var node = this.node; + final node = this.node; if (node is! SimpleIdentifier) { return; } diff --git a/pkg/analysis_server/lib/src/services/correction/dart/make_final.dart b/pkg/analysis_server/lib/src/services/correction/dart/make_final.dart index 3ff063a3fa7..aba8e02ef58 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/make_final.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/make_final.dart @@ -19,7 +19,7 @@ class MakeFinal extends CorrectionProducer { @override Future compute(ChangeBuilder builder) async { - var node = this.node; + final node = this.node; var parent = node.parent; var grandParent = parent?.parent; diff --git a/pkg/analysis_server/lib/src/services/correction/dart/make_return_type_nullable.dart b/pkg/analysis_server/lib/src/services/correction/dart/make_return_type_nullable.dart index 20b6cac9cc4..2f2107d7df9 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/make_return_type_nullable.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/make_return_type_nullable.dart @@ -20,7 +20,7 @@ class MakeReturnTypeNullable extends CorrectionProducer { return; } - var node = this.node; + final node = this.node; if (node is! Expression) { return; } diff --git a/pkg/analysis_server/lib/src/services/correction/dart/make_variable_not_final.dart b/pkg/analysis_server/lib/src/services/correction/dart/make_variable_not_final.dart index 0ac959f0c46..f3f1695d6cc 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/make_variable_not_final.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/make_variable_not_final.dart @@ -23,7 +23,7 @@ class MakeVariableNotFinal extends CorrectionProducer { @override Future compute(ChangeBuilder builder) async { - var node = this.node; + final node = this.node; if (node is! SimpleIdentifier) { return; } diff --git a/pkg/analysis_server/lib/src/services/correction/dart/remove_dead_code.dart b/pkg/analysis_server/lib/src/services/correction/dart/remove_dead_code.dart index 3c37c95bb6e..9f349e7fe50 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/remove_dead_code.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/remove_dead_code.dart @@ -16,7 +16,7 @@ class RemoveDeadCode extends CorrectionProducer { @override Future compute(ChangeBuilder builder) async { - var coveredNode = this.coveredNode; + final coveredNode = this.coveredNode; var parent = coveredNode?.parent; if (coveredNode is Expression) { diff --git a/pkg/analysis_server/lib/src/services/correction/dart/remove_interpolation_braces.dart b/pkg/analysis_server/lib/src/services/correction/dart/remove_interpolation_braces.dart index d63185f3666..c5ed78074b4 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/remove_interpolation_braces.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/remove_interpolation_braces.dart @@ -18,7 +18,7 @@ class RemoveInterpolationBraces extends CorrectionProducer { @override Future compute(ChangeBuilder builder) async { - var node = this.node; + final node = this.node; if (node is InterpolationExpression) { var right = node.rightBracket; if (right != null) { diff --git a/pkg/analysis_server/lib/src/services/correction/dart/remove_parameters_in_getter_declaration.dart b/pkg/analysis_server/lib/src/services/correction/dart/remove_parameters_in_getter_declaration.dart index cf13f538c95..236ac605f72 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/remove_parameters_in_getter_declaration.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/remove_parameters_in_getter_declaration.dart @@ -15,7 +15,7 @@ class RemoveParametersInGetterDeclaration extends CorrectionProducer { @override Future compute(ChangeBuilder builder) async { - var node = this.node; + final node = this.node; if (node is MethodDeclaration) { // Support for the analyzer error. var name = node.name; diff --git a/pkg/analysis_server/lib/src/services/correction/dart/remove_question_mark.dart b/pkg/analysis_server/lib/src/services/correction/dart/remove_question_mark.dart index 96e028015b6..7039b72be8c 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/remove_question_mark.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/remove_question_mark.dart @@ -18,17 +18,17 @@ class RemoveQuestionMark extends CorrectionProducer { @override Future compute(ChangeBuilder builder) async { - AstNode? node = this.node; - if (node is VariableDeclaration) { - var parent = node.parent; + AstNode? targetNode = node; + if (targetNode is VariableDeclaration) { + var parent = targetNode.parent; if (parent is VariableDeclarationList) { - node = parent.type; + targetNode = parent.type; } else { return; } } - if (node is TypeName) { - var questionMark = node.question; + if (targetNode is TypeName) { + var questionMark = targetNode.question; if (questionMark == null) { return; } diff --git a/pkg/analysis_server/lib/src/services/correction/dart/remove_this_expression.dart b/pkg/analysis_server/lib/src/services/correction/dart/remove_this_expression.dart index 68f13509c76..c9c41ae0a71 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/remove_this_expression.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/remove_this_expression.dart @@ -18,7 +18,7 @@ class RemoveThisExpression extends CorrectionProducer { @override Future compute(ChangeBuilder builder) async { - var node = this.node; + final node = this.node; if (node is ConstructorFieldInitializer) { var thisKeyword = node.thisKeyword; if (thisKeyword != null) { diff --git a/pkg/analysis_server/lib/src/services/correction/dart/replace_new_with_const.dart b/pkg/analysis_server/lib/src/services/correction/dart/replace_new_with_const.dart index e8db9a39140..fda74539530 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/replace_new_with_const.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/replace_new_with_const.dart @@ -18,12 +18,12 @@ class ReplaceNewWithConst extends CorrectionProducer { @override Future compute(ChangeBuilder builder) async { - AstNode? node = this.node; - if (node is ConstructorName) { - node = node.parent; + AstNode? targetNode = node; + if (targetNode is ConstructorName) { + targetNode = targetNode.parent; } - if (node is InstanceCreationExpression) { - final keyword = node.keyword; + if (targetNode is InstanceCreationExpression) { + final keyword = targetNode.keyword; if (keyword != null) { await builder.addDartFileEdit(file, (builder) { builder.addSimpleReplacement(range.token(keyword), 'const'); diff --git a/pkg/analysis_server/lib/src/services/correction/dart/replace_with_conditional_assignment.dart b/pkg/analysis_server/lib/src/services/correction/dart/replace_with_conditional_assignment.dart index 9d69d50d479..acdd6a4385b 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/replace_with_conditional_assignment.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/replace_with_conditional_assignment.dart @@ -19,7 +19,7 @@ class ReplaceWithConditionalAssignment extends CorrectionProducer { @override Future compute(ChangeBuilder builder) async { - var node = this.node; + final node = this.node; var ifStatement = node is IfStatement ? node : node.thisOrAncestorOfType(); if (ifStatement == null) { diff --git a/pkg/analysis_server/lib/src/services/correction/dart/shadow_field.dart b/pkg/analysis_server/lib/src/services/correction/dart/shadow_field.dart index c46f1591f0d..b18b4ef21c0 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/shadow_field.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/shadow_field.dart @@ -67,6 +67,7 @@ class ShadowField extends CorrectionProducer { builder.addInsertion(offset, (builder) { // TODO(brianwilkerson) Conditionally write a type annotation instead of // 'var' when we're able to discover user preferences. + // TODO(brianwilkerson) Consider writing `final` rather than `var`. builder.write('var '); builder.write(fieldName); builder.write(' = this.'); diff --git a/pkg/analysis_server/lib/src/services/correction/dart/wrap_in_future.dart b/pkg/analysis_server/lib/src/services/correction/dart/wrap_in_future.dart index c1892ff53ec..cbe9212b607 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/wrap_in_future.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/wrap_in_future.dart @@ -19,7 +19,7 @@ class WrapInFuture extends CorrectionProducer { // Extract the information needed to build the edit. // Expression? expression; - var node = this.node; + final node = this.node; if (node is ReturnStatement) { expression = node.expression; } else if (node is Expression) { diff --git a/pkg/analysis_server/lib/src/services/correction/fix/data_driven/add_type_parameter.dart b/pkg/analysis_server/lib/src/services/correction/fix/data_driven/add_type_parameter.dart index 86dcc3b5248..16317421f45 100644 --- a/pkg/analysis_server/lib/src/services/correction/fix/data_driven/add_type_parameter.dart +++ b/pkg/analysis_server/lib/src/services/correction/fix/data_driven/add_type_parameter.dart @@ -73,7 +73,7 @@ class AddTypeParameter extends Change<_Data> { return _TypeArgumentData(typeArguments, parent.argumentList.offset); } else if (parent is MethodDeclaration) { // invalid_override - var extendedType = this.extendedType; + final extendedType = this.extendedType; if (extendedType != null && !extendedType.validate(context)) { return null; } @@ -130,7 +130,7 @@ class AddTypeParameter extends Change<_Data> { void writeParameter(DartEditBuilder builder) { builder.write(name); - var extendedType = this.extendedType; + final extendedType = this.extendedType; if (extendedType != null) { builder.write(' extends '); extendedType.writeOn(builder, context); diff --git a/pkg/analysis_server/lib/src/services/correction/fix/data_driven/rename_parameter.dart b/pkg/analysis_server/lib/src/services/correction/fix/data_driven/rename_parameter.dart index 729692e6808..10725787819 100644 --- a/pkg/analysis_server/lib/src/services/correction/fix/data_driven/rename_parameter.dart +++ b/pkg/analysis_server/lib/src/services/correction/fix/data_driven/rename_parameter.dart @@ -114,7 +114,7 @@ extension on MethodDeclaration { /// Return the parameter of this method whose name matches the given [name], /// or `null` if there is no such parameter. FormalParameter? parameterNamed(String name) { - var parameters = this.parameters; + final parameters = this.parameters; if (parameters != null) { for (var parameter in parameters.parameters) { if (parameter.declaredElement?.name == name) { diff --git a/pkg/analysis_server/lib/src/services/correction/statement_analyzer.dart b/pkg/analysis_server/lib/src/services/correction/statement_analyzer.dart index 320aae7a6b7..9f1c68aa496 100644 --- a/pkg/analysis_server/lib/src/services/correction/statement_analyzer.dart +++ b/pkg/analysis_server/lib/src/services/correction/statement_analyzer.dart @@ -92,7 +92,7 @@ class StatementAnalyzer extends SelectionAnalyzer { @override void visitDoStatement(DoStatement node) { super.visitDoStatement(node); - var selectedNodes = this.selectedNodes; + final selectedNodes = this.selectedNodes; if (_contains(selectedNodes, node.body)) { invalidSelection( "Operation not applicable to a 'do' statement's body and expression."); @@ -104,7 +104,7 @@ class StatementAnalyzer extends SelectionAnalyzer { super.visitForStatement(node); var forLoopParts = node.forLoopParts; if (forLoopParts is ForParts) { - var selectedNodes = this.selectedNodes; + final selectedNodes = this.selectedNodes; bool containsInit; if (forLoopParts is ForPartsWithExpression) { containsInit = _contains(selectedNodes, forLoopParts.initialization); @@ -132,7 +132,7 @@ class StatementAnalyzer extends SelectionAnalyzer { @override void visitSwitchStatement(SwitchStatement node) { super.visitSwitchStatement(node); - var selectedNodes = this.selectedNodes; + final selectedNodes = this.selectedNodes; List switchMembers = node.members; for (var selectedNode in selectedNodes) { if (switchMembers.contains(selectedNode)) { @@ -146,7 +146,7 @@ class StatementAnalyzer extends SelectionAnalyzer { @override void visitTryStatement(TryStatement node) { super.visitTryStatement(node); - var firstSelectedNode = this.firstSelectedNode; + final firstSelectedNode = this.firstSelectedNode; if (firstSelectedNode != null) { if (firstSelectedNode == node.body || firstSelectedNode == node.finallyBlock) { @@ -169,7 +169,7 @@ class StatementAnalyzer extends SelectionAnalyzer { @override void visitWhileStatement(WhileStatement node) { super.visitWhileStatement(node); - var selectedNodes = this.selectedNodes; + final selectedNodes = this.selectedNodes; if (_contains(selectedNodes, node.condition) && _contains(selectedNodes, node.body)) { invalidSelection( diff --git a/pkg/analysis_server/lib/src/services/correction/status.dart b/pkg/analysis_server/lib/src/services/correction/status.dart index d148d34f857..990965890d9 100644 --- a/pkg/analysis_server/lib/src/services/correction/status.dart +++ b/pkg/analysis_server/lib/src/services/correction/status.dart @@ -55,7 +55,7 @@ class RefactoringStatus { /// Returns the message of the [RefactoringProblem] with highest severity; /// may be `null` if no problems. String? get message { - var problem = this.problem; + final problem = this.problem; if (problem == null) { return null; } diff --git a/pkg/analysis_server/lib/src/services/pub/pub_package_service.dart b/pkg/analysis_server/lib/src/services/pub/pub_package_service.dart index 7d7ebbe01f0..d0990db67fe 100644 --- a/pkg/analysis_server/lib/src/services/pub/pub_package_service.dart +++ b/pkg/analysis_server/lib/src/services/pub/pub_package_service.dart @@ -168,15 +168,15 @@ class PubPackageService { /// Begin a request to pre-load the package name list. void beginPackageNamePreload() { // If first time, try to read from disk. - var packageCache = this.packageCache; - if (packageCache == null) { - packageCache ??= readDiskCache() ?? PackageDetailsCache.empty(); - this.packageCache = packageCache; + var cache = packageCache; + if (cache == null) { + cache ??= readDiskCache() ?? PackageDetailsCache.empty(); + packageCache = cache; } // If there is no queued request, initialize one when the current cache expires. _nextPackageNameListRequestTimer ??= - Timer(packageCache.cacheTimeRemaining, _fetchFromServer); + Timer(cache.cacheTimeRemaining, _fetchFromServer); } /// Gets the cached package details for package [packageName]. diff --git a/pkg/analysis_server/lib/src/services/refactoring/extract_local.dart b/pkg/analysis_server/lib/src/services/refactoring/extract_local.dart index 16ca48bc078..2432c5bb72c 100644 --- a/pkg/analysis_server/lib/src/services/refactoring/extract_local.dart +++ b/pkg/analysis_server/lib/src/services/refactoring/extract_local.dart @@ -121,7 +121,7 @@ class ExtractLocalRefactoringImpl extends RefactoringImpl Future createChange() { var change = SourceChange(refactoringName); // prepare occurrences - List occurrences; + late final List occurrences; if (extractAll) { occurrences = this.occurrences; } else { @@ -130,7 +130,7 @@ class ExtractLocalRefactoringImpl extends RefactoringImpl occurrences.sort((a, b) => a.offset - b.offset); // If the whole expression of a statement is selected, like '1 + 2', // then convert it into a variable declaration statement. - var singleExpression = this.singleExpression; + final singleExpression = this.singleExpression; if (singleExpression != null && singleExpression.parent is ExpressionStatement && occurrences.length == 1) { @@ -490,7 +490,7 @@ class ExtractLocalRefactoringImpl extends RefactoringImpl // prepare selection String? selectionSource; - var singleExpression = this.singleExpression; + final singleExpression = this.singleExpression; if (singleExpression != null) { var tokens = TokenUtils.getNodeTokens(singleExpression); selectionSource = _encodeExpressionTokens(singleExpression, tokens); diff --git a/pkg/analysis_server/lib/src/services/refactoring/rename_local.dart b/pkg/analysis_server/lib/src/services/refactoring/rename_local.dart index eb2745eb02d..6fe772eeb3d 100644 --- a/pkg/analysis_server/lib/src/services/refactoring/rename_local.dart +++ b/pkg/analysis_server/lib/src/services/refactoring/rename_local.dart @@ -93,7 +93,7 @@ class RenameLocalRefactoringImpl extends RenameRefactoringImpl { /// Fills [elements] with [Element]s to rename. Future _prepareElements() async { - var element = this.element; + final element = this.element; if (element is ParameterElement && element.isNamed) { elements = await getHierarchyNamedParameters(searchEngine, element); } else { diff --git a/pkg/analysis_server/lib/src/utilities/extensions/ast.dart b/pkg/analysis_server/lib/src/utilities/extensions/ast.dart index 92403c0985c..af573e9fe2a 100644 --- a/pkg/analysis_server/lib/src/utilities/extensions/ast.dart +++ b/pkg/analysis_server/lib/src/utilities/extensions/ast.dart @@ -117,7 +117,7 @@ extension FunctionBodyExtensions on FunctionBody { extension MethodDeclarationExtension on MethodDeclaration { Token? get propertyKeywordGet { - var propertyKeyword = this.propertyKeyword; + final propertyKeyword = this.propertyKeyword; return propertyKeyword != null && propertyKeyword.keyword == Keyword.GET ? propertyKeyword : null; @@ -126,7 +126,7 @@ extension MethodDeclarationExtension on MethodDeclaration { extension VariableDeclarationListExtension on VariableDeclarationList { Token? get finalKeyword { - var keyword = this.keyword; + final keyword = this.keyword; return keyword != null && keyword.keyword == Keyword.FINAL ? keyword : null; } } diff --git a/pkg/analysis_server/lib/src/utilities/request_statistics.dart b/pkg/analysis_server/lib/src/utilities/request_statistics.dart index 39214091f6c..7cdf2343b51 100644 --- a/pkg/analysis_server/lib/src/utilities/request_statistics.dart +++ b/pkg/analysis_server/lib/src/utilities/request_statistics.dart @@ -218,7 +218,7 @@ class _RequestStatisticsItem { _RequestStatisticsItem(this.name, {this.timeValue}); Map toJson() { - var timeValue = this.timeValue; + final timeValue = this.timeValue; if (timeValue != null) { return { 'name': name, diff --git a/pkg/analysis_server/test/integration/support/integration_tests.dart b/pkg/analysis_server/test/integration/support/integration_tests.dart index 827f06d89a8..4585df22885 100644 --- a/pkg/analysis_server/test/integration/support/integration_tests.dart +++ b/pkg/analysis_server/test/integration/support/integration_tests.dart @@ -379,8 +379,8 @@ class MatchesJsonObject extends _RecursiveMatcher { mismatches.add(simpleDescription('is not a map')); return; } - var requiredFields = this.requiredFields; - var optionalFields = this.optionalFields; + final requiredFields = this.requiredFields; + final optionalFields = this.optionalFields; if (requiredFields != null) { requiredFields.forEach((String key, Matcher valueMatcher) { if (!item.containsKey(key)) { diff --git a/pkg/analysis_server/test/search/element_references_test.dart b/pkg/analysis_server/test/search/element_references_test.dart index 95151446e95..144cf4753c5 100644 --- a/pkg/analysis_server/test/search/element_references_test.dart +++ b/pkg/analysis_server/test/search/element_references_test.dart @@ -799,7 +799,7 @@ main() { } '''); await findElementReferences('ppp;', false); - var searchElement = this.searchElement!; + final searchElement = this.searchElement!; expect(searchElement.kind, ElementKind.PREFIX); expect(searchElement.name, 'ppp'); expect(searchElement.location!.startLine, 1); diff --git a/pkg/analysis_server/test/services/refactoring/inline_method_test.dart b/pkg/analysis_server/test/services/refactoring/inline_method_test.dart index 281b5f09b46..4a0f5519869 100644 --- a/pkg/analysis_server/test/services/refactoring/inline_method_test.dart +++ b/pkg/analysis_server/test/services/refactoring/inline_method_test.dart @@ -1760,11 +1760,11 @@ void f(bool p, bool p2, bool p3) { var status = await refactoring.checkInitialConditions(); assertRefactoringStatusOK(status); // configure - var deleteSource = this.deleteSource; + final deleteSource = this.deleteSource; if (deleteSource != null) { refactoring.deleteSource = deleteSource; } - var inlineAll = this.inlineAll; + final inlineAll = this.inlineAll; if (inlineAll != null) { refactoring.inlineAll = inlineAll; } diff --git a/pkg/analysis_server/test/stress/utilities/git.dart b/pkg/analysis_server/test/stress/utilities/git.dart index 05cc2a3ebf9..5db46e749a5 100644 --- a/pkg/analysis_server/test/stress/utilities/git.dart +++ b/pkg/analysis_server/test/stress/utilities/git.dart @@ -287,8 +287,8 @@ class DiffRecord { /// Return `true` if this diff applies to a file with the given name. bool isFor(String fileName) { - var srcPath = this.srcPath; - var dstPath = this.dstPath; + final srcPath = this.srcPath; + final dstPath = this.dstPath; return (srcPath != null && fileName == path.basename(srcPath)) || (dstPath != null && fileName == path.basename(dstPath)); } diff --git a/pkg/analysis_server/test/utils/test_support.dart b/pkg/analysis_server/test/utils/test_support.dart index a9179262749..a791cfb8acb 100644 --- a/pkg/analysis_server/test/utils/test_support.dart +++ b/pkg/analysis_server/test/utils/test_support.dart @@ -80,7 +80,7 @@ class ExpectedError { if (message != null && error.message != message) { return false; } - var messageContains = this.messageContains; + final messageContains = this.messageContains; if (messageContains != null && error.message.contains(messageContains) != true) { return false; diff --git a/pkg/analysis_server/tool/code_completion/completion_metrics.dart b/pkg/analysis_server/tool/code_completion/completion_metrics.dart index 596d1705647..99eea81bcd5 100644 --- a/pkg/analysis_server/tool/code_completion/completion_metrics.dart +++ b/pkg/analysis_server/tool/code_completion/completion_metrics.dart @@ -436,7 +436,7 @@ class CompletionMetrics { /// Perform any operations required in order to revert computing the kind of /// completions represented by this metrics collector. void disable() { - var disableFunction = this.disableFunction; + final disableFunction = this.disableFunction; if (disableFunction != null) { disableFunction(); } @@ -445,7 +445,7 @@ class CompletionMetrics { /// Perform any initialization required in order to compute the kind of /// completions represented by this metrics collector. void enable() { - var enableFunction = this.enableFunction; + final enableFunction = this.enableFunction; if (enableFunction != null) { enableFunction(); } diff --git a/pkg/analysis_server/tool/instrumentation/page/log_page.dart b/pkg/analysis_server/tool/instrumentation/page/log_page.dart index 6853dc140ba..9288cf542dd 100644 --- a/pkg/analysis_server/tool/instrumentation/page/log_page.dart +++ b/pkg/analysis_server/tool/instrumentation/page/log_page.dart @@ -224,7 +224,7 @@ function selectEntryGroup(pageStart) { /// Write the entries in the instrumentation log to the given [sink]. void _writeLeftColumn(StringSink sink) { var length = entries.length; - var pageLength = this.pageLength; + final pageLength = this.pageLength; var pageEnd = pageLength == null ? length : math.min(pageStart + pageLength, length); // diff --git a/pkg/analysis_server/tool/spec/api.dart b/pkg/analysis_server/tool/spec/api.dart index 95fddb4fcdf..8e6696e7eab 100644 --- a/pkg/analysis_server/tool/spec/api.dart +++ b/pkg/analysis_server/tool/spec/api.dart @@ -202,7 +202,7 @@ class Notification extends ApiNode { value: '$domainName.$event') ]; - var params = this.params; + final params = this.params; if (params != null) { fields.add(TypeObjectField('params', params, null)); } @@ -275,7 +275,7 @@ class Request extends ApiNode { value: '$domainName.$method') ]; - var params = this.params; + final params = this.params; if (params != null) { fields.add(TypeObjectField('params', params, null)); } @@ -292,7 +292,7 @@ class Request extends ApiNode { optional: true) ]; - var result = this.result; + final result = this.result; if (result != null) { fields.add(TypeObjectField('result', result, null)); }