Action doesn't see changes in xml file

I modify xml file in write action (some rename action):


Then I read the xml file in next action (some delete action) through VirtualFile.getInputStream() and don't see changes done by 1st action!

P.S. If open the xml file after 1st action, save the xml file and run the 2nd action then the 2nd action sees changes.

Please advice how to flush file changes to disk after 1st action.

3 comments
Comment actions Permalink

Hello Alex,

I modify xml file in write action (some rename action):

 XmlFile xmlFile = (XmlFile)
> PsiManager.getInstance(project).findFile(file);
> XmlDocument doc = xmlFile.getDocument();
> XmlTag tag = doc.getRootTag();
> tag.setAttribute("class", className);
> ]]>

Then I read the xml file in next action (some delete action) through
VirtualFile.getInputStream() and don't see changes done by 1st action!


Why do you use VirtualFile.getInputStream() rather than XmlFile.getText()?

Please advice how to flush file changes to disk after 1st action.


If you do need to ensure that changes are saved to disk, you can use FileDocumentManager.saveDocument(FileDocumentManager.getDocument(VirtualFile)).

--
Dmitry Jemerov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0
Comment actions Permalink

Why do you use VirtualFile.getInputStream() rather than XmlFile.getText()?

This fixes the problem.

Related question: Does Idea use PsiFile instances as cache (i.e. only one PsiFile in memory exists for each file in the project, or the PsiFile is created by request)?

0
Comment actions Permalink

Hello Alex,

Related question: Does Idea use PsiFile instances as cache (i.e. only
one PsiFile in memory exists for each file in the project, or the
PsiFile is created by request)?


Please refer to the following document for some explanations of this:
http://www.jetbrains.net/confluence/display/IDEADEV/IntelliJIDEA6.0ArchitecturalOverview

--
Dmitry Jemerov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0

Please sign in to leave a comment.