PsiComment (PsiElement element, boolean above) { PsiElement currentElement = element; PsiComment lastComment = null; boolean nextLine = false; while (true) { currentElement = above ? PsiTreeUtil.prevLeaf(currentElement) : PsiTreeUtil.nextLeaf(currentElement); if (currentElement == null) break; String elementText = currentElement.getText(); if (elementText == null) break; int newLines = StringUtil.countNewLines(elementText); if (newLines == 0 && !nextLine) continue; if (currentElement instanceof PsiComment) lastComment = (PsiComment)currentElement; if (newLines > (nextLine ? 0 : 1)) break; nextLine = true; } return lastComment; }