mirror of
https://github.com/dart-lang/sdk
synced 2024-10-06 14:49:43 +00:00
Enable the fix-all feature for the DartFixKind.ADD_EXPLICIT_CAST fix, tests been added as well.
Change-Id: I3d2273e0814ac14a597648456cd5035ec54360e5 Reviewed-on: https://dart-review.googlesource.com/57120 Reviewed-by: Jaime Wren <jwren@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Jaime Wren <jwren@google.com>
This commit is contained in:
parent
a1f6aa8a3b
commit
b6d20fa975
|
@ -90,8 +90,9 @@ bool hasFix(ErrorCode errorCode) =>
|
|||
class DartFixKind {
|
||||
static const ADD_ASYNC =
|
||||
const FixKind('ADD_ASYNC', 50, "Add 'async' modifier");
|
||||
static const ADD_EXPLICIT_CAST =
|
||||
const FixKind('ADD_EXPLICIT_CAST', 50, "Add cast");
|
||||
static const ADD_EXPLICIT_CAST = const FixKind(
|
||||
'ADD_EXPLICIT_CAST', 50, "Add cast",
|
||||
appliedTogetherMessage: "Add all casts in file");
|
||||
static const ADD_FIELD_FORMAL_PARAMETERS = const FixKind(
|
||||
'ADD_FIELD_FORMAL_PARAMETERS', 30, "Add final field formal parameters");
|
||||
static const ADD_MISSING_PARAMETER_POSITIONAL = const FixKind(
|
||||
|
|
|
@ -477,6 +477,28 @@ class B {}
|
|||
''');
|
||||
}
|
||||
|
||||
test_addExplicitCast_assignment_general_all() async {
|
||||
await resolveTestUnit('''
|
||||
f(A a) {
|
||||
B b, b2;
|
||||
b = a;
|
||||
b2 = a;
|
||||
}
|
||||
class A {}
|
||||
class B {}
|
||||
''');
|
||||
await assertHasFixAllFix(StaticTypeWarningCode.INVALID_ASSIGNMENT,
|
||||
DartFixKind.ADD_EXPLICIT_CAST, '''
|
||||
f(A a) {
|
||||
B b, b2;
|
||||
b = a as B;
|
||||
b2 = a as B;
|
||||
}
|
||||
class A {}
|
||||
class B {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_addExplicitCast_assignment_list() async {
|
||||
await resolveTestUnit('''
|
||||
f(List<A> a) {
|
||||
|
@ -496,6 +518,28 @@ class B {}
|
|||
''');
|
||||
}
|
||||
|
||||
test_addExplicitCast_assignment_list_all() async {
|
||||
await resolveTestUnit('''
|
||||
f(List<A> a) {
|
||||
List<B> b, b2;
|
||||
b = a.where((e) => e is B).toList();
|
||||
b2 = a.where((e) => e is B).toList();
|
||||
}
|
||||
class A {}
|
||||
class B {}
|
||||
''');
|
||||
await assertHasFixAllFix(StaticTypeWarningCode.INVALID_ASSIGNMENT,
|
||||
DartFixKind.ADD_EXPLICIT_CAST, '''
|
||||
f(List<A> a) {
|
||||
List<B> b, b2;
|
||||
b = a.where((e) => e is B).cast<B>().toList();
|
||||
b2 = a.where((e) => e is B).cast<B>().toList();
|
||||
}
|
||||
class A {}
|
||||
class B {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_addExplicitCast_assignment_map() async {
|
||||
await resolveTestUnit('''
|
||||
f(Map<A, B> a) {
|
||||
|
@ -515,6 +559,28 @@ class B {}
|
|||
''');
|
||||
}
|
||||
|
||||
test_addExplicitCast_assignment_map_all() async {
|
||||
await resolveTestUnit('''
|
||||
f(Map<A, B> a) {
|
||||
Map<B, A> b, b2;
|
||||
b = a;
|
||||
b2 = a;
|
||||
}
|
||||
class A {}
|
||||
class B {}
|
||||
''');
|
||||
await assertHasFixAllFix(StaticTypeWarningCode.INVALID_ASSIGNMENT,
|
||||
DartFixKind.ADD_EXPLICIT_CAST, '''
|
||||
f(Map<A, B> a) {
|
||||
Map<B, A> b, b2;
|
||||
b = a.cast<B, A>();
|
||||
b2 = a.cast<B, A>();
|
||||
}
|
||||
class A {}
|
||||
class B {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_addExplicitCast_assignment_needsParens() async {
|
||||
await resolveTestUnit('''
|
||||
f(A a) {
|
||||
|
@ -538,6 +604,32 @@ class B {}
|
|||
''');
|
||||
}
|
||||
|
||||
test_addExplicitCast_assignment_needsParens_all() async {
|
||||
await resolveTestUnit('''
|
||||
f(A a) {
|
||||
B b, b2;
|
||||
b = a..m();
|
||||
b2 = a..m();
|
||||
}
|
||||
class A {
|
||||
int m() => 0;
|
||||
}
|
||||
class B {}
|
||||
''');
|
||||
await assertHasFixAllFix(StaticTypeWarningCode.INVALID_ASSIGNMENT,
|
||||
DartFixKind.ADD_EXPLICIT_CAST, '''
|
||||
f(A a) {
|
||||
B b, b2;
|
||||
b = (a..m()) as B;
|
||||
b2 = (a..m()) as B;
|
||||
}
|
||||
class A {
|
||||
int m() => 0;
|
||||
}
|
||||
class B {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_addExplicitCast_assignment_set() async {
|
||||
await resolveTestUnit('''
|
||||
f(Set<A> a) {
|
||||
|
@ -557,6 +649,28 @@ class B {}
|
|||
''');
|
||||
}
|
||||
|
||||
test_addExplicitCast_assignment_set_all() async {
|
||||
await resolveTestUnit('''
|
||||
f(Set<A> a) {
|
||||
Set<B> b, b2;
|
||||
b = a;
|
||||
b2 = a;
|
||||
}
|
||||
class A {}
|
||||
class B {}
|
||||
''');
|
||||
await assertHasFixAllFix(StaticTypeWarningCode.INVALID_ASSIGNMENT,
|
||||
DartFixKind.ADD_EXPLICIT_CAST, '''
|
||||
f(Set<A> a) {
|
||||
Set<B> b, b2;
|
||||
b = a.cast<B>();
|
||||
b2 = a.cast<B>();
|
||||
}
|
||||
class A {}
|
||||
class B {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_addExplicitCast_BAD_as() async {
|
||||
await resolveTestUnit('''
|
||||
f(A a) {
|
||||
|
@ -597,6 +711,26 @@ class B {}
|
|||
''');
|
||||
}
|
||||
|
||||
test_addExplicitCast_declaration_general_all() async {
|
||||
await resolveTestUnit('''
|
||||
f(A a) {
|
||||
B b = a;
|
||||
B b2 = a;
|
||||
}
|
||||
class A {}
|
||||
class B {}
|
||||
''');
|
||||
await assertHasFixAllFix(StaticTypeWarningCode.INVALID_ASSIGNMENT,
|
||||
DartFixKind.ADD_EXPLICIT_CAST, '''
|
||||
f(A a) {
|
||||
B b = a as B;
|
||||
B b2 = a as B;
|
||||
}
|
||||
class A {}
|
||||
class B {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_addExplicitCast_declaration_list() async {
|
||||
await resolveTestUnit('''
|
||||
f(List<A> a) {
|
||||
|
@ -614,6 +748,26 @@ class B {}
|
|||
''');
|
||||
}
|
||||
|
||||
test_addExplicitCast_declaration_list_all() async {
|
||||
await resolveTestUnit('''
|
||||
f(List<A> a) {
|
||||
List<B> b = a.where((e) => e is B).toList();
|
||||
List<B> b2 = a.where((e) => e is B).toList();
|
||||
}
|
||||
class A {}
|
||||
class B {}
|
||||
''');
|
||||
await assertHasFixAllFix(StaticTypeWarningCode.INVALID_ASSIGNMENT,
|
||||
DartFixKind.ADD_EXPLICIT_CAST, '''
|
||||
f(List<A> a) {
|
||||
List<B> b = a.where((e) => e is B).cast<B>().toList();
|
||||
List<B> b2 = a.where((e) => e is B).cast<B>().toList();
|
||||
}
|
||||
class A {}
|
||||
class B {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_addExplicitCast_declaration_map() async {
|
||||
await resolveTestUnit('''
|
||||
f(Map<A, B> a) {
|
||||
|
@ -631,6 +785,26 @@ class B {}
|
|||
''');
|
||||
}
|
||||
|
||||
test_addExplicitCast_declaration_map_all() async {
|
||||
await resolveTestUnit('''
|
||||
f(Map<A, B> a) {
|
||||
Map<B, A> b = a;
|
||||
Map<B, A> b2 = a;
|
||||
}
|
||||
class A {}
|
||||
class B {}
|
||||
''');
|
||||
await assertHasFixAllFix(StaticTypeWarningCode.INVALID_ASSIGNMENT,
|
||||
DartFixKind.ADD_EXPLICIT_CAST, '''
|
||||
f(Map<A, B> a) {
|
||||
Map<B, A> b = a.cast<B, A>();
|
||||
Map<B, A> b2 = a.cast<B, A>();
|
||||
}
|
||||
class A {}
|
||||
class B {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_addExplicitCast_declaration_needsParens() async {
|
||||
await resolveTestUnit('''
|
||||
f(A a) {
|
||||
|
@ -652,6 +826,30 @@ class B {}
|
|||
''');
|
||||
}
|
||||
|
||||
test_addExplicitCast_declaration_needsParens_all() async {
|
||||
await resolveTestUnit('''
|
||||
f(A a) {
|
||||
B b = a..m();
|
||||
B b2 = a..m();
|
||||
}
|
||||
class A {
|
||||
int m() => 0;
|
||||
}
|
||||
class B {}
|
||||
''');
|
||||
await assertHasFixAllFix(StaticTypeWarningCode.INVALID_ASSIGNMENT,
|
||||
DartFixKind.ADD_EXPLICIT_CAST, '''
|
||||
f(A a) {
|
||||
B b = (a..m()) as B;
|
||||
B b2 = (a..m()) as B;
|
||||
}
|
||||
class A {
|
||||
int m() => 0;
|
||||
}
|
||||
class B {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_addExplicitCast_declaration_set() async {
|
||||
await resolveTestUnit('''
|
||||
f(Set<A> a) {
|
||||
|
@ -669,6 +867,26 @@ class B {}
|
|||
''');
|
||||
}
|
||||
|
||||
test_addExplicitCast_declaration_set_all() async {
|
||||
await resolveTestUnit('''
|
||||
f(Set<A> a) {
|
||||
Set<B> b = a;
|
||||
Set<B> b2 = a;
|
||||
}
|
||||
class A {}
|
||||
class B {}
|
||||
''');
|
||||
await assertHasFixAllFix(StaticTypeWarningCode.INVALID_ASSIGNMENT,
|
||||
DartFixKind.ADD_EXPLICIT_CAST, '''
|
||||
f(Set<A> a) {
|
||||
Set<B> b = a.cast<B>();
|
||||
Set<B> b2 = a.cast<B>();
|
||||
}
|
||||
class A {}
|
||||
class B {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_addFieldFormalParameters_flutter() async {
|
||||
addFlutterPackage();
|
||||
await resolveTestUnit('''
|
||||
|
|
Loading…
Reference in a new issue