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

MyGenericAttributeValue<PhpClass>

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

0
正式评论

 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.

0

Here is a whole code https://github.com/voleye/magento-phpstorm-plugin/tree/rename-php-class-in-xml

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)

0

Please, take a look http://www.jetbrains.org/intellij/sdk/docs/reference_guide/custom_language_support/rename_refactoring.html

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

 

 

0

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
https://github.com/voleye/magento2plugin

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

0

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

0

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

0

请先登录再写评论。