foldingDescriptors.add(foldingDescriptor);
}
}
if (child instanceof BasePsiElement) {
BasePsiElement basePsiElement = (BasePsiElement) child;
ElementType elementType = basePsiElement.getElementType();
int blockEndOffset = basePsiElement.getTextOffset() + basePsiElement.getTextLength();
boolean folded = false;
if (elementType.is(ElementTypeAttribute.FOLDABLE_BLOCK)) {
BasePsiElement subjectPsiElement = basePsiElement.lookupFirstPsiElement(ElementTypeAttribute.SUBJECT);
if (subjectPsiElement == null) {
PsiElement firstChild = basePsiElement.getFirstChild();
if (firstChild instanceof TokenPsiElement) {
subjectPsiElement = (BasePsiElement) firstChild;
}
}
if (subjectPsiElement != null && subjectPsiElement.getParent() == basePsiElement) {
int subjectEndOffset = subjectPsiElement.getTextOffset() + subjectPsiElement.getTextLength();
int subjectLineNumber = document.getLineNumber(subjectEndOffset);
int blockEndOffsetLineNumber = document.getLineNumber(blockEndOffset);
if (subjectLineNumber < blockEndOffsetLineNumber) {
TextRange textRange = new TextRange(subjectEndOffset, blockEndOffset);
FoldingDescriptor foldingDescriptor = new FoldingDescriptor(basePsiElement.getNode(), textRange);
foldingDescriptors.add(foldingDescriptor);
nestingIndex++;
folded = true;
}
}
}
if (!folded && elementType.is(ElementTypeAttribute.STATEMENT)) {
if (basePsiElement.containsLineBreaks()) {
TextRange textRange = null;
BasePsiElement firstPsiElement = basePsiElement.lookupFirstLeafPsiElement();
int firstElementEndOffset = firstPsiElement.getTextOffset() + firstPsiElement.getTextLength();
int firstElementLineNumber = document.getLineNumber(firstElementEndOffset);
BasePsiElement subjectPsiElement = basePsiElement.lookupFirstPsiElement(ElementTypeAttribute.SUBJECT);
if (subjectPsiElement != null && subjectPsiElement.getParent() == basePsiElement) {
int subjectEndOffset = subjectPsiElement.getTextOffset() + subjectPsiElement.getTextLength();
int subjectLineNumber = document.getLineNumber(subjectEndOffset);
if (subjectLineNumber == firstElementLineNumber) {
textRange = new TextRange(subjectEndOffset, blockEndOffset);
}