Rename action takes referenced element

Hi,

I'm trying to implement the Rename refactoring for the plugin I'm currently building (FitNesse, https://github.com/gshakhn/idea-fitnesse).

In FitNesse tables contain the information that has to be executed on a System under test (SUT).

So the first thing I did was figure out the text that identifies the "fixture" class that has to be executed. FitNesse uses a human readable version of the camel case syntax -- so "my fixture" will translate to a class named "MyFixture".

So far so good. I set up referencing stuff between the fixture class name in the FitNesse file and the Java class.

I added a RenameHandler and a NamesValidator (since FitNesse names can contain spaces).

Only when I try to rename, I always end up renaming the Java class. The friendly text in my FitNesse page is substituted by the real class name and that is what is edited. I would expect I can edit the FitNesse fixture name instead.

I traced it as much as I could and it looks like AnActionEvent.getData("psi.Element") tries to figure out the element underneath the cursor, but via PsiAwareTextEditorImpl and TargetElementUtilBase.findTargetElement() it ends up with the first reference found.

I'm clearly missing something. What does it take to rename my FixtureClass and not end up renaming the referenced Java class (its reference)?

Should I use a ReferenceContributor instead of using FixtureClass.getReference?

It might be worth noting that the FixtureClass (PSI) element is a composite element and contains words and whitespace that make up the fixture class name. Does this have something to do with it?

Regards,

Arjan

3 comments
Comment actions Permalink

Hi,

I'm still guessing what goes wrong. Could it have anything to do with the AST/PSI structure?

Screen Shot 2015-11-26 at 22.58.25.png
Arjan

0
Comment actions Permalink

Hi Arjan,

rename works on references and rename the reference target, e.g. in java int x = 0; <caret>x++; would rename x and it's reference. If you want to rename the Fitness element but not java class (reference would be renamed as well) then you don't need to make your element to refer the java class at the first place - the bind would be broken and that is not what users expect,

Anna

0
Comment actions Permalink

Hi Anna,

Thanks for your reply. Indeed I like to rename both the fixture class in my FitNesse page and the referenced class name. Only in my FitNesse page, the class is written as "my class", where the java implementation requires "MyClass". The FitNesse case uses graceful names (with spaces instead of camel case), to improve readability for non-technical people.

It get's problematic when I also want to rename a decision table input: here I define a name, say "my name", which maps to a method in my fixture method named "setMyName".

In essence, the names in the FitNesse page is not the same as the names in the Java classes, although there is a 1:1 translation.

Is it possible to make this work?

0

Please sign in to leave a comment.