本文整理汇总了Java中com.intellij.openapi.fileEditor.FileDocumentManager.getLineSeparator方法的典型用法代码示例。如果您正苦于以下问题:Java FileDocumentManager.getLineSeparator方法的具体用法?Java FileDocumentManager.getLineSeparator怎么用?Java FileDocumentManager.getLineSeparator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.openapi.fileEditor.FileDocumentManager
的用法示例。
在下文中一共展示了FileDocumentManager.getLineSeparator方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: add
import com.intellij.openapi.fileEditor.FileDocumentManager; //导入方法依赖的package包/类
@Override
public PsiElement add(@NotNull PsiElement element) throws IncorrectOperationException {
checkAdd(element);
if (element instanceof PsiDirectory) {
LOG.error("not implemented");
return null;
}
else if (element instanceof PsiFile) {
PsiFile originalFile = (PsiFile)element;
try {
VirtualFile newVFile;
final PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance(myManager.getProject());
if (originalFile instanceof PsiFileImpl) {
newVFile = myFile.createChildData(myManager, originalFile.getName());
String text = originalFile.getText();
final PsiFile psiFile = getManager().findFile(newVFile);
final Document document = psiFile == null ? null : psiDocumentManager.getDocument(psiFile);
final FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance();
if (document != null) {
document.setText(text);
fileDocumentManager.saveDocument(document);
}
else {
String lineSeparator = fileDocumentManager.getLineSeparator(newVFile, getProject());
if (!lineSeparator.equals("\n")) {
text = StringUtil.convertLineSeparators(text, lineSeparator);
}
LoadTextUtil.write(getProject(), newVFile, myManager, text, -1);
}
}
else {
byte[] storedContents = ((PsiBinaryFileImpl)originalFile).getStoredContents();
if (storedContents != null) {
newVFile = myFile.createChildData(myManager, originalFile.getName());
newVFile.setBinaryContent(storedContents);
}
else {
newVFile = VfsUtilCore.copyFile(null, originalFile.getVirtualFile(), myFile);
}
}
psiDocumentManager.commitAllDocuments();
PsiFile newFile = myManager.findFile(newVFile);
updateAddedFile(newFile);
return newFile;
}
catch (IOException e) {
throw new IncorrectOperationException(e);
}
}
else {
LOG.assertTrue(false);
return null;
}
}