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: 360
Registered: July 2009
Location: Dortmund
Senior Member

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

Regards,
~Karsten


Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.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 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

Previous Topic:AutoEditStrategy
Next Topic:JvmModelInferrer and code generation
Goto Forum:
  


Current Time: Sat Dec 20 07:30:35 GMT 2014

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

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