Search in sources :

Example 1 with CodeFoldingSettings

use of com.intellij.codeInsight.folding.CodeFoldingSettings in project intellij-plugins by JetBrains.

the class CfmlFoldingBuilder method isCollapsedByDefault.

public boolean isCollapsedByDefault(@NotNull ASTNode node) {
    CodeFoldingSettings settings = CodeFoldingSettings.getInstance();
    final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(node);
    if (element instanceof PsiComment) {
        // find out if file header
        final ASTNode parent = node.getTreeParent();
        ASTNode treePrev = node.getTreePrev();
        if (parent.getElementType() == CfmlElementTypes.CFML_FILE && treePrev == null) {
            return CodeFoldingSettings.getInstance().COLLAPSE_FILE_HEADER;
        } else {
            return CodeFoldingSettings.getInstance().COLLAPSE_DOC_COMMENTS;
        }
    } else if (element instanceof CfmlFunction || node.getElementType() == CfmlElementTypes.FUNCTIONBODY) {
        return settings.COLLAPSE_METHODS;
    }
    return false;
}
Also used : CodeFoldingSettings(com.intellij.codeInsight.folding.CodeFoldingSettings) CfmlFunction(com.intellij.coldFusion.model.psi.CfmlFunction) PsiComment(com.intellij.psi.PsiComment) ASTNode(com.intellij.lang.ASTNode) PsiElement(com.intellij.psi.PsiElement)

Example 2 with CodeFoldingSettings

use of com.intellij.codeInsight.folding.CodeFoldingSettings in project intellij-plugins by JetBrains.

the class DartFoldingBuilder method isRegionCollapsedByDefault.

protected boolean isRegionCollapsedByDefault(@NotNull final ASTNode node) {
    final IElementType elementType = node.getElementType();
    final PsiElement psiElement = node.getPsi();
    final CodeFoldingSettings settings = CodeFoldingSettings.getInstance();
    final DartCodeFoldingSettings dartSettings = DartCodeFoldingSettings.getInstance();
    // 1. File header
    if (psiElement instanceof DartFile)
        return settings.COLLAPSE_FILE_HEADER;
    // 2. Import and export statements
    if (psiElement instanceof DartImportOrExportStatement)
        return settings.COLLAPSE_IMPORTS;
    // 3. Part statements
    if (psiElement instanceof DartPartStatement)
        return dartSettings.isCollapseParts();
    if (// 4.1. Multiline doc comments
    elementType == DartTokenTypesSets.MULTI_LINE_DOC_COMMENT || elementType == DartTokenTypesSets.SINGLE_LINE_DOC_COMMENT) {
        // 4.2 and 4.4 never collapsed by default
        return settings.COLLAPSE_DOC_COMMENTS;
    }
    // 6. Function body
    if (psiElement instanceof DartFunctionBody)
        return settings.COLLAPSE_METHODS;
    // 7. Type arguments
    if (psiElement instanceof DartTypeArguments)
        return dartSettings.isCollapseGenericParameters();
    return false;
}
Also used : IElementType(com.intellij.psi.tree.IElementType) CodeFoldingSettings(com.intellij.codeInsight.folding.CodeFoldingSettings) PsiElement(com.intellij.psi.PsiElement)

Example 3 with CodeFoldingSettings

use of com.intellij.codeInsight.folding.CodeFoldingSettings in project intellij-plugins by JetBrains.

the class DartFoldingTest method doTestWithSpecificSettings.

private void doTestWithSpecificSettings(@Nullable final Consumer<CodeFoldingSettings> commonSettingsConsumer, @Nullable final Consumer<DartCodeFoldingSettings> dartCodeFoldingSettingsConsumer) {
    CodeFoldingSettings commonSettings = null;
    CodeFoldingSettings commonOriginalSettings = null;
    DartCodeFoldingSettings dartSettings = null;
    DartCodeFoldingSettings dartOriginalSettings = null;
    if (commonSettingsConsumer != null) {
        commonSettings = CodeFoldingSettings.getInstance();
        commonOriginalSettings = XmlSerializerUtil.createCopy(commonSettings);
    }
    if (dartCodeFoldingSettingsConsumer != null) {
        dartSettings = DartCodeFoldingSettings.getInstance();
        dartOriginalSettings = XmlSerializerUtil.createCopy(dartSettings);
    }
    try {
        if (commonSettingsConsumer != null) {
            commonSettingsConsumer.consume(commonSettings);
        }
        if (dartCodeFoldingSettingsConsumer != null) {
            dartCodeFoldingSettingsConsumer.consume(dartSettings);
        }
        doTest();
    } finally {
        if (commonSettingsConsumer != null) {
            XmlSerializerUtil.copyBean(commonOriginalSettings, commonSettings);
        }
        if (dartCodeFoldingSettingsConsumer != null) {
            XmlSerializerUtil.copyBean(dartOriginalSettings, dartSettings);
        }
    }
}
Also used : CodeFoldingSettings(com.intellij.codeInsight.folding.CodeFoldingSettings)

Aggregations

CodeFoldingSettings (com.intellij.codeInsight.folding.CodeFoldingSettings)3 PsiElement (com.intellij.psi.PsiElement)2 CfmlFunction (com.intellij.coldFusion.model.psi.CfmlFunction)1 ASTNode (com.intellij.lang.ASTNode)1 PsiComment (com.intellij.psi.PsiComment)1 IElementType (com.intellij.psi.tree.IElementType)1