List<TextRange> (@NotNull PsiElement e, @NotNull CharSequence editorText, int cursorOffset, @NotNull Editor editor) { List<TextRange> result = new ArrayList<>(expandToWholeLine(editorText, e.getTextRange(), false)); ASTNode node = BasicJavaAstTreeUtil.toNode(e); if (node == null) { return null; } final ASTNode elseKeyword = BasicJavaAstTreeUtil.getElseElement(node); if (elseKeyword != null) { final ASTNode then = BasicJavaAstTreeUtil.getThenBranch(node); if (then != null) { final TextRange thenRange = new TextRange(e.getTextRange().getStartOffset(), then.getTextRange().getEndOffset()); if (thenRange.contains(cursorOffset)) { result.addAll(expandToWholeLine(editorText, thenRange, false)); } } result.addAll(expandToWholeLine(editorText, new TextRange(elseKeyword.getTextRange().getStartOffset(), node.getTextRange().getEndOffset()), false)); final ASTNode branch = BasicJavaAstTreeUtil.getElseBranch(node); if (BasicJavaAstTreeUtil.is(branch, BASIC_IF_STATEMENT)) { final ASTNode element = BasicJavaAstTreeUtil.getElseElement(branch); if (element != null) { final ASTNode elseThen = BasicJavaAstTreeUtil.getThenBranch(branch); if (elseThen != null) { result.addAll(expandToWholeLine(editorText, new TextRange(elseKeyword.getTextRange().getStartOffset(), elseThen.getTextRange().getEndOffset()), false)); } } } } return result; }