lambda: accept ellipsis parameter when array expected (IDEA-117124)

This commit is contained in:
Anna Kozlova
2014-02-24 18:56:06 +01:00
parent d7d0eecd06
commit 7a70428d04
3 changed files with 22 additions and 6 deletions

View File

@@ -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;
}
}

View File

@@ -0,0 +1,8 @@
interface Var {
void var(int[] ps);
}
class Abc {
void foo() {
Var var = (int... ps) -> {};
}
}

View File

@@ -130,6 +130,10 @@ public class NewLambdaHighlightingTest extends LightDaemonAnalyzerTestCase {
doTest();
}
public void testIDEA117124() throws Exception {
doTest();
}
private void doTest() {
doTest(false);
}