DiffContent (@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()); }