mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-20 13:31:28 +07:00
add unchecked warning calls also for method references
This commit is contained in:
@@ -198,6 +198,18 @@ public class UncheckedWarningLocalInspectionBase extends BaseJavaBatchLocalInspe
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitMethodReferenceExpression(PsiMethodReferenceExpression expression) {
|
||||
super.visitMethodReferenceExpression(expression);
|
||||
if (IGNORE_UNCHECKED_CALL) return;
|
||||
final JavaResolveResult result = expression.advancedResolve(false);
|
||||
final String description = getUncheckedCallDescription(result);
|
||||
if (description != null) {
|
||||
final PsiElement referenceNameElement = expression.getReferenceNameElement();
|
||||
registerProblem(description, referenceNameElement != null ? referenceNameElement : expression, myGenerifyFixes);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitCallExpression(PsiCallExpression callExpression) {
|
||||
super.visitCallExpression(callExpression);
|
||||
@@ -383,8 +395,9 @@ public class UncheckedWarningLocalInspectionBase extends BaseJavaBatchLocalInspe
|
||||
|
||||
@Nullable
|
||||
private String getUncheckedCallDescription(JavaResolveResult resolveResult) {
|
||||
final PsiMethod method = (PsiMethod)resolveResult.getElement();
|
||||
if (method == null) return null;
|
||||
final PsiElement element = resolveResult.getElement();
|
||||
if (!(element instanceof PsiMethod)) return null;
|
||||
final PsiMethod method = (PsiMethod)element;
|
||||
final PsiSubstitutor substitutor = resolveResult.getSubstitutor();
|
||||
if (!PsiUtil.isRawSubstitutor(method, substitutor)) return null;
|
||||
final PsiParameter[] parameters = method.getParameterList().getParameters();
|
||||
|
||||
@@ -156,7 +156,11 @@ class MethodReferenceResolver implements ResolveCache.PolyVariantResolver<PsiMet
|
||||
final PsiSubstitutor receiverSubstitutor = pClass != null ? TypeConversionUtil
|
||||
.getClassSubstitutor(containingClass, pClass, pResult.getSubstitutor()) : null;
|
||||
if (receiverSubstitutor != null) {
|
||||
if (!method.hasTypeParameters() && signature.getParameterTypes().length == 1) return receiverSubstitutor;
|
||||
if (!method.hasTypeParameters()) {
|
||||
if (signature.getParameterTypes().length == 1 || PsiUtil.isRawSubstitutor(containingClass, receiverSubstitutor)) {
|
||||
return receiverSubstitutor;
|
||||
}
|
||||
}
|
||||
psiSubstitutor = receiverSubstitutor;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
class BBB {
|
||||
|
||||
static <T> void f() {
|
||||
TerminalOp<T, LinkedHashSet<T>> <warning descr="Variable 'reduceOp' is never used">reduceOp</warning> = BBB.<T, LinkedHashSet<T>>makeRef(LinkedHashSet::new, LinkedHashSet::add, LinkedHashSet::addAll);
|
||||
TerminalOp<T, LinkedHashSet<T>> <warning descr="Variable 'reduceOp' is never used">reduceOp</warning> = BBB.<T, LinkedHashSet<T>>makeRef(LinkedHashSet::new, LinkedHashSet::<warning descr="Unchecked call to 'add(E)' as a member of raw type 'HashSet'">add</warning>, LinkedHashSet::<warning descr="Unchecked call to 'addAll(Collection<? extends E>)' as a member of raw type 'AbstractCollection'">addAll</warning>);
|
||||
}
|
||||
|
||||
public static <T, U> TerminalOp<T, U> makeRef(U <warning descr="Parameter 'seed' is never used">seed</warning>, BiFunction<U, ? super T, U> <warning descr="Parameter 'reducer' is never used">reducer</warning>, BinaryOperator<U> <warning descr="Parameter 'combiner' is never used">combiner</warning>) {
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import java.util.*;
|
||||
|
||||
class Test {
|
||||
|
||||
interface I<T> {
|
||||
void m(List<T> l, T el);
|
||||
}
|
||||
|
||||
{
|
||||
I<String> i1 = List::add;
|
||||
System.out.println(i1);
|
||||
I i2 = List::<warning descr="Unchecked call to 'add(E)' as a member of raw type 'java.util.List'">add</warning>;
|
||||
System.out.println(i2);
|
||||
}
|
||||
}
|
||||
@@ -241,6 +241,10 @@ public class NewMethodRefHighlightingTest extends LightDaemonAnalyzerTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testUncheckedMethodReference() throws Exception {
|
||||
doTest(true);
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
doTest(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user