Refactoring of boolean expressions, pushing negating in #53620
Labels
area-devexp
For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.
devexp-refactoring
Issues with analysis server refactorings
P3
A lower priority bug or feature request
type-enhancement
A request for a change that isn't a bug
Is your feature request related to a problem? Please describe.
Eclipse can push unary negation down into the following parenthetical expression, using De Morgan's laws. It would be great if the Dart language server could do this too. ("Invert if-expression" already exists, so the logic is already mostly written...)
Before:
Insert the cursor right before or after '!' to initiate the "Push Down Negation" action.
After:
In some cases, the parentheses will be needed after the transformation; in some cases, the parentheses won't be needed (it depends on precedence). (On a broader note, it would be nice if the Dart linter recognized unnecessary parentheses, but I digress...)
The reverse should also be possible: Any expression should be able to be selected, and an "Double-negate" action should be available, that parenthesizes and negates the selected expression, again using De Morgan's:
Before:
Select
b || c
and select the "Double-negate" action.After:
Although some thought will have to be given to this to respect precedence, for example if the expression was
if (a && b || c)
andb || c
was selected for double-negation, this would violate precedence. So maybe this should only be able to be applied between boundaries with lower-precedence terms(Also maybe a better name than "Double-negate" should be chosen -- "Pull up negation" to mirror "Push down negation"?)
dart info
): 3.1.2The text was updated successfully, but these errors were encountered: