List<TextRange> (@NotNull PsiElement e, @NotNull CharSequence editorText, int cursorOffset, @NotNull Editor editor) { List<TextRange> result = new ArrayList<>(); ASTNode node = BasicJavaAstTreeUtil.toNode(e); if (node == null) { return result; } ASTNode firstChild = node.getFirstChildNode(); List<ASTNode> children = BasicJavaAstTreeUtil.getChildren(node); int i = 1; if (BasicJavaAstTreeUtil.is(firstChild, BASIC_DOC_COMMENT)) { while (BasicJavaAstTreeUtil.isWhiteSpace(children.get(i))) { i++; } TextRange range = new TextRange(children.get(i).getTextRange().getStartOffset(), e.getTextRange().getEndOffset()); result.add(range); result.addAll(expandToWholeLinesWithBlanks(editorText, range)); range = firstChild.getTextRange(); result.addAll(expandToWholeLinesWithBlanks(editorText, range)); firstChild = children.get(i++); } if (BasicJavaAstTreeUtil.is(firstChild, BASIC_JAVA_COMMENT_BIT_SET)) { while (BasicJavaAstTreeUtil.is(children.get(i), BASIC_JAVA_COMMENT_OR_WHITESPACE_BIT_SET)) { i++; } ASTNode last = BasicJavaAstTreeUtil.isWhiteSpace(children.get(i - 1)) ? children.get(i - 2) : children.get(i - 1); TextRange range = new TextRange(firstChild.getTextRange().getStartOffset(), last.getTextRange().getEndOffset()); if (range.contains(cursorOffset)) { result.addAll(expandToWholeLinesWithBlanks(editorText, range)); } range = new TextRange(children.get(i).getTextRange().getStartOffset(), e.getTextRange().getEndOffset()); result.add(range); result.addAll(expandToWholeLinesWithBlanks(editorText, range)); } result.add(node.getTextRange()); result.addAll(expandToWholeLinesWithBlanks(editorText, node.getTextRange())); if (BasicJavaAstTreeUtil.is(node, CLASS_SET)) { result.addAll(selectWithTypeParameters(node)); result.addAll(selectBetweenBracesLines(children, editorText)); } if (BasicJavaAstTreeUtil.is(node, BASIC_ANONYMOUS_CLASS)) { result.addAll(selectWholeBlock(node)); } return result; }