Rename refactoring, PHP class does not renamed in XML


Hi guys,

What is the right way to implement rename refactoring of PHP classes in XML?

<someTag some-class="Some\Php\Class">

For now I am using DOM API, and implement MyConverter

public class MyConverter extends ResolvingConverter<PhpClass> implements CustomReferenceConverter 

with method

public PsiReference[] createReferences(GenericDomValue value, PsiElement element, ConvertContext context) {...

After that I can run Find Usages and my class presents in search results under section "Usages in XML description"


But when I do rename refactoring the class does not renamed in XML.


Then I implemented 

public class MyRenameProcessor extends RenamePsiElementProcessor {...

with method 

public void prepareRenaming(PsiElement element, String newName, Map<PsiElement, String> allRenames) {...

and just add needed psiElements to the map allRenames - finally - rename works in XML

The question is: is it correct way? or maybe better (more convenient/official ) once exists?


P.S. By the way, when I declare PsiClass instead of PhpClass here


Debugger shows an error - can not find PsiClass... is it correct or there is something misconfigured from my side?

Official comment

 Please provide more details - 1. Can you please send whole code of all mentioned classes code or even the whole plugin? 2. version of Intellij SDK set up for project. 

PsiClass is an instance representing Java class or interface (see JavaDoc), so it's no PsiClass in PhpStorm's installation.


Here is a whole code

I have updated Intellij and PhpStorm to 2017.2, version of SDK is: IntelliJ IDEA IU-172.3317.76 (java version 1.8.0_131)


Please, take a look

In general you should provide PsiReference to PhpClass and implement handleElementRename() method.




Basically I have done the same, but if you look at PhpClassRenameProcessor you will see that all references filtered by "while" condition. So if my reference from xml is an PsiPolyVariantReferenceBase it will be removed from the list of references and as a result "handleElementRename" method will not be call.
Here is an implementation if any

I have tried to provid my own rename processor but the method "findReferences" does not calls. 


Looks like we third-party class references are not supported in rename at the moment. I've created an issue Star it and you'll get all updates for this issue.


You're welcome! Let us know if you face other issues. 


Please sign in to leave a comment.