Search in sources :

Example 6 with FormattingDocumentModelImpl

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

the class WhiteSpace method coveredByBlock.

/**
   * Allows to check if {@code 'myInitial'} property value stands for continuous white space text.
   * <p/>
   * The text is considered to be continuous {@code 'white space'} at following cases:
   * <ul>
   *   <li>{@code 'myInitial'} is empty string or string that contains white spaces only;</li>
   *   <li>{@code 'myInitial'} is a {@code CDATA} string which content is empty or consists from white spaces only;</li>
   *   <li>{@code 'myInitial'} string belongs to the same {@link PsiWhiteSpace} element;</li>
   * </ul>
   *
   * @param model     formatting model that is used to provide access to the {@code PSI API} if necessary
   * @return          {@code true} if {@code 'myInitial'} property value stands for white space;
   *                  {@code false} otherwise
   */
private boolean coveredByBlock(final FormattingDocumentModel model) {
    if (myInitial == null)
        return true;
    if (model.containsWhiteSpaceSymbolsOnly(myStart, myEnd))
        return true;
    if (!(model instanceof FormattingDocumentModelImpl))
        return false;
    PsiFile psiFile = ((FormattingDocumentModelImpl) model).getFile();
    if (psiFile == null)
        return false;
    PsiElement start = psiFile.findElementAt(myStart);
    PsiElement end = psiFile.findElementAt(myEnd - 1);
    // there maybe non-white text inside CDATA-encoded injected elements
    return start == end && start instanceof PsiWhiteSpace;
}
Also used : PsiFile(com.intellij.psi.PsiFile) FormattingDocumentModelImpl(com.intellij.psi.formatter.FormattingDocumentModelImpl) PsiElement(com.intellij.psi.PsiElement) PsiWhiteSpace(com.intellij.psi.PsiWhiteSpace)

Example 7 with FormattingDocumentModelImpl

use of com.intellij.psi.formatter.FormattingDocumentModelImpl in project kotlin by JetBrains.

the class KotlinFormattingModelBuilder method createModel.

@NotNull
@Override
public FormattingModel createModel(PsiElement element, CodeStyleSettings settings) {
    PsiFile containingFile = element.getContainingFile().getViewProvider().getPsi(KotlinLanguage.INSTANCE);
    KotlinBlock block = new KotlinBlock(containingFile.getNode(), NodeAlignmentStrategy.getNullStrategy(), Indent.getNoneIndent(), null, settings, KotlinSpacingRulesKt.createSpacingBuilder(settings, KotlinSpacingBuilderUtilImpl.INSTANCE));
    // it's needed until IDEA's issue with this document being created with wrong threading policy is fixed
    if (!element.isPhysical()) {
        FormattingDocumentModelImpl formattingDocumentModel = new FormattingDocumentModelImpl(new DocumentImpl(containingFile.getViewProvider().getContents(), true), containingFile);
        return new PsiBasedFormattingModel(containingFile, block, formattingDocumentModel);
    }
    return FormattingModelProvider.createFormattingModelForPsiFile(element.getContainingFile(), block, settings);
}
Also used : PsiBasedFormattingModel(com.intellij.psi.formatter.PsiBasedFormattingModel) PsiFile(com.intellij.psi.PsiFile) FormattingDocumentModelImpl(com.intellij.psi.formatter.FormattingDocumentModelImpl) DocumentImpl(com.intellij.openapi.editor.impl.DocumentImpl) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with FormattingDocumentModelImpl

use of com.intellij.psi.formatter.FormattingDocumentModelImpl 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)

Example 9 with FormattingDocumentModelImpl

use of com.intellij.psi.formatter.FormattingDocumentModelImpl in project intellij-plugins by JetBrains.

the class HbFormattingModelBuilder method createTemplateLanguageBlock.

@Override
public TemplateLanguageBlock createTemplateLanguageBlock(@NotNull ASTNode node, @Nullable Wrap wrap, @Nullable Alignment alignment, @Nullable List<DataLanguageBlockWrapper> foreignChildren, @NotNull CodeStyleSettings codeStyleSettings) {
    final FormattingDocumentModelImpl documentModel = FormattingDocumentModelImpl.createOn(node.getPsi().getContainingFile());
    HtmlPolicy policy = new HtmlPolicy(codeStyleSettings, documentModel);
    return HbTokenTypes.TAGS.contains(node.getElementType()) ? new HandlebarsTagBlock(node, wrap, alignment, this, codeStyleSettings, foreignChildren, policy) : new HandlebarsBlock(node, wrap, alignment, this, codeStyleSettings, foreignChildren, policy);
}
Also used : HtmlPolicy(com.intellij.psi.formatter.xml.HtmlPolicy) FormattingDocumentModelImpl(com.intellij.psi.formatter.FormattingDocumentModelImpl)

Aggregations

FormattingDocumentModelImpl (com.intellij.psi.formatter.FormattingDocumentModelImpl)9 NotNull (org.jetbrains.annotations.NotNull)6 PsiFile (com.intellij.psi.PsiFile)5 HtmlPolicy (com.intellij.psi.formatter.xml.HtmlPolicy)3 ASTNode (com.intellij.lang.ASTNode)2 XmlFormattingModel (com.intellij.lang.xml.XmlFormattingModel)2 XmlBlock (com.intellij.psi.formatter.xml.XmlBlock)2 Block (com.intellij.formatting.Block)1 DocumentImpl (com.intellij.openapi.editor.impl.DocumentImpl)1 TextRange (com.intellij.openapi.util.TextRange)1 PsiElement (com.intellij.psi.PsiElement)1 PsiWhiteSpace (com.intellij.psi.PsiWhiteSpace)1 CommonCodeStyleSettings (com.intellij.psi.codeStyle.CommonCodeStyleSettings)1 JavaCodeStyleSettings (com.intellij.psi.codeStyle.JavaCodeStyleSettings)1 PsiBasedFormattingModel (com.intellij.psi.formatter.PsiBasedFormattingModel)1 AbstractJavaBlock (com.intellij.psi.formatter.java.AbstractJavaBlock)1 PsiBasedFormatterModelWithShiftIndentInside (com.intellij.psi.impl.source.codeStyle.PsiBasedFormatterModelWithShiftIndentInside)1 FileElement (com.intellij.psi.impl.source.tree.FileElement)1