DAS: in producers, short circuit on node type before experiments

In both cases, we move a check that is _very_ likely to fail (is the node the cursor is on a ClassDeclaration? is the node the cursor is on an IfStatement?) to the top of `compute()`.

Change-Id: I30fedb0184f052b41a9bda7ce838ed1b34fdf470
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/415340
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
diff --git a/pkg/analysis_server/lib/src/services/correction/dart/convert_class_to_enum.dart b/pkg/analysis_server/lib/src/services/correction/dart/convert_class_to_enum.dart
index 07acab5..d11a66f 100644
--- a/pkg/analysis_server/lib/src/services/correction/dart/convert_class_to_enum.dart
+++ b/pkg/analysis_server/lib/src/services/correction/dart/convert_class_to_enum.dart
@@ -39,6 +39,10 @@
 
   @override
   Future<void> compute(ChangeBuilder builder) async {
+    var declaration = node;
+    if (declaration is! ClassDeclaration || declaration.name != token) {
+      return;
+    }
     if (!isEnabled(Feature.enhanced_enums)) {
       // If the library doesn't support enhanced_enums then the class can't be
       // converted.
@@ -51,17 +55,15 @@
       // the class.
       return;
     }
-    var declaration = node;
-    if (declaration is ClassDeclaration && declaration.name == token) {
-      var description = _EnumDescription.fromClass(
-        declaration,
-        strictCasts: analysisOptions.strictCasts,
-      );
-      if (description != null) {
-        await builder.addDartFileEdit(file, (builder) {
-          description.applyChanges(builder, utils);
-        });
-      }
+
+    var description = _EnumDescription.fromClass(
+      declaration,
+      strictCasts: analysisOptions.strictCasts,
+    );
+    if (description != null) {
+      await builder.addDartFileEdit(file, (builder) {
+        description.applyChanges(builder, utils);
+      });
     }
   }
 }
diff --git a/pkg/analysis_server/lib/src/services/correction/dart/convert_to_switch_statement.dart b/pkg/analysis_server/lib/src/services/correction/dart/convert_to_switch_statement.dart
index dd6c505..2cf5cb0 100644
--- a/pkg/analysis_server/lib/src/services/correction/dart/convert_to_switch_statement.dart
+++ b/pkg/analysis_server/lib/src/services/correction/dart/convert_to_switch_statement.dart
@@ -20,21 +20,20 @@
 
   @override
   CorrectionApplicability get applicability =>
-          // TODO(applicability): comment on why.
-          CorrectionApplicability
-          .singleLocation;
+      // TODO(applicability): comment on why.
+      CorrectionApplicability.singleLocation;
 
   @override
   AssistKind get assistKind => DartAssistKind.CONVERT_TO_SWITCH_STATEMENT;
 
   @override
   Future<void> compute(ChangeBuilder builder) async {
-    if (!isEnabled(Feature.patterns)) {
+    var ifStatement = node;
+    if (ifStatement is! IfStatement) {
       return;
     }
 
-    var ifStatement = node;
-    if (ifStatement is! IfStatement) {
+    if (!isEnabled(Feature.patterns)) {
       return;
     }
 
@@ -212,9 +211,8 @@
 
   @override
   CorrectionApplicability get applicability =>
-          // TODO(applicability): comment on why.
-          CorrectionApplicability
-          .singleLocation;
+      // TODO(applicability): comment on why.
+      CorrectionApplicability.singleLocation;
 
   @override
   AssistKind get assistKind => DartAssistKind.CONVERT_TO_SWITCH_STATEMENT;