same parameter value: ensure uast method references are correctly processed (IDEA-201335)

This commit is contained in:
Anna Kozlova
2018-10-29 12:49:19 +01:00
parent d86ba95372
commit 2f3520ab6f
4 changed files with 35 additions and 0 deletions
@@ -446,6 +446,9 @@ public class SameParameterValueInspection extends GlobalJavaBatchInspectionTool
if (!(uElement instanceof UReferenceExpression)) {
return false;
}
if (uElement instanceof UCallableReferenceExpression) {
return false;
}
UElement parent = uElement.getUastParent();
if (!(parent instanceof UCallExpression)) {
return false;
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>Test.java</file>
<line>8</line>
<description>Actual value of parameter 'string' is always 'hello'</description>
</problem>
</problems>
@@ -0,0 +1,18 @@
import java.util.function.Consumer;
class Test {
private void main() {
bar("hello", this::buzz);
}
private void bar(String string, Consumer<Integer> o) {
o.accept(1);
use(string);
}
private void buzz(int integer) {
use(integer);
}
private void use(Object a) {}
}
@@ -76,6 +76,10 @@ public class SameParameterValueLocalTest extends InspectionTestCase {
doTest(getGlobalTestDir(), myTool);
}
public void testMethodReferenceInCallArguments() {
doTest(getGlobalTestDir(), myTool);
}
public void testUsageCount() {
int previous = myGlobalTool.minimalUsageCount;
try {