extract enum: do not include constants when user don't ask to; check that variable was already migrated and getter is already not needed (IDEA-103509)

This commit is contained in:
anna
2013-04-12 18:31:06 +02:00
parent 2447ab7c9d
commit 33dee73821
10 changed files with 104 additions and 35 deletions
@@ -0,0 +1,12 @@
public enum EEnum {
FOO(0);
private int value;
public int getValue() {
return value;
}
EEnum(int value) {
this.value = value;
}
}
@@ -0,0 +1,6 @@
class Test {
public static final int BAR = 2;
void foo() {
System.out.println(EEnum.FOO.getValue());
}
}
@@ -0,0 +1,9 @@
class Usage {
void foo() {
EEnum i = EEnum.FOO;
}
void bar(int i ) {
i = B;
}
}
@@ -0,0 +1,7 @@
class Test {
public static final int FOO = 0;
public static final int BAR = 2;
void foo() {
System.out.println(FOO);
}
}
@@ -0,0 +1,9 @@
class Usage {
void foo() {
int i = Test.FOO;
}
void bar(int i ) {
i = B;
}
}
@@ -59,6 +59,10 @@ public class ExtractEnumTest extends MultiFileTestCase {
doTest(new RefactoringTestUtil.MemberDescriptor("FOO", PsiField.class, true));
}
public void testUsageInVariableInitializer() throws Exception {
doTest(new RefactoringTestUtil.MemberDescriptor("FOO", PsiField.class, true));
}
public void testForwardReferenceConflict() throws Exception {
doTest("Unable to migrate statement to enum constant.", false,
new RefactoringTestUtil.MemberDescriptor("FOO", PsiField.class, false),
@@ -149,6 +153,7 @@ public class ExtractEnumTest extends MultiFileTestCase {
if (member.hasModifierProperty(PsiModifier.STATIC) && member.hasModifierProperty(PsiModifier.FINAL) && ((PsiField)member).hasInitializer()) {
if (memberInfo.isToAbstract()) {
enumConstants.add(memberInfo);
memberInfo.setChecked(true);
}
}
}