mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-30 02:09:59 +07:00
allow functional expressions in nested conditional expressions (IDEA-164828)
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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 ? () -> {} : () -> {};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user