Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » [SOLVED] Folder renaming hook
[SOLVED] Folder renaming hook [message #1740128] Tue, 09 August 2016 13:47 Go to next message
Stéphane Galland is currently offline Stéphane GallandFriend
Messages: 123
Registered: July 2014
Location: Belfort, France
Senior Member
I have defined a grammar with the "package" keyword:
SarlScript returns xtend::XtendFile:
	{SarlScript}
	('package' package=QualifiedName ';'?)?
	importSection=XImportSection?
	xtendTypes+=Type*
;
...


Let consider a script located in folder FOLDER1.
When renaming the script's folder to "FOLDER2", I would like to run automatically a hook for updating the parameter of the package keyword in all the scripts in the folder (as the JDT refactoring mechanism already does).

What is the starting point for doing that? Must I extend an existing Xtext or Eclipse class? Must I define a specific extension point?

Thank you.
Stéphane.

[Updated on: Wed, 10 August 2016 07:53]

Report message to a moderator

Re: Folder renaming hook [message #1740130 is a reply to message #1740128] Tue, 09 August 2016 13:53 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14656
Registered: July 2009
Senior Member
hmmm i dont know if this will be easy. youll have to do most yourself. have a look at org.eclipse.xtend.ide.refactoring.XtendFileRenameParticipant

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Folder renaming hook [message #1740178 is a reply to message #1740130] Wed, 10 August 2016 07:53 Go to previous message
Stéphane Galland is currently offline Stéphane GallandFriend
Messages: 123
Registered: July 2014
Location: Belfort, France
Senior Member
Thank you for the pointer.
For the Xtend rename participant, I was able to create the renaming mechanism I want to.

For another who want to do a similar thing, I have added an extension point un my DSL.ui plugin:
   <extension
         point="org.eclipse.ltk.core.refactoring.renameParticipants">
      <renameParticipant
            class="dsl.ui.DSLExecutableExtensionFactory:dsl.ui.refactoring.DSLFileRenameParticipant"
            id="dsl.ui.refactoring.resourceRenameParticipant"
            name="DSL Rename Participant">
         <enablement>
	         <or>
	         	<and>
		           <instanceof
	                  value="org.eclipse.core.resources.IFile">
	               </instanceof>
		           <adapt type="org.eclipse.core.resources.IFile">
		              <test
		                    property="org.eclipse.core.resources.extension"
		                    value="dsl">
		              </test>
		           </adapt>
		       </and>
	           <instanceof
                  value="org.eclipse.jdt.core.IPackageFragment">
               </instanceof>
	         </or>
         </enablement>
      </renameParticipant>
   </extension>


Then, I have defined a class for doing the stuff:
public class DSLFileRenameParticipant extends AbstractProcessorBasedRenameParticipant {

	@Inject
	private IResourceSetProvider resourceSetProvider;

	@Inject
	private IRenameContextFactory renameContextFactory;

	@Override
	protected List<? extends IRenameElementContext> createRenameElementContexts(Object element) {
		// Do the job here
	}

	@Override
	protected String getNewName() {
		return trimFileExtension(super.getNewName());
	}

	protected String trimFileExtension(String fileName) {
		if (fileName.lastIndexOf('.') == -1)
			return fileName;
		return fileName.substring(0, fileName.lastIndexOf('.'));
	}

	@Override
	protected List<EObject> getRenamedElementsOrProxies(EObject originalTarget) {
		return singletonList(originalTarget);
	}

}


Stéphane.
Previous Topic:How to generate a method with a throws clause
Next Topic:Building heuristics - catch the changes
Goto Forum:
  


Current Time: Mon Mar 04 19:44:34 GMT 2024

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

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

Back to the top