Modifying ASTNodes directly does not require write access to file??

I've noticed strange behavior with editing ASTNode tree directly. First,
I noticed that if the file is not currently being edited, the PSI is not
updated, even if the PsiFile is directly queried and traversed. Is this
normal?

Second, I've noticed that modifying the ASTNode tree does not require
the file to be writable. This means it is edited without the VCS knowing
about it, and it means if the file is read-only on disk, IDEA pops up a
dialog box every few seconds saying "Cannot save file: permission
denied" after such a modification. This is obviously not normal, but is
there something I should be doing, or some method I should be calling,
before changing the file?

2 comments

Keith Lea wrote:

This is obviously not normal, but is
there something I should be doing, or some method I should be calling,
before changing the file?


com.intellij.openapi.fileEditor.FileDocumentManager.fileForDocumentCheckedOutSuccessfully()
may help.

Sascha

0

Sascha Weinreuter wrote:

Keith Lea wrote:

>> This is obviously not normal, but is there something I should be
>> doing, or some method I should be calling, before changing the file?


com.intellij.openapi.fileEditor.FileDocumentManager.fileForDocumentCheckedOutSuccessfully()
may help.

Sascha


Thanks, it works. I think it's a bug that the AST can be modified for
read-only Document. In investigating this I found a new way to peek at
IDEA functionality: setting breakpoints in JDK code (in this case
JDialog constructor), then browsing stack trace.

0

Please sign in to leave a comment.