use of org.eclipse.xtext.ui.refactoring.ui.IRenameElementContext in project xtext-xtend by eclipse.
the class XtendFileRenameParticipant method createRenameElementContexts.
@Override
protected List<? extends IRenameElementContext> createRenameElementContexts(Object element) {
if (super.getNewName().endsWith(".xtend")) {
IFile file = (IFile) element;
final IPath filePath = file.getFullPath();
final IPath newPath = file.getFullPath().removeLastSegments(1).append(getNewName() + ".xtend");
String className = trimFileExtension(file.getName());
if (className != null) {
ResourceSet resourceSet = resourceSetProvider.get(file.getProject());
URI resourceURI = URI.createPlatformResourceURI(file.getFullPath().toString(), true);
Resource resource = resourceSet.getResource(resourceURI, true);
if (resource != null && !resource.getContents().isEmpty()) {
for (XtendTypeDeclaration type : EcoreUtil2.eAllOfType(resource.getContents().get(0), XtendTypeDeclaration.class)) {
if (equal(className, type.getName())) {
IRenameElementContext renameElementContext = renameContextFactory.createRenameElementContext(type, null, null, (XtextResource) resource);
if (renameElementContext instanceof IChangeRedirector.Aware)
((IChangeRedirector.Aware) renameElementContext).setChangeRedirector(new IChangeRedirector() {
@Override
public IPath getRedirectedPath(IPath source) {
return source.equals(filePath) ? newPath : source;
}
});
return singletonList(renameElementContext);
}
}
}
}
}
return super.createRenameElementContexts(element);
}
use of org.eclipse.xtext.ui.refactoring.ui.IRenameElementContext in project xtext-xtend by eclipse.
the class JavaRefactoringIntegrationTest method createXtendRenameRefactoring.
protected ProcessorBasedRefactoring createXtendRenameRefactoring(final XtextEditor editor, final int offset, String newName) {
IRenameElementContext renameElementContext = createRenameElementContext(editor, offset);
ProcessorBasedRefactoring renameRefactoring = renameRefactoringProvider.getRenameRefactoring(renameElementContext);
RefactoringProcessor processor = renameRefactoring.getProcessor();
if (processor instanceof AbstractRenameProcessor)
((AbstractRenameProcessor) processor).setNewName(newName);
else if (processor instanceof JavaRenameProcessor)
((JavaRenameProcessor) processor).setNewElementName(newName);
return renameRefactoring;
}
Aggregations