Add quick fixes for new SDK constraint checks

Change-Id: I1a3d3b61e8f12b50bb3ad31b5d91612ef6b3e8aa
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/97700
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
diff --git a/pkg/analysis_server/lib/src/services/correction/fix_internal.dart b/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
index 0e9ef8b..1aa5bbf 100644
--- a/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
+++ b/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
@@ -340,7 +340,12 @@
     if (errorCode == HintCode.SDK_VERSION_SET_LITERAL) {
       await _addFix_updateSdkConstraints('2.2.0');
     }
-    if (errorCode == HintCode.SDK_VERSION_UI_AS_CODE) {
+    if (errorCode == HintCode.SDK_VERSION_AS_EXPRESSION_IN_CONST_CONTEXT ||
+        errorCode == HintCode.SDK_VERSION_BOOL_OPERATOR ||
+        errorCode == HintCode.SDK_VERSION_EQ_EQ_OPERATOR_IN_CONST_CONTEXT ||
+        errorCode == HintCode.SDK_VERSION_GT_GT_GT_OPERATOR ||
+        errorCode == HintCode.SDK_VERSION_IS_EXPRESSION_IN_CONST_CONTEXT ||
+        errorCode == HintCode.SDK_VERSION_UI_AS_CODE) {
       await _addFix_updateSdkConstraints('2.2.2');
     }
     if (errorCode == HintCode.TYPE_CHECK_IS_NOT_NULL) {
diff --git a/pkg/analysis_server/test/src/services/correction/fix/update_sdk_constraints_test.dart b/pkg/analysis_server/test/src/services/correction/fix/update_sdk_constraints_test.dart
index 4b957b3..a1b2445 100644
--- a/pkg/analysis_server/test/src/services/correction/fix/update_sdk_constraints_test.dart
+++ b/pkg/analysis_server/test/src/services/correction/fix/update_sdk_constraints_test.dart
@@ -3,6 +3,7 @@
 // BSD-style license that can be found in the LICENSE file.
 
 import 'package:analysis_server/src/services/correction/fix.dart';
+import 'package:analyzer/src/dart/analysis/experiments.dart';
 import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
 import 'package:test_reflective_loader/test_reflective_loader.dart';
 
@@ -23,6 +24,21 @@
     await testUpdate(from: 'any', to: '^2.1.0');
   }
 
+  test_asInConstContext() async {
+    createAnalysisOptionsFile(experiments: [EnableString.constant_update_2018]);
+    await testUpdate(content: '''
+const dynamic a = 2;
+const c = a as int;
+''', to: '^2.2.2');
+  }
+
+  test_boolOperator() async {
+    createAnalysisOptionsFile(experiments: [EnableString.constant_update_2018]);
+    await testUpdate(content: '''
+const c = true & false;
+''', to: '^2.2.2');
+  }
+
   test_caret() async {
     await testUpdate(from: '^2.0.0', to: '^2.1.0');
   }
@@ -31,6 +47,16 @@
     await testUpdate(from: "'>=2.0.0 <3.0.0'", to: "'>=2.1.0 <3.0.0'");
   }
 
+  test_eqEqOperatorInConstContext() async {
+    await testUpdate(content: '''
+class A {
+  const A();
+}
+const a = A();
+const c = a == null;
+''', to: '^2.2.2');
+  }
+
   test_gt() async {
     await testUpdate(from: "'>2.0.0'", to: "'>=2.1.0'");
   }
@@ -39,12 +65,36 @@
     await testUpdate(from: "'>=2.0.0'", to: "'>=2.1.0'");
   }
 
-  testUpdate({String from, String to}) async {
+  test_gtGtGtOperator() async {
+    createAnalysisOptionsFile(experiments: [EnableString.constant_update_2018]);
+    await testUpdate(content: '''
+class C {
+  C operator >>>(C other) => this;
+}
+''', to: '^2.2.2');
+  }
+
+  test_isInConstContext() async {
+    createAnalysisOptionsFile(experiments: [EnableString.constant_update_2018]);
+    await testUpdate(content: '''
+const a = 0;
+const c = a is int;
+''', to: '^2.2.2');
+  }
+
+  test_setLiteral() async {
+    await testUpdate(content: '''
+var s = <int>{};
+''', to: '^2.2.0');
+  }
+
+  testUpdate({String content, String from: '^2.0.0', String to}) async {
     updateTestPubspecFile('''
 environment:
   sdk: $from
 ''');
-    await resolveTestUnit('''
+    await resolveTestUnit(content ??
+        '''
 Future<int> zero() async => 0;
 ''');
     await assertHasFix('''