Rename behavior is different between editor and structure view

I implemented my own rename handler for certain tags in XML files. It works fine when I invoke it from the context menu in editor, but when I open the structure view and select Rename, it opens standard Rename XML Tag dialog even though I have my own rename dialog implemented. Is there any what to change that? I tried to run my plugin in the debugger, and it doesn't invoke my rename handler nor XmlTagRenameHandler, it goes straight to the PsiElementRernameHandler.



Hi Eugene,

XmlTagRenameHandler doesn't work from structure view because it explicitly requires the editor (for the check com.intellij.xml.refactoring.XmlTagRenameHandler#isAvailableOnDataContext it tries to find element com.intellij.xml.refactoring.XmlTagRenameHandler#getElement from the editor). If your handler can work without an editor, it should know, how to retrieve an element from the DataContext and return true in isAvailableOnDataContext.

Hope this helps,



Thanks, Anna, that definitely helps, everything works fine now!

I have a follow up question though. Here's what I'm trying to do. I'm working on a plugin for Mule ESB and Mule ESB uses XML-based configuration files. Those files contain tags <flow>, each one has an attribute "name" with unique value. For example:

<flow name="HelloWorld">
<logger message="Hello World"/>

So renaming a <flow> tag actually means changing the value of the "name" attribute. That part already works fine, thanks to you for the suggestion.

Now, some <flow> tags may contain references to other flow tags, e.g.

<flow-ref name="HelloWorld"/>

and there can be many <flow-ref> tags pointing to the same flow.

Here's the problem - when I rename <flow-ref>, it does rename the flow it is pointing to. That's because I do have a FlowRefPsiReference which looks like this:

public PsiElement resolve() {
final String flowName = getFlowName();
final XmlTag flow = MuleConfigUtils.findFlow(myElement, flowName);
if (flow != null) {
final XmlAttribute name = flow.getAttribute(MuleConfigConstants.NAME_ATTRIBUTE);
return name != null ? name.getValueElement() : null;
return null;

private String getFlowName() {
return myElement.getValue();

public Object[] getVariants() {
final List<DomElement> flow = MuleConfigUtils.getFlows(getElement().getProject());
return mapNotNull(flow, (Function<DomElement, Object>) domElement -> domElement.getXmlTag().getAttributeValue(MuleConfigConstants.NAME_ATTRIBUTE)).toArray();

The problem I'm having is when I rename the <flow> tag, none of the <flow-ref> tags is renamed. In my FlowRenameHandler I get the flow tag and I call;

 bt it returns an empty collection. So my question is, what am I doing wrong (or not doing)?



There are multiple things which could go wrong with references search. The common algorithm if you don't provide your own searcher:

1. find all textual occurrences in the scope (You need to check that the default effective scope of the search contains the file with the reference)

2. check if at position of that occurrence, there is a reference to the element to search

Most probably the problem is with resolve of the reference, the easiest way to debug starting from com.intellij.psi.PsiReference#isReferenceTo implementation.





Please sign in to leave a comment.