invert boolean for anonymous classes (IDEA-71076)

This commit is contained in:
anna
2011-06-20 21:21:07 +04:00
parent b130e75e43
commit 91d3996e1c
4 changed files with 53 additions and 2 deletions
@@ -110,8 +110,12 @@ public class InvertBooleanProcessor extends BaseRefactoringProcessor {
final Query<PsiReference> methodQuery = MethodReferencesSearch.search(method);
final Collection<PsiReference> methodRefs = methodQuery.findAll();
for (PsiReference ref : methodRefs) {
if (ref.getElement().getParent() instanceof PsiCall) {
final PsiCall call = (PsiCall)ref.getElement().getParent();
PsiElement parent = ref.getElement().getParent();
if (parent instanceof PsiAnonymousClass) {
parent = parent.getParent();
}
if (parent instanceof PsiCall) {
final PsiCall call = (PsiCall)parent;
final PsiReferenceExpression methodExpression = call instanceof PsiMethodCallExpression ?
((PsiMethodCallExpression)call).getMethodExpression() :
null;
@@ -0,0 +1,23 @@
abstract class DemoInvertBoolean {
boolean b;
DemoInvertBoolean(boolean <caret>b) {
this.b = b;
}
DemoInvertBoolean() {
this(true);//this true will be inverted
}
abstract void f1();
public static void main(String[] args) {
DemoInvertBoolean demo = new DemoInvertBoolean(true) {//this true will not be inverted
@Override
public void f1() {
}
};
}
}
@@ -0,0 +1,23 @@
abstract class DemoInvertBoolean {
boolean b;
DemoInvertBoolean(boolean <caret>bInverted) {
this.b = !bInverted;
}
DemoInvertBoolean() {
this(false);//this true will be inverted
}
abstract void f1();
public static void main(String[] args) {
DemoInvertBoolean demo = new DemoInvertBoolean(false) {//this true will not be inverted
@Override
public void f1() {
}
};
}
}
@@ -28,6 +28,7 @@ public class InvertBooleanTest extends LightCodeInsightTestCase {
public void testUnusedReturnValue() throws Exception { doTest(); }
public void testInnerClasses() throws Exception {doTest();}
public void testAnonymousClasses() throws Exception {doTest();}
private void doTest() throws Exception {
configureByFile(TEST_ROOT + getTestName(true) + ".java");