PsiFile delete

Answered

How to delete a PsiFile in intellij 15. because PsiFile.delete() is throwing exception(unsupported operation exception).. Thanks in advance.

0
8 comments

Hi,

It's ok to use PsiFile#delete method, at least in case you do that on default PsiFileImpl implementation. What is the exception you get? Attach full stacktrace please.

0
Avatar
Permanently deleted user
Thank you..This is code.
final
PsiFile file = PsiFileFactoryImpl.getInstance(project).createFileFromText(generatedFileName, fileType, text,
new Date().getTime(), true);
final DocumentContent documentContent=DiffContentFactory.getInstance().createDocument(project,file.getVirtualFile());
file.delete();
return DocumentContent;

when i run this code,then i am getting
[Caused by: java.lang.UnsupportedOperationException: deleteFile() not supported].
I am not getting what to do. actually i am beginner.




0

I'm not sure that it makes much sense to delete() a fake file, so the question is why are you doing this?

As for exception I believe there is a full stacktrace in logs that might tell you why it's happening.

0
Avatar
Permanently deleted user

if i'll not delete this file then it'll be in the memory that is why i want to delete and yeah of course there was a full stacktrace, just because of that i  got to know that it was throwing exception in file.delete(). and it's working in intellij 14.

0

Anyway the stacktrace is needed. Javadoc of PsiFile#delete method says that the exception is possible, without stacktrace I can't say why it happens

0
Avatar
Permanently deleted user

this is the stacktrace...

Caused by: java.lang.UnsupportedOperationException: deleteFile() not supported

                at com.intellij.openapi.vfs.DeprecatedVirtualFileSystem.deleteFile(DeprecatedVirtualFileSystem.java:142)

                at com.intellij.openapi.vfs.VirtualFile.delete(VirtualFile.java:457)

                at com.intellij.psi.impl.file.PsiFileImplUtil.doDelete(PsiFileImplUtil.java:75)

                at com.intellij.psi.impl.source.PsiFileImpl.delete(PsiFileImpl.java:520)

                at com.amazon.lumos.intellijcore.PreviewEditor.createDocContent(PreviewEditor.java:103)

                at com.amazon.lumos.intellijcore.PreviewEditor.createPreviewPanel(PreviewEditor.java:64)

                at com.amazon.lumos.util.UiHelper.showDiffPreview(UiHelper.java:144)

                at com.amazon.lumos.capability.qlang.InsertAction.showDiff(InsertAction.java:130)

                at com.amazon.lumos.capability.qlang.XmlCodeInsertAction.insert(XmlCodeInsertAction.java:114)

                at com.amazon.lumos.capability.qlang.InsertAction.insert(InsertAction.java:74)

                at com.amazon.lumos.capability.qlang.InsertAction.doAsync(InsertAction.java:80)

                ... 41 more

0

Here is the change that leads to this behavior: https://github.com/JetBrains/intellij-community/commit/99680a8633af6c88d4d3ce2b5e353f95596fd157

According to this I can see that the delete() method did nothing in IntelliJ 14 for fake virtual files. So I stick to the point that invoking delete() method on fake files doesn't make sense and it's unsupported operation indeed.

As for initial question: "How to delete a PsiFile in intellij 15.". The answer is to invoke PsiFile#delete method and as javadoc of this method says: the method might not support the modification.

0
Avatar
Permanently deleted user

Thank you :) 

0

Please sign in to leave a comment.