Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Plugin Development Environment (PDE) » Renaming a compilation unit(How do I properly rename a compilation unit in the plugin code? )
Renaming a compilation unit [message #1102214] Thu, 05 September 2013 10:17 Go to next message
Vahan Hovhannisyan is currently offline Vahan Hovhannisyan
Messages: 3
Registered: August 2013
Junior Member
So I'm trying write a code in my plugin that renames a given compilation unit. I've tried to use the org.eclipse.jdt.internal.corext.refactoring.rename.RenameCompilationUnitProcessor, but it doesn't work. I'm missing something, but can't figure out what. Also there seems to be no documentation on the topic, even the eclipse code is not properly documented. Can anyone help, please?
Here is a snapshot of my code:
CompositeChange composite = new DynamicValidationStateChange(RefactoringCoreMessages.ReorgPolicy_move);
RenameCompilationUnitProcessor renameProcessor = new RenameCompilationUnitProcessor(compUnit);
renameProcessor.setNewElementName("NewName");
Change renameChange = renameProcessor.createChange(new SubProgressMonitor(pm, 1));
if (renameChange instanceof CompositeChange) {
composite.merge(((CompositeChange) renameChange));
} else {
composite.add(renameChange);
}
composite.perform(pm);
Re: Renaming a compilation unit [message #1107447 is a reply to message #1102214] Thu, 12 September 2013 08:09 Go to previous message
Vahan Hovhannisyan is currently offline Vahan Hovhannisyan
Messages: 3
Registered: August 2013
Junior Member
OK, here is how I did it

//create move policy and processor for the compilation unit
IMovePolicy movePolicy = ReorgPolicyFactory.createMovePolicy(new IResource[] {compUnit.getResource()}, new IJavaElement[] {compUnit});
JavaMoveProcessor processor = new JavaMoveProcessor(movePolicy);
processor.setDestination(ReorgDestinationFactory.createDestination(newSource));
//the refactoring object
Refactoring refactoring = new ProcessorBasedRefactoring(processor);
//set a refactoring wizard
RefactoringWizard wizard = new ReorgMoveWizard(processor, refactoring);
Shell activeShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
wizard.setContainer(new RefactoringWizardDialog(activeShell, wizard));
//set reorg queries (no idea what it is used for, but doesn't work without it)
processor.setCreateTargetQueries(new CreateTargetQueries(wizard));
processor.setReorgQueries(new ReorgQueries(activeShell));
//perform the refactoring and return its success result
CreateChangeOperation create = new CreateChangeOperation(new CheckConditionsOperation(ref, CheckConditionsOperation.ALL_CONDITIONS), RefactoringStatus.WARNING);
PerformChangeOperation perform = new PerformChangeOperation(create);
IWorkspace workspace = ResourcesPlugin.getWorkspace();
try {
workspace.run(perform, new NullProgressMonitor());
} catch (CoreException e) {
e.printStackTrace();
}

Previous Topic: Issue with Plugin devlopment.
Next Topic:TabbedProperties wont appear
Goto Forum:
  


Current Time: Fri Jul 25 23:17:39 EDT 2014

Powered by FUDForum. Page generated in 0.01509 seconds