do not fail on int,byte -> atomic long type migration

This commit is contained in:
Dmitry Batkovich
2017-06-06 13:55:58 +03:00
parent 27a2f1517d
commit 2ede55bd8c
5 changed files with 24 additions and 4 deletions
@@ -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;
}
@@ -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));
}
}
@@ -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:
@@ -0,0 +1,5 @@
import java.util.concurrent.atomic.AtomicLong;
class Test {
AtomicLong a = new AtomicLong(100);
}
@@ -0,0 +1,3 @@
class Test {
long a = 100;
}