boolean (@NotNull Project project, @NotNull Editor editor, @NotNull PsiElement element) { final PsiLambdaExpression lambdaExpression = PsiTreeUtil.getParentOfType(element, PsiLambdaExpression.class, false); if (lambdaExpression != null) { PsiElement body = lambdaExpression.getBody(); if (body == null) return false; //is a valid lambda PsiType functionalInterfaceType = lambdaExpression.getFunctionalInterfaceType(); if (functionalInterfaceType == null || LambdaUtil.getFunctionalInterfaceReturnType(functionalInterfaceType) == null) { return false; } //can types be specified if (LambdaUtil.createLambdaParameterListWithFormalTypes(functionalInterfaceType, lambdaExpression, false) == null) { return false; } PsiExpression asMethodReference = LambdaCanBeMethodReferenceInspection .canBeMethodReferenceProblem(body, lambdaExpression.getParameterList().getParameters(), functionalInterfaceType, null); if (asMethodReference != null) return false; try { PsiElement[] toExtract = body instanceof PsiCodeBlock ? ((PsiCodeBlock)body).getStatements() : new PsiElement[]{body}; ControlFlowWrapper wrapper = new ControlFlowWrapper(body, toExtract); wrapper.prepareExitStatements(toExtract, body); PsiVariable[] outputVariables = wrapper.getOutputVariables(); List<PsiVariable> inputVariables = wrapper.getInputVariables(body, toExtract, outputVariables); return inputVariables.stream() .allMatch(variable -> variable instanceof PsiParameter && ((PsiParameter)variable).getDeclarationScope() == lambdaExpression); } catch (PrepareFailedException | ControlFlowWrapper.ExitStatementsNotSameException ignored) { } } return false; }