void (final PsiElement element) { PsiElement prevSibling = PsiTreeUtil.skipWhitespacesBackward(element); synchronized (myFoldingData) { if (myLastElement == null || prevSibling != myLastElement) { myFoldingData.add(new FoldingDescriptor(element, element.getTextRange())); } else { FoldingDescriptor lastDescriptor = myFoldingData.get(myFoldingData.size()-1); final TextRange range = new TextRange(lastDescriptor.getRange().getStartOffset(), element.getTextRange().getEndOffset()); myFoldingData.set(myFoldingData.size()-1, new FoldingDescriptor(lastDescriptor.getElement(), range)); } } myLastElement = element; }