Search in sources :

Example 11 with FilesTooBigForDiffException

use of com.intellij.util.diff.FilesTooBigForDiffException in project intellij-community by JetBrains.

the class SrcFileAnnotator method doGetLineMapping.

@Nullable
private SoftReference<TIntIntHashMap> doGetLineMapping(final long date, boolean oldToNew, MyEditorBean editorBean) {
    VirtualFile virtualFile = editorBean.getVFile();
    final byte[] oldContent;
    synchronized (LOCK) {
        if (myOldContent == null) {
            if (ApplicationManager.getApplication().isDispatchThread())
                return null;
            final LocalHistory localHistory = LocalHistory.getInstance();
            byte[] byteContent = localHistory.getByteContent(virtualFile, new FileRevisionTimestampComparator() {

                public boolean isSuitable(long revisionTimestamp) {
                    return revisionTimestamp < date;
                }
            });
            if (byteContent == null && virtualFile.getTimeStamp() > date) {
                byteContent = loadFromVersionControl(date, virtualFile);
            }
            myOldContent = new SoftReference<>(byteContent);
        }
        oldContent = myOldContent.get();
    }
    if (oldContent == null)
        return null;
    String[] coveredLines = getCoveredLines(oldContent, virtualFile);
    final Document document = editorBean.getDocument();
    if (document == null)
        return null;
    String[] currentLines = getUpToDateLines(document);
    String[] oldLines = oldToNew ? coveredLines : currentLines;
    String[] newLines = oldToNew ? currentLines : coveredLines;
    Diff.Change change;
    try {
        change = Diff.buildChanges(oldLines, newLines);
    } catch (FilesTooBigForDiffException e) {
        LOG.info(e);
        return null;
    }
    return new SoftReference<>(getCoverageVersionToCurrentLineMapping(change, oldLines.length));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FilesTooBigForDiffException(com.intellij.util.diff.FilesTooBigForDiffException) Diff(com.intellij.util.diff.Diff) FileRevisionTimestampComparator(com.intellij.history.FileRevisionTimestampComparator) Document(com.intellij.openapi.editor.Document) SoftReference(com.intellij.reference.SoftReference) LocalHistory(com.intellij.history.LocalHistory) Nullable(org.jetbrains.annotations.Nullable)

Example 12 with FilesTooBigForDiffException

use of com.intellij.util.diff.FilesTooBigForDiffException in project intellij-community by JetBrains.

the class PersistentRangeMarker method translateViaDiff.

@Nullable
static Pair<TextRange, LinesCols> translateViaDiff(@NotNull final DocumentEventImpl event, @NotNull LinesCols linesCols) {
    try {
        int myStartLine = event.translateLineViaDiffStrict(linesCols.myStartLine);
        Document document = event.getDocument();
        if (myStartLine < 0 || myStartLine >= document.getLineCount()) {
            return null;
        }
        int start = document.getLineStartOffset(myStartLine) + linesCols.myStartColumn;
        if (start >= document.getTextLength())
            return null;
        int myEndLine = event.translateLineViaDiffStrict(linesCols.myEndLine);
        if (myEndLine < 0 || myEndLine >= document.getLineCount()) {
            return null;
        }
        int end = document.getLineStartOffset(myEndLine) + linesCols.myEndColumn;
        if (end > document.getTextLength() || end < start)
            return null;
        if (end > event.getDocument().getTextLength() || myEndLine < myStartLine || myStartLine == myEndLine && linesCols.myEndColumn < linesCols.myStartColumn || event.getDocument().getLineCount() < myEndLine) {
            return null;
        }
        return Pair.create(new TextRange(start, end), new LinesCols(myStartLine, linesCols.myStartColumn, myEndLine, linesCols.myEndColumn));
    } catch (FilesTooBigForDiffException e) {
        return null;
    }
}
Also used : FilesTooBigForDiffException(com.intellij.util.diff.FilesTooBigForDiffException) TextRange(com.intellij.openapi.util.TextRange) Document(com.intellij.openapi.editor.Document) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

FilesTooBigForDiffException (com.intellij.util.diff.FilesTooBigForDiffException)12 TextRange (com.intellij.openapi.util.TextRange)6 Document (com.intellij.openapi.editor.Document)4 NotNull (org.jetbrains.annotations.NotNull)4 Nullable (org.jetbrains.annotations.Nullable)3 DiffFragment (com.intellij.openapi.diff.ex.DiffFragment)2 DiffString (com.intellij.openapi.diff.impl.string.DiffString)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 FutureTask (java.util.concurrent.FutureTask)2 TestFrameworks (com.intellij.codeInsight.TestFrameworks)1 FormatChangedTextUtil (com.intellij.codeInsight.actions.FormatChangedTextUtil)1 FileRevisionTimestampComparator (com.intellij.history.FileRevisionTimestampComparator)1 LocalHistory (com.intellij.history.LocalHistory)1 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1 ReadAction (com.intellij.openapi.application.ReadAction)1 Fragment (com.intellij.openapi.diff.impl.fragments.Fragment)1 LineFragment (com.intellij.openapi.diff.impl.fragments.LineFragment)1 DiffCorrection (com.intellij.openapi.diff.impl.processing.DiffCorrection)1 DiffFragmentsProcessor (com.intellij.openapi.diff.impl.processing.DiffFragmentsProcessor)1 LineBlocks (com.intellij.openapi.diff.impl.splitter.LineBlocks)1