How to create com.intellij.psi.xml.XmlFile from com.intellij.openapi.vfs.Virtual file?

How to create com.intellij.psi.xml.XmlFile from com.intellij.openapi.vfs.Virtual file?
Does my edits on newly created XmlFile will change actual file on the disk?

1
2 comments

See IntelliJ IDEA Architectural Overview.

1. You do not create PsiFile manually. Use PsiManager.getInstance(project).findFile()

2. Not immediately. In general you shouldn't care about file saving. It may be needed only before invoking some external process that uses the files. To force saving use FileDocumentManager.getInstance().saveAllDocuments() or ApplicationManager.getApplication().saveAll()

0

As suggested already, you can use the PsiManager.

Here is an extract from my plugin

 
val psiFile = PsiManager.getInstance(project).findFile(virtualFile)
val xmlFile = psiFile.asInstanceOf[XmlFile] // Typecast if Java
 If you are working with the DOM and want access to DomElements, use the DomManager by passing your Xml PSI file and your root DomElement interface


DomManager.getDomProkect(project).getFileElement(xmlFile, RootDomElement.class)

You may find http://confluence.jetbrains.com/display/IDEADEV/IntelliJ+IDEA+Architectural+Overview useful :)

Alan

1

Please sign in to leave a comment.