lambda -> meth ref: varargs

This commit is contained in:
Anna Kozlova
2014-11-12 12:20:39 +01:00
parent 89d1df1dc0
commit 1d2a8e0571
4 changed files with 38 additions and 1 deletions

View File

@@ -125,8 +125,15 @@ public class LambdaCanBeMethodReferenceInspection extends BaseJavaBatchLocalInsp
if (argumentList == null) {
return false;
}
int offset = parameters.length - psiMethod.getParameterList().getParametersCount();
final int calledParametersCount = psiMethod.getParameterList().getParametersCount();
final PsiExpression[] expressions = argumentList.getExpressions();
final int offset = parameters.length - calledParametersCount;
if (expressions.length > calledParametersCount) {
return false;
}
for (int i = 0; i < expressions.length; i++) {
if (!resolvesToParameter(expressions[i], parameters[i + offset])) {
return false;

View File

@@ -0,0 +1,9 @@
// "Replace lambda with method reference" "true"
class Example {
public void m(String... s) {
}
{
Runnable r = this::m;
}
}

View File

@@ -0,0 +1,9 @@
// "Replace lambda with method reference" "true"
class Example {
public void m(String... s) {
}
{
Runnable r = () -> <caret>m();
}
}

View File

@@ -0,0 +1,12 @@
// "Replace lambda with method reference" "false"
import java.util.function.Function;
class Example {
public String m(String... s) {
return "";
}
{
Function<String, String> r = (s) -> m(s, s);
}
}