Search in sources :

Example 1 with DiffContentFactoryEx

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

the class DiffActionExecutor method createRemote.

@Nullable
protected DiffContent createRemote(final VcsRevisionNumber revisionNumber) throws IOException, VcsException {
    final ContentRevision fileRevision = myDiffProvider.createFileContent(revisionNumber, mySelectedFile);
    if (fileRevision == null)
        return null;
    DiffContentFactoryEx contentFactory = DiffContentFactoryEx.getInstanceEx();
    DiffContent diffContent;
    if (fileRevision instanceof BinaryContentRevision) {
        FilePath filePath = fileRevision.getFile();
        final byte[] content = ((BinaryContentRevision) fileRevision).getBinaryContent();
        if (content == null)
            return null;
        diffContent = contentFactory.createBinary(myProject, content, filePath.getFileType(), filePath.getName());
    } else if (fileRevision instanceof ByteBackedContentRevision) {
        byte[] content = ((ByteBackedContentRevision) fileRevision).getContentAsBytes();
        if (content == null)
            throw new VcsException("Failed to load content");
        diffContent = contentFactory.createFromBytes(myProject, content, fileRevision.getFile());
    } else {
        String content = fileRevision.getContent();
        if (content == null)
            throw new VcsException("Failed to load content");
        diffContent = contentFactory.create(myProject, content, fileRevision.getFile());
    }
    diffContent.putUserData(DiffUserDataKeysEx.REVISION_INFO, Pair.create(fileRevision.getFile(), fileRevision.getRevisionNumber()));
    return diffContent;
}
Also used : BinaryContentRevision(com.intellij.openapi.vcs.changes.BinaryContentRevision) ContentRevision(com.intellij.openapi.vcs.changes.ContentRevision) ByteBackedContentRevision(com.intellij.openapi.vcs.changes.ByteBackedContentRevision) BinaryContentRevision(com.intellij.openapi.vcs.changes.BinaryContentRevision) DiffContentFactoryEx(com.intellij.diff.DiffContentFactoryEx) DiffContent(com.intellij.diff.contents.DiffContent) ByteBackedContentRevision(com.intellij.openapi.vcs.changes.ByteBackedContentRevision) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with DiffContentFactoryEx

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

the class ChangeDiffRequestProducer method createContent.

@NotNull
public static DiffContent createContent(@Nullable Project project, @Nullable ContentRevision revision, @NotNull UserDataHolder context, @NotNull ProgressIndicator indicator) throws DiffRequestProducerException {
    try {
        indicator.checkCanceled();
        if (revision == null)
            return DiffContentFactory.getInstance().createEmpty();
        FilePath filePath = revision.getFile();
        DiffContentFactoryEx contentFactory = DiffContentFactoryEx.getInstanceEx();
        if (revision instanceof CurrentContentRevision) {
            VirtualFile vFile = ((CurrentContentRevision) revision).getVirtualFile();
            if (vFile == null)
                throw new DiffRequestProducerException("Can't get current revision content");
            return contentFactory.create(project, vFile);
        }
        if (revision instanceof BinaryContentRevision) {
            byte[] content = ((BinaryContentRevision) revision).getBinaryContent();
            if (content == null) {
                throw new DiffRequestProducerException("Can't get binary revision content");
            }
            return contentFactory.createFromBytes(project, content, filePath);
        }
        if (revision instanceof ByteBackedContentRevision) {
            byte[] revisionContent = ((ByteBackedContentRevision) revision).getContentAsBytes();
            if (revisionContent == null)
                throw new DiffRequestProducerException("Can't get revision content");
            return contentFactory.createFromBytes(project, revisionContent, filePath);
        } else {
            String revisionContent = revision.getContent();
            if (revisionContent == null)
                throw new DiffRequestProducerException("Can't get revision content");
            return contentFactory.create(project, revisionContent, filePath);
        }
    } catch (IOException | VcsException e) {
        LOG.info(e);
        throw new DiffRequestProducerException(e);
    }
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) VirtualFile(com.intellij.openapi.vfs.VirtualFile) DiffRequestProducerException(com.intellij.diff.chains.DiffRequestProducerException) VcsException(com.intellij.openapi.vcs.VcsException) DiffContentFactoryEx(com.intellij.diff.DiffContentFactoryEx) IOException(java.io.IOException) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

DiffContentFactoryEx (com.intellij.diff.DiffContentFactoryEx)2 DiffRequestProducerException (com.intellij.diff.chains.DiffRequestProducerException)1 DiffContent (com.intellij.diff.contents.DiffContent)1 FilePath (com.intellij.openapi.vcs.FilePath)1 VcsException (com.intellij.openapi.vcs.VcsException)1 BinaryContentRevision (com.intellij.openapi.vcs.changes.BinaryContentRevision)1 ByteBackedContentRevision (com.intellij.openapi.vcs.changes.ByteBackedContentRevision)1 ContentRevision (com.intellij.openapi.vcs.changes.ContentRevision)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 IOException (java.io.IOException)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1