diff --git a/java/java-impl-refactorings/src/com/intellij/refactoring/typeMigration/TypeMigrationLabeler.java b/java/java-impl-refactorings/src/com/intellij/refactoring/typeMigration/TypeMigrationLabeler.java index 8fd9068e2ce00..971be07abfd39 100644 --- a/java/java-impl-refactorings/src/com/intellij/refactoring/typeMigration/TypeMigrationLabeler.java +++ b/java/java-impl-refactorings/src/com/intellij/refactoring/typeMigration/TypeMigrationLabeler.java @@ -324,7 +324,7 @@ public void change(@NotNull TypeMigrationUsageInfo usageInfo, @NotNull Consumer< else if ((element instanceof PsiField || element instanceof PsiLocalVariable) && isMultiVariableDeclaration((PsiVariable)element)) { final PsiTypeElement typeElement = ((PsiVariable)element).getTypeElement(); - myVariableMigration.putValue(typeElement, usageInfo); + if (typeElement != null) myVariableMigration.putValue(typeElement, usageInfo); } else { TypeMigrationReplacementUtil.migrateMemberOrVariableType(element, project, getTypeEvaluator().getType(usageInfo)); @@ -581,7 +581,7 @@ boolean addMigrationRoot(PsiElement element, return false; } final PsiElement resolved = Util.normalizeElement(element); - if (!canBeRoot(resolved, myRules.getSearchScope())) { + if (!canBeRoot(resolved, myRules.getSearchScope()) || resolved instanceof PsiEnumConstant) { return false; } final PsiType originalType = getElementType(resolved); diff --git a/java/typeMigration/test/com/intellij/refactoring/TypeMigrationTest.java b/java/typeMigration/test/com/intellij/refactoring/TypeMigrationTest.java index cba2faf726237..f728112d45d0d 100644 --- a/java/typeMigration/test/com/intellij/refactoring/TypeMigrationTest.java +++ b/java/typeMigration/test/com/intellij/refactoring/TypeMigrationTest.java @@ -52,6 +52,10 @@ public void testEnumConstant() { doTestFirstParamType("Test", PsiTypes.byteType()); } + public void testMigrateEnumType() { + doTestFieldType("someEnum", PsiTypes.intType()); + } + public void testVarargsAndBoxing() { doTestFieldType("x", PsiTypes.longType()); } diff --git a/java/typeMigration/testData/refactoring/typeMigration/migrateEnumType/after/Test.items b/java/typeMigration/testData/refactoring/typeMigration/migrateEnumType/after/Test.items new file mode 100644 index 0000000000000..c8b750b4aa25b --- /dev/null +++ b/java/typeMigration/testData/refactoring/typeMigration/migrateEnumType/after/Test.items @@ -0,0 +1,8 @@ +Types: +PsiField:someEnum : int + +Conversions: + +New expression type changes: +Fails: +SomeEnum.ENUM_VALUE_1->int diff --git a/java/typeMigration/testData/refactoring/typeMigration/migrateEnumType/after/Test.java b/java/typeMigration/testData/refactoring/typeMigration/migrateEnumType/after/Test.java new file mode 100644 index 0000000000000..fccffc13ca216 --- /dev/null +++ b/java/typeMigration/testData/refactoring/typeMigration/migrateEnumType/after/Test.java @@ -0,0 +1,6 @@ +class Test { + private int someEnum = SomeEnum.ENUM_VALUE_1; + public enum SomeEnum { + ENUM_VALUE_1, ENUM_VALUE_2 + } +} \ No newline at end of file diff --git a/java/typeMigration/testData/refactoring/typeMigration/migrateEnumType/before/Test.java b/java/typeMigration/testData/refactoring/typeMigration/migrateEnumType/before/Test.java new file mode 100644 index 0000000000000..1333c2e110051 --- /dev/null +++ b/java/typeMigration/testData/refactoring/typeMigration/migrateEnumType/before/Test.java @@ -0,0 +1,6 @@ +class Test { + private SomeEnum someEnum = SomeEnum.ENUM_VALUE_1; + public enum SomeEnum { + ENUM_VALUE_1, ENUM_VALUE_2 + } +} \ No newline at end of file