Search in sources :

Example 1 with NewLineBlocksIterator

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

the class NewLineBlocksIteratorTest method testFirstBlockOnNewLineNotStartsIt.

public void testFirstBlockOnNewLineNotStartsIt() throws IOException, JDOMException {
    String text = "[]varx []=r'''\n" + "'''";
    TestData data = FormatterEngineTestsKt.extractFormattingTestData(text);
    Document document = EditorFactory.getInstance().createDocument(data.getTextToFormat());
    NewLineBlocksIterator iterator = new NewLineBlocksIterator(data.getRootBlock(), document);
    checkStartOffsets(new int[] { 0 }, iterator);
}
Also used : TestData(com.intellij.formatting.engine.TestData) Document(com.intellij.openapi.editor.Document) NewLineBlocksIterator(com.intellij.psi.formatter.common.NewLineBlocksIterator)

Example 2 with NewLineBlocksIterator

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

the class AbstractNewLineBlocksIteratorTest method newLineBlockIterator.

@NotNull
protected static Iterator<Block> newLineBlockIterator() {
    FormattingModelBuilder builder = LanguageFormatting.INSTANCE.forContext(myFile);
    Assert.assertNotNull(builder);
    CodeStyleSettings settings = CodeStyleSettingsManager.getInstance(getProject()).getCurrentSettings();
    FormattingModel model = builder.createModel(myFile, settings);
    Block root = model.getRootBlock();
    Document document = PsiDocumentManager.getInstance(getProject()).getDocument(myFile);
    Assert.assertNotNull(document);
    return new NewLineBlocksIterator(root, document);
}
Also used : FormattingModel(com.intellij.formatting.FormattingModel) CodeStyleSettings(com.intellij.psi.codeStyle.CodeStyleSettings) FormattingModelBuilder(com.intellij.formatting.FormattingModelBuilder) Block(com.intellij.formatting.Block) Document(com.intellij.openapi.editor.Document) NewLineBlocksIterator(com.intellij.psi.formatter.common.NewLineBlocksIterator) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with NewLineBlocksIterator

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

the class FormatterBasedLineIndentInfoBuilder method getBlocksStartingNewLine.

@NotNull
private List<Block> getBlocksStartingNewLine() {
    NewLineBlocksIterator newLineBlocksIterator = new NewLineBlocksIterator(myRootBlock, myDocument, myProgressIndicator);
    List<Block> newLineBlocks = new ArrayList<>();
    int currentLine = 0;
    while (newLineBlocksIterator.hasNext() && currentLine < MAX_NEW_LINE_BLOCKS_TO_PROCESS) {
        Block next = newLineBlocksIterator.next();
        if (next instanceof ASTBlock && ((ASTBlock) next).getNode() instanceof PsiComment) {
            continue;
        }
        newLineBlocks.add(next);
        currentLine++;
    }
    return newLineBlocks;
}
Also used : PsiComment(com.intellij.psi.PsiComment) ASTBlock(com.intellij.formatting.ASTBlock) ArrayList(java.util.ArrayList) AbstractBlock(com.intellij.psi.formatter.common.AbstractBlock) ASTBlock(com.intellij.formatting.ASTBlock) Block(com.intellij.formatting.Block) NewLineBlocksIterator(com.intellij.psi.formatter.common.NewLineBlocksIterator) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

NewLineBlocksIterator (com.intellij.psi.formatter.common.NewLineBlocksIterator)3 Block (com.intellij.formatting.Block)2 Document (com.intellij.openapi.editor.Document)2 NotNull (org.jetbrains.annotations.NotNull)2 ASTBlock (com.intellij.formatting.ASTBlock)1 FormattingModel (com.intellij.formatting.FormattingModel)1 FormattingModelBuilder (com.intellij.formatting.FormattingModelBuilder)1 TestData (com.intellij.formatting.engine.TestData)1 PsiComment (com.intellij.psi.PsiComment)1 CodeStyleSettings (com.intellij.psi.codeStyle.CodeStyleSettings)1 AbstractBlock (com.intellij.psi.formatter.common.AbstractBlock)1 ArrayList (java.util.ArrayList)1