mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-08 15:09:39 +07:00
atomic migration: wrap with new when initializer doesn't refer to migrated code (IDEA-246579)
GitOrigin-RevId: 3c4d1372c4d17ec41702e58a5517ff31ff0ec60f
This commit is contained in:
committed by
intellij-monorepo-bot
parent
65aab2a928
commit
316d1a9875
@@ -49,7 +49,7 @@ public class AtomicConversionRule extends TypeConversionRule {
|
||||
if (to instanceof PsiClassType) {
|
||||
AtomicConversionType type = AtomicConversionType.getConversionType(from, (PsiClassType)to, context);
|
||||
if (type != null) {
|
||||
return findDirectConversion(context, to, from, type);
|
||||
return findDirectConversion(context, to, from, type, labeler);
|
||||
}
|
||||
}
|
||||
if (from instanceof PsiClassType && AtomicConversionType.getConversionType(to, (PsiClassType)from, context) != null) {
|
||||
@@ -67,7 +67,8 @@ public class AtomicConversionRule extends TypeConversionRule {
|
||||
public static TypeConversionDescriptor findDirectConversion(PsiElement context,
|
||||
PsiType to,
|
||||
PsiType from,
|
||||
AtomicConversionType type) {
|
||||
AtomicConversionType type,
|
||||
TypeMigrationLabeler labeler) {
|
||||
final PsiClass toTypeClass = PsiUtil.resolveClassInType(to);
|
||||
LOG.assertTrue(toTypeClass != null);
|
||||
final String qualifiedName = toTypeClass.getQualifiedName();
|
||||
@@ -166,11 +167,15 @@ public class AtomicConversionRule extends TypeConversionRule {
|
||||
}
|
||||
return from instanceof PsiArrayType
|
||||
? findDirectConversionForAtomicReferenceArray(context, to, from, type)
|
||||
: findDirectConversionForAtomicReference(context, to, from, type);
|
||||
: findDirectConversionForAtomicReference(context, to, from, type, labeler);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static TypeConversionDescriptor findDirectConversionForAtomicReference(PsiElement context, PsiType to, PsiType from, AtomicConversionType type) {
|
||||
private static TypeConversionDescriptor findDirectConversionForAtomicReference(PsiElement context,
|
||||
PsiType to,
|
||||
PsiType from,
|
||||
AtomicConversionType type,
|
||||
TypeMigrationLabeler labeler) {
|
||||
final PsiElement parent = context.getParent();
|
||||
if (parent instanceof PsiAssignmentExpression) {
|
||||
final IElementType operationSign = ((PsiAssignmentExpression)parent).getOperationTokenType();
|
||||
@@ -186,7 +191,9 @@ public class AtomicConversionRule extends TypeConversionRule {
|
||||
final PsiExpression expression = context.getParent() instanceof PsiMethodCallExpression && qualifierExpression != null
|
||||
? qualifierExpression
|
||||
: (PsiExpression)context;
|
||||
return new TypeConversionDescriptor("$qualifier$", "$qualifier$.get()", expression);
|
||||
if (expression instanceof PsiReferenceExpression && to.equals(labeler.getTypeEvaluator().getType(expression))) {
|
||||
return new TypeConversionDescriptor("$qualifier$", "$qualifier$.get()", expression);
|
||||
}
|
||||
}
|
||||
else if (context instanceof PsiAssignmentExpression) {
|
||||
final PsiAssignmentExpression assignment = (PsiAssignmentExpression)context;
|
||||
|
||||
@@ -102,4 +102,8 @@ public class TypeMigrationByAtomicRuleTest extends TypeMigrationTestBase{
|
||||
public void testLiteralMigration() {
|
||||
doTestFieldType("a", getElementFactory().createTypeFromText("java.util.concurrent.atomic.AtomicLong", null));
|
||||
}
|
||||
|
||||
public void testFieldDeclaration() {
|
||||
doTestFieldType("a", getElementFactory().createTypeFromText("java.util.concurrent.atomic.AtomicReference<java.lang.String>", null));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
Types:
|
||||
PsiField:FOO : java.util.concurrent.atomic.AtomicReference<java.lang.String>
|
||||
PsiField:a : java.util.concurrent.atomic.AtomicReference<java.lang.String>
|
||||
PsiReferenceExpression:FOO : java.util.concurrent.atomic.AtomicReference<java.lang.String>
|
||||
PsiReferenceExpression:a : java.util.concurrent.atomic.AtomicReference<java.lang.String>
|
||||
|
||||
Conversions:
|
||||
"foo" -> new java.util.concurrent.atomic.AtomicReference<java.lang.String>($val$) $val$
|
||||
a -> $qualifier$.get() $qualifier$ a
|
||||
|
||||
New expression type changes:
|
||||
Fails:
|
||||
@@ -0,0 +1,10 @@
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
class Test {
|
||||
static final AtomicReference<String> FOO = new AtomicReference<String>("foo");
|
||||
AtomicReference<String> a = FOO;
|
||||
|
||||
{
|
||||
System.out.println(a.get());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
class Test {
|
||||
static final String FOO = "foo";
|
||||
String a = FOO;
|
||||
|
||||
{
|
||||
System.out.println(a);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user