diff --git a/java/typeMigration/src/com/intellij/refactoring/typeMigration/rules/AtomicConversionRule.java b/java/typeMigration/src/com/intellij/refactoring/typeMigration/rules/AtomicConversionRule.java index 86be70f05ee9..2acf82df2ac3 100644 --- a/java/typeMigration/src/com/intellij/refactoring/typeMigration/rules/AtomicConversionRule.java +++ b/java/typeMigration/src/com/intellij/refactoring/typeMigration/rules/AtomicConversionRule.java @@ -40,15 +40,15 @@ public class AtomicConversionRule extends TypeConversionRule { } private static boolean isAtomicTypeMigration(PsiType from, PsiClassType to, PsiExpression context) { - if (PsiType.INT.equals(from) && to.getCanonicalText().equals(AtomicInteger.class.getName())) { + if (PsiType.INT.isAssignableFrom(from) && to.getCanonicalText().equals(AtomicInteger.class.getName())) { + return true; + } + if (PsiType.LONG.isAssignableFrom(from) && to.getCanonicalText().equals(AtomicLong.class.getName())) { return true; } if (from.equals(PsiType.INT.createArrayType()) && to.getCanonicalText().equals(AtomicIntegerArray.class.getName())) { return true; } - if (PsiType.LONG.equals(from) && to.getCanonicalText().equals(AtomicLong.class.getName())) { - return true; - } if (from.equals(PsiType.LONG.createArrayType()) && to.getCanonicalText().equals(AtomicLongArray.class.getName())) { return true; } diff --git a/java/typeMigration/test/com/intellij/refactoring/TypeMigrationByAtomicRuleTest.java b/java/typeMigration/test/com/intellij/refactoring/TypeMigrationByAtomicRuleTest.java index aeecfe6bfdc1..9e781175898f 100644 --- a/java/typeMigration/test/com/intellij/refactoring/TypeMigrationByAtomicRuleTest.java +++ b/java/typeMigration/test/com/intellij/refactoring/TypeMigrationByAtomicRuleTest.java @@ -100,4 +100,8 @@ public class TypeMigrationByAtomicRuleTest extends TypeMigrationTestBase{ public void testChainedInitialization() { doTestFieldType("a", myJavaFacade.getElementFactory().createTypeFromText("java.util.concurrent.atomic.AtomicInteger", null)); } + + public void testLiteralMigration() { + doTestFieldType("a", myJavaFacade.getElementFactory().createTypeFromText("java.util.concurrent.atomic.AtomicLong", null)); + } } \ No newline at end of file diff --git a/java/typeMigration/testData/refactoring/typeMigrationByAtomic/literalMigration/after/Test.items b/java/typeMigration/testData/refactoring/typeMigrationByAtomic/literalMigration/after/Test.items new file mode 100644 index 000000000000..33f6b9a33cf9 --- /dev/null +++ b/java/typeMigration/testData/refactoring/typeMigrationByAtomic/literalMigration/after/Test.items @@ -0,0 +1,8 @@ +Types: +PsiField:a : java.util.concurrent.atomic.AtomicLong + +Conversions: +100 -> new java.util.concurrent.atomic.AtomicLong($val$) $val$ 100 + +New expression type changes: +Fails: diff --git a/java/typeMigration/testData/refactoring/typeMigrationByAtomic/literalMigration/after/Test.java b/java/typeMigration/testData/refactoring/typeMigrationByAtomic/literalMigration/after/Test.java new file mode 100644 index 000000000000..ec7370c3df80 --- /dev/null +++ b/java/typeMigration/testData/refactoring/typeMigrationByAtomic/literalMigration/after/Test.java @@ -0,0 +1,5 @@ +import java.util.concurrent.atomic.AtomicLong; + +class Test { + AtomicLong a = new AtomicLong(100); +} \ No newline at end of file diff --git a/java/typeMigration/testData/refactoring/typeMigrationByAtomic/literalMigration/before/Test.java b/java/typeMigration/testData/refactoring/typeMigrationByAtomic/literalMigration/before/Test.java new file mode 100644 index 000000000000..e229caf913c4 --- /dev/null +++ b/java/typeMigration/testData/refactoring/typeMigrationByAtomic/literalMigration/before/Test.java @@ -0,0 +1,3 @@ +class Test { + long a = 100; +} \ No newline at end of file