mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-05-06 05:10:22 +07:00
lambda: accept ellipsis parameter when array expected (IDEA-117124)
This commit is contained in:
@@ -176,8 +176,8 @@ public class PsiLambdaExpressionImpl extends ExpressionPsiElement implements Psi
|
||||
PsiParameter parameter = lambdaParameters[lambdaParamIdx];
|
||||
final PsiTypeElement typeElement = parameter.getTypeElement();
|
||||
if (typeElement != null) {
|
||||
final PsiType lambdaFormalType = typeElement.getType();
|
||||
final PsiType methodParameterType = parameterTypes[lambdaParamIdx];
|
||||
final PsiType lambdaFormalType = toArray(typeElement.getType());
|
||||
final PsiType methodParameterType = toArray(parameterTypes[lambdaParamIdx]);
|
||||
if (!lambdaFormalType.equals(methodParameterType)) {
|
||||
return false;
|
||||
}
|
||||
@@ -186,10 +186,7 @@ public class PsiLambdaExpressionImpl extends ExpressionPsiElement implements Psi
|
||||
|
||||
if (checkReturnType) {
|
||||
final String uniqueVarName = JavaCodeStyleManager.getInstance(getProject()).suggestUniqueVariableName("l", this, true);
|
||||
String canonicalText = leftType.getCanonicalText();
|
||||
if (leftType instanceof PsiEllipsisType) {
|
||||
canonicalText = ((PsiEllipsisType)leftType).toArrayType().getCanonicalText();
|
||||
}
|
||||
final String canonicalText = toArray(leftType).getCanonicalText();
|
||||
final PsiStatement assignmentFromText = JavaPsiFacade.getElementFactory(getProject())
|
||||
.createStatementFromText(canonicalText + " " + uniqueVarName + " = " + getText(), this);
|
||||
final PsiLocalVariable localVariable = (PsiLocalVariable)((PsiDeclarationStatement)assignmentFromText).getDeclaredElements()[0];
|
||||
@@ -201,4 +198,11 @@ public class PsiLambdaExpressionImpl extends ExpressionPsiElement implements Psi
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static PsiType toArray(PsiType paramType) {
|
||||
if (paramType instanceof PsiEllipsisType) {
|
||||
return ((PsiEllipsisType)paramType).toArrayType();
|
||||
}
|
||||
return paramType;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
interface Var {
|
||||
void var(int[] ps);
|
||||
}
|
||||
class Abc {
|
||||
void foo() {
|
||||
Var var = (int... ps) -> {};
|
||||
}
|
||||
}
|
||||
@@ -130,6 +130,10 @@ public class NewLambdaHighlightingTest extends LightDaemonAnalyzerTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testIDEA117124() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
doTest(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user