More consistent API

RUBY-7865 feature request: ability to collapse commented out code
This commit is contained in:
Oleg Shpynov
2011-02-21 13:57:20 +03:00
parent 6da30b8e53
commit a26fab124c
12 changed files with 27 additions and 17 deletions
@@ -26,6 +26,7 @@ import com.intellij.lang.folding.FoldingBuilderEx;
import com.intellij.lang.folding.FoldingDescriptor;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.TextRange;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.*;
import com.intellij.psi.util.PsiUtil;
@@ -59,7 +60,7 @@ public class SuppressWarningsFoldingBuilder extends FoldingBuilderEx {
}
@Override
public String getPlaceholderText(@NotNull ASTNode node) {
public String getPlaceholderText(@NotNull ASTNode node, TextRange range) {
final PsiElement element = node.getPsi();
if (element instanceof PsiAnnotation) {
return "/" + StringUtil.join(((PsiAnnotation)element).getParameterList().getAttributes(), new Function<PsiNameValuePair, String>() {
@@ -166,7 +166,7 @@ public class JavaFoldingBuilder extends FoldingBuilderEx implements DumbAware {
}
@NotNull
public String getPlaceholderText(@NotNull final ASTNode node) {
public String getPlaceholderText(@NotNull final ASTNode node, TextRange range) {
return getPlaceholderText(SourceTreeToPsiMap.treeElementToPsi(node));
}
@@ -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,9 +57,9 @@ public class CompositeFoldingBuilder extends FoldingBuilderEx implements DumbAwa
return descriptors.toArray(new FoldingDescriptor[descriptors.size()]);
}
public String getPlaceholderText(@NotNull ASTNode node) {
public String getPlaceholderText(@NotNull ASTNode node, TextRange range) {
final FoldingBuilder builder = node.getUserData(FOLDING_BUILDER);
return builder == null ? node.getText() : builder.getPlaceholderText(node);
return builder == null ? node.getText() : builder.getPlaceholderText(node, range);
}
public boolean isCollapsedByDefault(@NotNull ASTNode node) {
@@ -18,6 +18,7 @@ package com.intellij.lang.folding;
import com.intellij.lang.ASTNode;
import com.intellij.lang.Language;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.util.TextRange;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -45,11 +46,13 @@ public interface 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 folded range
* @return the placeholder text.
*/
@Nullable
String getPlaceholderText(@NotNull ASTNode node);
String getPlaceholderText(@NotNull ASTNode node, TextRange range);
/**
* Returns the default collapsed state for the folding region related to the specified 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,13 @@ 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
* @return the placeholder text.
*/
@Nullable
public abstract String getPlaceholderText(@NotNull ASTNode node);
public abstract String getPlaceholderText(@NotNull ASTNode node, TextRange range);
/**
* Returns the default collapsed state for the folding region related to the specified node.
@@ -47,7 +47,7 @@ public class FoldingDescriptor {
* Creates a folding region related to the specified AST node and covering the specified
* text range.
* @param node The node to which the folding region is related. The node is then passed to
* {@link FoldingBuilder#getPlaceholderText(com.intellij.lang.ASTNode)} and
* {@link FoldingBuilder#getPlaceholderText(com.intellij.lang.ASTNode, com.intellij.openapi.util.TextRange)} and
* {@link FoldingBuilder#isCollapsedByDefault(com.intellij.lang.ASTNode)}.
* @param range The folded text range.
*/
@@ -67,7 +67,7 @@ public class FoldingDescriptor {
* Creates a folding region related to the specified AST node and covering the specified
* text range.
* @param node The node to which the folding region is related. The node is then passed to
* {@link com.intellij.lang.folding.FoldingBuilder#getPlaceholderText(com.intellij.lang.ASTNode)} and
* {@link FoldingBuilder#getPlaceholderText(com.intellij.lang.ASTNode, com.intellij.openapi.util.TextRange)} and
* {@link com.intellij.lang.folding.FoldingBuilder#isCollapsedByDefault(com.intellij.lang.ASTNode)}.
* @param range The folded text range.
* @param group Regions with the same group instance expand and collapse together.
@@ -82,7 +82,7 @@ public class FoldingDescriptor {
* Creates a folding region related to the specified AST node and covering the specified
* text range.
* @param node The node to which the folding region is related. The node is then passed to
* {@link com.intellij.lang.folding.FoldingBuilder#getPlaceholderText(com.intellij.lang.ASTNode)} and
* {@link FoldingBuilder#getPlaceholderText(com.intellij.lang.ASTNode, com.intellij.openapi.util.TextRange)} and
* {@link com.intellij.lang.folding.FoldingBuilder#isCollapsedByDefault(com.intellij.lang.ASTNode)}.
* @param range The folded text range.
* @param group Regions with the same group instance expand and collapse together.
@@ -134,7 +134,7 @@ public class FoldingDescriptor {
final Language lang = psiElement.getLanguage();
final FoldingBuilder foldingBuilder = LanguageFolding.INSTANCE.forLanguage(lang);
if (foldingBuilder != null) {
return foldingBuilder.getPlaceholderText(myElement);
return foldingBuilder.getPlaceholderText(myElement, myRange);
}
return null;
}
@@ -5,6 +5,7 @@ import com.intellij.lang.folding.FoldingBuilder;
import com.intellij.lang.folding.FoldingDescriptor;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.tree.TokenSet;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -42,7 +43,7 @@ public abstract class IndentationFoldingBuilder implements FoldingBuilder, DumbA
}
@Nullable
public String getPlaceholderText(@NotNull final ASTNode node) {
public String getPlaceholderText(@NotNull final ASTNode node, TextRange range) {
final StringBuilder builder = new StringBuilder();
ASTNode child = node.getFirstChildNode();
String text;
@@ -223,7 +223,7 @@ public class GroovyFoldingBuilder implements FoldingBuilder, GroovyElementTypes,
return text.contains("\n") || text.contains("\r") || text.contains("\r\n");
}
public String getPlaceholderText(@NotNull ASTNode node) {
public String getPlaceholderText(@NotNull ASTNode node, TextRange range) {
final IElementType elemType = node.getElementType();
if (BLOCK_SET.contains(elemType) || elemType == CLOSABLE_BLOCK) {
return "{...}";
@@ -28,6 +28,7 @@ import com.intellij.lang.properties.psi.impl.PropertyImpl;
import com.intellij.lang.properties.psi.impl.PropertyStubImpl;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.TextRange;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.*;
import com.intellij.psi.impl.JavaConstantExpressionEvaluator;
@@ -112,7 +113,7 @@ public class PropertyFoldingBuilder extends FoldingBuilderEx {
}
public String getPlaceholderText(@NotNull ASTNode node) {
public String getPlaceholderText(@NotNull ASTNode node, TextRange range) {
final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(node);
if (element instanceof PsiLiteralExpression) {
return getI18nMessage((PsiLiteralExpression)element);
@@ -52,7 +52,7 @@ public class RncFoldingBuilder implements FoldingBuilder {
: FoldingDescriptor.EMPTY;
}
public String getPlaceholderText(@NotNull ASTNode node) {
public String getPlaceholderText(@NotNull ASTNode node, TextRange range) {
final IElementType type = node.getElementType();
if (type == RncTokenTypes.LBRACE) {
return "{ ... }";
@@ -40,7 +40,7 @@ public class GeneratedCodeFoldingBuilder extends FoldingBuilderEx {
return visitor.myFoldingData.toArray(new FoldingDescriptor[visitor.myFoldingData.size()]);
}
public String getPlaceholderText(@NotNull ASTNode node) {
public String getPlaceholderText(@NotNull ASTNode node, TextRange range) {
return UIDesignerBundle.message("uidesigner.generated.code.folding.placeholder.text");
}
@@ -206,7 +206,7 @@ public class XmlFoldingBuilder implements FoldingBuilder, DumbAware {
return false;
}
public String getPlaceholderText(@NotNull ASTNode node) {
public String getPlaceholderText(@NotNull ASTNode node, TextRange range) {
final PsiElement psi = node.getPsi();
if (psi instanceof XmlTag ||
psi instanceof XmlComment ||