Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » xText rename refactor (xText rename refactor )
xText rename refactor [message #1052294] Mon, 29 April 2013 22:59 Go to next message
April Dai is currently offline April DaiFriend
Messages: 3
Registered: April 2013
Junior Member
wanted to know if xText rename refactor can be used without UI context. rename refactor fails if no editor is available from IRenameContext.

All the refactor plugins are under org.eclipse.xtext.ui.refactoring, seems like there is no core plugin which does not require a UI context for rename refactor to work.

Has anyone encountered the same issue? Is there a work around?

Thanks,
Re: xText rename refactor [message #1053476 is a reply to message #1052294] Mon, 06 May 2013 08:16 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten ThomsFriend
Messages: 762
Registered: July 2009
Location: Dortmund, Germany
Senior Member

You observed that right - refactoring support is dependent on UI and cannot be used without.

Regards,
~Karsten


Need professional support for Xtext, EMF, Eclipse IDE?
Go to: http://devhub.karakun.com
Twitter : @kthoms
Blog : www.karsten-thoms.de
Re: xText rename refactor [message #1064973 is a reply to message #1053476] Sat, 22 June 2013 09:24 Go to previous messageGo to next message
Michael Ernst is currently offline Michael ErnstFriend
Messages: 49
Registered: July 2010
Member
Are there plans to realize such a feature without the ui context. I would also like to use it. What's the best way to realize a rename feature without UI? Simply changing the emf meta model does not update the references, but how to do so? I have no other artifacts involed, so I want to rename locale variable names.

Regards,
Michael
Re: xText rename refactor [message #1065022 is a reply to message #1052294] Sun, 23 June 2013 14:09 Go to previous messageGo to next message
Michael Ernst is currently offline Michael ErnstFriend
Messages: 49
Registered: July 2010
Member
Found a solution which works for me, but I would prefer it, if I could realize this via a Framework implementation.

My ugly but working solution to rename elements which have no references to other artifacts:


  1. load the Xtext Resource so it is available via the emf model element
  2. select the model element which should be renamed
  3. Use the method NodeModelUtils.findNodesForFeature to get the node which contains the name of the element which should be renamed and store it in a list of nodes.
  4. Iterate through the model and select all references to the model element which should be renamed and add their nodes (access them also by using the method NodeModelUtils.findNodesForFeature) to the list of nodes
  5. sort all nodes by their total offset
  6. use the root node of (node.getRootNode) to access the whole parsed text and replace the content like in the snippet below.
    String rootNodeText = compositeNode.getRootNode().getText();
    String newText = rootNodeText;
    int currentAdaptedOffset = 0;
    int adaptOffset = toName.length() - fromName.length();
    for( INode node : nodes )
    {
       int totalOffset = node.getTotalOffset();
       int position = currentAdaptedOffset + totalOffset;
       newText = newText.substring( 0, position ) + toName + newText.substring( position + fromName.length() );
       currentAdaptedOffset += adaptOffset;
    }

  7. parse the updated text and check for syntax errors


Kind regards
Michael

[Updated on: Sun, 23 June 2013 14:12]

Report message to a moderator

Re: xText rename refactor [message #1722706 is a reply to message #1065022] Mon, 08 February 2016 12:42 Go to previous message
aurel pestell is currently offline aurel pestellFriend
Messages: 90
Registered: October 2013
Location: Sweden
Member
Hi Michael,

I you found a better way to solve your problem ?
Thanks !
Previous Topic:Passing XExpressions as arguments outside of an XBlockExpression
Next Topic:Xcore with xtext-maven-plugin: unmapped ecore model path
Goto Forum:
  


Current Time: Fri Apr 19 10:13:22 GMT 2024

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

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

Back to the top