diff --git a/pkg/analysis_server/analyzer_use_new_elements.txt b/pkg/analysis_server/analyzer_use_new_elements.txt index 1ba8ccbba0b1..3d23e47b6a32 100644 --- a/pkg/analysis_server/analyzer_use_new_elements.txt +++ b/pkg/analysis_server/analyzer_use_new_elements.txt @@ -242,6 +242,7 @@ lib/src/services/correction/dart/convert_flutter_children.dart lib/src/services/correction/dart/convert_for_each_to_for_loop.dart lib/src/services/correction/dart/convert_into_async_body.dart lib/src/services/correction/dart/convert_into_block_body.dart +lib/src/services/correction/dart/convert_into_final_field.dart lib/src/services/correction/dart/convert_into_getter.dart lib/src/services/correction/dart/convert_into_is_not.dart lib/src/services/correction/dart/convert_quotes.dart diff --git a/pkg/analysis_server/lib/src/services/correction/dart/convert_into_final_field.dart b/pkg/analysis_server/lib/src/services/correction/dart/convert_into_final_field.dart index 129d8c0b999c..4bcd366c8763 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/convert_into_final_field.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/convert_into_final_field.dart @@ -6,7 +6,7 @@ import 'package:analysis_server/src/services/correction/assist.dart'; import 'package:analysis_server/src/utilities/extensions/ast.dart'; import 'package:analysis_server_plugin/edit/dart/correction_producer.dart'; import 'package:analyzer/dart/ast/ast.dart'; -import 'package:analyzer/dart/element/element.dart'; +import 'package:analyzer/dart/element/element2.dart'; import 'package:analyzer/src/utilities/extensions/ast.dart'; import 'package:analyzer_plugin/utilities/assist/assist.dart'; import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart'; @@ -48,19 +48,21 @@ class ConvertIntoFinalField extends ResolvedCorrectionProducer { return; } + var getterElement = getter.declaredFragment?.element; + if (getterElement is! GetterElement) { + return; + } + + var variable = getterElement.variable3; + if (variable == null) { + return; + } + // Check that there is no corresponding setter. - { - var element = getter.declaredElement; - if (element == null) { - return; - } - var enclosing = element.enclosingElement3; - if (enclosing is InterfaceElement) { - if (enclosing.getSetter(element.name) != null) { - return; - } - } + if (variable.setter != null) { + return; } + // Try to find the returned expression. Expression? expression; {