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(){
  public void
beforeContentsChange(VirtualFileEvent event) {

But how to listen changes of xml tag specifically? For example

Before change:
<tag id="1"/>

After change:
<tag id="2"/>

VirtualFileManager.getInstance().addVirtualFileListener(new VirtualXmlFileAdapter(){

  public void beforeXmlAttributeChange(String oldValue/*==1*/, String newValue/*==2*/) {
    super.beforeXmlAttributeChange(oldValue, newValue);
1 comment
Comment actions Permalink

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.


Please sign in to leave a comment.