Propagate information about text range while creating placeholder text.

Back compatibility with existing plugins shouldn't be broken. [r=den]
This commit is contained in:
Oleg Shpynov
2011-07-12 09:24:26 +04:00
committed by Roman Chernyatchik
parent f106dd8253
commit d5d730b5da
3 changed files with 19 additions and 3 deletions
@@ -18,8 +18,9 @@ package com.intellij.lang.folding;
import com.intellij.lang.ASTNode;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
@@ -56,6 +57,14 @@ public class CompositeFoldingBuilder extends FoldingBuilderEx implements DumbAwa
return descriptors.toArray(new FoldingDescriptor[descriptors.size()]);
}
@Override
public String getPlaceholderText(@NotNull ASTNode node, @NotNull TextRange range) {
final FoldingBuilder builder = node.getUserData(FOLDING_BUILDER);
return builder == null ? node.getText() : builder instanceof FoldingBuilderEx
? ((FoldingBuilderEx)builder).getPlaceholderText(node, range) : builder.getPlaceholderText(node);
}
@Override
public String getPlaceholderText(@NotNull ASTNode node) {
final FoldingBuilder builder = node.getUserData(FOLDING_BUILDER);
return builder == null ? node.getText() : builder.getPlaceholderText(node);
@@ -18,6 +18,7 @@ package com.intellij.lang.folding;
import com.intellij.lang.ASTNode;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -54,11 +55,15 @@ public abstract class FoldingBuilderEx implements FoldingBuilder {
* Returns the text which is displayed in the editor for the folding region related to the
* specified node when the folding region is collapsed.
*
*
* @param node the node for which the placeholder text is requested.
* @param range text range within whole file to fold
* @return the placeholder text.
*/
@Nullable
public abstract String getPlaceholderText(@NotNull ASTNode node);
public String getPlaceholderText(@NotNull ASTNode node, @NotNull TextRange range){
return getPlaceholderText(node);
}
/**
* Returns the default collapsed state for the folding region related to the specified node.
@@ -134,7 +134,9 @@ public class FoldingDescriptor {
final Language lang = psiElement.getLanguage();
final FoldingBuilder foldingBuilder = LanguageFolding.INSTANCE.forLanguage(lang);
if (foldingBuilder != null) {
return foldingBuilder.getPlaceholderText(myElement);
return foldingBuilder instanceof FoldingBuilderEx
? ((FoldingBuilderEx)foldingBuilder).getPlaceholderText(myElement, myRange)
: foldingBuilder.getPlaceholderText(myElement);
}
return null;
}