From d8b0b80a26d78445e6f2b9a5a98ffca81e68f88e Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Mon, 18 Jan 2021 13:53:28 +0100 Subject: [PATCH] unchecked warning: keep warning for all generic class types (IDEA-259694) GitOrigin-RevId: b5a09baadfb6837a9de679b2577732faaa05bcdb --- .../com/intellij/psi/util/PsiTypesUtil.java | 24 +++++++++---------- .../NoUncheckedWarningOnRawSubstitutor.java | 17 ++++++++++++- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/java/java-psi-api/src/com/intellij/psi/util/PsiTypesUtil.java b/java/java-psi-api/src/com/intellij/psi/util/PsiTypesUtil.java index 8aeb64730d0f..501124bd2421 100644 --- a/java/java-psi-api/src/com/intellij/psi/util/PsiTypesUtil.java +++ b/java/java-psi-api/src/com/intellij/psi/util/PsiTypesUtil.java @@ -523,7 +523,7 @@ public final class PsiTypesUtil { * Implicit type arguments of types based on inner classes of generic outer classes are explicitly checked */ public static boolean mentionsTypeParameters(@Nullable PsiType type, Set typeParameters) { - return mentionsTypeParametersOrUnboundedWildcard(type, typeParameters, false); + return mentionsTypeParametersOrUnboundedWildcard(type, typeParameters); } /** @@ -535,13 +535,14 @@ public final class PsiTypesUtil { PsiMethod method = (PsiMethod)element; PsiSubstitutor substitutor = resolveResult.getSubstitutor(); if (PsiUtil.isRawSubstitutor(method, substitutor)) { - Set typeParameters = new HashSet<>(substitutor.getSubstitutionMap().keySet()); - for (PsiTypeParameter parameter : method.getTypeParameters()) { - typeParameters.remove(parameter); - } for (PsiParameter t : method.getParameterList().getParameters()) { - if (mentionsTypeParametersOrUnboundedWildcard(t.getType(), typeParameters, true)) { - return true; + PsiType type = t.getType().getDeepComponentType(); + if (type instanceof PsiClassType) { + PsiClass aClass = ((PsiClassType)type).resolveGenerics().getElement(); + if (aClass instanceof PsiTypeParameter || + aClass != null && PsiUtil.typeParametersIterator(aClass).hasNext()) { + return true; + } } } return false; @@ -551,8 +552,7 @@ public final class PsiTypesUtil { } private static boolean mentionsTypeParametersOrUnboundedWildcard(@Nullable PsiType type, - Set typeParameters, - boolean acceptUnboundedWildcard) { + Set typeParameters) { if (type == null) return false; return type.accept(new PsiTypeVisitor() { @Override @@ -563,10 +563,8 @@ public final class PsiTypesUtil { @Override public Boolean visitWildcardType(@NotNull PsiWildcardType wildcardType) { final PsiType bound = wildcardType.getBound(); - if (bound != null) { - return bound.accept(this); - } - return acceptUnboundedWildcard; + return bound != null ? bound.accept(this) + : Boolean.valueOf(false); } @Override diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/NoUncheckedWarningOnRawSubstitutor.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/NoUncheckedWarningOnRawSubstitutor.java index 277bbc975fc6..c0ad531f7b4b 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/NoUncheckedWarningOnRawSubstitutor.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/NoUncheckedWarningOnRawSubstitutor.java @@ -6,6 +6,21 @@ interface I {} class Bar implements I { Predicate p; { - Foo.process(p, new Bar()); + Foo.process(p, new Bar()); + } +} +class Bar2 { + void m(Provider provider) { + provider.provide(p()); + provider.provide1(1); + } + + static class Provider<T> { + void provide(Predicate consumer){ } + void provide1(Integer i) {} + } + + Predicate p() { + return null; } }