String (@NotNull FoldingDescriptor foldingDescriptor) { String cachedText = foldingDescriptor.getCachedPlaceholderText(); // Some folding descriptors override the getPlaceholderText() method. If they don't, the default implementation // in CompositeFoldingBuilder will return the element text. In this case, we will need to ensure that the // getPlaceholderText() will be a delegate to the folding builder, which we achieve by not storing any cached text. String textFromGetText = foldingDescriptor.getPlaceholderText(); boolean placeholderTextIsFallback = Objects.equals(textFromGetText, foldingDescriptor.getElement().getText()); return placeholderTextIsFallback ? cachedText : textFromGetText; }