Daniel,
position caret at "if" keyword and press Alt+Enter.
Choose "Invert If Condition".

Friendly,
Dmitry

Daniel wrote:
> May I suggest the addition of a simple refactoring that will toggle between the 
>following:[pre]if (!c) { a(); } else { b(); }[/pre]and the following:[pre]if (c) { 
>b(); } else { a(); }[/pre]
> 
> This refactoring is most often used to eliminate unnecessary negations after the 
>introduction of an else-clause. For example, the following code is good as it 
>is:[pre]if (!(isValid())) {
>     throw new Exception("It's not valid, man.");
> }[/pre]while this modified version is awkward:[pre]if (!(isValid())) {
>     throw new Exception("It's not valid, man.");
> } else {
>     System.out.println("It's valid -- good work!");
> }[/pre]Reversing this conditional normalizes and simplifies it by removing the 
>unneeded negation:[pre]if (isValid()) {
>     System.out.println("It's valid -- good work!");
> } else {
>     throw new Exception("It's not valid, man.");
> }[/pre]
> 
> While this may seem trivial, it probably is, too. However, it still involves 
>copying/pasting twice, deleting two parentheses and a negation sign, and 
>double-checking it's still the same conditional.
> 
> This common procedure could -- and should, IMHO -- be automated, reducing the work 
>to a few keystrokes.


-- 
Dmitry Lomov
JetBrains Inc. / IntelliJ Labs
http://www.intellij.com
"Develop with pleasure!"

_______________________________________________
Eap-features mailing list
[EMAIL PROTECTED]
http://lists.jetbrains.com/mailman/listinfo/eap-features

Reply via email to