@@ -20,39 +20,39 @@ class UseDifferentDivisionOperator extends MultiCorrectionProducer {
2020
2121 @override
2222 Future <List <ResolvedCorrectionProducer >> get producers async {
23- var exp = node;
24- if (exp case BinaryExpression _) {
25- return switch (exp .operator .type) {
26- TokenType .SLASH => [
27- _UseDifferentDivisionOperator (
28- context: context,
29- fixKind: DartFixKind .USE_EFFECTIVE_INTEGER_DIVISION ,
30- ),
31- ],
32- TokenType .TILDE_SLASH => [
33- _UseDifferentDivisionOperator (
34- context: context,
35- fixKind: DartFixKind .USE_DIVISION ,
36- ),
37- ],
38- _ => const [],
39- };
40- } else if (exp case AssignmentExpression _) {
41- return switch (exp .operator .type) {
42- TokenType .SLASH_EQ => [
43- _UseDifferentDivisionOperator (
44- context: context,
45- fixKind: DartFixKind .USE_EFFECTIVE_INTEGER_DIVISION ,
46- ),
47- ],
48- TokenType .TILDE_SLASH_EQ => [
49- _UseDifferentDivisionOperator (
50- context: context,
51- fixKind: DartFixKind .USE_DIVISION ,
52- ),
53- ],
54- _ => const [],
55- };
23+ switch ( node) {
24+ case BinaryExpression node :
25+ return switch (node .operator .type) {
26+ TokenType .SLASH => [
27+ _UseDifferentDivisionOperator (
28+ context: context,
29+ fixKind: DartFixKind .USE_EFFECTIVE_INTEGER_DIVISION ,
30+ ),
31+ ],
32+ TokenType .TILDE_SLASH => [
33+ _UseDifferentDivisionOperator (
34+ context: context,
35+ fixKind: DartFixKind .USE_DIVISION ,
36+ ),
37+ ],
38+ _ => const [],
39+ };
40+ case AssignmentExpression node :
41+ return switch (node .operator .type) {
42+ TokenType .SLASH_EQ => [
43+ _UseDifferentDivisionOperator (
44+ context: context,
45+ fixKind: DartFixKind .USE_EFFECTIVE_INTEGER_DIVISION ,
46+ ),
47+ ],
48+ TokenType .TILDE_SLASH_EQ => [
49+ _UseDifferentDivisionOperator (
50+ context: context,
51+ fixKind: DartFixKind .USE_DIVISION ,
52+ ),
53+ ],
54+ _ => const [],
55+ };
5656 }
5757 return const [];
5858 }
@@ -75,17 +75,17 @@ class _UseDifferentDivisionOperator extends ResolvedCorrectionProducer {
7575
7676 @override
7777 Future <void > compute (ChangeBuilder builder) async {
78- var exp = node;
7978 DartType ? leftType;
8079 Token operator ;
81- if (exp case BinaryExpression _) {
82- leftType = exp.leftOperand.staticType;
83- operator = exp.operator ;
84- } else if (exp case AssignmentExpression _) {
85- leftType = exp.writeType;
86- operator = exp.operator ;
87- } else {
88- return ;
80+ switch (node) {
81+ case BinaryExpression node:
82+ leftType = node.leftOperand.staticType;
83+ operator = node.operator ;
84+ case AssignmentExpression node:
85+ leftType = node.writeType;
86+ operator = node.operator ;
87+ default :
88+ return ;
8989 }
9090 if (leftType == null ) {
9191 return ;
@@ -131,23 +131,20 @@ class _UseDifferentDivisionOperator extends ResolvedCorrectionProducer {
131131
132132extension on DartType {
133133 Set <_DivisionOperator > get divisionOperators {
134- // See operators defined for this type element.
135- if (element3 case InterfaceElement2 interfaceElement) {
136- return {
137- for (var method in interfaceElement.methods2)
138- // No need to test for eq operators, as they are not explicitly defined.
139- if (method.name3 == TokenType .SLASH .lexeme)
140- _DivisionOperator .division
141- else if (method.name3 == TokenType .TILDE_SLASH .lexeme)
142- _DivisionOperator .effectiveIntegerDivision,
143- ...interfaceElement.allSupertypes.expand (
144- (type) => type.divisionOperators,
145- ),
146- };
147- } else if (element3 case TypeParameterElement2 typeParameterElement) {
148- return typeParameterElement.bound? .divisionOperators ?? const {};
134+ switch (element3) {
135+ case InterfaceElement2 element:
136+ return {
137+ for (var method in element.methods2)
138+ // No need to test for eq operators, as they are not explicitly defined.
139+ if (method.name3 == TokenType .SLASH .lexeme)
140+ _DivisionOperator .division
141+ else if (method.name3 == TokenType .TILDE_SLASH .lexeme)
142+ _DivisionOperator .effectiveIntegerDivision,
143+ ...element.allSupertypes.expand ((type) => type.divisionOperators),
144+ };
145+ case TypeParameterElement2 element:
146+ return element.bound? .divisionOperators ?? const {};
149147 }
150-
151148 return const {};
152149 }
153150}
0 commit comments