Elements. Migrate MakeVariableNullable.

Change-Id: I478238743d655841203a753681815004d50c6db6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/387406
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
diff --git a/pkg/analysis_server/analyzer_use_new_elements.txt b/pkg/analysis_server/analyzer_use_new_elements.txt
index 9536e9f..7dc63a8 100644
--- a/pkg/analysis_server/analyzer_use_new_elements.txt
+++ b/pkg/analysis_server/analyzer_use_new_elements.txt
@@ -318,6 +318,7 @@
 lib/src/services/correction/dart/make_return_type_nullable.dart
 lib/src/services/correction/dart/make_super_invocation_last.dart
 lib/src/services/correction/dart/make_variable_not_final.dart
+lib/src/services/correction/dart/make_variable_nullable.dart
 lib/src/services/correction/dart/organize_imports.dart
 lib/src/services/correction/dart/qualify_reference.dart
 lib/src/services/correction/dart/remove_annotation.dart
diff --git a/pkg/analysis_server/lib/src/services/correction/dart/make_variable_nullable.dart b/pkg/analysis_server/lib/src/services/correction/dart/make_variable_nullable.dart
index ad39307..688a519 100644
--- a/pkg/analysis_server/lib/src/services/correction/dart/make_variable_nullable.dart
+++ b/pkg/analysis_server/lib/src/services/correction/dart/make_variable_nullable.dart
@@ -4,11 +4,11 @@
 
 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/ast/token.dart';
-import 'package:analyzer/dart/element/element.dart';
+import 'package:analyzer/dart/element/element2.dart';
 import 'package:analyzer/dart/element/nullability_suffix.dart';
 import 'package:analyzer/dart/element/type.dart';
+import 'package:analyzer/src/dart/ast/ast.dart';
 import 'package:analyzer/src/dart/ast/extensions.dart';
 import 'package:analyzer/src/dart/element/type.dart';
 import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart';
@@ -47,7 +47,8 @@
       var parent = node.parent;
       if (parent is AssignmentExpression && parent.rightHandSide == node) {
         await _forAssignment(builder, node, parent);
-      } else if (parent is VariableDeclaration && parent.initializer == node) {
+      } else if (parent is VariableDeclarationImpl &&
+          parent.initializer == node) {
         await _forVariableDeclaration(builder, node, parent);
       }
     }
@@ -57,14 +58,14 @@
   /// given [variable] that is located in the given [block] or in a surrounding
   /// block. Return `null` if the declaration can't be found.
   VariableDeclarationList? _findDeclaration(
-      LocalVariableElement variable, Block? block) {
+      LocalVariableElement2 variable, Block? block) {
     var currentBlock = block;
     while (currentBlock != null) {
       for (var statement in currentBlock.statements) {
         if (statement is VariableDeclarationStatement) {
           var variableList = statement.variables;
           for (var declaration in variableList.variables) {
-            if (declaration.declaredElement == variable) {
+            if (declaration.declaredElement2 == variable) {
               return variableList;
             }
           }
@@ -82,8 +83,8 @@
       return;
     }
 
-    var element = leftHandSide.staticElement;
-    if (element is! LocalVariableElement) {
+    var element = leftHandSide.element;
+    if (element is! LocalVariableElement2) {
       return;
     }
 
@@ -200,7 +201,7 @@
   }
 
   Future<void> _forVariableDeclaration(ChangeBuilder builder, Expression node,
-      VariableDeclaration parent) async {
+      VariableDeclarationImpl parent) async {
     var declarationList = parent.parent;
     if (declarationList is! VariableDeclarationList) {
       return;
@@ -209,7 +210,7 @@
       return;
     }
 
-    var oldType = parent.declaredElement!.type;
+    var oldType = parent.type;
     if (oldType is! InterfaceTypeImpl && oldType is! RecordTypeImpl) {
       return;
     }