mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
accept casts as unchecked from generic types with type parameter with upper bounds as type argument: check parameter bounds first
This commit is contained in:
@@ -101,6 +101,18 @@ public class TypesDistinctProver {
|
||||
|
||||
final PsiClassType.ClassResolveResult classResolveResult1 = PsiUtil.resolveGenericsClassInType(type1);
|
||||
final PsiClassType.ClassResolveResult classResolveResult2 = PsiUtil.resolveGenericsClassInType(type2);
|
||||
|
||||
final PsiClass boundClass1 = classResolveResult1.getElement();
|
||||
final PsiClass boundClass2 = classResolveResult2.getElement();
|
||||
|
||||
if (boundClass1 instanceof PsiTypeParameter && level < 2) {
|
||||
if (!distinguishFromTypeParam((PsiTypeParameter)boundClass1, boundClass2, type1)) return false;
|
||||
}
|
||||
|
||||
if (boundClass2 instanceof PsiTypeParameter && level < 2) {
|
||||
if (!distinguishFromTypeParam((PsiTypeParameter)boundClass2, boundClass1, type2)) return false;
|
||||
}
|
||||
|
||||
if (Comparing.equal(TypeConversionUtil.erasure(type1), TypeConversionUtil.erasure(type2))) {
|
||||
final PsiSubstitutor substitutor1 = classResolveResult1.getSubstitutor();
|
||||
final PsiSubstitutor substitutor2 = classResolveResult2.getSubstitutor();
|
||||
@@ -124,16 +136,6 @@ public class TypesDistinctProver {
|
||||
if (level < 2) return false;
|
||||
}
|
||||
|
||||
final PsiClass boundClass1 = classResolveResult1.getElement();
|
||||
final PsiClass boundClass2 = classResolveResult2.getElement();
|
||||
|
||||
if (boundClass1 instanceof PsiTypeParameter && level < 2) {
|
||||
if (!distinguishFromTypeParam((PsiTypeParameter)boundClass1, boundClass2, type1)) return false;
|
||||
}
|
||||
|
||||
if (boundClass2 instanceof PsiTypeParameter && level < 2) {
|
||||
if (!distinguishFromTypeParam((PsiTypeParameter)boundClass2, boundClass1, type2)) return false;
|
||||
}
|
||||
return type2 != null && type1 != null && !type1.equals(type2) &&
|
||||
(!InheritanceUtil.isInheritorOrSelf(boundClass1, boundClass2, true) ||
|
||||
!InheritanceUtil.isInheritorOrSelf(boundClass2, boundClass1, true));
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
import java.util.Map;
|
||||
|
||||
class Test {
|
||||
public static <M extends Map<String, Integer>> void groupingBy(Supplier<M> mapFactory) {
|
||||
Supplier<Map<String, Integer>> mangledFactory = <warning descr="Unchecked cast: 'Test.Supplier<M>' to 'Test.Supplier<java.util.Map<java.lang.String,java.lang.Integer>>'">(Supplier<Map<String, Integer>>) mapFactory</warning>;
|
||||
System.out.println(mangledFactory);
|
||||
}
|
||||
|
||||
interface Supplier<<warning descr="Type parameter 'G' is never used">G</warning>> {}
|
||||
}
|
||||
|
||||
@@ -484,6 +484,10 @@ public class GenericsHighlightingTest extends LightDaemonAnalyzerTestCase {
|
||||
doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_7, false);
|
||||
}
|
||||
|
||||
public void testCastFromGenericTypeWithTypeParameterWithExtendsAsArgument() throws Exception {
|
||||
doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_7, true);
|
||||
}
|
||||
|
||||
public void testJavaUtilCollections_NoVerify() throws Exception {
|
||||
PsiClass collectionsClass = getJavaFacade().findClass("java.util.Collections", GlobalSearchScope.moduleWithLibrariesScope(getModule()));
|
||||
assertNotNull(collectionsClass);
|
||||
|
||||
Reference in New Issue
Block a user