[element model] migrate `prefer_final_in_for_each`

Bug: https://github.com/dart-lang/linter/issues/5099
Change-Id: I172356e3db5d2f145e6e91596de018018ea57f1f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/388583
Commit-Queue: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
diff --git a/pkg/linter/analyzer_use_new_elements.txt b/pkg/linter/analyzer_use_new_elements.txt
index 232d7cd..acb0fae 100644
--- a/pkg/linter/analyzer_use_new_elements.txt
+++ b/pkg/linter/analyzer_use_new_elements.txt
@@ -26,6 +26,7 @@
 lib/src/rules/avoid_shadowing_type_parameters.dart
 lib/src/rules/avoid_single_cascade_in_expression_statements.dart
 lib/src/rules/avoid_slow_async_io.dart
+lib/src/rules/avoid_type_to_string.dart
 lib/src/rules/avoid_types_on_closure_parameters.dart
 lib/src/rules/avoid_unnecessary_containers.dart
 lib/src/rules/avoid_unstable_final_fields.dart
@@ -96,7 +97,9 @@
 lib/src/rules/prefer_double_quotes.dart
 lib/src/rules/prefer_equal_for_default_values.dart
 lib/src/rules/prefer_expression_function_bodies.dart
+lib/src/rules/prefer_final_in_for_each.dart
 lib/src/rules/prefer_for_elements_to_map_fromIterable.dart
+lib/src/rules/prefer_function_declarations_over_variables.dart
 lib/src/rules/prefer_generic_function_type_aliases.dart
 lib/src/rules/prefer_if_elements_to_conditional_expressions.dart
 lib/src/rules/prefer_if_null_operators.dart
diff --git a/pkg/linter/lib/src/rules/prefer_final_in_for_each.dart b/pkg/linter/lib/src/rules/prefer_final_in_for_each.dart
index 918740c..d6d6a67 100644
--- a/pkg/linter/lib/src/rules/prefer_final_in_for_each.dart
+++ b/pkg/linter/lib/src/rules/prefer_final_in_for_each.dart
@@ -45,10 +45,10 @@
     if (loopVariable.isFinal) return;
 
     var function = node.thisOrAncestorOfType<FunctionBody>();
-    var loopVariableElement = loopVariable.declaredElement;
+    var loopVariableElement = loopVariable.declaredElement2;
     if (function != null &&
         loopVariableElement != null &&
-        !function.isPotentiallyMutatedInScope(loopVariableElement)) {
+        !function.isPotentiallyMutatedInScope2(loopVariableElement)) {
       var name = loopVariable.name;
       rule.reportLintForToken(name,
           errorCode: LinterLintCode.prefer_final_in_for_each_variable,
@@ -92,9 +92,9 @@
 extension on FunctionBody {
   bool potentiallyMutates(Object pattern) {
     if (pattern is! DeclaredVariablePattern) return true;
-    var element = pattern.declaredElement;
+    var element = pattern.declaredElement2;
     if (element == null) return true;
-    return isPotentiallyMutatedInScope(element.declaration);
+    return isPotentiallyMutatedInScope2(element.baseElement);
   }
 
   bool potentiallyMutatesAnyField(List<PatternField> fields) =>