static void selectReturnValueInEditor( final PsiReturnStatement returnStatement, final Editor editor) { final PsiExpression returnValue = returnStatement.getReturnValue(); LOG.assertTrue(returnValue != null, returnStatement); TextRange range = returnValue.getTextRange(); int offset = range.getStartOffset(); editor.getCaretModel().moveToOffset(offset); editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE); editor.getSelectionModel().setSelection(range.getEndOffset(), range.getStartOffset()); }
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; }