Search in sources :

Example 1 with PsiBasedFormattingModel

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

Aggregations

DocumentImpl (com.intellij.openapi.editor.impl.DocumentImpl)1 PsiFile (com.intellij.psi.PsiFile)1 FormattingDocumentModelImpl (com.intellij.psi.formatter.FormattingDocumentModelImpl)1 PsiBasedFormattingModel (com.intellij.psi.formatter.PsiBasedFormattingModel)1 NotNull (org.jetbrains.annotations.NotNull)1