mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 15:19:59 +07:00
Java Type Migration: add cast if necessary when converting to ThreadLocal (IDEA-248610)
GitOrigin-RevId: 15b83a4b1281356a007783e13d8a50e44870e6cf
This commit is contained in:
committed by
intellij-monorepo-bot
parent
18c1ad1b54
commit
93a9db98dc
@@ -169,6 +169,13 @@ public class ThreadLocalConversionRule extends TypeConversionRule {
|
||||
PsiExpression initializer,
|
||||
String boxedTypeName) {
|
||||
if (PsiUtil.isLanguageLevel8OrHigher(initializer)) {
|
||||
if (from instanceof PsiPrimitiveType) {
|
||||
PsiType parameterType = ((PsiClassType)to).getParameters()[0];
|
||||
PsiPrimitiveType unboxed = PsiPrimitiveType.getUnboxedType(parameterType);
|
||||
if (unboxed != null && !from.equals(unboxed)) {
|
||||
return "java.lang.ThreadLocal.withInitial(() -> (" + unboxed.getCanonicalText() + ")$qualifier$)";
|
||||
}
|
||||
}
|
||||
return "java.lang.ThreadLocal.withInitial(() -> $qualifier$)";
|
||||
}
|
||||
return "new " +
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
// "Convert to 'ThreadLocal'" "true"
|
||||
class T {
|
||||
private static final ThreadLocal<Long> l = ThreadLocal.withInitial(() -> (long) 1); // choose "Convert to ThreadLocal" intention
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
// "Convert to 'ThreadLocal'" "true"
|
||||
class T {
|
||||
private static final long <caret>l = 1; // choose "Convert to ThreadLocal" intention
|
||||
}
|
||||
Reference in New Issue
Block a user