void (@NotNull FoldingStack foldingStack, @NotNull ASTNode node, @NotNull List<? super FoldingDescriptor> descriptors, int currDepth) { FoldingStack localFoldingStack = isCustomFoldingRoot(node) ? new FoldingStack() : foldingStack; for (ASTNode child = node.getFirstChildNode(); child != null; child = child.getTreeNext()) { ProgressManager.checkCanceled(); if (isCustomRegionStart(child)) { localFoldingStack.push(child); } else if (isCustomRegionEnd(child)) { if (!localFoldingStack.isEmpty()) { ASTNode startNode = localFoldingStack.pop(); int startOffset = startNode.getTextRange().getStartOffset(); TextRange range = new TextRange(startOffset, child.getTextRange().getEndOffset()); descriptors.add(new FoldingDescriptor(startNode, range)); Set<ASTNode> nodeSet = ourCustomRegionElements.get(); nodeSet.add(startNode); nodeSet.add(child); } } else { if (currDepth < myMaxLookupDepth.asInteger()) { addCustomFoldingRegionsRecursively(localFoldingStack, child, descriptors, currDepth + 1); } } } }