mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
unused return value inspection: method reference awareness (IDEA-134991)
This commit is contained in:
@@ -211,6 +211,14 @@ public class RefJavaUtilImpl extends RefJavaUtil{
|
||||
PsiMethod psiMethod = (PsiMethod)psiResolved;
|
||||
RefMethodImpl refMethod = (RefMethodImpl)refResolved;
|
||||
|
||||
if (refExpression instanceof PsiMethodReferenceExpression) {
|
||||
PsiType returnType = psiMethod.getReturnType();
|
||||
if (!psiMethod.isConstructor() && returnType != PsiType.VOID) {
|
||||
refMethod.setReturnValueUsed(true);
|
||||
addTypeReference(psiFrom, returnType, refFrom.getRefManager());
|
||||
}
|
||||
return;
|
||||
}
|
||||
PsiMethodCallExpression call = PsiTreeUtil.getParentOfType(
|
||||
refExpression,
|
||||
PsiMethodCallExpression.class
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<problems/>
|
||||
@@ -0,0 +1,13 @@
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.DoubleSupplier;
|
||||
|
||||
class B {
|
||||
|
||||
public void test(Consumer<DoubleSupplier> consumer) {
|
||||
consumer.accept(this::method);
|
||||
}
|
||||
|
||||
private double method() {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,10 @@ package com.intellij.codeInspection;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.codeInspection.unusedReturnValue.UnusedReturnValue;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.roots.LanguageLevelProjectExtension;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.testFramework.IdeaTestUtil;
|
||||
import com.intellij.testFramework.InspectionTestCase;
|
||||
|
||||
public class UnusedReturnValueTest extends InspectionTestCase {
|
||||
@@ -39,7 +43,17 @@ public class UnusedReturnValueTest extends InspectionTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
|
||||
public void testMethodReference() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Sdk getTestProjectSdk() {
|
||||
Sdk sdk = IdeaTestUtil.getMockJdk18();
|
||||
LanguageLevelProjectExtension.getInstance(getProject()).setLanguageLevel(LanguageLevel.JDK_1_8);
|
||||
return sdk;
|
||||
}
|
||||
|
||||
public void testSimpleSetter() throws Exception {
|
||||
try {
|
||||
myTool.IGNORE_BUILDER_PATTERN = true;
|
||||
|
||||
Reference in New Issue
Block a user