use of com.intellij.lang.folding.FoldingDescriptor in project intellij-community by JetBrains.
the class PythonFoldingBuilder method foldLongStrings.
private static void foldLongStrings(ASTNode node, List<FoldingDescriptor> descriptors) {
//don't want to fold docstrings like """\n string \n """
boolean shouldFoldDocString = getDocStringOwnerType(node) != null && StringUtil.countNewLines(node.getChars()) > 1;
boolean shouldFoldString = getDocStringOwnerType(node) == null && StringUtil.countNewLines(node.getChars()) > 0;
if (shouldFoldDocString || shouldFoldString) {
descriptors.add(new FoldingDescriptor(node, node.getTextRange()));
}
}
use of com.intellij.lang.folding.FoldingDescriptor in project intellij-community by JetBrains.
the class PythonFoldingBuilder method foldStatementList.
private static void foldStatementList(ASTNode node, List<FoldingDescriptor> descriptors) {
IElementType elType = node.getTreeParent().getElementType();
if (elType == PyElementTypes.FUNCTION_DECLARATION || elType == PyElementTypes.CLASS_DECLARATION || ifFoldBlocks(node, elType)) {
ASTNode colon = node.getTreeParent().findChildByType(PyTokenTypes.COLON);
if (colon != null && colon.getStartOffset() + 1 < node.getTextRange().getEndOffset() - 1) {
final CharSequence chars = node.getChars();
int nodeStart = node.getTextRange().getStartOffset();
int endOffset = node.getTextRange().getEndOffset();
while (endOffset > colon.getStartOffset() + 2 && endOffset > nodeStart && Character.isWhitespace(chars.charAt(endOffset - nodeStart - 1))) {
endOffset--;
}
descriptors.add(new FoldingDescriptor(node, new TextRange(colon.getStartOffset() + 1, endOffset)));
} else {
TextRange range = node.getTextRange();
if (range.getStartOffset() < range.getEndOffset() - 1) {
// only for ranges at least 1 char wide
descriptors.add(new FoldingDescriptor(node, range));
}
}
}
}
use of com.intellij.lang.folding.FoldingDescriptor in project android by JetBrains.
the class ResourceFoldingBuilder method buildFoldRegions.
@Override
@NotNull
public FoldingDescriptor[] buildFoldRegions(@NotNull PsiElement element, @NotNull Document document, boolean quick) {
if (!(element instanceof PsiJavaFile || element instanceof XmlFile) || quick && !UNIT_TEST_MODE || !isFoldingEnabled()) {
return FoldingDescriptor.EMPTY;
}
final List<FoldingDescriptor> result = new ArrayList<FoldingDescriptor>();
if (element instanceof PsiJavaFile) {
final PsiJavaFile file = (PsiJavaFile) element;
file.accept(new JavaRecursiveElementWalkingVisitor() {
@Override
public void visitReferenceExpression(PsiReferenceExpression expression) {
InlinedResource inlinedResource = findJavaExpressionReference(expression);
if (inlinedResource != NONE) {
result.add(inlinedResource.getDescriptor());
}
super.visitReferenceExpression(expression);
}
});
} else {
final XmlFile file = (XmlFile) element;
file.accept(new XmlRecursiveElementVisitor() {
@Override
public void visitXmlAttributeValue(XmlAttributeValue value) {
InlinedResource inlinedResource = findXmlValueReference(value);
if (inlinedResource != NONE) {
FoldingDescriptor descriptor = inlinedResource.getDescriptor();
if (descriptor != null) {
result.add(descriptor);
}
}
super.visitXmlAttributeValue(value);
}
});
}
return result.toArray(new FoldingDescriptor[result.size()]);
}
use of com.intellij.lang.folding.FoldingDescriptor in project intellij-plugins by JetBrains.
the class GherkinFoldingBuilder method appendDescriptors.
private void appendDescriptors(ASTNode node, List<FoldingDescriptor> descriptors) {
if (BLOCKS_TO_FOLD.contains(node.getElementType()) && node.getTextRange().getLength() >= 2) {
descriptors.add(new FoldingDescriptor(node, node.getTextRange()));
}
ASTNode child = node.getFirstChildNode();
while (child != null) {
appendDescriptors(child, descriptors);
child = child.getTreeNext();
}
}
use of com.intellij.lang.folding.FoldingDescriptor in project intellij-plugins by JetBrains.
the class CfmlFoldingBuilder method buildFoldRegions.
@NotNull
public FoldingDescriptor[] buildFoldRegions(@NotNull ASTNode node, @NotNull Document document) {
final PsiElement element = node.getPsi();
if (element instanceof CfmlFile) {
final CfmlFile file = (CfmlFile) element;
final PsiElement[] children = file.getChildren();
Collection<FoldingDescriptor> result = new LinkedList<>();
for (PsiElement child : children) {
if (child != null && (child instanceof CfmlCompositeElement || child instanceof PsiComment)) {
List<FoldingDescriptor> descriptors = new ArrayList<>();
addFoldingDescriptors(descriptors, child, document);
result.addAll(descriptors);
}
}
return result.toArray(FoldingDescriptor.EMPTY);
}
return FoldingDescriptor.EMPTY;
}
Aggregations