Skip to content

Commit

Permalink
Elements. Migrate ConvertIntoFinalField.
Browse files Browse the repository at this point in the history
Change-Id: I13e4a74ecf0ab252c68abbcd204c1ec89612f35f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/386738
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
  • Loading branch information
scheglov authored and Commit Queue committed Sep 29, 2024
1 parent 3c43538 commit 02cc824
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
1 change: 1 addition & 0 deletions pkg/analysis_server/analyzer_use_new_elements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
{
Expand Down

0 comments on commit 02cc824

Please sign in to comment.