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;
}
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);
}
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);
}
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);
}
Aggregations