Skip to content

Commit

Permalink
[Element mode] Migrate convert_to_initializing_formal and convert_to_…
Browse files Browse the repository at this point in the history
…map_literal correction producers

Change-Id: I7afd7d49b62cde780e6a3da3231035a323b7a012
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/387324
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Keerti Parthasarathy <keertip@google.com>
  • Loading branch information
keertip authored and Commit Queue committed Sep 30, 2024
1 parent fa3dfe9 commit 3920bba
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import 'package:analysis_server/src/services/correction/fix.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';
Expand Down Expand Up @@ -77,8 +77,8 @@ class ConvertToInitializingFormal extends ResolvedCorrectionProducer {
return;
}

var fieldElement = node.fieldName.staticElement;
if (fieldElement is! VariableElement) {
var fieldElement = node.fieldName.element;
if (fieldElement is! VariableElement2) {
return;
}

Expand Down Expand Up @@ -107,9 +107,9 @@ class ConvertToInitializingFormal extends ResolvedCorrectionProducer {
if (expression is! SimpleIdentifier) {
return null;
}
var parameterElement = expression.staticElement;
var parameterElement = expression.element;
for (var parameter in constructor.parameters.parameters) {
if (parameter.declaredElement == parameterElement) {
if (parameter.declaredFragment?.element == parameterElement) {
parameter = parameter.notDefault;
return parameter is SimpleFormalParameter ? parameter : null;
}
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/services/correction/fix.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/dart/element/type.dart';
import 'package:analyzer_plugin/utilities/assist/assist.dart';
import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart';
Expand Down Expand Up @@ -45,7 +45,7 @@ class ConvertToMapLiteral extends ResolvedCorrectionProducer {
creation.constructorName.name != null ||
creation.argumentList.arguments.isNotEmpty ||
type is! InterfaceType ||
!_isMapClass(type.element)) {
!_isMapClass(type.element3)) {
return;
}
//
Expand Down Expand Up @@ -83,8 +83,8 @@ class ConvertToMapLiteral extends ResolvedCorrectionProducer {

/// Return `true` if the [element] represents either the class `Map` or
/// `LinkedHashMap`.
bool _isMapClass(InterfaceElement element) =>
element == typeProvider.mapElement ||
bool _isMapClass(InterfaceElement2 element) =>
element == typeProvider.mapElement2 ||
(element.name == 'LinkedHashMap' &&
element.library.name == 'dart.collection');
element.library2.name == 'dart.collection');
}

0 comments on commit 3920bba

Please sign in to comment.