same parameter value inspection should not warn if method is used in method reference expression (IDEA-207552)

This commit is contained in:
Dmitry Batkovich
2019-02-20 16:16:55 +03:00
parent 11f35c7b0d
commit dc6de37979
6 changed files with 35 additions and 0 deletions
@@ -401,6 +401,7 @@ public class RefJavaUtilImpl extends RefJavaUtil {
!PsiType.VOID
.equals(LambdaUtil.getFunctionalInterfaceReturnType(getFunctionalInterfaceType((UCallableReferenceExpression)refExpression)))) {
refMethod.setReturnValueUsed(true);
refMethod.setParametersAreUnknown();
addTypeReference(uFrom, returnType, refFrom.getRefManager());
}
return;
@@ -152,6 +152,15 @@ public class RefMethodImpl extends RefJavaElementImpl implements RefMethod {
}
}
public void setParametersAreUnknown() {
for (RefParameter parameter : myParameters) {
((RefParameterImpl)parameter).clearTemplateValue();
}
for (RefMethod method : getSuperMethods()) {
((RefMethodImpl)method).setParametersAreUnknown();
}
}
private static boolean isAppMain(PsiMethod psiMethod, RefMethod refMethod) {
if (!refMethod.isStatic()) return false;
if (!PsiType.VOID.equals(psiMethod.getReturnType())) return false;
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems/>
@@ -0,0 +1,14 @@
public class Test {
public void foo() {
bar(null);
List<String> strings = Collections.singletonList("NotNull!");
strings.forEach(this::bar);
}
private void bar(@Nullable String goo) {
System.out.println(goo);
}
}
@@ -94,4 +94,8 @@ public class SameParameterValueLocalTest extends InspectionTestCase {
public void testOverrideGroovy() {
doTest(getGlobalTestDir(), myTool);
}
public void testMethodReferences() {
doTest(getGlobalTestDir(), myTool);
}
}
@@ -105,4 +105,8 @@ public class SameParameterValueTest extends InspectionTestCase {
public void testOverrideGroovy() {
doTest(getTestDir(), myTool, false, true);
}
public void testMethodReferences() {
doTest(getTestDir(), myTool, false, true);
}
}