Search in sources :

Example 6 with DocumentEx

use of com.intellij.openapi.editor.ex.DocumentEx in project intellij-community by JetBrains.

the class InjectedPsiCachedValueProvider method compute.

@Override
public CachedValueProvider.Result<MultiHostRegistrarImpl> compute(PsiElement element) {
    PsiFile hostPsiFile = element.getContainingFile();
    if (hostPsiFile == null)
        return null;
    FileViewProvider viewProvider = hostPsiFile.getViewProvider();
    final DocumentEx hostDocument = (DocumentEx) viewProvider.getDocument();
    if (hostDocument == null)
        return null;
    PsiManager psiManager = viewProvider.getManager();
    final Project project = psiManager.getProject();
    InjectedLanguageManagerImpl injectedManager = InjectedLanguageManagerImpl.getInstanceImpl(project);
    final MultiHostRegistrarImpl result = doCompute(element, injectedManager, project, hostPsiFile);
    return CachedValueProvider.Result.create(result, PsiModificationTracker.MODIFICATION_COUNT, hostDocument);
}
Also used : DocumentEx(com.intellij.openapi.editor.ex.DocumentEx) Project(com.intellij.openapi.project.Project) FileViewProvider(com.intellij.psi.FileViewProvider) PsiManager(com.intellij.psi.PsiManager) PsiFile(com.intellij.psi.PsiFile)

Example 7 with DocumentEx

use of com.intellij.openapi.editor.ex.DocumentEx in project intellij-community by JetBrains.

the class PersistentRangeHighlighterImpl method translatedViaDiff.

private boolean translatedViaDiff(DocumentEvent e, DocumentEventImpl event) {
    try {
        myLine = event.translateLineViaDiff(myLine);
    } catch (FilesTooBigForDiffException ignored) {
        return false;
    }
    if (myLine < 0 || myLine >= getDocument().getLineCount()) {
        invalidate(e);
    } else {
        DocumentEx document = getDocument();
        setIntervalStart(document.getLineStartOffset(myLine));
        setIntervalEnd(document.getLineEndOffset(myLine));
    }
    return true;
}
Also used : DocumentEx(com.intellij.openapi.editor.ex.DocumentEx) FilesTooBigForDiffException(com.intellij.util.diff.FilesTooBigForDiffException)

Example 8 with DocumentEx

use of com.intellij.openapi.editor.ex.DocumentEx in project intellij-community by JetBrains.

the class FoldingModelSupport method getFoldedRanges.

@NotNull
private List<FoldedRangeState> getFoldedRanges(int index, @NotNull Settings settings) {
    ApplicationManager.getApplication().assertReadAccessAllowed();
    List<FoldedRangeState> ranges = new ArrayList<>();
    DocumentEx document = myEditors[index].getDocument();
    for (FoldedBlock[] blocks : myFoldings) {
        LineRange expanded = null;
        LineRange collapsed = null;
        for (FoldedBlock folding : blocks) {
            FoldRegion region = folding.getRegion(index);
            if (region == null || !region.isValid())
                continue;
            if (region.isExpanded()) {
                if (expanded == null) {
                    int line1 = document.getLineNumber(region.getStartOffset());
                    int line2 = document.getLineNumber(region.getEndOffset()) + 1;
                    expanded = new LineRange(line1, line2);
                }
            } else {
                int line1 = document.getLineNumber(region.getStartOffset());
                int line2 = document.getLineNumber(region.getEndOffset()) + 1;
                collapsed = new LineRange(line1, line2);
                break;
            }
        }
        if (expanded != null || collapsed != null) {
            ranges.add(new FoldedRangeState(expanded, collapsed));
        }
    }
    return ranges;
}
Also used : DocumentEx(com.intellij.openapi.editor.ex.DocumentEx) ArrayList(java.util.ArrayList) FoldRegion(com.intellij.openapi.editor.FoldRegion) LineRange(com.intellij.diff.util.LineRange) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with DocumentEx

use of com.intellij.openapi.editor.ex.DocumentEx in project intellij-community by JetBrains.

the class SmartPsiElementPointersTest method testMoveText.

public void testMoveText() {
    PsiJavaFile file = (PsiJavaFile) configureByText(JavaFileType.INSTANCE, "class C1{}\nclass C2 {}");
    DocumentEx document = (DocumentEx) file.getViewProvider().getDocument();
    SmartPsiElementPointer<PsiClass> pointer1 = createPointer(file.getClasses()[0]);
    SmartPsiElementPointer<PsiClass> pointer2 = createPointer(file.getClasses()[1]);
    assertEquals("C1", pointer1.getElement().getName());
    assertEquals("C2", pointer2.getElement().getName());
    PlatformTestUtil.tryGcSoftlyReachableObjects();
    assertNull(((SmartPointerEx) pointer1).getCachedElement());
    assertNull(((SmartPointerEx) pointer2).getCachedElement());
    TextRange range = file.getClasses()[1].getTextRange();
    ApplicationManager.getApplication().runWriteAction(() -> document.moveText(range.getStartOffset(), range.getEndOffset(), 0));
    PsiDocumentManager.getInstance(myProject).commitAllDocuments();
    assertEquals("C1", pointer1.getElement().getName());
    assertEquals("C2", pointer2.getElement().getName());
}
Also used : DocumentEx(com.intellij.openapi.editor.ex.DocumentEx) TextRange(com.intellij.openapi.util.TextRange)

Example 10 with DocumentEx

use of com.intellij.openapi.editor.ex.DocumentEx 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)

Aggregations

DocumentEx (com.intellij.openapi.editor.ex.DocumentEx)87 Document (com.intellij.openapi.editor.Document)12 NotNull (org.jetbrains.annotations.NotNull)8 RangeMarkerEx (com.intellij.openapi.editor.ex.RangeMarkerEx)7 Project (com.intellij.openapi.project.Project)7 TextRange (com.intellij.openapi.util.TextRange)7 LightVirtualFile (com.intellij.testFramework.LightVirtualFile)7 PsiFile (com.intellij.psi.PsiFile)6 Nullable (org.jetbrains.annotations.Nullable)5 EditorEx (com.intellij.openapi.editor.ex.EditorEx)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 MockVirtualFile (com.intellij.mock.MockVirtualFile)3 FoldRegion (com.intellij.openapi.editor.FoldRegion)3 PsiDocumentManager (com.intellij.psi.PsiDocumentManager)3 DocumentWindow (com.intellij.injected.editor.DocumentWindow)2 DocumentBulkUpdateListener (com.intellij.openapi.editor.ex.DocumentBulkUpdateListener)2 DocumentImpl (com.intellij.openapi.editor.impl.DocumentImpl)2 DocumentMarkupModel (com.intellij.openapi.editor.impl.DocumentMarkupModel)2 RangeHighlighter (com.intellij.openapi.editor.markup.RangeHighlighter)2 FileDocumentManagerAdapter (com.intellij.openapi.fileEditor.FileDocumentManagerAdapter)2