mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-05-06 05:10:22 +07:00
AIOOBE
This commit is contained in:
@@ -129,8 +129,23 @@ public class LambdaCanBeMethodReferenceInspection extends BaseJavaBatchLocalInsp
|
||||
final int calledParametersCount = psiMethod.getParameterList().getParametersCount();
|
||||
final PsiExpression[] expressions = argumentList.getExpressions();
|
||||
|
||||
final PsiExpression qualifier;
|
||||
if (callExpression instanceof PsiMethodCallExpression) {
|
||||
qualifier = ((PsiMethodCallExpression)callExpression).getMethodExpression().getQualifierExpression();
|
||||
}
|
||||
else if (callExpression instanceof PsiNewExpression) {
|
||||
qualifier = ((PsiNewExpression)callExpression).getQualifier();
|
||||
}
|
||||
else {
|
||||
qualifier = null;
|
||||
}
|
||||
|
||||
if (expressions.length == 0 && parameters.length == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
final int offset = parameters.length - calledParametersCount;
|
||||
if (expressions.length > calledParametersCount) {
|
||||
if (expressions.length > calledParametersCount || offset < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -139,23 +154,8 @@ public class LambdaCanBeMethodReferenceInspection extends BaseJavaBatchLocalInsp
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (offset > 0) {
|
||||
final PsiExpression qualifier;
|
||||
if (callExpression instanceof PsiMethodCallExpression) {
|
||||
qualifier = ((PsiMethodCallExpression)callExpression).getMethodExpression().getQualifierExpression();
|
||||
}
|
||||
else if (callExpression instanceof PsiNewExpression) {
|
||||
qualifier = ((PsiNewExpression)callExpression).getQualifier();
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!resolvesToParameter(qualifier, parameters[0])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return offset == 0 || resolvesToParameter(qualifier, parameters[0]);
|
||||
}
|
||||
|
||||
private static boolean resolvesToParameter(PsiExpression expression, PsiParameter parameter) {
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
// "Replace lambda with method reference" "false"
|
||||
class Example {
|
||||
public void m(String ss, String... s) {
|
||||
}
|
||||
|
||||
{
|
||||
Runnable r = () -> <caret>m("", "");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user