Renaming PsiMethod declaration from PsiLiteralExpression
Hey everyone,
I finally managed to make my plugin work correctly with PsiReferenceContributor. My reference contributor returns PsiMethod on it's resolve method. Now I have the following working:
- Literall expression is highligted
- Go to declaration works
- Find usages from my expression and the method work correctly
- Renaming the method works correctly
What I am struggling with is when I want to rename the from within the expression that I have. My expression does not contain the entire name of the method, it just contains the name of the property. Something really similar like in JSP, FTL etc.
When I try to do renaming of the method then the inplace text is changed into the name of the method. Which I understand that it is expected, but how can I can I disable it and trigger a dialog renaming?
Note: Inplace renaming in ftl files does not work, I have not tried JSP yet (it might be the same).
Thanks a lot for the help. In case anyone wants to see what exactly it is happening have, this is the plugin: https://github.com/mapstruct/mapstruct-idea
请先登录再写评论。
Hi Filip,
you need to provide your own com.intellij.refactoring.rename.RenameHandler. The logic to choose applicable handler is encapsulated here: com.intellij.refactoring.rename.RenameHandlerRegistry#getRenameHandler
Anna
Thanks for the reply Ana. I saw trying to avoid that as I wanted to have the same functionality as the MemberInplaceRenameNandler.
I ended up registering my own RenameHandler that extends MemberInplaceRenameHandler and is available when I need it, and it returns my own MemberInplaceRenamer that just returns false for performInplaceRename. This means that I am relying on your logic in the registry and if something is changed there then I will have problems with it :).
Filip
I don't think that's a good idea to inherit from MemberInplaceRenameHandler. If your handler happens to be the first, it would be just removed and ordinal one would be used.
I know that it is not a good idea, but the alternative would be to copy everything from the MemberInplaceRenameHandler and VariableInplaceRenameHandler in order to invoke the dialog only. I don't want to do that, as I want to rely on IDEA infrastructure as much as possible.
I wrote in the plugin.xml that my handler should be last.
Maybe in the first version of the plugin I can go like this, and when I learn more about the plugin development, I could improve it.
BTW, Can I use the LightFixtureCompletionTestCase to write tests for the dialog renaming, or should I do something else for that?
com.intellij.refactoring.rename.PsiElementRenameHandler is a better candidate to be overridden.
CompletionTestCase is designed for completion. You need something like com.intellij.testFramework.fixtures.CodeInsightTestFixture#renameElementAtCaretUsingHandler.