Skip to content

Commit f1be302

Browse files
srawlinsCommit Queue
authored andcommitted
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 <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent 01a3bc4 commit f1be302

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

pkg/analysis_server/lib/src/services/correction/dart/convert_class_to_enum.dart

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ class ConvertClassToEnum extends ResolvedCorrectionProducer {
3939

4040
@override
4141
Future<void> compute(ChangeBuilder builder) async {
42+
var declaration = node;
43+
if (declaration is! ClassDeclaration || declaration.name != token) {
44+
return;
45+
}
4246
if (!isEnabled(Feature.enhanced_enums)) {
4347
// If the library doesn't support enhanced_enums then the class can't be
4448
// converted.
@@ -51,17 +55,15 @@ class ConvertClassToEnum extends ResolvedCorrectionProducer {
5155
// the class.
5256
return;
5357
}
54-
var declaration = node;
55-
if (declaration is ClassDeclaration && declaration.name == token) {
56-
var description = _EnumDescription.fromClass(
57-
declaration,
58-
strictCasts: analysisOptions.strictCasts,
59-
);
60-
if (description != null) {
61-
await builder.addDartFileEdit(file, (builder) {
62-
description.applyChanges(builder, utils);
63-
});
64-
}
58+
59+
var description = _EnumDescription.fromClass(
60+
declaration,
61+
strictCasts: analysisOptions.strictCasts,
62+
);
63+
if (description != null) {
64+
await builder.addDartFileEdit(file, (builder) {
65+
description.applyChanges(builder, utils);
66+
});
6567
}
6668
}
6769
}

pkg/analysis_server/lib/src/services/correction/dart/convert_to_switch_statement.dart

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,20 @@ class ConvertIfStatementToSwitchStatement extends ResolvedCorrectionProducer {
2020

2121
@override
2222
CorrectionApplicability get applicability =>
23-
// TODO(applicability): comment on why.
24-
CorrectionApplicability
25-
.singleLocation;
23+
// TODO(applicability): comment on why.
24+
CorrectionApplicability.singleLocation;
2625

2726
@override
2827
AssistKind get assistKind => DartAssistKind.CONVERT_TO_SWITCH_STATEMENT;
2928

3029
@override
3130
Future<void> compute(ChangeBuilder builder) async {
32-
if (!isEnabled(Feature.patterns)) {
31+
var ifStatement = node;
32+
if (ifStatement is! IfStatement) {
3333
return;
3434
}
3535

36-
var ifStatement = node;
37-
if (ifStatement is! IfStatement) {
36+
if (!isEnabled(Feature.patterns)) {
3837
return;
3938
}
4039

@@ -212,9 +211,8 @@ class ConvertSwitchExpressionToSwitchStatement
212211

213212
@override
214213
CorrectionApplicability get applicability =>
215-
// TODO(applicability): comment on why.
216-
CorrectionApplicability
217-
.singleLocation;
214+
// TODO(applicability): comment on why.
215+
CorrectionApplicability.singleLocation;
218216

219217
@override
220218
AssistKind get assistKind => DartAssistKind.CONVERT_TO_SWITCH_STATEMENT;

0 commit comments

Comments
 (0)