From 1d90288608d3e21d357432c981f9891a21297e89 Mon Sep 17 00:00:00 2001 From: Konstantin Shcheglov Date: Mon, 30 Sep 2024 15:46:09 +0000 Subject: [PATCH] Elements. Migrate MakeFieldNotFinal. Change-Id: Ieefeb8122fb4d1239058689fd613b62791dc640a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/387404 Commit-Queue: Konstantin Shcheglov Reviewed-by: Samuel Rawlins --- .../analyzer_use_new_elements.txt | 1 + .../correction/dart/make_field_not_final.dart | 16 +++++++--------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/pkg/analysis_server/analyzer_use_new_elements.txt b/pkg/analysis_server/analyzer_use_new_elements.txt index db99f76b777a..903d0ef1586b 100644 --- a/pkg/analysis_server/analyzer_use_new_elements.txt +++ b/pkg/analysis_server/analyzer_use_new_elements.txt @@ -308,6 +308,7 @@ lib/src/services/correction/dart/join_if_with_outer.dart lib/src/services/correction/dart/join_variable_declaration.dart lib/src/services/correction/dart/make_class_abstract.dart lib/src/services/correction/dart/make_conditional_on_debug_mode.dart +lib/src/services/correction/dart/make_field_not_final.dart lib/src/services/correction/dart/make_field_public.dart lib/src/services/correction/dart/make_final.dart lib/src/services/correction/dart/make_required_named_parameters_first.dart 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 5b7ca8854332..3009a1ebaf1b 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 @@ -6,7 +6,7 @@ import 'package:analysis_server/src/services/correction/fix.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/dart/ast/extensions.dart'; import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart'; import 'package:analyzer_plugin/utilities/fixes/fixes.dart'; @@ -35,18 +35,15 @@ class MakeFieldNotFinal extends ResolvedCorrectionProducer { return; } - var getter = node.writeOrReadElement; - if (getter is! PropertyAccessorElement) { - return; - } + var getter = node.writeOrReadElement2; // The accessor must be a getter, and it must be synthetic. - if (!(getter.isGetter && getter.isSynthetic)) { + if (!(getter is GetterElement && getter.isSynthetic)) { return; } // The variable must be not synthetic, and have no setter yet. - var variable = getter.variable2; + var variable = getter.variable3; if (variable == null) { return; } @@ -55,11 +52,12 @@ class MakeFieldNotFinal extends ResolvedCorrectionProducer { } // It must be a field declaration. - if (getter.enclosingElement3 is! ClassElement) { + if (getter.enclosingElement2 is! ClassElement2) { return; } - var declaration = await sessionHelper.getElementDeclaration(variable); + var declaration = + await sessionHelper.getElementDeclaration2(variable.firstFragment!); var variableNode = declaration?.node; if (variableNode is! VariableDeclaration) { return;