PsiElement (@NotNull PsiLambdaExpression lambda, Document document, int line) { ApplicationManager.getApplication().assertReadAccessAllowed(); TextRange lineRange = DocumentUtil.getLineTextRange(document, line); if (!intersects(lineRange, lambda)) return null; PsiElement body = lambda.getBody(); if (body == null || !intersects(lineRange, body)) return null; if (body instanceof PsiCodeBlock) { PsiStatement[] statements = ((PsiCodeBlock)body).getStatements(); if (statements.length > 0) { for (PsiStatement statement : statements) { // return first statement starting on the line if (lineRange.contains(statement.getTextOffset())) { return statement; } // otherwise check all children else if (intersects(lineRange, statement)) { for (PsiElement element : SyntaxTraverser.psiTraverser(statement)) { if (lineRange.contains(element.getTextOffset())) { return element; } } } } return null; } } return body; }