TextRange (PsiElement element) { PsiElement first = null; PsiElement last = null; for (PsiElement cur = element; GeeseUtil.isClosureRBrace(cur) && GeeseUtil.isClosureContainLF(cur); cur = getNext(cur)) { last = cur; } for (PsiElement cur = element; GeeseUtil.isClosureRBrace(cur) && GeeseUtil.isClosureContainLF(cur); cur = getPrev(cur)) { first = cur; } LOG.assertTrue(first != null); LOG.assertTrue(last != null); return new TextRange(first.getTextRange().getStartOffset(), last.getTextRange().getEndOffset()); }