allow functional expressions in nested conditional expressions (IDEA-164828)

This commit is contained in:
Anna.Kozlova
2016-12-01 11:40:03 +01:00
parent a8800a9a04
commit 936294e05d
2 changed files with 17 additions and 3 deletions

View File

@@ -127,9 +127,17 @@ public class LambdaUtil {
@Contract("null -> false")
public static boolean isValidLambdaContext(@Nullable PsiElement context) {
context = PsiUtil.skipParenthesizedExprUp(context);
return isAssignmentOrInvocationContext(context) ||
context instanceof PsiTypeCastExpression ||
context instanceof PsiConditionalExpression && isAssignmentOrInvocationContext(PsiUtil.skipParenthesizedExprUp(context.getParent()));
if (isAssignmentOrInvocationContext(context) || context instanceof PsiTypeCastExpression) {
return true;
}
if (context instanceof PsiConditionalExpression) {
PsiElement parentContext = PsiUtil.skipParenthesizedExprUp(context.getParent());
if (isAssignmentOrInvocationContext(parentContext)) return true;
if (parentContext instanceof PsiConditionalExpression) {
return isValidLambdaContext(parentContext);
}
}
return false;
}
private static boolean isAssignmentOrInvocationContext(PsiElement context) {

View File

@@ -27,4 +27,10 @@ class Test1 {
II ik2 = (II)(ik1 = (b ? (s)-> true : (s)->false));
(b ? <error descr="Lambda expression not expected here">(s) -> true</error> : ik)._("");
}
}
class Test2 {
void f() {
final Runnable one=true ? null : true ? () -> {} : () -> {};
}
}