move static members: process anonymous class creation (IDEADEV-39807)

This commit is contained in:
Anna Kozlova
2009-08-25 19:44:04 +04:00
parent 5f3a983068
commit 8888a8b67d
8 changed files with 48 additions and 5 deletions
@@ -4,7 +4,6 @@
*/
package com.intellij.refactoring.move.moveMembers;
import com.intellij.codeInsight.ChangeContextUtil;
import com.intellij.lang.LanguageExtension;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
@@ -377,10 +376,18 @@ public class MoveMembersProcessor extends BaseRefactoringProcessor {
}
}
else if (scope instanceof PsiNewExpression) {
final PsiMethod refElement = ((PsiNewExpression)scope).resolveConstructor();
if (refElement != null) {
if (!RefactoringHierarchyUtil.willBeInTargetClass(refElement, membersToMove, newContext, false)) {
checkAccessibility(refElement, newContext, null, member, conflicts);
final PsiNewExpression newExpression = (PsiNewExpression)scope;
final PsiAnonymousClass anonymousClass = newExpression.getAnonymousClass();
if (anonymousClass != null) {
if (!RefactoringHierarchyUtil.willBeInTargetClass(anonymousClass, membersToMove, newContext, false)){
checkAccessibility(anonymousClass, newContext, anonymousClass, member, conflicts);
}
} else {
final PsiMethod refElement = newExpression.resolveConstructor();
if (refElement != null) {
if (!RefactoringHierarchyUtil.willBeInTargetClass(refElement, membersToMove, newContext, false)) {
checkAccessibility(refElement, newContext, null, member, conflicts);
}
}
}
}
@@ -62,6 +62,10 @@ public class MoveMembersTest extends MultiFileTestCase {
doTest("C", "B", 0);
}
public void testProtectedConstructor() throws Exception {
doTest("pack1.A", "pack1.C", 0);
}
public void testOtherPackageImport() throws Exception {
doTest("pack1.ClassWithStaticMethod", "pack2.OtherClass", 1);
}
@@ -0,0 +1,4 @@
package pack1;
public class A {
}
@@ -0,0 +1,7 @@
package pack1;
public class C {
public static void foo() {
new B(){};
}
}
@@ -0,0 +1,5 @@
package pack2;
public class B {
protected B(){}
}
@@ -0,0 +1,7 @@
package pack1;
public class A {
public static void foo() {
new B(){};
}
}
@@ -0,0 +1,4 @@
package pack1;
public class C {
}
@@ -0,0 +1,5 @@
package pack2;
public class B {
protected B(){}
}