Fix for crash in AddMissingEnumCaseClauses.
R=brianwilkerson@google.com, pquitslund@google.com Change-Id: I0dc8c3158eb4b46247e415ff36c33991598bce9c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/157861 Reviewed-by: Phil Quitslund <pquitslund@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
+4
@@ -16,7 +16,11 @@ class AddMissingEnumCaseClauses extends CorrectionProducer {
|
||||
|
||||
@override
|
||||
Future<void> compute(ChangeBuilder builder) async {
|
||||
if (node is! SwitchStatement) {
|
||||
return;
|
||||
}
|
||||
var statement = node as SwitchStatement;
|
||||
|
||||
String enumName;
|
||||
var enumConstantNames = <String>[];
|
||||
var expressionType = statement.expression.staticType;
|
||||
|
||||
+22
-6
@@ -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/error/error.dart';
|
||||
import 'package:analyzer/src/error/codes.dart';
|
||||
import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
@@ -20,17 +21,21 @@ class AddMissingEnumCaseClausesTest extends FixProcessorTest {
|
||||
@override
|
||||
FixKind get kind => DartFixKind.ADD_MISSING_ENUM_CASE_CLAUSES;
|
||||
|
||||
Future<void> assertHasFixWithFilter(String expected) async {
|
||||
var noError = true;
|
||||
await assertHasFix(expected, errorFilter: (error) {
|
||||
if (noError &&
|
||||
bool Function(AnalysisError) get _filter {
|
||||
var hasError = false;
|
||||
return (error) {
|
||||
if (!hasError &&
|
||||
error.errorCode ==
|
||||
StaticWarningCode.MISSING_ENUM_CONSTANT_IN_SWITCH) {
|
||||
noError = false;
|
||||
hasError = true;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
Future<void> assertHasFixWithFilter(String expected) async {
|
||||
await assertHasFix(expected, errorFilter: _filter);
|
||||
}
|
||||
|
||||
Future<void> test_empty() async {
|
||||
@@ -59,6 +64,17 @@ void f(E e) {
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_incomplete_switchStatement() async {
|
||||
await resolveTestUnit(r'''
|
||||
enum E {a, b, c}
|
||||
|
||||
void f(E e) {
|
||||
switch(e
|
||||
}
|
||||
''');
|
||||
await assertNoFix(errorFilter: _filter);
|
||||
}
|
||||
|
||||
Future<void> test_nonEmpty() async {
|
||||
await resolveTestUnit('''
|
||||
enum E {a, b, c}
|
||||
|
||||
Reference in New Issue
Block a user