Search in sources :

Example 1 with DocumentImpl

use of com.intellij.openapi.editor.impl.DocumentImpl in project kotlin by JetBrains.

the class AbstractFormatterTest method doTextTest.

public void doTextTest(final Action action, final String text, File fileAfter, String extension) throws IncorrectOperationException {
    final PsiFile file = createFile("A" + extension, text);
    if (myLineRange != null) {
        DocumentImpl document = new DocumentImpl(text);
        myTextRange = new TextRange(document.getLineStartOffset(myLineRange.getStartOffset()), document.getLineEndOffset(myLineRange.getEndOffset()));
    }
    final PsiDocumentManager manager = PsiDocumentManager.getInstance(getProject());
    final Document document = manager.getDocument(file);
    CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() {

        @Override
        public void run() {
            ApplicationManager.getApplication().runWriteAction(new Runnable() {

                @Override
                public void run() {
                    document.replaceString(0, document.getTextLength(), text);
                    manager.commitDocument(document);
                    try {
                        TextRange rangeToUse = myTextRange;
                        if (rangeToUse == null) {
                            rangeToUse = file.getTextRange();
                        }
                        ACTIONS.get(action).run(file, rangeToUse.getStartOffset(), rangeToUse.getEndOffset());
                    } catch (IncorrectOperationException e) {
                        assertTrue(e.getLocalizedMessage(), false);
                    }
                }
            });
        }
    }, "", "");
    if (document == null) {
        fail("Don't expect the document to be null");
        return;
    }
    KotlinTestUtils.assertEqualsToFile(fileAfter, document.getText());
    manager.commitDocument(document);
    KotlinTestUtils.assertEqualsToFile(fileAfter, file.getText());
}
Also used : PsiFile(com.intellij.psi.PsiFile) TextRange(com.intellij.openapi.util.TextRange) IncorrectOperationException(com.intellij.util.IncorrectOperationException) Document(com.intellij.openapi.editor.Document) DocumentImpl(com.intellij.openapi.editor.impl.DocumentImpl) PsiDocumentManager(com.intellij.psi.PsiDocumentManager)

Example 2 with DocumentImpl

use of com.intellij.openapi.editor.impl.DocumentImpl in project intellij-community by JetBrains.

the class EduAnswerPlaceholderPainter method createGuardedBlocks.

public static void createGuardedBlocks(@NotNull final Editor editor, AnswerPlaceholder placeholder) {
    Document document = editor.getDocument();
    if (document instanceof DocumentImpl) {
        DocumentImpl documentImpl = (DocumentImpl) document;
        List<RangeMarker> blocks = documentImpl.getGuardedBlocks();
        Pair<Integer, Integer> offsets = StudyUtils.getPlaceholderOffsets(placeholder, editor.getDocument());
        Integer start = offsets.first;
        Integer end = offsets.second;
        if (start != 0) {
            createGuardedBlock(editor, blocks, start - 1, start);
        }
        if (end != document.getTextLength()) {
            createGuardedBlock(editor, blocks, end, end + 1);
        }
    }
}
Also used : RangeMarker(com.intellij.openapi.editor.RangeMarker) Document(com.intellij.openapi.editor.Document) DocumentImpl(com.intellij.openapi.editor.impl.DocumentImpl)

Example 3 with DocumentImpl

use of com.intellij.openapi.editor.impl.DocumentImpl in project intellij-community by JetBrains.

the class SvnPropertiesDiffViewer method convertRequest.

//
// Initial step
//
@NotNull
private static Pair<WrapperRequest, List<DiffChange>> convertRequest(@NotNull SvnPropertiesDiffRequest request, boolean embedded) {
    List<PropertyRecord> records = collectRecords(request);
    StringBuilder builder1 = new StringBuilder();
    StringBuilder builder2 = new StringBuilder();
    List<DiffChange> diffChanges = new ArrayList<>();
    int totalLines = 0;
    for (PropertyRecord record : records) {
        int start = totalLines;
        String before = StringUtil.notNullize(record.getBefore());
        String after = StringUtil.notNullize(record.getAfter());
        builder1.append(before);
        builder2.append(after);
        int lines1 = StringUtil.countNewLines(before);
        int lines2 = StringUtil.countNewLines(after);
        int appendedLines = Math.max(lines1, lines2) + 1;
        totalLines += appendedLines;
        for (int i = lines1; i < appendedLines; i++) {
            builder1.append('\n');
        }
        for (int i = lines2; i < appendedLines; i++) {
            builder2.append('\n');
        }
        diffChanges.add(new DiffChange(record, start, totalLines, start, totalLines));
    }
    Document document1 = new DocumentImpl(builder1);
    Document document2 = new DocumentImpl(builder2);
    return Pair.create(new WrapperRequest(request, document1, document2, embedded), diffChanges);
}
Also used : ArrayList(java.util.ArrayList) Document(com.intellij.openapi.editor.Document) DocumentImpl(com.intellij.openapi.editor.impl.DocumentImpl) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with DocumentImpl

use of com.intellij.openapi.editor.impl.DocumentImpl in project intellij-community by JetBrains.

the class PsiDocumentManagerBase method getLastCommittedDocument.

@NotNull
public DocumentEx getLastCommittedDocument(@NotNull Document document) {
    if (document instanceof FrozenDocument)
        return (DocumentEx) document;
    if (document instanceof DocumentWindow) {
        DocumentWindow window = (DocumentWindow) document;
        Document delegate = window.getDelegate();
        if (delegate instanceof FrozenDocument)
            return (DocumentEx) window;
        if (!window.isValid()) {
            throw new AssertionError("host committed: " + isCommitted(delegate) + ", window=" + window);
        }
        UncommittedInfo info = myUncommittedInfos.get(delegate);
        DocumentWindow answer = info == null ? null : info.myFrozenWindows.get(document);
        if (answer == null)
            answer = freezeWindow(window);
        if (info != null)
            answer = ConcurrencyUtil.cacheOrGet(info.myFrozenWindows, window, answer);
        return (DocumentEx) answer;
    }
    assert document instanceof DocumentImpl;
    UncommittedInfo info = myUncommittedInfos.get(document);
    return info != null ? info.myFrozen : ((DocumentImpl) document).freeze();
}
Also used : DocumentWindow(com.intellij.injected.editor.DocumentWindow) DocumentEx(com.intellij.openapi.editor.ex.DocumentEx) FrozenDocument(com.intellij.openapi.editor.impl.FrozenDocument) Document(com.intellij.openapi.editor.Document) FrozenDocument(com.intellij.openapi.editor.impl.FrozenDocument) DocumentImpl(com.intellij.openapi.editor.impl.DocumentImpl) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with DocumentImpl

use of com.intellij.openapi.editor.impl.DocumentImpl in project intellij-community by JetBrains.

the class PsiDocumentManagerBase method beforeDocumentChange.

@Override
public void beforeDocumentChange(@NotNull DocumentEvent event) {
    if (myStopTrackingDocuments || myProject.isDisposed())
        return;
    final Document document = event.getDocument();
    VirtualFile virtualFile = FileDocumentManager.getInstance().getFile(document);
    boolean isRelevant = virtualFile != null && isRelevant(virtualFile);
    if (document instanceof DocumentImpl && !myUncommittedInfos.containsKey(document)) {
        myUncommittedInfos.put(document, new UncommittedInfo((DocumentImpl) document));
    }
    final FileViewProvider viewProvider = getCachedViewProvider(document);
    boolean inMyProject = viewProvider != null && viewProvider.getManager() == myPsiManager;
    if (!isRelevant || !inMyProject) {
        return;
    }
    final List<PsiFile> files = viewProvider.getAllFiles();
    PsiFile psiCause = null;
    for (PsiFile file : files) {
        if (file == null) {
            throw new AssertionError("View provider " + viewProvider + " (" + viewProvider.getClass() + ") returned null in its files array: " + files + " for file " + viewProvider.getVirtualFile());
        }
        if (PsiToDocumentSynchronizer.isInsideAtomicChange(file)) {
            psiCause = file;
        }
    }
    if (psiCause == null) {
        beforeDocumentChangeOnUnlockedDocument(viewProvider);
    }
    ((SingleRootFileViewProvider) viewProvider).beforeDocumentChanged(psiCause);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Document(com.intellij.openapi.editor.Document) FrozenDocument(com.intellij.openapi.editor.impl.FrozenDocument) DocumentImpl(com.intellij.openapi.editor.impl.DocumentImpl)

Aggregations

DocumentImpl (com.intellij.openapi.editor.impl.DocumentImpl)32 Document (com.intellij.openapi.editor.Document)13 NotNull (org.jetbrains.annotations.NotNull)6 RangeMarker (com.intellij.openapi.editor.RangeMarker)4 TextRange (com.intellij.openapi.util.TextRange)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 PsiFile (com.intellij.psi.PsiFile)3 EditorEx (com.intellij.openapi.editor.ex.EditorEx)2 FrozenDocument (com.intellij.openapi.editor.impl.FrozenDocument)2 Project (com.intellij.openapi.project.Project)2 PsiDocumentManager (com.intellij.psi.PsiDocumentManager)2 FileComparisonFailure (com.intellij.rt.execution.junit.FileComparisonFailure)2 RelativePoint (com.intellij.ui.awt.RelativePoint)2 IncorrectOperationException (com.intellij.util.IncorrectOperationException)2 ArrayList (java.util.ArrayList)2 CloudLineBreakpointType (com.google.cloud.tools.intellij.debugger.CloudLineBreakpointType)1 InlayInfo (com.intellij.codeInsight.hints.InlayInfo)1 Breakpoint (com.intellij.debugger.ui.breakpoints.Breakpoint)1 ResultItem (com.intellij.execution.filters.Filter.ResultItem)1 HyperlinkInfo (com.intellij.execution.filters.HyperlinkInfo)1