Search in sources :

Example 1 with DataLanguageBlockWrapper

use of com.intellij.formatting.templateLanguages.DataLanguageBlockWrapper in project intellij-community by JetBrains.

the class BlockTreeNode method update.

@Override
protected void update(PresentationData presentation) {
    String name = myBlock.getClass().getSimpleName();
    if (myBlock instanceof DataLanguageBlockWrapper) {
        name += " (" + ((DataLanguageBlockWrapper) myBlock).getOriginal().getClass().getSimpleName() + ")";
    }
    presentation.addText(name, SimpleTextAttributes.REGULAR_ATTRIBUTES);
    if (myBlock.getIndent() != null) {
        presentation.addText(" " + String.valueOf(myBlock.getIndent()).replaceAll("[<>]", " "), SimpleTextAttributes.GRAY_ATTRIBUTES);
    } else {
        presentation.addText(" Indent: null", SimpleTextAttributes.GRAY_ATTRIBUTES);
    }
    if (myBlock.getAlignment() != null) {
        float d = 1.f * System.identityHashCode(myBlock.getAlignment()) / Integer.MAX_VALUE;
        Color color = new JBColor(Color.HSBtoRGB(1.0f * d, .3f, .7f), Color.HSBtoRGB(1.0f * d, .3f, .8f));
        presentation.addText(" " + String.valueOf(myBlock.getAlignment()), new SimpleTextAttributes(SimpleTextAttributes.STYLE_BOLD, color));
    }
    if (myBlock.getWrap() != null) {
        presentation.addText(" " + String.valueOf(myBlock.getWrap()), new SimpleTextAttributes(SimpleTextAttributes.STYLE_ITALIC, PlatformColors.BLUE));
    }
}
Also used : JBColor(com.intellij.ui.JBColor) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) JBColor(com.intellij.ui.JBColor) DataLanguageBlockWrapper(com.intellij.formatting.templateLanguages.DataLanguageBlockWrapper)

Example 2 with DataLanguageBlockWrapper

use of com.intellij.formatting.templateLanguages.DataLanguageBlockWrapper in project intellij-plugins by JetBrains.

the class CfmlBlock method getChildAttributes.

@NotNull
@Override
public ChildAttributes getChildAttributes(int newChildIndex) {
    List<Block> childBlockList = getSubBlocks();
    if (newChildIndex > 0 && newChildIndex - 1 < childBlockList.size()) {
        ASTBlock prevBlock = (ASTBlock) childBlockList.get(newChildIndex - 1);
        if (prevBlock != null) {
            Indent indent;
            Alignment alignment = myAlignmentProcessor.createChildAlignment();
            ASTNode prevNode = prevBlock.getNode();
            if (prevNode != null) {
                PsiElement prevTreePsiElement = prevNode.getTreePrev() != null ? prevNode.getTreePrev().getPsi() : null;
                IElementType prevBlockType = prevNode.getElementType();
                if (prevBlockType == CfscriptTokenTypes.L_CURLYBRACKET) {
                    if (myNode.getElementType() == CfmlElementTypes.FUNCTION_DEFINITION && mySettings.METHOD_BRACE_STYLE == CommonCodeStyleSettings.NEXT_LINE_SHIFTED2) {
                        indent = Indent.getSpaceIndent(superSettings.getIndentSize(CfmlFileType.INSTANCE) * 2);
                    } else if (mySettings.BRACE_STYLE == CommonCodeStyleSettings.NEXT_LINE_SHIFTED2) {
                        indent = Indent.getSpaceIndent(superSettings.getIndentSize(CfmlFileType.INSTANCE) * 2);
                    } else {
                        indent = Indent.getNormalIndent();
                    }
                } else if (myNode.getElementType() == CfmlStubElementTypes.CFML_FILE) {
                    indent = Indent.getNoneIndent();
                } else if ((prevBlockType == CfmlTokenTypes.R_ANGLEBRACKET) && prevTreePsiElement != null && !prevTreePsiElement.getText().equalsIgnoreCase("cfscript")) {
                    indent = Indent.getNormalIndent();
                } else if ((prevBlockType == CfmlTokenTypes.CLOSER) && prevTreePsiElement != null && !prevTreePsiElement.getText().equalsIgnoreCase("cfscript")) {
                    indent = null;
                } else if (prevBlockType == CfmlElementTypes.TAG || prevBlockType == CfmlElementTypes.ARGUMENT_TAG || prevBlockType == CfmlElementTypes.COMPONENT_TAG || prevBlockType == CfmlElementTypes.FUNCTION_TAG || prevBlockType == CfmlElementTypes.SCRIPT_TAG) {
                    indent = Indent.getNormalIndent();
                } else if (prevBlockType == CfmlTokenTypes.COMMENT || prevBlockType == CfmlElementTypes.TEMPLATE_TEXT) {
                    //getChildAttributes(newChildIndex - 1).getChildIndent();
                    indent = prevBlock.getIndent();
                } else {
                    indent = Indent.getNormalIndent();
                }
            } else {
                indent = ((DataLanguageBlockWrapper) prevBlock).getOriginal().getIndent();
            }
            return new ChildAttributes(indent, alignment);
        }
    }
    return super.getChildAttributes(newChildIndex);
}
Also used : IElementType(com.intellij.psi.tree.IElementType) ASTNode(com.intellij.lang.ASTNode) TemplateLanguageBlock(com.intellij.formatting.templateLanguages.TemplateLanguageBlock) PsiElement(com.intellij.psi.PsiElement) DataLanguageBlockWrapper(com.intellij.formatting.templateLanguages.DataLanguageBlockWrapper) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

DataLanguageBlockWrapper (com.intellij.formatting.templateLanguages.DataLanguageBlockWrapper)2 TemplateLanguageBlock (com.intellij.formatting.templateLanguages.TemplateLanguageBlock)1 ASTNode (com.intellij.lang.ASTNode)1 PsiElement (com.intellij.psi.PsiElement)1 IElementType (com.intellij.psi.tree.IElementType)1 JBColor (com.intellij.ui.JBColor)1 SimpleTextAttributes (com.intellij.ui.SimpleTextAttributes)1 NotNull (org.jetbrains.annotations.NotNull)1