mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-30 10:20:15 +07:00
anonymous -> method ref: collapse receiver method references to raw receiver (IDEA-153261)
This commit is contained in:
@@ -436,12 +436,11 @@ public class LambdaCanBeMethodReferenceInspection extends BaseJavaBatchLocalInsp
|
||||
return getClassReferenceName(nonAmbiguousContainingClass);
|
||||
}
|
||||
|
||||
if (containingClass.isPhysical() && qualifierExpression instanceof PsiReferenceExpression && !PsiTypesUtil.isGetClass(psiMethod)) {
|
||||
final PsiElement resolve = ((PsiReferenceExpression)qualifierExpression).resolve();
|
||||
final boolean parameterWithoutFormalType = resolve instanceof PsiParameter && ((PsiParameter)resolve).getTypeElement() == null;
|
||||
if (parameterWithoutFormalType && ArrayUtil.find(parameters, resolve) > -1) {
|
||||
return getClassReferenceName(containingClass);
|
||||
}
|
||||
if (containingClass.isPhysical() &&
|
||||
qualifierExpression instanceof PsiReferenceExpression &&
|
||||
!PsiTypesUtil.isGetClass(psiMethod) &&
|
||||
ArrayUtil.find(parameters, ((PsiReferenceExpression)qualifierExpression).resolve()) > -1) {
|
||||
return getClassReferenceName(containingClass);
|
||||
}
|
||||
|
||||
final PsiType qualifierExpressionType = qualifierExpression.getType();
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
// "Replace with method reference" "true"
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
class MyTest {
|
||||
|
||||
Function<List<?>, String> TO_TEXT = Object::toString;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// "Replace with method reference" "true"
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
class MyTest {
|
||||
|
||||
Function<List<?>, String> TO_TEXT = new Func<caret>tion<List<?>, String>() {
|
||||
@Override
|
||||
public String apply(List<?> lst) {
|
||||
return lst.toString();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -16,7 +16,7 @@ class Box<T>
|
||||
}
|
||||
|
||||
{
|
||||
foo(Box<String>::getValue);
|
||||
foo((Function<Box<String>, String>) Box::getValue);
|
||||
}
|
||||
|
||||
<K> void foo(Function<Box<K>, K> f){}
|
||||
|
||||
@@ -5,6 +5,6 @@ import java.util.List;
|
||||
class Sample {
|
||||
List<Exception> foo = new ArrayList<>();
|
||||
{
|
||||
foo.forEach(Exception::printStackTrace);
|
||||
foo.forEach(Throwable::printStackTrace);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@ package com.intellij.codeInsight.daemon.quickFix;
|
||||
|
||||
import com.intellij.codeInspection.AnonymousCanBeMethodReferenceInspection;
|
||||
import com.intellij.codeInspection.LocalInspectionTool;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.testFramework.IdeaTestUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
||||
@@ -36,4 +38,8 @@ public class Anonymous2MethodReferenceInspectionTest extends LightQuickFixParame
|
||||
return "/codeInsight/daemonCodeAnalyzer/quickFix/anonymous2methodReference";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Sdk getProjectJDK() {
|
||||
return IdeaTestUtil.getMockJdk18();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user