boolean (List<? super FoldingDescriptor> foldings, PsiElement elementToFold, Document document) { PsiUtilCore.ensureValid(elementToFold); TextRange range = getRangeToFold(elementToFold); if (range == null) return false; if(range.getStartOffset() >= 0 && range.getEndOffset() <= elementToFold.getContainingFile().getTextRange().getEndOffset() && range.getEndOffset() <= document.getTextLength() // psi and document maybe not in sync after error ) { int startLine = document.getLineNumber(range.getStartOffset()); int endLine = document.getLineNumber(range.getEndOffset() - 1); final boolean entity = isEntity(elementToFold); if (startLine < endLine || elementToFold instanceof XmlAttribute || entity) { if (range.getStartOffset() + MIN_TEXT_RANGE_LENGTH < range.getEndOffset() || entity) { ASTNode node = elementToFold.getNode(); String placeholder = getLanguagePlaceholderText(node, range); foldings.add(placeholder != null ? new FoldingDescriptor(node, range, null, placeholder) : new FoldingDescriptor(node, range)); return true; } } } return false; }