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(); document.moveText(range.getStartOffset(), range.getEndOffset(), 0); System.out.println(pointer1.getRange()); System.out.println(pointer2.getRange()); PsiDocumentManager.getInstance(myProject).commitAllDocuments(); assertEquals("C1", pointer1.getElement().getName()); assertEquals("C2", pointer2.getElement().getName()); }
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; }
private void reinitDocumentIndentOptions() { if (myEditor == null) return; final Project project = myEditor.getProject(); final DocumentEx document = myEditor.getDocument(); if (project == null || project.isDisposed()) return; final PsiDocumentManager psiManager = PsiDocumentManager.getInstance(project); final PsiFile file = psiManager.getPsiFile(document); if (file == null) return; CodeStyleSettings settings = CodeStyleSettingsManager.getInstance(project).getCurrentSettings(); CommonCodeStyleSettings.IndentOptions options = settings.getIndentOptionsByFile(file); if (CodeStyleSettings.isRecalculateForCommittedDocument(options)) { PsiDocumentManager.getInstance(project).performForCommittedDocument(document, new Runnable() { @Override public void run() { CodeStyleSettingsManager.updateDocumentIndentOptions(project, document); } }); } else { CodeStyleSettingsManager.updateDocumentIndentOptions(project, document); } }
/** * Updates state of the current context object in order to point to the end of the given collapsed fold region. * * @param foldRegion collapsed fold region to process */ private void advance(FoldRegion foldRegion, int placeHolderWidthInPixels) { lastFoldStartPosition = currentPosition.clone(); lastFold = foldRegion; int visualLineBefore = currentPosition.visualLine; int logicalLineBefore = currentPosition.logicalLine; int logicalColumnBefore = currentPosition.logicalColumn; currentPosition.advance(foldRegion, -1); currentPosition.x += placeHolderWidthInPixels; int collapsedFoldingWidthInColumns = currentPosition.logicalColumn; if (currentPosition.logicalLine <= logicalLineBefore) { // Single-line fold region. collapsedFoldingWidthInColumns = currentPosition.logicalColumn - logicalColumnBefore; } else { final DocumentEx document = myEditor.getDocument(); int endFoldLine = document.getLineNumber(foldRegion.getEndOffset()); logicalLineData.endLineOffset = document.getLineEndOffset(endFoldLine); } notifyListenersOnFoldRegion(foldRegion, collapsedFoldingWidthInColumns, visualLineBefore); tokenStartOffset = myContext.currentPosition.offset; softWrapStartOffset = foldRegion.getEndOffset(); lastFoldEndPosition = currentPosition.clone(); }
public void testSaveDocument_DoNotSaveIfModStampEqualsToFile() throws Exception { final VirtualFile file = createFile(); final DocumentEx document = (DocumentEx)myDocumentManager.getDocument(file); assertNotNull(file.toString(), document); WriteCommandAction.runWriteCommandAction(myProject, new Runnable() { @Override public void run() { document.insertString(0, "zzz"); document.setModificationStamp(file.getModificationStamp()); } }); getProject().getMessageBus().connect(getTestRootDisposable()).subscribe(AppTopics.FILE_DOCUMENT_SYNC, new FileDocumentManagerAdapter() { @Override public void beforeDocumentSaving(@NotNull Document documentToSave) { assertNotSame(document, documentToSave); } }); myDocumentManager.saveDocument(document); }
public void testSuccessiveBulkModeOperations() throws Exception { initText("some text"); DocumentEx document = (DocumentEx)myEditor.getDocument(); document.setInBulkUpdate(true); document.replaceString(4, 5, "-"); document.setInBulkUpdate(false); myEditor.getCaretModel().moveToOffset(9); document.setInBulkUpdate(true); document.replaceString(4, 5, "+"); document.setInBulkUpdate(false); checkResultByText("some+text<caret>"); }
private RangeMarkerImpl(@NotNull DocumentEx document, int start, int end, boolean register, boolean greedyToLeft, boolean greedyToRight) { if (start < 0) { throw new IllegalArgumentException("Wrong start: " + start+"; end="+end); } if (end > document.getTextLength()) { throw new IllegalArgumentException("Wrong end: " + end+ "; document length="+document.getTextLength()+"; start="+start); } if (start > end){ throw new IllegalArgumentException("start > end: start=" + start+"; end="+end); } myDocument = document; myId = counter.next(); if (register) { registerInTree(start, end, greedyToLeft, greedyToRight, 0); } }
private void doSync(@NotNull final PsiTreeChangeEvent event, boolean force, @NotNull final DocSyncAction syncAction) { if (!toProcessPsiEvent()) return; final PsiFile psiFile = event.getFile(); if (!(psiFile instanceof PsiFileEx) || !((PsiFileEx)psiFile).isContentsLoaded()) return; final DocumentEx document = getCachedDocument(psiFile, force); if (document == null) return; performAtomically(psiFile, new Runnable() { @Override public void run() { syncAction.syncDocument(document, (PsiTreeChangeEventImpl)event); } }); final boolean insideTransaction = myTransactionsMap.containsKey(document); if (!insideTransaction) { document.setModificationStamp(psiFile.getViewProvider().getModificationStamp()); if (LOG.isDebugEnabled()) { PsiDocumentManagerBase.checkConsistency(psiFile, document); } } }
private static void doCommitTransaction(@NotNull Document document, @NotNull DocumentChangeTransaction documentChangeTransaction) { DocumentEx ex = (DocumentEx) document; ex.suppressGuardedExceptions(); try { boolean isReadOnly = !document.isWritable(); ex.setReadOnly(false); for (Map.Entry<TextRange, CharSequence> entry : documentChangeTransaction.myAffectedFragments.descendingMap().entrySet()) { ex.replaceString(entry.getKey().getStartOffset(), entry.getKey().getEndOffset(), entry.getValue()); } ex.setReadOnly(isReadOnly); } finally { ex.unSuppressGuardedExceptions(); } }
@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; 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(); }
private static Runnable rememberDocumentState(final Editor _editor) { final Editor editor = InjectedLanguageUtil.getTopLevelEditor(_editor); final String documentText = editor.getDocument().getText(); final int caret = editor.getCaretModel().getOffset(); final int selStart = editor.getSelectionModel().getSelectionStart(); final int selEnd = editor.getSelectionModel().getSelectionEnd(); final int vOffset = editor.getScrollingModel().getVerticalScrollOffset(); final int hOffset = editor.getScrollingModel().getHorizontalScrollOffset(); return new Runnable() { @Override public void run() { DocumentEx document = (DocumentEx) editor.getDocument(); document.replaceString(0, document.getTextLength(), documentText); editor.getCaretModel().moveToOffset(caret); editor.getSelectionModel().setSelection(selStart, selEnd); editor.getScrollingModel().scrollHorizontally(hOffset); editor.getScrollingModel().scrollVertically(vOffset); } }; }
private void updateStatus() { Editor editor = FileEditorManager.getInstance(myProject).getSelectedTextEditor(); if (editor == null || !editor.getContentComponent().hasFocus()){ return; } final Document document = editor.getDocument(); if (document instanceof DocumentEx && ((DocumentEx)document).isInBulkUpdate()) return; int offset = editor.getCaretModel().getOffset(); DaemonCodeAnalyzer codeAnalyzer = DaemonCodeAnalyzer.getInstance(myProject); HighlightInfo info = ((DaemonCodeAnalyzerImpl)codeAnalyzer).findHighlightByOffset(document, offset, false, HighlightSeverity.WARNING); String text = info != null && info.getDescription() != null ? info.getDescription() : ""; StatusBar statusBar = WindowManager.getInstance().getStatusBar(editor.getContentComponent(), myProject); if (statusBar != null && !text.equals(statusBar.getInfo())) { statusBar.setInfo(text, "updater"); } }
@Override public void documentChanged(DocumentEvent event) { DocumentEx document = getDocument(); if (document.isInBulkUpdate()) { return; } if (document.getTextLength() > 0) { addLineSeparatorPainterIfNeed(); int startDocLine = document.getLineNumber(event.getOffset()); int endDocLine = document.getLineNumber(event.getOffset() + event.getNewLength()); if (event.getOldLength() > event.getNewLength() || startDocLine != endDocLine || StringUtil.indexOf(event.getOldFragment(), '\n') != -1) { updateGutterSize(startDocLine, endDocLine); } } else if (event.getOldLength() > 0) { documentCleared(); } }
@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); }
@Override protected void setDone(boolean done) { super.setDone(done); if (myResetBulkUpdateState) { DocumentEx document = getAffectedDocument(myModel); if (document != null) { document.setInBulkUpdate(false); myResetBulkUpdateState = false; } } if (done) { myModel.commitChanges(); } }
protected void updateRawHtmlText(final String htmlTxt) { final DocumentEx myDocument = myTextViewer.getDocument(); if (project.isDisposed()) return; ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { if (project.isDisposed()) return; CommandProcessor.getInstance().executeCommand(project, new Runnable() { @Override public void run() { if (project.isDisposed()) return; myDocument.replaceString(0, myDocument.getTextLength(), htmlTxt); final CaretModel caretModel = myTextViewer.getCaretModel(); if (caretModel.getOffset() >= myDocument.getTextLength()) { caretModel.moveToOffset(myDocument.getTextLength()); } } }, null, null, UndoConfirmationPolicy.DEFAULT, myDocument); } }); }
public static SelectionDescription createSelection(final Editor editor, final int lineIndex) { return new SelectionDescription(editor) { public void select() { if(myIsActive) return; myIsActive = true; DocumentEx doc = (DocumentEx)editor.getDocument(); editor.getSelectionModel().setSelection( doc.getLineStartOffset(lineIndex), doc.getLineEndOffset(lineIndex) + doc.getLineSeparatorLength(lineIndex) ); } public void remove() { if(!myIsActive) return; myIsActive = false; myEditor.getSelectionModel().removeSelection(); } }; }
public EditorChangeAction(DocumentEx document, int offset, CharSequence oldString, CharSequence newString, long oldTimeStamp) { super(document); Charset charset = EncodingManager.getInstance().getEncoding(FileDocumentManager.getInstance().getFile(document), false); myCharset = charset == null ? Charset.defaultCharset() : charset; myOffset = offset; myOldString = oldString == null ? "" : compressCharSequence(oldString, myCharset); myNewString = newString == null ? "" : compressCharSequence(newString, myCharset); myOldTimeStamp = oldTimeStamp; myNewTimeStamp = document.getModificationStamp(); }
@Override public HighlighterIterator createIterator(int startOffset) { synchronized (this) { final Document document = getDocument(); if(document instanceof DocumentEx && ((DocumentEx)document).isInBulkUpdate()) { ((DocumentEx)document).setInBulkUpdate(false); // bulk mode failed } if (mySegments.getSegmentCount() == 0 && document != null && document.getTextLength() > 0) { // bulk mode was reset doSetText(document.getCharsSequence()); } final int latestValidOffset = mySegments.getLastValidOffset(); return new HighlighterIteratorImpl(startOffset <= latestValidOffset ? startOffset : latestValidOffset); } }
RangeHighlighterImpl(@NotNull MarkupModel model, int start, int end, int layer, @NotNull HighlighterTargetArea target, TextAttributes textAttributes, boolean greedyToLeft, boolean greedyToRight) { super((DocumentEx)model.getDocument(), start, end,false); data = new RangeHighlighterData(model, target, textAttributes) { @NotNull @Override public RangeHighlighterEx getRangeHighlighter() { return RangeHighlighterImpl.this; } }; registerInTree(start, end, greedyToLeft, greedyToRight, layer); }
private boolean translatedViaDiff(DocumentEvent e, DocumentEventImpl event) { try { setLine(event.translateLineViaDiff(getLine())); } catch (FilesTooBigForDiffException e1) { return false; } if (getLine() < 0 || getLine() >= getDocument().getLineCount()) { invalidate(e); } else { DocumentEx document = getDocument(); setIntervalStart(document.getLineStartOffset(getLine())); setIntervalEnd(document.getLineEndOffset(getLine())); } return true; }
/** * Updates state of the current context object in order to point to the end of the given collapsed fold region. * * @param foldRegion collapsed fold region to process */ private void advance(FoldRegion foldRegion, int placeHolderWidthInPixels) { lastFoldStartPosition = currentPosition.clone(); lastFold = foldRegion; int visualLineBefore = currentPosition.visualLine; int logicalLineBefore = currentPosition.logicalLine; int logicalColumnBefore = currentPosition.logicalColumn; currentPosition.advance(foldRegion); currentPosition.x += placeHolderWidthInPixels; int collapsedFoldingWidthInColumns = currentPosition.logicalColumn; if (currentPosition.logicalLine <= logicalLineBefore) { // Single-line fold region. collapsedFoldingWidthInColumns = currentPosition.logicalColumn - logicalColumnBefore; } else { final DocumentEx document = myEditor.getDocument(); int endFoldLine = document.getLineNumber(foldRegion.getEndOffset()); logicalLineData.endLineOffset = document.getLineEndOffset(endFoldLine); } notifyListenersOnFoldRegion(foldRegion, collapsedFoldingWidthInColumns, visualLineBefore); tokenStartOffset = myContext.currentPosition.offset; softWrapStartOffset = foldRegion.getEndOffset(); lastFoldEndPosition = currentPosition.clone(); }
public void testSaveDocument_DoNotSaveIfModStampEqualsToFile() throws Exception { final VirtualFile file = new MockVirtualFile("test.txt", "test") { @NotNull @Override public OutputStream getOutputStream(Object requestor, long newModificationStamp, long newTimeStamp) throws IOException { fail(); throw new IOException(); } }; DocumentEx document = (DocumentEx)myDocumentManager.getDocument(file); assertNotNull(file.toString(), document); document.insertString(0, "zzz"); document.setModificationStamp(file.getModificationStamp()); myDocumentManager.saveDocument(document); }
private void updateStatus() { Editor editor = FileEditorManager.getInstance(myProject).getSelectedTextEditor(); if (editor == null || !editor.getContentComponent().hasFocus()){ return; } final Document document = editor.getDocument(); if (document instanceof DocumentEx && ((DocumentEx)document).isInBulkUpdate()) return; int offset = editor.getCaretModel().getOffset(); DaemonCodeAnalyzer codeAnalyzer = DaemonCodeAnalyzer.getInstance(myProject); HighlightInfo info = ((DaemonCodeAnalyzerImpl)codeAnalyzer).findHighlightByOffset(document, offset, false, HighlightSeverity.WARNING); String text = info != null && info.getDescription() != null ? info.getDescription() : ""; StatusBar statusBar = WindowManager.getInstance().getStatusBar(editor.getContentComponent(), myProject); if (statusBar instanceof StatusBarEx) { StatusBarEx barEx = (StatusBarEx)statusBar; if (!text.equals(barEx.getInfo())){ statusBar.setInfo(text, "updater"); } } }
public TextPainter(DocumentEx editorDocument, EditorHighlighter highlighter, String fileName, Project project, FileType fileType, List<LineMarkerInfo> separators) { myCodeStyleSettings = CodeStyleSettingsManager.getSettings(project); myDocument = editorDocument; myPrintSettings = PrintSettings.getInstance(); String fontName = myPrintSettings.FONT_NAME; int fontSize = myPrintSettings.FONT_SIZE; myPlainFont = new Font(fontName, Font.PLAIN, fontSize); myBoldFont = new Font(fontName, Font.BOLD, fontSize); myItalicFont = new Font(fontName, Font.ITALIC, fontSize); myBoldItalicFont = new Font(fontName, Font.BOLD | Font.ITALIC, fontSize); myHighlighter = highlighter; myHeaderFont = new Font(myPrintSettings.FOOTER_HEADER_FONT_NAME, Font.PLAIN, myPrintSettings.FOOTER_HEADER_FONT_SIZE); myFileName = fileName; mySegmentEnd = myDocument.getTextLength(); myFileType = fileType; myMethodSeparators = separators != null ? separators.toArray(new LineMarkerInfo[separators.size()]) : new LineMarkerInfo[0]; myCurrentMethodSeparator = 0; }
@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); if (injectedManager == null) return null; //for tests final MultiHostRegistrarImpl result = doCompute(element, injectedManager, project, hostPsiFile); return CachedValueProvider.Result.create(result, PsiModificationTracker.MODIFICATION_COUNT, hostDocument); }
public void testBulkUpdate() throws Exception{ final PomModel model = PomManager.getModel(getProject()); final Listener listener = new Listener(model.getModelAspect(XmlAspect.class)); model.addModelListener(listener); final PsiFile file = createFile("a.xml", "<a/>"); new WriteCommandAction(getProject()) { @Override protected void run(Result result) throws Throwable { final Document document = PsiDocumentManager.getInstance(getProject()).getDocument(file); ((DocumentEx)document).setInBulkUpdate(true); document.insertString(0, " "); commitDocument(document); ((DocumentEx)document).setInBulkUpdate(false); } }.execute(); assertFileTextEquals(getTestName(false) + ".txt", listener.getEventString()); }
public void testSaveDocument_DoNotSaveIfModStampEqualsToFile() throws Exception { final VirtualFile file = createFile(); final DocumentEx document = (DocumentEx)myDocumentManager.getDocument(file); assertNotNull(file.toString(), document); WriteCommandAction.runWriteCommandAction(myProject, new Runnable() { @Override public void run() { document.insertString(0, "zzz"); document.setModificationStamp(file.getModificationStamp()); } }); getProject().getMessageBus().connect(getTestRootDisposable()).subscribe(AppTopics.FILE_DOCUMENT_SYNC, new FileDocumentManagerAdapter() { @Override public void beforeDocumentSaving(@Nonnull Document documentToSave) { assertNotSame(document, documentToSave); } }); myDocumentManager.saveDocument(document); }
public static void runBatchFoldingOperationOutsideOfBulkUpdate(@Nonnull Editor editor, @Nonnull Runnable operation) { DocumentEx document = ObjectUtils.tryCast(editor.getDocument(), DocumentEx.class); if (document != null && document.isInBulkUpdate()) { MessageBusConnection connection = ApplicationManager.getApplication().getMessageBus().connect(); disposeWithEditor(editor, connection); connection.subscribe(DocumentBulkUpdateListener.TOPIC, new DocumentBulkUpdateListener.Adapter() { @Override public void updateFinished(@Nonnull Document doc) { if (doc == editor.getDocument()) { editor.getFoldingModel().runBatchFoldingOperation(operation); connection.disconnect(); } } }); } else { editor.getFoldingModel().runBatchFoldingOperation(operation); } }
/** * Updates state of the current context object in order to point to the end of the given collapsed fold region. * * @param foldRegion collapsed fold region to process */ private void advance(FoldRegion foldRegion, int placeHolderWidthInPixels) { lastFoldStartPosition = currentPosition.clone(); lastFold = foldRegion; int logicalLineBefore = currentPosition.logicalLine; currentPosition.advance(foldRegion); currentPosition.x += placeHolderWidthInPixels; if (currentPosition.logicalLine > logicalLineBefore) { final DocumentEx document = myEditor.getDocument(); int endFoldLine = document.getLineNumber(foldRegion.getEndOffset()); logicalLineData.endLineOffset = document.getLineEndOffset(endFoldLine); } tokenStartOffset = myContext.currentPosition.offset; softWrapStartOffset = foldRegion.getEndOffset(); lastFoldEndPosition = currentPosition.clone(); }
private RangeMarkerImpl(@Nonnull DocumentEx document, int start, int end, boolean register, boolean greedyToLeft, boolean greedyToRight) { if (start < 0) { throw new IllegalArgumentException("Wrong start: " + start+"; end="+end); } if (end > document.getTextLength()) { throw new IllegalArgumentException("Wrong end: " + end+ "; document length="+document.getTextLength()+"; start="+start); } if (start > end){ throw new IllegalArgumentException("start > end: start=" + start+"; end="+end); } myDocument = document; myId = counter.next(); if (register) { registerInTree(start, end, greedyToLeft, greedyToRight, 0); } }
private static void doCommitTransaction(@Nonnull Document document, @Nonnull DocumentChangeTransaction documentChangeTransaction) { DocumentEx ex = (DocumentEx)document; ex.suppressGuardedExceptions(); try { boolean isReadOnly = !document.isWritable(); ex.setReadOnly(false); for (Map.Entry<TextRange, CharSequence> entry : documentChangeTransaction.myAffectedFragments.descendingMap().entrySet()) { ex.replaceString(entry.getKey().getStartOffset(), entry.getKey().getEndOffset(), entry.getValue()); } ex.setReadOnly(isReadOnly); } finally { ex.unSuppressGuardedExceptions(); } }
CommitTask(@Nonnull final Project project, @Nonnull final Document document, @Nonnull final List<Pair<PsiFileImpl, FileASTNode>> oldFileNodes, @Nonnull ProgressIndicator indicator, @Nonnull Object reason, @Nullable TransactionId context, @Nonnull CharSequence lastCommittedText) { this.document = document; this.project = project; this.indicator = indicator; this.reason = reason; myCreationContext = context; myLastCommittedText = lastCommittedText; myOldFileNodes = oldFileNodes; modificationSequence = ((DocumentEx)document).getModificationSequence(); }
@Nonnull public DocumentEx getLastCommittedDocument(@Nonnull 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(); }
@Nullable private static List<DiffFragment> calcPatchInnerDifferences(@Nonnull PatchChangeBuilder.Hunk hunk, @Nonnull ApplyPatchViewer viewer) { LineRange deletionRange = hunk.getPatchDeletionRange(); LineRange insertionRange = hunk.getPatchInsertionRange(); if (deletionRange.isEmpty() || insertionRange.isEmpty()) return null; try { DocumentEx patchDocument = viewer.getPatchEditor().getDocument(); CharSequence deleted = DiffUtil.getLinesContent(patchDocument, deletionRange.start, deletionRange.end); CharSequence inserted = DiffUtil.getLinesContent(patchDocument, insertionRange.start, insertionRange.end); return ByWord.compare(deleted, inserted, ComparisonPolicy.DEFAULT, DumbProgressIndicator.INSTANCE); } catch (DiffTooBigException ignore) { return null; } }