@@ -170,14 +170,16 @@ class _DivisionMigrationVisitor extends MigrationVisitor {
170
170
/// Allows division within this parenthesized expression.
171
171
///
172
172
/// If these parentheses contain a `/` operation that is migrated to a
173
- /// function call, the now-unnecessary parentheses will be removed.
173
+ /// function call and [negated] is false, the now-unnecessary parentheses
174
+ /// will be removed.
174
175
@override
175
- void visitParenthesizedExpression (ParenthesizedExpression node) {
176
+ void visitParenthesizedExpression (ParenthesizedExpression node,
177
+ {bool negated = false }) {
176
178
_withContext (() {
177
179
var expression = node.expression;
178
180
if (expression is BinaryOperationExpression &&
179
181
expression.operator == BinaryOperator .dividedBy) {
180
- if (_visitSlashOperation (expression)) {
182
+ if (_visitSlashOperation (expression) && ! negated ) {
181
183
addPatch (patchDelete (node.span, end: 1 ));
182
184
addPatch (patchDelete (node.span, start: node.span.length - 1 ));
183
185
}
@@ -187,6 +189,19 @@ class _DivisionMigrationVisitor extends MigrationVisitor {
187
189
}, isDivisionAllowed: true );
188
190
}
189
191
192
+ /// Sets [_negatedParenthesized] to true when about to visit a negated
193
+ /// parenthesized expression.
194
+ @override
195
+ void visitUnaryOperationExpression (UnaryOperationExpression node) {
196
+ var operand = node.operand;
197
+ if (node.operator == UnaryOperator .minus &&
198
+ operand is ParenthesizedExpression ) {
199
+ visitParenthesizedExpression (operand, negated: true );
200
+ return ;
201
+ }
202
+ super .visitUnaryOperationExpression (node);
203
+ }
204
+
190
205
/// Allows division within this return rule.
191
206
@override
192
207
void visitReturnRule (ReturnRule node) {
0 commit comments