use of com.intellij.lang.folding.FoldingBuilder in project intellij-community by JetBrains.
the class FoldingPolicy method isCollapseByDefault.
public static boolean isCollapseByDefault(PsiElement element) {
final Language lang = element.getLanguage();
final FoldingBuilder foldingBuilder = LanguageFolding.INSTANCE.forLanguage(lang);
try {
return foldingBuilder != null && foldingBuilder.isCollapsedByDefault(element.getNode());
} catch (IndexNotReadyException e) {
LOG.error(e);
return false;
}
}
use of com.intellij.lang.folding.FoldingBuilder in project intellij-community by JetBrains.
the class FoldingUpdate method getFoldingsFor.
private static void getFoldingsFor(@NotNull PsiFile file, @NotNull Document document, @NotNull FoldingMap elementsToFoldMap, boolean quick) {
final FileViewProvider viewProvider = file.getViewProvider();
TextRange docRange = TextRange.from(0, document.getTextLength());
for (final Language language : viewProvider.getLanguages()) {
final PsiFile psi = viewProvider.getPsi(language);
final FoldingBuilder foldingBuilder = LanguageFolding.INSTANCE.forLanguage(language);
if (psi != null && foldingBuilder != null) {
for (FoldingDescriptor descriptor : LanguageFolding.buildFoldingDescriptors(foldingBuilder, psi, document, quick)) {
PsiElement psiElement = descriptor.getElement().getPsi();
if (psiElement == null) {
LOG.error("No PSI for folding descriptor " + descriptor);
continue;
}
if (!docRange.contains(descriptor.getRange())) {
diagnoseIncorrectRange(psi, document, language, foldingBuilder, descriptor, psiElement);
continue;
}
elementsToFoldMap.putValue(psiElement, descriptor);
}
}
}
}
use of com.intellij.lang.folding.FoldingBuilder in project intellij-community by JetBrains.
the class DocumentFoldingInfo method buildRanges.
@NotNull
private static Map<PsiElement, FoldingDescriptor> buildRanges(@NotNull Editor editor, @NotNull PsiFile psiFile) {
final FoldingBuilder foldingBuilder = LanguageFolding.INSTANCE.forLanguage(psiFile.getLanguage());
final ASTNode node = psiFile.getNode();
if (node == null)
return Collections.emptyMap();
final FoldingDescriptor[] descriptors = LanguageFolding.buildFoldingDescriptors(foldingBuilder, psiFile, editor.getDocument(), true);
Map<PsiElement, FoldingDescriptor> ranges = new HashMap<>();
for (FoldingDescriptor descriptor : descriptors) {
final ASTNode ast = descriptor.getElement();
final PsiElement psi = ast.getPsi();
if (psi != null) {
ranges.put(psi, descriptor);
}
}
return ranges;
}
Aggregations