move member: restore qualifier in switch labels for non-enum constants (IDEA-147539)

This commit is contained in:
Anna Kozlova
2015-11-06 16:21:29 +01:00
parent a73d1238ff
commit 25d3334300
6 changed files with 44 additions and 10 deletions
@@ -179,14 +179,15 @@ public class MoveJavaMemberHandler implements MoveMemberHandler {
changeQualifier(refExpr, usage.qualifierClass, usage.member);
}
else {
final PsiReferenceParameterList parameterList = refExpr.getParameterList();
if (parameterList != null && parameterList.getTypeArguments().length == 0 && !(refExpr instanceof PsiMethodReferenceExpression)){
refExpr.setQualifierExpression(null);
} else {
final Project project = element.getProject();
final PsiClass targetClass =
JavaPsiFacade.getInstance(project).findClass(options.getTargetClassName(), GlobalSearchScope.projectScope(project));
if (targetClass != null) {
final Project project = element.getProject();
final PsiClass targetClass =
JavaPsiFacade.getInstance(project).findClass(options.getTargetClassName(), GlobalSearchScope.projectScope(project));
if (targetClass != null) {
final PsiReferenceParameterList parameterList = refExpr.getParameterList();
if ((targetClass.isEnum() || PsiTreeUtil.isAncestor(targetClass, element, true)) && parameterList != null && parameterList.getTypeArguments().length == 0 && !(refExpr instanceof PsiMethodReferenceExpression)) {
refExpr.setQualifierExpression(null);
}
else {
changeQualifier(refExpr, targetClass, usage.member);
}
}
@@ -0,0 +1,13 @@
public class B {
public static final String FOO = "FOO";
}
class U {
public void example(String foo) {
switch (foo) {
case B.FOO:
break;
}
}
}
@@ -0,0 +1,3 @@
public interface A {
public static final String FOO = "FOO";
}
@@ -0,0 +1,12 @@
public class B {
}
class U {
public void example(String foo) {
switch (foo) {
case A.FOO:
break;
}
}
}
@@ -18,7 +18,6 @@ package com.intellij.refactoring;
import com.intellij.JavaTestUtil;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.roots.LanguageLevelProjectExtension;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;
@@ -174,7 +173,11 @@ public class MoveMembersTest extends MultiFileTestCase {
public void testEscalateVisibility1() throws Exception {
doTest("A", "B", true, VisibilityUtil.ESCALATE_VISIBILITY, 0);
}
public void testStringConstantInSwitchLabelExpression() throws Exception {
doTest("A", "B", true, VisibilityUtil.ESCALATE_VISIBILITY, 0);
}
public void testMultipleWithDependencies() throws Exception {
doTest("A", "B", true, VisibilityUtil.ESCALATE_VISIBILITY, 0, 1);
}