Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Refactoring command with custom Refactor class fails(Implemented refactor classes like in xtext source for extractvariable but handler doesn't get executed)
Refactoring command with custom Refactor class fails [message #1815926] Tue, 15 October 2019 11:09 Go to next message
Martin Moser is currently offline Martin MoserFriend
Messages: 18
Registered: January 2019
Junior Member
Hi all,

I need some advice in implementing a refactoring action for my DSL based files.

My goal is to implement an extraction command which extracts the selected lines of the editor into another file.

I found the ExtractVariable command in the xtext sources and tried to implement something similar. (org.eclipse.xtext.xbase.ui.refactoring.ExtractVariableHandler)

There the ExtractVariableHandler makes use of ExtractVariableRefactoring.

I also created such a handler making use of my custom refactoring action.
Once I trigger the refactoring action from the menu nothing happens.
The ExtractVariableHandler class makes use of a refactoringProvider which is a
Provider<ExtractVariableRefactoring> object.
In my case I changed that to Provider<MyDslExtractRefactoring>, but then the handler isn't triggered anymore.
Once I set the class of my refactoring provider to anything else like Provider<ExtractVariableRefactoring> the execute() method of the handler is triggered.

Is it necessary to register or inject that Refactoring close anywhere else?

In my plugin.xml I introduced the handler only.

Thanks in advance!

best regards,
Martin
Re: Refactoring command with custom Refactor class fails [message #1815927 is a reply to message #1815926] Tue, 15 October 2019 11:12 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
How does your plugin.xml look like
Do you make correct use of yourdslexecutableextensionfactory
Did you debug for exceptions


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Refactoring command with custom Refactor class fails [message #1815936 is a reply to message #1815927] Tue, 15 October 2019 13:20 Go to previous messageGo to next message
Martin Moser is currently offline Martin MoserFriend
Messages: 18
Registered: January 2019
Junior Member
Hi Christian,

thanks for your fast reply.
I couldn't find any exceptions yet.

In the plugin.xml I have just added the handler for now:

<!-- Introduce Create DR Refactoring -->
<extension point="org.eclipse.ui.handlers">
<handler
class="de.test.dsl.ui.MyDslExecutableExtensionFactory:de.test.dsl.ui.refactoring.ExtractDrHandler"
commandId="de.test.dsl.ui.refactoring.ExtractDrHandler">
<activeWhen>
<reference
definitionId="de.test.dsl.mydsl.Editor.opened">
</reference>
</activeWhen>
</handler>
</extension>
<extension point="org.eclipse.ui.menus">
<menuContribution
locationURI="popup:#TextEditorContext?after=group.edit">
<command commandId="de.test.dsl.ui.refactoring.ExtractDrHandler"
style="push">
<visibleWhen checkEnabled="false">
<reference
definitionId="de.test.dsl.mydsl.Editor.opened">
</reference>
</visibleWhen>
</command>
</menuContribution>
</extension>
<!-- TODO -->

Then I created the class "de.test.dsl.ui.refactoring.ExtractDrHandler"

There I added this member:
@Inject
private Provider<ExtractDrRefactoring> refactoringProvider;

The other members are just a copy of the ExtractVariableHandler.

Then I created the class "de.test.dsl.ui.refactoring.ExtractDrRefactoring".
It extends the Refactoring class and is a copy of ExtractVariableRefactoring.

I can see the popup entry in the menu but clicking doesn't do anything.
I also cannot debug to the handler as it seems that the handler is never reached.

Thanks again!

best regards,
Martin
Re: Refactoring command with custom Refactor class fails [message #1815938 is a reply to message #1815936] Tue, 15 October 2019 14:21 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
so if you debug your handler wont stop?
you may also have a look at

https://dietrich-it.de/xtext/2011/10/15/xtext-calling-the-generator-from-a-context-menu.html


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Refactoring command with custom Refactor class fails [message #1815941 is a reply to message #1815938] Tue, 15 October 2019 15:08 Go to previous message
Martin Moser is currently offline Martin MoserFriend
Messages: 18
Registered: January 2019
Junior Member
Hi Christian,

thanks for your efforts and the link.

I have re-implemented the handler and the refactoring class and now it's working.

At the beginning I copied all members from the ExtractVariable and the also the RenameHandler to my file.
Now I tried to use the required steps only.

Perhaps some of those injection commands failed there.

Best regards,
Martin
Previous Topic:Disable NodeModel
Next Topic:generateTracedFile is undefined for the type IFileSystemAccess2
Goto Forum:
  


Current Time: Fri Apr 26 12:29:37 GMT 2024

Powered by FUDForum. Page generated in 0.03769 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top