void (ASTNode node, List<FoldingDescriptor> descriptors) { final TextRange nodeRange = node.getTextRange(); if (nodeRange.isEmpty()) { return; } final IElementType elType = node.getTreeParent().getElementType(); if (elType == PyElementTypes.FUNCTION_DECLARATION || elType == PyElementTypes.CLASS_DECLARATION || ifFoldBlocks(node, elType)) { final ASTNode colon = node.getTreeParent().findChildByType(PyTokenTypes.COLON); final int nodeEnd = nodeRange.getEndOffset(); if (colon != null && nodeEnd - (colon.getStartOffset() + 1) > 1) { final CharSequence chars = node.getChars(); final int nodeStart = nodeRange.getStartOffset(); final int foldStart = colon.getStartOffset() + 1; int foldEnd = nodeEnd; while (foldEnd > Math.max(nodeStart, foldStart + 1) && Character.isWhitespace(chars.charAt(foldEnd - nodeStart - 1))) { foldEnd--; } descriptors.add(new FoldingDescriptor(node, new TextRange(foldStart, foldEnd))); } else if (nodeRange.getLength() > 1) { // only for ranges at least 1 char wide descriptors.add(new FoldingDescriptor(node, nodeRange)); } } }