boolean (PsiExpression expr, PsiMethod method, PsiType expectedReturnType) { if (expr instanceof PsiLambdaExpression && ((PsiLambdaExpression)expr).hasFormalParameterTypes() || expr instanceof PsiMethodReferenceExpression && ((PsiMethodReferenceExpression)expr).isExact()) { if (method != null) { final PsiElement parent = PsiUtil.skipParenthesizedExprUp(expr.getParent()); PsiType paramType = null; if (parent instanceof PsiExpressionList) { final PsiElement gParent = parent.getParent(); PsiTypeParameterListOwner owner = getTypeParameterOwner(method, gParent); if (owner != null) { final int idx = LambdaUtil.getLambdaIdx((PsiExpressionList)parent, expr); final PsiParameter[] parameters = method.getParameterList().getParameters(); if (idx > parameters.length - 1) { final PsiType lastParamType = parameters[parameters.length - 1].getType(); paramType = parameters[parameters.length - 1].isVarArgs() ? ((PsiEllipsisType)lastParamType).getComponentType() : lastParamType; } else { paramType = parameters[idx].getType(); } if (isTypeParameterType(owner, paramType)) return false; } } else if (expectedReturnType != null && (parent instanceof PsiLambdaExpression || parent instanceof PsiReturnStatement && PsiTreeUtil.getParentOfType(parent, PsiLambdaExpression.class, true, PsiMethod.class) != null)) { if (isTypeParameterType(method, expectedReturnType)) return false; paramType = expectedReturnType; } if (expr instanceof PsiLambdaExpression) { for (PsiExpression expression : LambdaUtil.getReturnExpressions((PsiLambdaExpression)expr)) { if (!isPertinentToApplicability(expression, method, LambdaUtil.getFunctionalInterfaceReturnType(paramType))) return false; } return true; } } } if (expr instanceof PsiLambdaExpression) { return ((PsiLambdaExpression)expr).hasFormalParameterTypes(); } if (expr instanceof PsiMethodReferenceExpression) { return ((PsiMethodReferenceExpression)expr).isExact(); } if (expr instanceof PsiParenthesizedExpression) { return isPertinentToApplicability(((PsiParenthesizedExpression)expr).getExpression(), method); } if (expr instanceof PsiConditionalExpression) { final PsiExpression thenExpression = ((PsiConditionalExpression)expr).getThenExpression(); if (!isPertinentToApplicability(thenExpression, method)) return false; final PsiExpression elseExpression = ((PsiConditionalExpression)expr).getElseExpression(); if (!isPertinentToApplicability(elseExpression, method)) return false; } return true; }