escalate visibility for moved class (IDEA-119683)

This commit is contained in:
Anna Kozlova
2014-04-11 22:21:16 +02:00
parent 288b080dd7
commit 1977e48c1a
6 changed files with 53 additions and 10 deletions
@@ -250,6 +250,23 @@ public class MoveInnerProcessor extends BaseRefactoringProcessor {
reference.bindToElement(newClass);
}
for (UsageInfo usage : usages) {
final PsiElement element = usage.getElement();
final PsiElement parent = element != null ? element.getParent() : null;
if (parent instanceof PsiNewExpression) {
final PsiMethod resolveConstructor = ((PsiNewExpression)parent).resolveConstructor();
for (PsiMethod method : newClass.getConstructors()) {
if (resolveConstructor == method) {
final PsiElement place = usage.getElement();
if (place != null) {
VisibilityUtil.escalateVisibility(method, place);
}
break;
}
}
}
}
if (field != null) {
final PsiExpression paramAccessExpression = factory.createExpressionFromText(myParameterNameOuterClass, null);
for (final PsiMethod constructor : newClass.getConstructors()) {
@@ -42,16 +42,6 @@ public class MoveJavaInnerHandler implements MoveInnerHandler {
if (makePublic) {
PsiUtil.setModifierProperty(newClass, PsiModifier.PUBLIC, true);
}
final PsiMethod[] constructors = newClass.getConstructors();
for (PsiMethod constructor : constructors) {
final PsiModifierList modifierList = constructor.getModifierList();
modifierList.setModifierProperty(PsiModifier.PRIVATE, false);
modifierList.setModifierProperty(PsiModifier.PROTECTED, false);
if (makePublic && !newClass.isEnum()) {
modifierList.setModifierProperty(PsiModifier.PUBLIC, true);
}
}
}
else {
newClass = (PsiClass)options.getTargetContainer().add(innerClass);
@@ -0,0 +1,8 @@
package p;
class A {
public void test() {
B.foo();
}
}
@@ -0,0 +1,9 @@
package p;
class B {
private B() {
System.out.println("Constructor");
}
static void foo(){}
}
@@ -0,0 +1,15 @@
package p;
class A {
public void test() {
B.foo();
}
private class B {
private B() {
System.out.println("Constructor");
}
static void foo(){}
}
}
@@ -85,6 +85,10 @@ public class MoveInnerTest extends MultiFileTestCase {
doTest(createAction("p.A.B", "B", false, null, false, false, null));
}
public void testConstructorUtilClassVisibility() throws Exception {
doTest(createAction("p.A.B", "B", false, null, false, false, null));
}
public void testFieldAccessInSuper() throws Exception {
doTest(createAction("p.A.B", "B", true, "a", false, false, null));
}