Search in sources :

Example 1 with FormattingDocumentModelImpl

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

the class XmlFormattingModelBuilder method createModel.

@Override
@NotNull
public FormattingModel createModel(final PsiElement element, final CodeStyleSettings settings) {
    final ASTNode root = TreeUtil.getFileElement((TreeElement) SourceTreeToPsiMap.psiElementToTree(element));
    final FormattingDocumentModelImpl documentModel = FormattingDocumentModelImpl.createOn(element.getContainingFile());
    return new XmlFormattingModel(element.getContainingFile(), createBlock(settings, root, documentModel), documentModel);
}
Also used : ASTNode(com.intellij.lang.ASTNode) FormattingDocumentModelImpl(com.intellij.psi.formatter.FormattingDocumentModelImpl) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with FormattingDocumentModelImpl

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

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

the class RangesAssert method assertInvalidRanges.

public void assertInvalidRanges(final int startOffset, final int newEndOffset, FormattingDocumentModel model, String message) {
    final StringBuilder buffer = new StringBuilder();
    buffer.append("Invalid formatting blocks:").append(message).append("\n");
    buffer.append("Start offset:");
    buffer.append(startOffset);
    buffer.append(" end offset:");
    buffer.append(newEndOffset);
    buffer.append("\n");
    int minOffset = Math.max(Math.min(startOffset, newEndOffset) - 20, 0);
    int maxOffset = Math.min(Math.max(startOffset, newEndOffset) + 20, model.getTextLength());
    buffer.append("Affected text fragment:[").append(minOffset).append(",").append(maxOffset).append("] - '").append(model.getText(new TextRange(minOffset, maxOffset))).append("'\n");
    final StringBuilder messageBuffer = new StringBuilder();
    messageBuffer.append("Invalid ranges during formatting");
    if (model instanceof FormattingDocumentModelImpl) {
        messageBuffer.append(" in ").append(((FormattingDocumentModelImpl) model).getFile().getLanguage());
    }
    buffer.append("File text:(").append(model.getTextLength()).append(")\n'");
    buffer.append(model.getText(new TextRange(0, model.getTextLength())).toString());
    buffer.append("'\n");
    buffer.append("model (").append(model.getClass()).append("): ").append(model);
    Throwable currentThrowable = new Throwable();
    if (model instanceof FormattingDocumentModelImpl) {
        final FormattingDocumentModelImpl modelImpl = (FormattingDocumentModelImpl) model;
        buffer.append("Psi Tree:\n");
        final PsiFile file = modelImpl.getFile();
        final List<PsiFile> roots = file.getViewProvider().getAllFiles();
        for (PsiFile root : roots) {
            buffer.append("Root ");
            DebugUtil.treeToBuffer(buffer, root.getNode(), 0, false, true, true, true);
        }
        buffer.append('\n');
        currentThrowable = makeLanguageStackTrace(currentThrowable, file);
    }
    LogMessageEx.error(LOG, messageBuffer.toString(), currentThrowable, buffer.toString());
}
Also used : TextRange(com.intellij.openapi.util.TextRange) PsiFile(com.intellij.psi.PsiFile) FormattingDocumentModelImpl(com.intellij.psi.formatter.FormattingDocumentModelImpl)

Example 4 with FormattingDocumentModelImpl

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

the class JavaFormattingModelBuilder method createModel.

@Override
@NotNull
public FormattingModel createModel(final PsiElement element, final CodeStyleSettings settings) {
    final FileElement fileElement = TreeUtil.getFileElement((TreeElement) SourceTreeToPsiMap.psiElementToTree(element));
    LOG.assertTrue(fileElement != null, "File element should not be null for " + element);
    CommonCodeStyleSettings commonSettings = settings.getCommonSettings(JavaLanguage.INSTANCE);
    JavaCodeStyleSettings customJavaSettings = settings.getCustomSettings(JavaCodeStyleSettings.class);
    Block block = AbstractJavaBlock.newJavaBlock(fileElement, commonSettings, customJavaSettings);
    FormattingDocumentModelImpl model = FormattingDocumentModelImpl.createOn(element.getContainingFile());
    return new PsiBasedFormatterModelWithShiftIndentInside(element.getContainingFile(), block, model);
}
Also used : CommonCodeStyleSettings(com.intellij.psi.codeStyle.CommonCodeStyleSettings) FileElement(com.intellij.psi.impl.source.tree.FileElement) Block(com.intellij.formatting.Block) AbstractJavaBlock(com.intellij.psi.formatter.java.AbstractJavaBlock) JavaCodeStyleSettings(com.intellij.psi.codeStyle.JavaCodeStyleSettings) FormattingDocumentModelImpl(com.intellij.psi.formatter.FormattingDocumentModelImpl) PsiBasedFormatterModelWithShiftIndentInside(com.intellij.psi.impl.source.codeStyle.PsiBasedFormatterModelWithShiftIndentInside) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with FormattingDocumentModelImpl

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

the class PropertiesFormattingModelBuilder method createModel.

@NotNull
@Override
public PropertiesFormattingModel createModel(PsiElement element, CodeStyleSettings settings) {
    final ASTNode root = TreeUtil.getFileElement((TreeElement) SourceTreeToPsiMap.psiElementToTree(element));
    final FormattingDocumentModelImpl documentModel = FormattingDocumentModelImpl.createOn(element.getContainingFile());
    return new PropertiesFormattingModel(root, documentModel, settings);
}
Also used : ASTNode(com.intellij.lang.ASTNode) FormattingDocumentModelImpl(com.intellij.psi.formatter.FormattingDocumentModelImpl) NotNull(org.jetbrains.annotations.NotNull)

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