private void registerNestedClosures( @NotNull DfaInstructionState instructionState, @NotNull PsiLambdaExpression expr) { DfaMemoryState state = instructionState.getMemoryState(); PsiElement body = expr.getBody(); if (body != null) { myNestedClosures.putValue(body, createClosureState(state)); } }
public static List<PsiExpression> getReturnExpressions(PsiLambdaExpression lambdaExpression) { final PsiElement body = lambdaExpression.getBody(); if (body instanceof PsiExpression) { // if (((PsiExpression)body).getType() != PsiType.VOID) return Collections.emptyList(); return Collections.singletonList((PsiExpression) body); } final List<PsiExpression> result = new ArrayList<PsiExpression>(); for (PsiReturnStatement returnStatement : getReturnStatements(lambdaExpression)) { final PsiExpression returnValue = returnStatement.getReturnValue(); if (returnValue != null) { result.add(returnValue); } } return result; }
@Nullable public static PsiElement getFirstElementOnTheLine( 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) { for (PsiStatement statement : ((PsiCodeBlock) body).getStatements()) { if (intersects(lineRange, statement)) { return statement; } } return null; } return body; }
public static List<PsiReturnStatement> getReturnStatements(PsiLambdaExpression lambdaExpression) { final PsiElement body = lambdaExpression.getBody(); final List<PsiReturnStatement> result = new ArrayList<PsiReturnStatement>(); if (body != null) { body.accept( new JavaRecursiveElementVisitor() { @Override public void visitReturnStatement(PsiReturnStatement statement) { result.add(statement); } @Override public void visitClass(PsiClass aClass) {} @Override public void visitLambdaExpression(PsiLambdaExpression expression) {} }); } return result; }