use of org.eclipse.xtext.ide.server.rename.ServerRefactoringIssueAcceptor in project xtext-core by eclipse.
the class RenameService method rename.
@Override
public WorkspaceEdit rename(final WorkspaceManager workspaceManager, final RenameParams renameParams, final CancelIndicator cancelIndicator) {
WorkspaceEdit _xblockexpression = null;
{
final URI uri = this._uriExtensions.toUri(renameParams.getTextDocument().getUri());
final ServerRefactoringIssueAcceptor issueAcceptor = this.issueProvider.get();
final Function2<Document, XtextResource, WorkspaceEdit> _function = (Document document, XtextResource resource) -> {
final ProjectManager projectManager = workspaceManager.getProjectManager(uri);
final XtextResourceSet resourceSet = projectManager.createNewResourceSet(projectManager.getIndexState().getResourceDescriptions());
resourceSet.getLoadOptions().put(ResourceDescriptionsProvider.LIVE_SCOPE, Boolean.valueOf(true));
final int offset = document.getOffSet(renameParams.getPosition());
final WorkspaceEdit workspaceEdit = new WorkspaceEdit();
final Resource xtextResource = resourceSet.getResource(resource.getURI(), true);
if ((xtextResource instanceof XtextResource)) {
final EObject element = this._eObjectAtOffsetHelper.resolveElementAt(((XtextResource) xtextResource), offset);
if (((element == null) || element.eIsProxy())) {
StringConcatenation _builder = new StringConcatenation();
_builder.append("No element found at position line:");
int _line = renameParams.getPosition().getLine();
_builder.append(_line);
_builder.append(" column:");
int _character = renameParams.getPosition().getCharacter();
_builder.append(_character);
issueAcceptor.add(RefactoringIssueAcceptor.Severity.FATAL, _builder.toString());
} else {
String _newName = renameParams.getNewName();
URI _uRI = EcoreUtil.getURI(element);
final RenameChange change = new RenameChange(_newName, _uRI);
final IChangeSerializer changeSerializer = this.changeSerializerProvider.get();
final RenameContext context = new RenameContext(Collections.<RenameChange>unmodifiableList(CollectionLiterals.<RenameChange>newArrayList(change)), resourceSet, changeSerializer, issueAcceptor);
this.renameStrategy.applyRename(context);
final ChangeConverter changeConverter = this.converterFactory.create(workspaceManager, workspaceEdit);
changeSerializer.applyModifications(changeConverter);
}
} else {
issueAcceptor.add(RefactoringIssueAcceptor.Severity.FATAL, "Loaded resource is not an XtextResource", resource.getURI());
}
return workspaceEdit;
};
_xblockexpression = workspaceManager.<WorkspaceEdit>doRead(uri, _function);
}
return _xblockexpression;
}
Aggregations