Skip to main content



      Home
Home » Modeling » TMF (Xtext) » xText rename refactor (xText rename refactor )
xText rename refactor [message #1052294] Mon, 29 April 2013 18:59 Go to next message
Eclipse UserFriend
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 04:16 Go to previous messageGo to next message
Eclipse UserFriend
You observed that right - refactoring support is dependent on UI and cannot be used without.

Regards,
~Karsten
Re: xText rename refactor [message #1064973 is a reply to message #1053476] Sat, 22 June 2013 05:24 Go to previous messageGo to next message
Eclipse UserFriend
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 10:09 Go to previous messageGo to next message
Eclipse UserFriend
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 10:12] by Moderator

Re: xText rename refactor [message #1722706 is a reply to message #1065022] Mon, 08 February 2016 07:42 Go to previous message
Eclipse UserFriend
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: Wed Jul 16 13:10:56 EDT 2025

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

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

Back to the top