mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
DfaPsiUtil#getFunctionalParameterNullability: use known type nullability for SAM parameters
This commit is contained in:
@@ -30,6 +30,7 @@ import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.util.*;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.NullableFunction;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.JBIterable;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
@@ -129,9 +130,16 @@ public class DfaPsiUtil {
|
||||
if(nullness != Nullness.UNKNOWN) {
|
||||
return nullness;
|
||||
}
|
||||
PsiMethod sam = LambdaUtil.getFunctionalInterfaceMethod(function.getFunctionalInterfaceType());
|
||||
PsiClassType type = ObjectUtils.tryCast(function.getFunctionalInterfaceType(), PsiClassType.class);
|
||||
PsiMethod sam = LambdaUtil.getFunctionalInterfaceMethod(type);
|
||||
if (sam != null && index < sam.getParameterList().getParametersCount()) {
|
||||
return getElementNullability(null, sam.getParameterList().getParameters()[index]);
|
||||
PsiParameter parameter = sam.getParameterList().getParameters()[index];
|
||||
nullness = getElementNullability(null, parameter);
|
||||
if(nullness != Nullness.UNKNOWN) {
|
||||
return nullness;
|
||||
}
|
||||
PsiType parameterType = type.resolveGenerics().getSubstitutor().substitute(parameter.getType());
|
||||
return getTypeNullability(parameterType);
|
||||
}
|
||||
return Nullness.UNKNOWN;
|
||||
}
|
||||
|
||||
@@ -28,6 +28,10 @@ public class MethodReferenceConstantValue {
|
||||
}
|
||||
}
|
||||
|
||||
public void test(List<@foo.NotNull String> list) {
|
||||
list.removeIf(<warning descr="Method reference result is always 'false'">Objects::isNull</warning>);
|
||||
}
|
||||
|
||||
interface X {
|
||||
boolean action(@Nullable MethodReferenceConstantValue a, @NotNull String b);
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ public class DataFlowInspection8Test extends DataFlowInspectionTestCase {
|
||||
public void testNullableVoidLambda() { doTest(); }
|
||||
public void testNullableForeachVariable() { doTestWithCustomAnnotations(); }
|
||||
public void testGenericParameterNullity() { doTestWithCustomAnnotations(); }
|
||||
public void testMethodReferenceConstantValue() { doTest(); }
|
||||
public void testMethodReferenceConstantValue() { doTestWithCustomAnnotations(); }
|
||||
|
||||
public void testOptionalOfNullable() { doTest(); }
|
||||
public void testOptionalOrElse() { doTest(); }
|
||||
|
||||
Reference in New Issue
Block a user