TextRange (@NotNull ASTNode astNode) { Ref<TextRange> result = Ref.create(astNode.getTextRange()); IElementType elementType = astNode.getElementType(); ASTNode sibling = astNode.getTreePrev(); while (sibling != null && processSibling(sibling, result, elementType)) { sibling = sibling.getTreePrev(); } sibling = astNode.getTreeNext(); while (sibling != null && processSibling(sibling, result, elementType)) { sibling = sibling.getTreeNext(); } assert result.get().getEndOffset() <= myDocument.getTextLength() : "PSI-document mismatch"; return result.get(); }