mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Java Type Migration: Fix "Convert to ThreadLocal" with subtypes (IDEA-230719)
GitOrigin-RevId: cfcfabbd08f1774900f15089d6fcf651756d743f
This commit is contained in:
committed by
intellij-monorepo-bot
parent
e34a39c296
commit
5b120de0b7
+1
-1
@@ -55,7 +55,7 @@ public class ThreadLocalConversionRule extends TypeConversionRule {
|
||||
}
|
||||
}
|
||||
else {
|
||||
return TypeConversionUtil.isAssignable(from, PsiUtil.captureToplevelWildcards(toTypeParameterValue, context));
|
||||
return TypeConversionUtil.isAssignable(toTypeParameterValue, from);
|
||||
}
|
||||
}
|
||||
return !PsiUtil.isLanguageLevel5OrHigher(context);
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.refactoring;
|
||||
|
||||
import com.intellij.codeInsight.ConvertToAtomicIntentionTest;
|
||||
import com.intellij.codeInsight.ConvertToLongAdderIntentionTest;
|
||||
import com.intellij.codeInsight.ConvertToThreadLocalIntention6Test;
|
||||
import com.intellij.codeInsight.ConvertToThreadLocalIntentionTest;
|
||||
import com.intellij.codeInsight.inspections.GuavaInspectionTest;
|
||||
@@ -17,11 +19,10 @@ import org.junit.runners.Suite;
|
||||
ChangeTypeSignatureTest.class,
|
||||
WildcardTypeMigrationTest.class,
|
||||
ConvertToAtomicIntentionTest.class,
|
||||
ConvertToLongAdderIntentionTest.class,
|
||||
ConvertToThreadLocalIntentionTest.class,
|
||||
ConvertToThreadLocalIntention6Test.class,
|
||||
GuavaInspectionTest.class,
|
||||
GuavaInspectionTest.class,
|
||||
GuavaInspectionTest.class,
|
||||
})
|
||||
public class AllTypeMigrationTestSuite {
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.refactoring;
|
||||
|
||||
import com.intellij.psi.CommonClassNames;
|
||||
@@ -125,7 +126,7 @@ public class WildcardTypeMigrationTest extends TypeMigrationTestBase{
|
||||
}
|
||||
|
||||
//List<? super String> is not assignable to List<String> though it is possible to pass string where ? super String was
|
||||
public void _testThreadLocalProducerSuper() {
|
||||
public void testThreadLocalProducerSuper() {
|
||||
doTestFirstParamType("method",
|
||||
getElementFactory().createTypeFromText("java.lang.ThreadLocal<java.util.List<? super String>>", null));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
// "Convert to 'ThreadLocal'" "true"
|
||||
import java.util.Date;
|
||||
|
||||
class X {
|
||||
private static final ThreadLocal<DateFormat> dateFormat = ThreadLocal.withInitial(() -> new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z"));
|
||||
|
||||
public String getDateString() {
|
||||
return dateFormat.get().format(new Date());
|
||||
}
|
||||
}
|
||||
abstract class DateFormat {
|
||||
|
||||
public final String format(Date date) {
|
||||
return date.toString();
|
||||
}
|
||||
}
|
||||
class SimpleDateFormat extends DateFormat {
|
||||
public SimpleDateFormat(String patten) {}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// "Convert to 'ThreadLocal'" "true"
|
||||
import java.util.Date;
|
||||
|
||||
class X {
|
||||
private static DateFormat <caret>dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z");
|
||||
|
||||
public String getDateString() {
|
||||
return dateFormat.format(new Date());
|
||||
}
|
||||
}
|
||||
abstract class DateFormat {
|
||||
|
||||
public final String format(Date date) {
|
||||
return date.toString();
|
||||
}
|
||||
}
|
||||
class SimpleDateFormat extends DateFormat {
|
||||
public SimpleDateFormat(String patten) {}
|
||||
}
|
||||
+2
-1
@@ -1,9 +1,10 @@
|
||||
Types:
|
||||
PsiMethodCallExpression:l.substring(0) : java.lang.String
|
||||
PsiParameter:l : java.lang.ThreadLocal<? super java.lang.String>
|
||||
PsiReferenceExpression:l : java.lang.ThreadLocal<? super java.lang.String>
|
||||
|
||||
Conversions:
|
||||
l.substring(0) -> $qualifier$.get() $qualifier$ l
|
||||
|
||||
New expression type changes:
|
||||
Fails:
|
||||
l->java.lang.ThreadLocal<? super java.lang.String>
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
class Test {
|
||||
void method(ThreadLocal<? super String> l) {
|
||||
l.substring(0);
|
||||
l.get().substring(0);
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -1,9 +1,10 @@
|
||||
Types:
|
||||
PsiMethodCallExpression:l.add("") : boolean
|
||||
PsiParameter:l : java.lang.ThreadLocal<java.util.List<? extends java.lang.String>>
|
||||
PsiReferenceExpression:l : java.lang.ThreadLocal<java.util.List<? extends java.lang.String>>
|
||||
|
||||
Conversions:
|
||||
l.add("") -> $qualifier$.get() $qualifier$ l
|
||||
|
||||
New expression type changes:
|
||||
Fails:
|
||||
l->java.lang.ThreadLocal<java.util.List<? extends java.lang.String>>
|
||||
|
||||
+1
-1
@@ -2,6 +2,6 @@ import java.util.*;
|
||||
|
||||
class Test {
|
||||
void method(ThreadLocal<List<? extends String>> l) {
|
||||
l.add("");
|
||||
l.get().add("");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user