use of org.eclipse.xtext.ui.refactoring2.rename.ISimpleNameProvider in project xtext-eclipse by eclipse.
the class DefaultRenameElementHandler method isRefactoringEnabled.
protected boolean isRefactoringEnabled(IRenameElementContext renameElementContext, XtextResource resource) {
ResourceSet resourceSet = resource.getResourceSet();
if (renameElementContext != null && resourceSet != null) {
EObject targetElement = resourceSet.getEObject(renameElementContext.getTargetElementURI(), true);
if (targetElement != null && !targetElement.eIsProxy()) {
if (targetElement.eResource() == resource && renameElementContext.getTriggeringEditorSelection() instanceof ITextSelection) {
ITextSelection textSelection = (ITextSelection) renameElementContext.getTriggeringEditorSelection();
ITextRegion selectedRegion = new TextRegion(textSelection.getOffset(), textSelection.getLength());
INode crossReferenceNode = eObjectAtOffsetHelper.getCrossReferenceNode(resource, selectedRegion);
if (crossReferenceNode == null) {
// selection is on the declaration. make sure it's the name
ITextRegion significantRegion = locationInFileProvider.getSignificantTextRegion(targetElement);
if (!significantRegion.contains(selectedRegion))
return false;
}
}
IRenameStrategy.Provider renameStrategyProvider = globalServiceProvider.findService(targetElement, IRenameStrategy.Provider.class);
try {
if (renameStrategyProvider.get(targetElement, renameElementContext) != null) {
return true;
} else {
IRenameStrategy2 strategy2 = globalServiceProvider.findService(targetElement, IRenameStrategy2.class);
ISimpleNameProvider simpleNameProvider = globalServiceProvider.findService(targetElement, ISimpleNameProvider.class);
return strategy2 != null && simpleNameProvider.canRename(targetElement);
}
} catch (NoSuchStrategyException e) {
MessageDialog.openInformation(Display.getCurrent().getActiveShell(), "Cannot rename element", e.getMessage());
}
}
}
return false;
}
Aggregations