本文整理汇总了Java中com.intellij.openapi.vfs.VfsUtil.saveText方法的典型用法代码示例。如果您正苦于以下问题:Java VfsUtil.saveText方法的具体用法?Java VfsUtil.saveText怎么用?Java VfsUtil.saveText使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.openapi.vfs.VfsUtil
的用法示例。
在下文中一共展示了VfsUtil.saveText方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createChildFile
import com.intellij.openapi.vfs.VfsUtil; //导入方法依赖的package包/类
public static void createChildFile(@NotNull VirtualFile taskDir, @NotNull String name, @NotNull String text) throws IOException {
String newDirectories = null;
String fileName = name;
VirtualFile dir = taskDir;
if (name.contains("/")) {
int pos = name.lastIndexOf("/");
fileName = name.substring(pos + 1);
newDirectories = name.substring(0, pos);
}
if (newDirectories != null) {
dir = VfsUtil.createDirectoryIfMissing(taskDir, newDirectories);
}
if (dir != null) {
VirtualFile virtualTaskFile = dir.findChild(fileName);
if (virtualTaskFile == null) {
virtualTaskFile = dir.createChildData(taskDir, fileName);
}
if (EduUtils.isImage(name)) {
virtualTaskFile.setBinaryContent(Base64.decodeBase64(text));
}
else {
VfsUtil.saveText(virtualTaskFile, text);
}
}
}
示例2: testSCR5929
import com.intellij.openapi.vfs.VfsUtil; //导入方法依赖的package包/类
public void testSCR5929() throws Exception {
String text = "class A{ /** @see a.B */ }";
VirtualFile vFileA = myFixture.addFileToProject("A.java", text).getVirtualFile();
VirtualFile dir = myFixture.getTempDirFixture().findOrCreateDir("a");
VirtualFile vFileB = dir.createChildData(null, "B.java");
text = "class B{}";
VfsUtil.saveText(vFileB, text);
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
PsiFile fileA = getPsiManager().findFile(vFileA);
PsiJavaFile fileACopy = (PsiJavaFile)fileA.copy();
PsiClass aClass = fileACopy.getClasses()[0];
aClass.setName("A2");
fileA.getContainingDirectory().add(fileACopy);
}
示例3: createFileFromTemplate
import com.intellij.openapi.vfs.VfsUtil; //导入方法依赖的package包/类
@Nullable
public static VirtualFile createFileFromTemplate(final String templateName, final VirtualFile parent, final String fileName) {
parent.refresh(false, false);
final FileTemplate template = FileTemplateManager.getDefaultInstance().getJ2eeTemplate(templateName);
try {
final String text = template.getText(FileTemplateManager.getDefaultInstance().getDefaultProperties());
VirtualFile file = parent.findChild(fileName);
if (file == null) {
file = parent.createChildData(AppEngineSupportProvider.class, fileName);
}
VfsUtil.saveText(file, text);
return file;
}
catch (IOException e) {
LOG.error(e);
return null;
}
}
示例4: testUpdateCache2
import com.intellij.openapi.vfs.VfsUtil; //导入方法依赖的package包/类
public void testUpdateCache2() throws Exception {
VirtualFile child = myRootDir.findChild("1.java");
VfsUtil.saveText(child, "xxx");
PsiDocumentManager.getInstance(myProject).commitAllDocuments();
FileDocumentManager.getInstance().saveAllDocuments();
final CacheManager cache = CacheManager.SERVICE.getInstance(myProject);
final TodoCacheManager todocache = TodoCacheManager.SERVICE.getInstance(myProject);
final GlobalSearchScope scope = GlobalSearchScope.projectScope(myProject);
checkResult(new String[] {"1.java"}, convert(cache.getFilesWithWord("xxx", UsageSearchContext.ANY, scope, false)));
checkResult(new String[]{}, convert(cache.getFilesWithWord("a", UsageSearchContext.ANY, scope, false)));
checkResult(new String[]{"2.java"}, convert(cache.getFilesWithWord("b", UsageSearchContext.ANY,scope, false)));
checkResult(new String[]{"2.java", "3.java"}, convert(cache.getFilesWithWord("c", UsageSearchContext.ANY,scope, false)));
checkResult(new String[]{"2.java", "3.java"}, convert(cache.getFilesWithWord("d", UsageSearchContext.ANY,scope, false)));
checkResult(new String[]{"3.java"}, convert(cache.getFilesWithWord("e", UsageSearchContext.ANY,scope, false)));
checkResult(new String[]{"3.java"}, convert(todocache.getFilesWithTodoItems()));
assertEquals(0, todocache.getTodoCount(myRootDir.findChild("1.java"), TodoIndexPatternProvider.getInstance()));
assertEquals(0, todocache.getTodoCount(myRootDir.findChild("2.java"), TodoIndexPatternProvider.getInstance()));
assertEquals(2, todocache.getTodoCount(myRootDir.findChild("3.java"), TodoIndexPatternProvider.getInstance()));
}
示例5: testFileCreation
import com.intellij.openapi.vfs.VfsUtil; //导入方法依赖的package包/类
public void testFileCreation() throws Exception {
final CacheManager cache = CacheManager.SERVICE.getInstance(myProject);
final TodoCacheManager todocache = TodoCacheManager.SERVICE.getInstance(myProject);
checkCache(cache, todocache);
VirtualFile child = myRootDir.createChildData(null, "4.java");
VfsUtil.saveText(child, "xxx //todo");
PsiDocumentManager.getInstance(myProject).commitAllDocuments();
final GlobalSearchScope scope = GlobalSearchScope.projectScope(myProject);
checkResult(new String[]{"4.java"}, convert(cache.getFilesWithWord("xxx", UsageSearchContext.ANY, scope, false)));
checkResult(new String[]{"1.java"}, convert(cache.getFilesWithWord("a", UsageSearchContext.ANY, scope, false)));
checkResult(new String[]{"1.java", "2.java"}, convert(cache.getFilesWithWord("b", UsageSearchContext.ANY, scope, false)));
checkResult(new String[]{"1.java", "2.java", "3.java"}, convert(cache.getFilesWithWord("c", UsageSearchContext.ANY, scope, false)));
checkResult(new String[]{"2.java", "3.java"}, convert(cache.getFilesWithWord("d", UsageSearchContext.ANY, scope, false)));
checkResult(new String[]{"3.java"}, convert(cache.getFilesWithWord("e", UsageSearchContext.ANY, scope, false)));
checkResult(new String[]{"1.java", "3.java", "4.java"}, convert(todocache.getFilesWithTodoItems()));
assertEquals(1, todocache.getTodoCount(myRootDir.findChild("1.java"), TodoIndexPatternProvider.getInstance()));
assertEquals(0, todocache.getTodoCount(myRootDir.findChild("2.java"), TodoIndexPatternProvider.getInstance()));
assertEquals(2, todocache.getTodoCount(myRootDir.findChild("3.java"), TodoIndexPatternProvider.getInstance()));
assertEquals(1, todocache.getTodoCount(myRootDir.findChild("4.java"), TodoIndexPatternProvider.getInstance()));
}
示例6: outputXmlToRes
import com.intellij.openapi.vfs.VfsUtil; //导入方法依赖的package包/类
public void outputXmlToRes(File targetResDir) {
String currentFilePath = myContext.getImagePath();
// At output step, we can ignore the errors since they have been exposed in the previous step.
String xmlFileContent = generateVectorXml(new File(currentFilePath), null);
String xmlFileName = myContext.getAssetName();
// Here get the XML file content, and write into targetResDir / drawable / ***.xml
File file = new File(targetResDir, SdkConstants.FD_RES_DRAWABLE + File.separator +
xmlFileName + SdkConstants.DOT_XML);
try {
VirtualFile directory = VfsUtil.createDirectories(file.getParentFile().getAbsolutePath());
VirtualFile xmlFile = directory.findChild(file.getName());
if (xmlFile == null || !xmlFile.exists()) {
xmlFile = directory.createChildData(this, file.getName());
}
VfsUtil.saveText(xmlFile, xmlFileContent);
}
catch (IOException e) {
LOG.error(e);
}
}
示例7: setupFileEditorAndDocument
import com.intellij.openapi.vfs.VfsUtil; //导入方法依赖的package包/类
@NotNull
private static Document setupFileEditorAndDocument(@NotNull String fileName, @NotNull String fileText) throws IOException {
EncodingProjectManager.getInstance(getProject()).setEncoding(null, CharsetToolkit.UTF8_CHARSET);
EncodingProjectManager.getInstance(ProjectManager.getInstance().getDefaultProject()).setEncoding(null, CharsetToolkit.UTF8_CHARSET);
PostprocessReformattingAspect.getInstance(ourProject).doPostponedFormatting();
deleteVFile();
myVFile = getSourceRoot().createChildData(null, fileName);
VfsUtil.saveText(myVFile, fileText);
final FileDocumentManager manager = FileDocumentManager.getInstance();
final Document document = manager.getDocument(myVFile);
assertNotNull("Can't create document for '" + fileName + "'", document);
manager.reloadFromDisk(document);
document.insertString(0, " ");
document.deleteString(0, 1);
myFile = getPsiManager().findFile(myVFile);
assertNotNull("Can't create PsiFile for '" + fileName + "'. Unknown file type most probably.", myFile);
assertTrue(myFile.isPhysical());
myEditor = createEditor(myVFile);
myVFile.setCharset(CharsetToolkit.UTF8_CHARSET);
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
return document;
}
示例8: saveHistory
import com.intellij.openapi.vfs.VfsUtil; //导入方法依赖的package包/类
private void saveHistory() {
try {
if (getModel().getEntries().isEmpty()) return;
if (myRootType.isHidden()) {
saveHistoryOld();
return;
}
AccessToken token = ApplicationManager.getApplication().acquireWriteActionLock(getClass());
try {
VirtualFile file = HistoryRootType.getInstance().findFile(null, getHistoryName(myRootType, myId), ScratchFileService.Option.create_if_missing);
VfsUtil.saveText(file, StringUtil.join(getModel().getEntries(), myRootType.getEntrySeparator()));
}
finally {
token.finish();
}
}
catch (Exception ex) {
LOG.error(ex);
}
}
示例9: testBookmarkManagerDoesNotHardReferenceDocuments
import com.intellij.openapi.vfs.VfsUtil; //导入方法依赖的package包/类
public void testBookmarkManagerDoesNotHardReferenceDocuments() throws IOException {
@NonNls String text =
"public class Test {\n" +
"}";
myVFile = getSourceRoot().createChildData(null, getTestName(false) + ".txt");
VfsUtil.saveText(myVFile, text);
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
Bookmark bookmark = getManager().addTextBookmark(myVFile, 1, "xxx");
assertNotNull(bookmark);
LeakHunter.checkLeak(getManager(), Document.class);
Document document = FileDocumentManager.getInstance().getDocument(myVFile);
assertNotNull(document);
document.insertString(0, "line 0\n");
assertEquals(2, bookmark.getLine());
myEditor = createEditor(myVFile);
checkBookmarkNavigation(bookmark);
}
示例10: setFileText
import com.intellij.openapi.vfs.VfsUtil; //导入方法依赖的package包/类
/**
* @deprecated to be removed after IDEA 15. Use {@link VfsUtil#saveText(VirtualFile, String)} instead.
*/
public static void setFileText(@Nullable Project project, final VirtualFile virtualFile, final String text) throws IOException {
if (project == null) {
project = ProjectUtil.guessProjectForFile(virtualFile);
}
if (project != null) {
final PsiFile psiFile = PsiManager.getInstance(project).findFile(virtualFile);
final PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance(project);
final Document document = psiFile == null? null : psiDocumentManager.getDocument(psiFile);
if (document != null) {
document.setText(text != null ? text : "");
psiDocumentManager.commitDocument(document);
FileDocumentManager.getInstance().saveDocument(document);
return;
}
}
VfsUtil.saveText(virtualFile, text != null ? text : "");
virtualFile.refresh(false, false);
}
示例11: run
import com.intellij.openapi.vfs.VfsUtil; //导入方法依赖的package包/类
@Override
protected void run(@NotNull Result<Object> result) throws Throwable {
File moduleLocation = GradleUtil.getModuleDefaultPath(myProject.getBaseDir(), myGradlePath);
try {
VirtualFile moduleRoot = VfsUtil.createDirectoryIfMissing(moduleLocation.getAbsolutePath());
VirtualFile sourceFile = VfsUtil.findFileByIoFile(myArchivePath, true);
if (sourceFile != null && moduleRoot != null) {
if (myMove) {
sourceFile.move(this, moduleRoot);
}
else {
VfsUtil.copy(this, sourceFile, moduleRoot);
}
VirtualFile buildGradle = moduleRoot.createChildData(this, SdkConstants.FN_BUILD_GRADLE);
VfsUtil.saveText(buildGradle, getBuildGradleText(myArchivePath));
if (mySettingsFile == null) {
mySettingsFile = GradleSettingsFile.getOrCreate(myProject);
}
mySettingsFile.addModule(myGradlePath, VfsUtilCore.virtualToIoFile(moduleRoot));
for (Module module : myModulesToAddDependency) {
addDependency(module, myGradlePath);
}
}
}
catch (IOException e) {
Logger.getInstance(WrapArchiveWizardPath.class).error(e);
}
}
示例12: testSmartPointersSurvivePsiFileUnload
import com.intellij.openapi.vfs.VfsUtil; //导入方法依赖的package包/类
public void testSmartPointersSurvivePsiFileUnload() throws IOException {
final VirtualFile vfile = myRoot.createChildData(this, "X.txt");
String xxx = "xxx";
String text = xxx + " " + xxx + " " + xxx;
VfsUtil.saveText(vfile, text);
PsiFile psiFile = PsiManager.getInstance(getProject()).findFile(vfile);
assertTrue(String.valueOf(psiFile), psiFile instanceof PsiPlainTextFile);
SmartPointerManagerImpl manager = getPointerManager();
TextRange range1 = TextRange.from(text.indexOf(xxx), xxx.length());
SmartPsiFileRange pointer1 = manager.createSmartPsiFileRangePointer(psiFile, range1);
TextRange range2 = TextRange.from(text.lastIndexOf(xxx), xxx.length());
SmartPsiFileRange pointer2 = manager.createSmartPsiFileRangePointer(psiFile, range2);
assertNotNull(FileDocumentManager.getInstance().getCachedDocument(vfile));
SoftReference<PsiFile> ref = new SoftReference<PsiFile>(psiFile);
psiFile = null;
while (ref.get() != null) {
PlatformTestUtil.tryGcSoftlyReachableObjects();
}
assertNull(FileDocumentManager.getInstance().getCachedDocument(vfile));
assertEquals(pointer1.getRange(), range1);
WriteCommandAction.runWriteCommandAction(getProject(), new Runnable() {
@Override
public void run() {
FileDocumentManager.getInstance().getDocument(vfile).insertString(0, " ");
}
});
assertEquals(range1.shiftRight(1), pointer1.getRange());
assertEquals(range2.shiftRight(1), pointer2.getRange());
}
示例13: createVFile
import com.intellij.openapi.vfs.VfsUtil; //导入方法依赖的package包/类
public VirtualFile createVFile(@NotNull VirtualFile parentDir, @NotNull String name, @NotNull String text) {
try {
final VirtualFile virtualFile = parentDir.createChildData(this, name);
VfsUtil.saveText(virtualFile, text + "\n");
return virtualFile;
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
示例14: clearContent
import com.intellij.openapi.vfs.VfsUtil; //导入方法依赖的package包/类
public static void clearContent(VirtualFile file) {
Assert.assertNotNull(file);
try {
VfsUtil.saveText(file, "");
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
示例15: loadHistory
import com.intellij.openapi.vfs.VfsUtil; //导入方法依赖的package包/类
public boolean loadHistory(String id, VirtualFile consoleFile) {
try {
VirtualFile file = myRootType.isHidden() ? null :
HistoryRootType.getInstance().findFile(null, getHistoryName(myRootType, id), ScratchFileService.Option.existing_only);
if (file == null) {
if (loadHistoryOld(id)) {
if (!myRootType.isHidden()) {
// migrate content
AccessToken token = ApplicationManager.getApplication().acquireWriteActionLock(getClass());
try {
VfsUtil.saveText(consoleFile, myContent);
}
finally {
token.finish();
}
}
return true;
}
return false;
}
String[] split = VfsUtilCore.loadText(file).split(myRootType.getEntrySeparator());
getModel().resetEntries(Arrays.asList(split));
return true;
}
catch (Exception ignored) {
return false;
}
}