Search in sources :

Example 1 with XmlBlock

use of com.intellij.psi.formatter.xml.XmlBlock in project intellij-community by JetBrains.

the class HtmlFormattingModelBuilder method createModel.

@Override
@NotNull
public FormattingModel createModel(final PsiElement element, final CodeStyleSettings settings) {
    final PsiFile psiFile = element.getContainingFile();
    final FormattingDocumentModelImpl documentModel = FormattingDocumentModelImpl.createOn(psiFile);
    return new XmlFormattingModel(psiFile, new XmlBlock(SourceTreeToPsiMap.psiElementToTree(psiFile), null, null, new HtmlPolicy(settings, documentModel), null, null, false), documentModel);
}
Also used : HtmlPolicy(com.intellij.psi.formatter.xml.HtmlPolicy) XmlBlock(com.intellij.psi.formatter.xml.XmlBlock) PsiFile(com.intellij.psi.PsiFile) XmlFormattingModel(com.intellij.lang.xml.XmlFormattingModel) FormattingDocumentModelImpl(com.intellij.psi.formatter.FormattingDocumentModelImpl) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with XmlBlock

use of com.intellij.psi.formatter.xml.XmlBlock in project android by JetBrains.

the class AndroidXmlFormattingModelBuilder method createDelegatingBlock.

private static Block createDelegatingBlock(FormattingModel model, AndroidXmlCodeStyleSettings.MySettings customSettings, CodeStyleSettings settings) {
    final Block block = model.getRootBlock();
    if (block instanceof XmlBlock) {
        final XmlBlock b = (XmlBlock) block;
        final XmlPolicy policy = customSettings.createXmlPolicy(settings, model.getDocumentModel());
        return new XmlBlock(b.getNode(), b.getWrap(), b.getAlignment(), policy, b.getIndent(), b.getTextRange()) {

            @Override
            protected XmlTagBlock createTagBlock(ASTNode child, Indent indent, Wrap wrap, Alignment alignment) {
                return new XmlTagBlock(child, wrap, alignment, myXmlFormattingPolicy, indent != null ? indent : Indent.getNoneIndent(), isPreserveSpace());
            }
        };
    } else {
        return block;
    }
}
Also used : XmlPolicy(com.intellij.psi.formatter.xml.XmlPolicy) XmlTagBlock(com.intellij.psi.formatter.xml.XmlTagBlock) XmlBlock(com.intellij.psi.formatter.xml.XmlBlock) ASTNode(com.intellij.lang.ASTNode) XmlTagBlock(com.intellij.psi.formatter.xml.XmlTagBlock) XmlBlock(com.intellij.psi.formatter.xml.XmlBlock)

Example 3 with XmlBlock

use of com.intellij.psi.formatter.xml.XmlBlock in project intellij-community by JetBrains.

the class XsltFormattingModelBuilder method getDelegatingBlock.

static Block getDelegatingBlock(final CodeStyleSettings settings, FormattingModel baseModel) {
    final Block block = baseModel.getRootBlock();
    if (block instanceof XmlBlock) {
        final XmlBlock xmlBlock = (XmlBlock) block;
        final XmlPolicy xmlPolicy = new XmlPolicy(settings, baseModel.getDocumentModel()) {

            @Override
            public boolean keepWhiteSpacesInsideTag(XmlTag xmlTag) {
                return super.keepWhiteSpacesInsideTag(xmlTag) || isXslTextTag(xmlTag);
            }

            @Override
            public boolean isTextElement(XmlTag tag) {
                return super.isTextElement(tag) || isXslTextTag(tag) || isXslValueOfTag(tag);
            }
        };
        final ASTNode node = xmlBlock.getNode();
        final Wrap wrap = xmlBlock.getWrap();
        final Alignment alignment = xmlBlock.getAlignment();
        final Indent indent = xmlBlock.getIndent();
        final TextRange textRange = xmlBlock.getTextRange();
        return new XmlBlock(node, wrap, alignment, xmlPolicy, indent, textRange);
    } else {
        return block;
    }
}
Also used : XmlPolicy(com.intellij.psi.formatter.xml.XmlPolicy) XmlBlock(com.intellij.psi.formatter.xml.XmlBlock) ASTNode(com.intellij.lang.ASTNode) XmlBlock(com.intellij.psi.formatter.xml.XmlBlock) TextRange(com.intellij.openapi.util.TextRange) XmlTag(com.intellij.psi.xml.XmlTag)

Example 4 with XmlBlock

use of com.intellij.psi.formatter.xml.XmlBlock in project intellij-community by JetBrains.

the class XhtmlFormattingModelBuilder method createModel.

@Override
@NotNull
public FormattingModel createModel(final PsiElement element, final CodeStyleSettings settings) {
    final PsiFile psiFile = element.getContainingFile();
    final FormattingDocumentModelImpl documentModel = FormattingDocumentModelImpl.createOn(psiFile);
    return new XmlFormattingModel(psiFile, new XmlBlock(SourceTreeToPsiMap.psiElementToTree(psiFile), null, null, new HtmlPolicy(settings, documentModel), null, null, false), documentModel);
}
Also used : HtmlPolicy(com.intellij.psi.formatter.xml.HtmlPolicy) XmlBlock(com.intellij.psi.formatter.xml.XmlBlock) PsiFile(com.intellij.psi.PsiFile) XmlFormattingModel(com.intellij.lang.xml.XmlFormattingModel) FormattingDocumentModelImpl(com.intellij.psi.formatter.FormattingDocumentModelImpl) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

XmlBlock (com.intellij.psi.formatter.xml.XmlBlock)4 ASTNode (com.intellij.lang.ASTNode)2 XmlFormattingModel (com.intellij.lang.xml.XmlFormattingModel)2 PsiFile (com.intellij.psi.PsiFile)2 FormattingDocumentModelImpl (com.intellij.psi.formatter.FormattingDocumentModelImpl)2 HtmlPolicy (com.intellij.psi.formatter.xml.HtmlPolicy)2 XmlPolicy (com.intellij.psi.formatter.xml.XmlPolicy)2 NotNull (org.jetbrains.annotations.NotNull)2 TextRange (com.intellij.openapi.util.TextRange)1 XmlTagBlock (com.intellij.psi.formatter.xml.XmlTagBlock)1 XmlTag (com.intellij.psi.xml.XmlTag)1