FoldingBuilder (final String textToFold, final String placeholderText, final boolean overrideGetText) { return new CustomFoldingBuilder() { @Override protected void buildLanguageFoldRegions( @NotNull List<FoldingDescriptor> descriptors, @NotNull PsiElement root, @NotNull Document document, boolean quick) { final int index = root.getText().indexOf(textToFold); TextRange textRange = new TextRange(index, index + textToFold.length()); if (overrideGetText) { descriptors.add(new FoldingDescriptor(root.getNode(), textRange) { @Nullable @Override public String getPlaceholderText() { return placeholderText; } }); } else { descriptors.add(new FoldingDescriptor(root.getNode(), textRange, null, placeholderText, true, Collections.emptySet())); } } @Override protected String getLanguagePlaceholderText(@NotNull ASTNode node, @NotNull TextRange range) { return ""; } @Override protected boolean isRegionCollapsedByDefault(@NotNull ASTNode node) { return true; } }; }