void (final PsiElement element, List<? super FoldingDescriptor> descriptors, Set<? super PsiElement> usedComments) { ASTNode node = element.getNode(); if (node == null) return; IElementType type = node.getElementType(); if (TokenSets.BLOCK_SET.contains(type) && !isSingleHighLevelClassBody(element) || type == GroovyElementTypes.CLOSABLE_BLOCK) { if (isMultiline(element)) { collapseBlock(descriptors, element); } } // comments if (type.equals(GroovyTokenTypes.mML_COMMENT) && isMultiline(element) && isWellEndedComment(element)) { descriptors.add(new FoldingDescriptor(node, node.getTextRange(), null, "/*...*/", isFileHeader(node) && JavaCodeFoldingSettings.getInstance().isCollapseFileHeader(), Collections.emptySet())); } if (type.equals(GroovyDocElementTypes.GROOVY_DOC_COMMENT) && isMultiline(element) && isWellEndedComment(element)) { descriptors.add(new FoldingDescriptor(node, node.getTextRange(), null, "/**...*/", isFileHeader(node) ? JavaCodeFoldingSettings.getInstance().isCollapseFileHeader() : JavaCodeFoldingSettings.getInstance().isCollapseJavadocs(), Collections.emptySet())); } if (type.equals(GroovyTokenTypes.mSL_COMMENT) && usedComments.add(element) && !isCustomRegionElement(element)) { PsiElement end = null; for (PsiElement current = element.getNextSibling(); current != null; current = current.getNextSibling()) { if (PsiImplUtil.isWhiteSpaceOrNls(current)) continue; IElementType elementType = current.getNode().getElementType(); if (elementType == GroovyTokenTypes.mSL_COMMENT && usedComments.add(current) && !isCustomRegionElement(current)) { end = current; continue; } break; } if (end != null) { final TextRange range = new TextRange(element.getTextRange().getStartOffset(), end.getTextRange().getEndOffset()); descriptors.add(new FoldingDescriptor(node, range, null, "...", isFileHeader(node) ? JavaCodeFoldingSettings.getInstance().isCollapseFileHeader() : JavaCodeFoldingSettings.getInstance().isCollapseEndOfLineComments(), Collections.emptySet())); } } //multiline strings addFoldingForStrings(descriptors, node); Set<PsiElement> newUsedComments = new HashSet<>(); for (PsiElement child = element.getFirstChild(); child != null; child = child.getNextSibling()) { appendDescriptors(child, descriptors, newUsedComments); } if (element instanceof GroovyFile) { processImports(descriptors, ((GroovyFile)element).getImportStatements()); } }