Handing refactorings based on parameter renames

I've been really pleased with the experience of building an IntelliJ plugin thus far. So far, I've managed to do some very advanced things. But recently, I've come up against what seems to be an intractable problem.

Well, here's the issue I filed: http://youtrack.jetbrains.com/issue/IDEA-103964

I was told that I need to implement a VariableInplaceRenamer perform the desired behavior. Which I tried to do, which resulted in me having to disable the existing one built in for Java. That's not very good. Because that means I need to re-implement all the same functionality that the existing one already had! I don't want to override parameter renaming behavior. Instead, I simply want my plugin to rename elements in an HTML file that correspond to whatever the new parameter name is.

I've got this working perfectly with field renames using a RenamePsiElementProcessor. But trying to get this to work with parameters has been incredibly difficult, and has left me feeling like I'm really missing something.

3 comments

Hi Mike,

I don't think that I ever advice you to implement VariableInplaceRenamer.

I adviced you to implement an interface which enlarges the scope of your parameter (com.intellij.psi.search.UseScopeEnlarger). It seems to me to be a solution for the problem. IDEA would rename your parameter in HTML file with your rename processor as well as it would find reference to the parameter with "search for strings and text occurrences" off etc. If you would explain why it doesn't suite you, you would give me a chance to help.

0

I'm not sure how to use UseScopeEnlarger in the way you describe, as it is not an interface. It is an abstract class.

Can you give me an example of how this would work in practice?

0

You can provide additional scope for your parameter and include there your html file. In oder to do it you need to extend UseScopeEnlarger abstract class with one method, register it in your plugin.xml and provide in the implementation smth like this:
if (isMyParameter(element)) {
  return GlobalSearchScope.filesScope(findMyHtmlFiles(element));
}

Then local rename won't work for your element then and normal processors would start to work. As side effect you'll get find usages to find parameters in associated html files.

You may see as an example org.jetbrains.idea.devkit.DevKitUseScopeEnlarger. It does extend scope of extension points to be available everywhere in the project.

0

Please sign in to leave a comment.