org.eclipse.xtext.ui.refactoring.impl.RenameElementProcessor Java Examples

The following examples show how to use org.eclipse.xtext.ui.refactoring.impl.RenameElementProcessor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RenameRefactoringIntegrationTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected Change createChange(URI targetElementURI, String newName) throws Exception {
	RenameElementProcessor processor = processorProvider.get();
	processor.initialize(new IRenameElementContext.Impl(targetElementURI, RefactoringPackage.Literals.ELEMENT,
			null, null, null));
	processor.setNewName(newName);
	RefactoringStatus initialStatus = processor.checkInitialConditions(new NullProgressMonitor());
	assertTrue("Initial RefactoringStatus is OK", initialStatus.isOK());
	RefactoringStatus finalStatus = processor.checkFinalConditions(new NullProgressMonitor(), null);
	assertTrue("Final RefactoringStatus is OK", finalStatus.isOK());
	final Change change = processor.createChange(new NullProgressMonitor());
	assertNotNull("RenameElementProcessor created changes", change);
	return change;
}
 
Example #2
Source File: CombinedJvmJdtRenameRefactoringProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public RenameProcessor getRenameProcessor(IRenameElementContext renameElementContext) {
	RenameElementProcessor processor = null;
	if (renameElementContext instanceof JvmModelJdtRenameParticipantContext)
		processor = jdtRenameParticipantProcessorProvider.get();
	else if (renameElementContext instanceof CombinedJvmJdtRenameContext)
		processor = combinedRenameProcessorProvider.get();
	if (processor != null) {
		if (processor.initialize(renameElementContext))
			return processor;
		else
			return null;
	}
	return super.getRenameProcessor(renameElementContext);
}
 
Example #3
Source File: XtendJdtRenameParticipantProcessor.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @return true, if the triggering refactoring targets an Xtend element. 
 */
protected boolean isXtendRename() {
	JdtRenameParticipant jdtRenameParticipant = ((JvmModelJdtRenameParticipantContext) getRenameElementContext())
			.getJdtRenameParticipant();
	RefactoringProcessor triggeringProcessor = jdtRenameParticipant.getProcessor().getRefactoring().getProcessor();
	if(triggeringProcessor instanceof RenameElementProcessor) {
		EClass targetElementEClass = ((RenameElementProcessor) triggeringProcessor).getRenameElementContext().getTargetElementEClass();
		return targetElementEClass.getEPackage() == XtendPackage.eINSTANCE;
	}
	return false;
}
 
Example #4
Source File: XtendQuickfixProvider.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Fix(IssueCodes.WRONG_FILE)
public void fixWrongFileRenameClass(final Issue issue, final IssueResolutionAcceptor acceptor) {
	URI uri = issue.getUriToProblem();
	String className = uri.trimFileExtension().lastSegment();
	String label = String.format("Rename class to '%s'", className);
	acceptor.accept(issue, label, label, null, (element, context) -> {
		context.getXtextDocument().modify(resource -> {
			IRenameElementContext renameContext = renameContextFactory.createRenameElementContext(element, null,
					new TextSelection(context.getXtextDocument(), issue.getOffset(), issue.getLength()), resource);
			final ProcessorBasedRefactoring refactoring = renameRefactoringProvider.getRenameRefactoring(renameContext);
			((RenameElementProcessor) refactoring.getProcessor()).setNewName(className);
			PlatformUI.getWorkbench().getActiveWorkbenchWindow().run(true, true, monitor -> {
				try {
					if (!refactoring.checkFinalConditions(monitor).isOK())
						return;
					Change change = refactoring.createChange(monitor);
					change.initializeValidationData(monitor);
					PerformChangeOperation performChangeOperation = new PerformChangeOperation(change);
					performChangeOperation.setUndoManager(RefactoringCore.getUndoManager(), refactoring.getName());
					performChangeOperation.setSchedulingRule(ResourcesPlugin.getWorkspace().getRoot());
					performChangeOperation.run(monitor);
				} catch (CoreException e) {
					logger.error(e);
				}
			});
			return null;
		});
	});
}
 
Example #5
Source File: XtendUiModule.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends RenameElementProcessor> bindRenameElementProcessor() {
	return XtendRenameElementProcessor.class;
}