How to listen changes of xml attributes in xml files?
I know how to listen changes in file in general
VirtualFileManager.getInstance().addVirtualFileListener(new VirtualFileAdapter(){
@Override
public void beforeContentsChange(VirtualFileEvent event) {
super.beforeContentsChange(event);
}
});
But how to listen changes of xml tag specifically? For example
Before change:
<tag id="1"/>
After change:
<tag id="2"/>
Pseudocode:
VirtualFileManager.getInstance().addVirtualFileListener(new VirtualXmlFileAdapter(){
@Override
public void beforeXmlAttributeChange(String oldValue/*==1*/, String newValue/*==2*/) {
super.beforeXmlAttributeChange(oldValue, newValue);
}
});
Please sign in to leave a comment.
You can use PsiTreeChangeListener to detect changes in the PSI tree. There is no API to add listeners to specific kinds of changes such as changes in XML attributes; you need to analyze the PsiTreeChangeEvent instances yourself and understand whether they describe a change that is relevant for your plugin.