PsiElement (@NotNull final Document document, @NotNull PsiElement destination) { final PsiElement statement = PsiTreeUtil.getParentOfType(destination, PyStatement.class, false); if (statement == null) return destination; if (destination instanceof PsiComment) { if (document.getLineNumber(destination.getTextOffset()) == document.getLineNumber(statement.getTextOffset())) destination = statement; } else destination = statement; return destination; }