invert boolean: leave expressions with unused return value untouched (IDEA-56568 )

This commit is contained in:
anna
2010-07-19 22:45:47 +04:00
parent 8d13f7d3ea
commit 9ebf19b75e
4 changed files with 22 additions and 1 deletions
@@ -233,7 +233,9 @@ public class InvertBooleanProcessor extends BaseRefactoringProcessor {
((PsiPrefixExpression)expression.getParent()).getOperationSign().getTokenType() == JavaTokenType.EXCL) {
expression = (PsiExpression)expression.getParent();
}
expression.replace(CodeInsightServicesUtil.invertCondition(expression));
if (!(expression.getParent() instanceof PsiExpressionStatement)) {
expression.replace(CodeInsightServicesUtil.invertCondition(expression));
}
}
catch (IncorrectOperationException e) {
LOG.error(e);
@@ -0,0 +1,9 @@
class C {
boolean f<caret>oo() {
return false;
}
void bar() {
foo();
}
}
@@ -0,0 +1,9 @@
class C {
boolean fooInverted() {
return true;
}
void bar() {
fooInverted();
}
}
@@ -25,6 +25,7 @@ public class InvertBooleanTest extends LightCodeInsightTestCase {
public void testParameter() throws Exception { doTest(); } //inverting boolean parameter
public void testParameter1() throws Exception { doTest(); } //inverting boolean parameter more advanced stuff
public void testUnusedReturnValue() throws Exception { doTest(); }
private void doTest() throws Exception {
configureByFile(TEST_ROOT + getTestName(true) + ".java");