void (@NotNull final List<? super FoldingDescriptor> list, @NotNull PsiElement scope, @NotNull final Set<? super PsiElement> processedComments, @NotNull final Document document, final boolean quick) { final boolean dumb = DumbService.isDumb(scope.getProject()); scope.accept(new JavaRecursiveElementWalkingVisitor() { @Override public void visitClass(@NotNull PsiClass aClass) { if (dumb || !addClosureFolding(aClass, document, list, processedComments, quick)) { addToFold(list, aClass, document, true, getCodeBlockPlaceholder(null), classRange(aClass), JavaCodeFoldingSettings.getInstance().isCollapseInnerClasses()); addFoldsForClass(list, aClass, document, processedComments, quick); } } @Override public void visitVariable(@NotNull PsiVariable variable) { if (!dumb && JavaCodeFoldingSettings.getInstance().isReplaceVarWithInferredType()) { addLocalVariableTypeFolding(list, variable, quick); } super.visitVariable(variable); } @Override public void visitMethodCallExpression(@NotNull PsiMethodCallExpression expression) { if (!dumb) { addMethodGenericParametersFolding(list, expression, document, quick); } super.visitMethodCallExpression(expression); } @Override public void visitNewExpression(@NotNull PsiNewExpression expression) { if (!dumb) { addGenericParametersFolding(list, expression, document, quick); } super.visitNewExpression(expression); } @Override public void visitLambdaExpression(@NotNull PsiLambdaExpression expression) { PsiElement body = expression.getBody(); if (body instanceof PsiCodeBlock) { addToFold(list, expression, document, true, getCodeBlockPlaceholder(expression.getBody()), lambdaRange(expression), JavaCodeFoldingSettings.getInstance().isCollapseAnonymousClasses()); } super.visitLambdaExpression(expression); } @Override public void visitCodeBlock(@NotNull PsiCodeBlock block) { if (Registry.is("java.folding.icons.for.control.flow", true) && block.getStatementCount() > 0) { addToFold(list, block, document, false, getCodeBlockPlaceholder(block), block.getTextRange(), false); } super.visitCodeBlock(block); } @Override public void visitComment(@NotNull PsiComment comment) { addCommentToFold(list, comment, document, processedComments); super.visitComment(comment); } }); }