use of com.intellij.diff.contents.DocumentContent in project intellij-community by JetBrains.
the class FileHistoryDialogTest method testContentForCurrentRevision.
public void testContentForCurrentRevision() throws IOException {
VirtualFile f = createChildData(myRoot, "f.txt");
setBinaryContent(f, "old".getBytes());
setBinaryContent(f, "current".getBytes());
FileHistoryDialogModel m = createFileModelAndSelectRevisions(f, 0, 0);
assertDiffContents("old", "current", m);
assertTrue(getRightDiffContent(m) instanceof DocumentContent);
}
use of com.intellij.diff.contents.DocumentContent in project intellij-community by JetBrains.
the class PsiDiffContentFactory method fromPsiElement.
@Nullable
private static DiffContent fromPsiElement(@NotNull PsiElement psiElement) {
DiffContentFactory factory = DiffContentFactory.getInstance();
if (psiElement instanceof PsiFile) {
return factory.create(psiElement.getProject(), ((PsiFile) psiElement).getVirtualFile());
} else if (psiElement instanceof PsiDirectory) {
return factory.create(psiElement.getProject(), ((PsiDirectory) psiElement).getVirtualFile());
}
PsiFile containingFile = psiElement.getContainingFile();
if (containingFile == null) {
String text = psiElement.getText();
if (text == null)
return null;
return factory.create(psiElement.getProject(), text, psiElement.getLanguage().getAssociatedFileType(), false);
}
DocumentContent wholeFileContent = factory.createDocument(psiElement.getProject(), containingFile.getVirtualFile());
if (wholeFileContent == null)
return null;
return factory.createFragment(psiElement.getProject(), wholeFileContent, psiElement.getTextRange());
}
use of com.intellij.diff.contents.DocumentContent in project intellij-community by JetBrains.
the class LangDiffIgnoredRangeProvider method getLanguage.
@Nullable
private static Language getLanguage(@NotNull Project project, @NotNull DiffContent content) {
Language language = content.getUserData(DiffUserDataKeys.LANGUAGE);
if (language != null)
return language;
FileType type = content.getContentType();
if (type instanceof LanguageFileType)
language = ((LanguageFileType) type).getLanguage();
if (language != null && content instanceof DocumentContent) {
VirtualFile highlightFile = ((DocumentContent) content).getHighlightFile();
if (highlightFile != null)
language = LanguageSubstitutors.INSTANCE.substituteLanguage(language, highlightFile, project);
}
return language;
}
use of com.intellij.diff.contents.DocumentContent in project intellij-community by JetBrains.
the class ListenerDiffViewerBase method onInit.
@Override
protected void onInit() {
super.onInit();
VirtualFileListener fileListener = createFileListener(myRequest);
if (fileListener != null)
VirtualFileManager.getInstance().addVirtualFileListener(fileListener, this);
DocumentListener documentListener = createDocumentListener();
List<Document> documents = ContainerUtil.mapNotNull(myRequest.getContents(), (content) -> {
return content instanceof DocumentContent ? ((DocumentContent) content).getDocument() : null;
});
TextDiffViewerUtil.installDocumentListeners(documentListener, documents, this);
}
use of com.intellij.diff.contents.DocumentContent in project intellij-community by JetBrains.
the class UnifiedDiffViewer method performRediff.
@Override
@NotNull
protected Runnable performRediff(@NotNull final ProgressIndicator indicator) {
try {
indicator.checkCanceled();
final Document document1 = getContent1().getDocument();
final Document document2 = getContent2().getDocument();
final CharSequence[] texts = ReadAction.compute(() -> {
return new CharSequence[] { document1.getImmutableCharSequence(), document2.getImmutableCharSequence() };
});
final List<LineFragment> fragments = myTextDiffProvider.compare(texts[0], texts[1], indicator);
final DocumentContent content1 = getContent1();
final DocumentContent content2 = getContent2();
indicator.checkCanceled();
TwosideDocumentData data = ReadAction.compute(() -> {
indicator.checkCanceled();
UnifiedFragmentBuilder builder = new UnifiedFragmentBuilder(fragments, document1, document2, myMasterSide);
builder.exec();
indicator.checkCanceled();
EditorHighlighter highlighter = buildHighlighter(myProject, content1, content2, texts[0], texts[1], builder.getRanges(), builder.getText().length());
UnifiedEditorRangeHighlighter rangeHighlighter = new UnifiedEditorRangeHighlighter(myProject, document1, document2, builder.getRanges());
return new TwosideDocumentData(builder, highlighter, rangeHighlighter);
});
UnifiedFragmentBuilder builder = data.getBuilder();
FileType fileType = content2.getContentType() == null ? content1.getContentType() : content2.getContentType();
LineNumberConvertor convertor1 = builder.getConvertor1();
LineNumberConvertor convertor2 = builder.getConvertor2();
List<LineRange> changedLines = builder.getChangedLines();
boolean isContentsEqual = builder.isEqual();
CombinedEditorData editorData = new CombinedEditorData(builder.getText(), data.getHighlighter(), data.getRangeHighlighter(), fileType, convertor1.createConvertor(), convertor2.createConvertor());
return apply(editorData, builder.getBlocks(), convertor1, convertor2, changedLines, isContentsEqual);
} catch (DiffTooBigException e) {
return () -> {
clearDiffPresentation();
myPanel.setTooBigContent();
};
} catch (ProcessCanceledException e) {
throw e;
} catch (Throwable e) {
LOG.error(e);
return () -> {
clearDiffPresentation();
myPanel.setErrorContent();
};
}
}
Aggregations